diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-05-04 10:33:34 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-05-04 10:36:37 +0200 |
commit | 0e16f0947492ea7bfbae4d5f56452f0a0b93b7ab (patch) | |
tree | d7c06f5c678a8c1268035541656a95c048910bc0 /youtube_dl | |
parent | 09dd418f5318a071aa80b82f6c9efeada9608584 (diff) |
Work on twitch.tv chapters (#810)
Diffstat (limited to 'youtube_dl')
-rwxr-xr-x | youtube_dl/InfoExtractors.py | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 568bca702..1c985272f 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -3304,7 +3304,13 @@ class JustinTVIE(InfoExtractor): # starts at 1 and increases. Can we treat all parts as one video? _VALID_URL = r"""(?x)^(?:http://)?(?:www\.)?(?:twitch|justin)\.tv/ - ([^/]+)(?:/b/([^/]+))?/?(?:\#.*)?$""" + (?: + (?P<channelid>[^/]+)| + (?:(?:[^/]+)/b/(?P<videoid>[^/]+))| + (?:(?:[^/]+)/c/(?P<chapterid>[^/]+)) + ) + /?(?:\#.*)?$ + """ _JUSTIN_PAGE_LIMIT = 100 IE_NAME = u'justin.tv' @@ -3346,18 +3352,43 @@ class JustinTVIE(InfoExtractor): def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) if mobj is None: - self._downloader.report_error(u'invalid URL: %s' % url) - return + raise ExtractorError(u'invalid URL: %s' % url) - api = 'http://api.justin.tv' - video_id = mobj.group(mobj.lastindex) + api_base = 'http://api.justin.tv' paged = False - if mobj.lastindex == 1: + if mobj.group('channelid'): paged = True - api += '/channel/archives/%s.json' + video_id = mobj.group('channelid') + api = api_base + '/channel/archives/%s.json' % video_id + elif mobj.group('chapterid'): + chapter_id = mobj.group('chapterid') + # youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457 + + webpage = self._download_webpage(url, chapter_id) + m = re.search(r'PP\.archive_id = "([0-9]+)";', webpage) + if not m: + raise ExtractorError('Cannot find archive of a chapter') + archive_id = m.group(1) + + api = api_base + '/broadcast/by_chapter/%s.json' % chapter_id + chapter_info_json = self._download_webpage(api, chapter_id, + note='Downloading chapter information', + errnote='Chapter information download failed') + chapter_info = json.loads(chapter_info_json) + video_info = filter(lambda ci: str(ci['id']) == archive_id, chapter_info) + + video_url = 'TODO:SERVER_NAME' + '/archives/' + vi['file_name'] + '?start=TODO:startid' + + # Result: http://store36.media36.justin.tv/archives/2012-12-2/live_user_firmbelief_1354484906.flv?start=51670615 + # (this may not be playable, may need to craft some additional headers) + # TODO: title ("GOD", from webpage?) + # TODO: ext (from vi['file_name']) + # print(json.dumps(video_info, indent=2)) + # return + raise NotImplementedError('twitch.tv chapters are not yet supported, sorry (See https://github.com/rg3/youtube-dl/issues/810 )') else: - api += '/broadcast/by_archive/%s.json' - api = api % (video_id,) + video_id = mobj.group('videoid') + api = api_base + '/broadcast/by_archive/%s.json' % video_id self.report_extraction(video_id) |