mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-10 06:52:54 +08:00
[youku] better error handling
blocked videos used to cause death by TypeError, now we report what the server says
This commit is contained in:
parent
cdbccafed9
commit
8199f044b4
6
run
Executable file
6
run
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import youtube_dl
|
||||
|
||||
if __name__ == '__main__':
|
||||
youtube_dl.main()
|
@ -9,6 +9,7 @@ import time
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
UnavailableVideoError,
|
||||
)
|
||||
|
||||
|
||||
@ -66,6 +67,12 @@ class YoukuIE(InfoExtractor):
|
||||
self.report_extraction(video_id)
|
||||
try:
|
||||
config = json.loads(jsondata)
|
||||
error_code = config['data'][0].get('error_code')
|
||||
if error_code:
|
||||
# -8 means blocked outside China.
|
||||
error = config['data'][0].get('error') # Chinese and English, separated by newline.
|
||||
self.to_screen(error or u'Server reported error %i' % error_code)
|
||||
raise UnavailableVideoError()
|
||||
|
||||
video_title = config['data'][0]['title']
|
||||
seed = config['data'][0]['seed']
|
||||
@ -89,6 +96,7 @@ class YoukuIE(InfoExtractor):
|
||||
|
||||
fileid = config['data'][0]['streamfileids'][format]
|
||||
keys = [s['k'] for s in config['data'][0]['segs'][format]]
|
||||
# segs is usually a dictionary, but an empty *list* if an error occured.
|
||||
except (UnicodeDecodeError, ValueError, KeyError):
|
||||
raise ExtractorError(u'Unable to extract info section')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user