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

Problem while running youtube-dl as a Python script #177

Closed
samrat opened this issue Sep 26, 2011 · 12 comments
Closed

Problem while running youtube-dl as a Python script #177

samrat opened this issue Sep 26, 2011 · 12 comments

Comments

@samrat
Copy link

@samrat samrat commented Sep 26, 2011

When I try to run youtube-dl as a Python script using
python youtubedl.py
(youtube.dl.py is a Python file with youtube-dl's source code), the download completes successfully but the Python script fails to terminate. How can this problem be solved?

@phihag
Copy link
Contributor

@phihag phihag commented Sep 26, 2011

Sorry, I can't reproduce this problem on my machine. Can you include the full command-line which reproduces the problem? (Or does it occur when literally executing youtube-dl without arguments?) Also, a screenshot would be nice.

What operating system and Python version are you on?

@samrat
Copy link
Author

@samrat samrat commented Sep 26, 2011

phihad- python youtubedl.py -o 'filename.flv' http://youtube.com/watch?v=VIDEOID

As I mentioned before, the video downloads fully, its just that youtube-dl doesn't close, so that the flow of my program can continue.

@phihag
Copy link
Contributor

@phihag phihag commented Sep 26, 2011

Sorry samrat, but I need a little more information than that. A screenshot would be nice, and it should also contain the output of

python youtubedl.py --version
python --version

For example, your above command shows the following result for me on debian sid (x64):

$ python youtubedl.py -o 'filename.flv' http://youtube.com/watch?v=VIDEOID
[youtube] Setting language
[youtube] VIDEOID: Downloading video webpage
ERROR: unable to download video webpage: HTTP Error 404: Not Found
$ # youtube-dl stopped here.

Also, if you're executing youtube-dl this in another program, could you share the relevant code portion? It might be a bug in there.

@samrat
Copy link
Author

@samrat samrat commented Sep 26, 2011

Here's the code I used to execute youtube-dl:
download_command = "python2.7 youtubedl.py -o '../data/%s' %s;" % (filename, youtube_url) os.system(download_command)

and the output:

[youtube] Setting language
[youtube] rIkVeAb56Z4: Downloading video webpage
[youtube] rIkVeAb56Z4: Downloading video info webpage
[youtube] rIkVeAb56Z4: Extracting video information
[download] Destination: ../data/hello.flv
[download] 100.0% of 1.68M at   21.11k/s ETA 00:00 ```





@phihag
Copy link
Contributor

@phihag phihag commented Sep 26, 2011

os.system executes youtube-dl in a subshell. In this subshell, an ampersand (&) in the URL makes youtube-dl run in the background. Instead, us the subprocess module.

import subprocess
subprocess.Popen(['python2.7', 'youtubedl.py', '-o','../data' + filename, youtube_url]).communicate()

You could also put the URL in quotes, but that will fail (and allow anyone who enters the URL shell access) if it contains quotes.

@phihag phihag closed this Sep 26, 2011
@samrat
Copy link
Author

@samrat samrat commented Sep 26, 2011

phihag- I tried using subprocess too, the problem still persists.

@phihag phihag reopened this Sep 26, 2011
@phihag
Copy link
Contributor

@phihag phihag commented Sep 26, 2011

@samrat It's not about using subprocess in general, but the way you construct the command. Can you post an extract of the subprocess version of your code?

@samrat
Copy link
Author

@samrat samrat commented Sep 26, 2011

def download(youtube_url): filename = 'hello.flv' download_command = "python2.7 youtubedl.py -o '../data/%s' %s;" % (filename, youtube_url.encode('utf8')) args = shlex.split(download_command) subprocess.Popen(args).communicate() return filename

@phihag
Copy link
Contributor

@phihag phihag commented Sep 26, 2011

@samrat This variant has the exact same problem, only with spaces instead of the ampersand in the URL. Why are you constructing the command as a string instead of a list, as I suggested?

Also, can you reproduce the problem in an interactive shell? If not, can you give us (or upload) a small demo program that reproduces the issue without requiring any user input?

@samrat
Copy link
Author

@samrat samrat commented Sep 27, 2011

@phihag- Thank you, constructing the command as a list seems to solve the problem.

@samrat samrat closed this Sep 27, 2011
@ghost
Copy link

@ghost ghost commented Nov 19, 2012

Can you please post how you solved the issue?

@phihag
Copy link
Contributor

@phihag phihag commented Nov 19, 2012

@Anilmorab See my previous comment for the solution.

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
2 participants
You can’t perform that action at this time.