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

Error Checking #743

Closed
gdsaxton opened this issue Mar 12, 2013 · 4 comments
Closed

Error Checking #743

gdsaxton opened this issue Mar 12, 2013 · 4 comments

Comments

@gdsaxton
Copy link

@gdsaxton gdsaxton commented Mar 12, 2013

Hi,

Just started using youtube-dl -- great program! I am wondering if there is a way to check whether the video downloaded -- or at least started to.

I'm using youtube-dl within Python, and iterating over URLs in a 'video_url' column in a database, as in the following lines

all_videos = session.query(VIDEOS).all()
for row in all_videos[:20]:
campaign_name = row.charity_name
video_id = '_%(id)s.%(ext)s'
video_name = 'videos/'+campaign_name+video_id
os.system ( "youtube-dl '%s' -o '%s'" % (video_url, video_name) )
row.video_downloaded = 'yes'

Most of the time, this works great, but on at least one Vimeo video I get this error:

[vimeo] 59354216: Downloading webpage
[vimeo] 59354216: Extracting information
ERROR: unable to extract info section

So, what I'm wondering is if there is a way to check whether there is an error, or check whether the video downloaded correctly, so that I can note in the 'video_downloaded' column whether the video downloaded or not? Sorry if this is a bit of a novice question -- I'd appreciate any help!

Best,

Greg

@cinereous
Copy link

@cinereous cinereous commented Mar 13, 2013

As a Python neophyte, I can't give you a good answer, but a kludge would be --- check the output of the system call and see if it contains "ERROR" (
if "ERROR" in output: print "Not downloaded." <--- or, look for 100% or any other term you'd see on success).

Of course, if youtube-dl does the standard unix thing of returning 0 on success, you could just check for that:
result = os.system ("youtube-dl '%s' -o '%s'" % (video_url, video_name) )
if result:
print "Error."

@maximeg
Copy link

@maximeg maximeg commented Mar 13, 2013

Well, I use a simple way, checking for the downloaded file, as an error can occurs in many way (youtube-dl could fail without displaying "error", if there is any bug).

In ruby, I do :

  def self.import_with_youtubedl(url, tmp_path)
    raise StandardError.new("youtube-dl is not on the system") unless system("which youtube-dl >> /dev/null")

    result = `youtube-dl -f 18 -o "#{tmp_path}/video.%(ext)s" "#{url}"`

    ["video.mp4", "video.flv"].each do |file_name|
      file_path = tmp_path.join(file_name)
      return file_path if File.exists?(file_path)
    end

    return nil if result =~ /Falling back on generic information extractor/i

    raise StandardError.new("Cannot get with youtube-dl: #{result}")
  end

It returns me the file path of the downloaded video, or nil if youtube-dl couldn't download it (all extractors tried).

@gdsaxton
Copy link
Author

@gdsaxton gdsaxton commented Mar 13, 2013

Thanks @maximeg and @cinereous for your suggestions! I tried @cinereous's suggestion and implemented this:

result = os.system ( "youtube-dl '%s' -o '%s' -f 18 " % (video_url, video_name) )  
#result == 0 when it downloaded successfully, result == 256, and possibly other values, when unsuccessful
if result == 0:
    row.video_downloaded = 'success!'
else:
    row.video_downloaded = 'VIDEO FAILED TO DOWNLOAD'

It worked! Thanks for the help!

Cheers,

Greg

@ocisly
Copy link
Contributor

@ocisly ocisly commented May 23, 2014

@phihag this has also been resolved (and can be closed)

@phihag phihag closed this May 23, 2014
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
5 participants
You can’t perform that action at this time.