ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
131.25k stars 9.93k forks source link

Use proper error handling for subtitles #914

Open jaimeMF opened 11 years ago

jaimeMF commented 11 years ago

Each IE that extract subtitles should handle the errors internally. If they are not available, it should report a warning, and if it finds them, set the dictionary of subtitles. The main goal is to stop using tuples for handling errors.

See this weird error from a Travis test (https://travis-ci.org/rg3/youtube-dl/jobs/83670969):

ERROR: test_youtube_list_subtitles (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------

Traceback (most recent call last):

File "/home/travis/build/rg3/youtube-dl/test/test_youtube_subtitles.py", line 99, in test_youtube_list_subtitles

info_dict = IE.extract('QRS8MkLhQmM')

File "/home/travis/build/rg3/youtube-dl/youtube_dl/extractor/common.py", line 91, in extract

return self._real_extract(url)

File "/home/travis/build/rg3/youtube-dl/youtube_dl/extractor/youtube.py", line 473, in _real_extract

self._list_available_subtitles(video_id)

File "/home/travis/build/rg3/youtube-dl/youtube_dl/extractor/youtube.py", line 158, in _list_available_subtitles

self.report_video_subtitles_available(video_id, sub_lang_list)

File "/home/travis/build/rg3/youtube-dl/youtube_dl/extractor/youtube.py", line 117, in report_video_subtitles_available

sub_lang = ",".join(list(sub_lang_list.keys()))

AttributeError: 'tuple' object has no attribute 'keys'
FiloSottile commented 11 years ago

Related: I'm occasionally getting this ton of errors with subtitles.

They are at least very unstable.

======================================================================
ERROR: test_youtube_list_subtitles (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/filosottile/git/youtube-dl/test/test_youtube_subtitles.py", line 99, in test_youtube_list_subtitles
    info_dict = IE.extract('QRS8MkLhQmM')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 91, in extract
    return self._real_extract(url)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 473, in _real_extract
    self._list_available_subtitles(video_id)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 158, in _list_available_subtitles
    self.report_video_subtitles_available(video_id, sub_lang_list)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 117, in report_video_subtitles_available
    sub_lang = ",".join(list(sub_lang_list.keys()))
AttributeError: 'tuple' object has no attribute 'keys'
-------------------- >> begin captured stdout << ---------------------
[youtube] Setting language
[youtube] QRS8MkLhQmM: Downloading video webpage
[youtube] QRS8MkLhQmM: Downloading video info webpage
[youtube] QRS8MkLhQmM: Extracting video information
[youtube] QRS8MkLhQmM: Checking available subtitles

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: test_youtube_onlysubtitles (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/filosottile/git/youtube-dl/test/test_youtube_subtitles.py", line 77, in test_youtube_onlysubtitles
    info_dict = IE.extract('QRS8MkLhQmM')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 91, in extract
    return self._real_extract(url)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 457, in _real_extract
    video_subtitles = self._request_automatic_caption(video_id, video_webpage)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 204, in _request_automatic_caption
    sub = self._download_webpage(subtitles_url, video_id, u'Downloading automatic captions')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 145, in _download_webpage
    return self._download_webpage_handle(url_or_request, video_id, note, errnote)[0]
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 124, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 120, in _request_webpage
    raise ExtractorError(u'%s: %s' % (errnote, compat_str(err)), sys.exc_info()[2])
ExtractorError: Unable to download webpage: HTTP Error 404: Not Found; please report this issue on GitHub.
-------------------- >> begin captured stdout << ---------------------
[youtube] Setting language
[youtube] QRS8MkLhQmM: Downloading video webpage
[youtube] QRS8MkLhQmM: Downloading video info webpage
[youtube] QRS8MkLhQmM: Extracting video information
[youtube] QRS8MkLhQmM: Checking available subtitles
[youtube] QRS8MkLhQmM: Looking for automatic captions
[youtube] QRS8MkLhQmM: Downloading automatic captions

--------------------- >> end captured stdout << ----------------------; please report this issue on GitHub.

======================================================================
ERROR: test_youtube_subtitles_format (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/filosottile/git/youtube-dl/test/test_youtube_subtitles.py", line 92, in test_youtube_subtitles_format
    info_dict = IE.extract('QRS8MkLhQmM')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 91, in extract
    return self._real_extract(url)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 457, in _real_extract
    video_subtitles = self._request_automatic_caption(video_id, video_webpage)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 204, in _request_automatic_caption
    sub = self._download_webpage(subtitles_url, video_id, u'Downloading automatic captions')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 145, in _download_webpage
    return self._download_webpage_handle(url_or_request, video_id, note, errnote)[0]
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 124, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 120, in _request_webpage
    raise ExtractorError(u'%s: %s' % (errnote, compat_str(err)), sys.exc_info()[2])
ExtractorError: Unable to download webpage: HTTP Error 404: Not Found; please report this issue on GitHub.
-------------------- >> begin captured stdout << ---------------------
[youtube] Setting language
[youtube] QRS8MkLhQmM: Downloading video webpage
[youtube] QRS8MkLhQmM: Downloading video info webpage
[youtube] QRS8MkLhQmM: Extracting video information
[youtube] QRS8MkLhQmM: Checking available subtitles
[youtube] QRS8MkLhQmM: Looking for automatic captions
[youtube] QRS8MkLhQmM: Downloading automatic captions

--------------------- >> end captured stdout << ----------------------; please report this issue on GitHub.

======================================================================
ERROR: test_youtube_subtitles_it (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/filosottile/git/youtube-dl/test/test_youtube_subtitles.py", line 69, in test_youtube_subtitles_it
    info_dict = IE.extract('QRS8MkLhQmM')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 91, in extract
    return self._real_extract(url)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 457, in _real_extract
    video_subtitles = self._request_automatic_caption(video_id, video_webpage)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/youtube.py", line 204, in _request_automatic_caption
    sub = self._download_webpage(subtitles_url, video_id, u'Downloading automatic captions')
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 145, in _download_webpage
    return self._download_webpage_handle(url_or_request, video_id, note, errnote)[0]
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 124, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote)
  File "/Users/filosottile/git/youtube-dl/youtube_dl/extractor/common.py", line 120, in _request_webpage
    raise ExtractorError(u'%s: %s' % (errnote, compat_str(err)), sys.exc_info()[2])
ExtractorError: Unable to download webpage: HTTP Error 404: Not Found; please report this issue on GitHub.
-------------------- >> begin captured stdout << ---------------------
[youtube] Setting language
[youtube] QRS8MkLhQmM: Downloading video webpage
[youtube] QRS8MkLhQmM: Downloading video info webpage
[youtube] QRS8MkLhQmM: Extracting video information
[youtube] QRS8MkLhQmM: Checking available subtitles
[youtube] QRS8MkLhQmM: Looking for automatic captions
[youtube] QRS8MkLhQmM: Downloading automatic captions

--------------------- >> end captured stdout << ----------------------; please report this issue on GitHub.

======================================================================
FAIL: test_youtube_allsubtitles (test_youtube_subtitles.TestYoutubeSubtitles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/filosottile/git/youtube-dl/test/test_youtube_subtitles.py", line 86, in test_youtube_allsubtitles
    self.assertEqual(len(subtitles), 13)
AssertionError: 1 != 13
-------------------- >> begin captured stdout << ---------------------
[youtube] Setting language
[youtube] QRS8MkLhQmM: Downloading video webpage
[youtube] QRS8MkLhQmM: Downloading video info webpage
[youtube] QRS8MkLhQmM: Extracting video information
[youtube] QRS8MkLhQmM: Checking available subtitles
[youtube] QRS8MkLhQmM: Vevo video detected.

--------------------- >> end captured stdout << ----------------------
jaimeMF commented 11 years ago

It also happens to me sometimes, the first thing I'll do is disable automatic captions by default and then use dictionaries everywhere (at least the error messages will make sense). The most strange error is the one trying to download all the subtitles, I gess it doesn't find subtitles and we end with just a tuple with the error message.

LAP2008 commented 11 years ago

this Error you have with the subtitles looks similar to the error i get in Issue #930 Except im trying to download Videos