10se1ucgo / pyjam

An open source, cross-platform audio player for Source and GoldSrc engine based games, written in Python
http://10se1ucgo.github.io/pyjam
GNU Lesser General Public License v3.0
31 stars 4 forks source link

Converting a specific song #5

Closed gabsens closed 8 years ago

gabsens commented 8 years ago

Feature Request

The audio converter converts all songs in a given folder each time it is called. When the folder contains numerous files, it takes some time. The correct thing to do is deleting the source of songs that have already been converted (tedious).

Could you either automatically delete the source of songs that have already been converted (once conversion is over for example), or let the user choose which songs he wants to convert in the given folder?

10se1ucgo commented 8 years ago

Sure, I already implemented a check box option that will automatically delete the source if selected, but I forgot to push it to git. I'll do it as soon as I get home.

EDIT: Nevermind, the system was ugly and buggy. Using your second idea instead.

10se1ucgo commented 8 years ago

Implemented your second idea in 17d68c6. Please tell me if it fits your needs.

gabsens commented 8 years ago

Thank you, it's exactly what I was looking for.

Nevertheless, https://github.com/10se1ucgo/pyjam/commit/17d68c6c2dcf57336ea44a10aec1e1e883e8359c has some nasty mistakes, but I was hopefully able to fix them. The edit you made to cmd in the convert_audio() function has multiple flaws. Firstly, the new cmd is an array of strings, although it should be a string. We should be working with ' '.join(cmd) instead. Secondly, you should add some quotes delimiters in front of the file paths, otherwise ffmpeg will throw an error message whenever there are spaces in the file names or directories.

Here's my working version of convert_audio() (with Shell=True for OSX)

def convert_audio(file, dest, rate, vol, codec="pcm_s16le"):
    # type: (str, str, int or str, int, str) -> int
    # cmd = '{ff} -y -i "{i}" -map_metadata -1 -ac 1 -aq 100 -acodec {codec} -ar {rate} -af volume={vol} "{dest}.wav"'
    # cmd = cmd.format(ff=find(), i=file, codec=codec, rate=rate, vol=vol / 100, dest=dest)
    cmd = [find(), '-y', '-i', '"'+file+'"', '-map_metadata', '-1', '-ac', '1', '-aq', '100',
           '-acodec', codec, '-af', 'volume={vol}'.format(vol=vol/100), '"'+dest+'.wav'+'"']
    return subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT,shell=True)
10se1ucgo commented 8 years ago

subprocess can take a sequence (list, tuple, w/e)

Here's some info: http://stackoverflow.com/a/15109975

This should (in theory) fix the need for using shell=True.

As for the directories/files needing quotes, I'll fix that in a sec. This shouldn't be necessary, actually. Though, 'dest.wav' still needs to be specified.

gabsens commented 8 years ago

Yes it works without Shell=True, very cool. I'd say the program is fully functional on OSX now. If I manage to deploy it as an app, it would definitely be on par with SLAM.

10se1ucgo commented 8 years ago

Awesome. If you'd like to try, I personally use pyinstaller

10se1ucgo commented 8 years ago

A side-effect of fixing the conversion command seems to have fixed some weird threading error on Linux. Neat :^)

gabsens commented 8 years ago

does this song work for you in CS GO once it's converted? https://www.youtube.com/watch?v=126iKrAZGRU

I get no audio feedback for this one in particular, very weird

10se1ucgo commented 8 years ago

Seems to work for me. Not sure why its not working for you.

gabsens commented 8 years ago

I found why, ffmpeg converts my files to 44k sampling rate, even though 22050 is specified... What should I do ?

10se1ucgo commented 8 years ago

Are you on the latest version? I fixed this a while ago.

gabsens commented 8 years ago

Yeah you're right. One last thing, after downloading, converting a song and pressing the "cancel" button, the main window stays blocked (all the buttons are un-clickable)

10se1ucgo commented 8 years ago

Is this cancelling half-way through or cancelling after the conversion is over? For some reason, the progress dialog doesn't destroy itself until the user presses "OK" on the dialog telling them that conversion is complete.

gabsens commented 8 years ago

No, once the conversion is over, I'm back to the "pyjam Audio Converter" menu, I hit "Cancel" to go to the main menu, but all the buttons of the main window GUI are unclickable

10se1ucgo commented 8 years ago

ah, I see. I'll look into that