Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For --extract-audio, allow ffmpeg and ffprobe to exist in the working directory instead of just the path. #438

Closed
archagon opened this issue Sep 28, 2012 · 5 comments

Comments

@archagon
Copy link

@archagon archagon commented Sep 28, 2012

I'm writing a script that depends on youtube-dl and its audio conversion feature, and I want to make it as portable and easy-to-use as possible. As a result, I don't want to require the user to install ffmpeg/ffprobe, only to copy them to the working directory. As far as I can tell, the only required change would be to add a check for the working directory to detect_executables, in addition to os.environ["PATH"]. As a test, I copy/pasted the required code into my script and made a similar change, and it seems to work perfectly.

@phihag
Copy link
Contributor

@phihag phihag commented Sep 28, 2012

There's a reason why PATH doesn't contain . by default. If I type youtube-dl --extract-audio ..., I do not want to allow everyone who can access cwd to run arbitrary code as me. (See the somewhat recent string of software vulnerabilities on Windows for why this is bad).

Instead, your script should just modify PATH to include the directory where ffmpeg is located. In a shell script, that would look like:

#!/bin/sh
PATH="$PATH:$(dirname $0)/ffmpeg/" youtube-dl "$@"

Alternatively, we could also include an option like --ffmpeg-location which you could pass to youtube-dl. If the above doesn't work out for some reason, please open a new issue (don't forget why modifying $PATH doesn't work in your case) for such a feature.

@phihag phihag closed this Sep 28, 2012
@archagon
Copy link
Author

@archagon archagon commented Sep 28, 2012

This is great to know, thank you. I'm unfortunately not too familiar with setting/changing the path, but wouldn't doing it like you said be a permanent system-wide change? Or is it temporary for the duration of the script? And do you know if it's reproducible on Windows? (I'm aiming for cross-platform compatibility.)

@phihag
Copy link
Contributor

@phihag phihag commented Sep 29, 2012

No, the changed PATH only applies to that one invocation of youtube-dl (and its subprocesses).

I don't know whether this exact syntax works in a Windows bat file. You can, however, change the environment variable for the duration of your script, like this (exact syntax may vary):

:: Windows bat file
set PATH=%PATH%;%~dp0%/ffmpeg
youtube-dl ...
:: PATH is still changed here, but that shouldn't break anything.
:: The value only applies for your script.
@archagon
Copy link
Author

@archagon archagon commented Sep 30, 2012

After a bit of tinkering, I got it to work. I set my environment like so before my script's execution:

current_path = os.environ["PATH"]
os.environ["PATH"] = current_directory + os.pathsep + current_path

Unfortunately, on Windows, youtube-dl still does not find ffmpeg.exe/ffprobe.exe in the working directory by default. However, once I renamed ffmpeg.exe and ffprobe.exe to just ffmpeg and ffprobe, it worked perfectly. I think you might need to add a check for .exe files, since os.path.isfile(exe_file) and os.access(exe_file, os.X_OK) return False for just ffmpeg/ffprobe. (Or it's possible that I'm doing something horribly wrong.)

@FiloSottile
Copy link
Collaborator

@FiloSottile FiloSottile commented Sep 30, 2012

Uh, you are right, opening an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.