+ video_id = mobj.group('channelid')
+ api = api_base + '/channel/archives/%s.json' % video_id
+ elif mobj.group('chapterid'):
+ chapter_id = mobj.group('chapterid')
+
+ webpage = self._download_webpage(url, chapter_id)
+ m = re.search(r'PP\.archive_id = "([0-9]+)";', webpage)
+ if not m:
+ raise ExtractorError(u'Cannot find archive of a chapter')
+ archive_id = m.group(1)
+
+ api = api_base + '/broadcast/by_chapter/%s.xml' % chapter_id
+ chapter_info_xml = self._download_webpage(api, chapter_id,
+ note=u'Downloading chapter information',
+ errnote=u'Chapter information download failed')
+ doc = xml.etree.ElementTree.fromstring(chapter_info_xml)
+ for a in doc.findall('.//archive'):
+ if archive_id == a.find('./id').text:
+ break
+ else:
+ raise ExtractorError(u'Could not find chapter in chapter information')
+
+ video_url = a.find('./video_file_url').text
+ video_ext = video_url.rpartition('.')[2] or u'flv'
+
+ chapter_api_url = u'https://api.twitch.tv/kraken/videos/c' + chapter_id
+ chapter_info_json = self._download_webpage(chapter_api_url, u'c' + chapter_id,
+ note='Downloading chapter metadata',
+ errnote='Download of chapter metadata failed')
+ chapter_info = json.loads(chapter_info_json)
+
+ bracket_start = int(doc.find('.//bracket_start').text)
+ bracket_end = int(doc.find('.//bracket_end').text)
+
+ # TODO determine start (and probably fix up file)
+ # youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457
+ #video_url += u'?start=' + TODO:start_timestamp
+ # bracket_start is 13290, but we want 51670615
+ self._downloader.report_warning(u'Chapter detected, but we can just download the whole file. '
+ u'Chapter starts at %s and ends at %s' % (formatSeconds(bracket_start), formatSeconds(bracket_end)))
+
+ info = {
+ 'id': u'c' + chapter_id,
+ 'url': video_url,
+ 'ext': video_ext,
+ 'title': chapter_info['title'],
+ 'thumbnail': chapter_info['preview'],
+ 'description': chapter_info['description'],
+ 'uploader': chapter_info['channel']['display_name'],
+ 'uploader_id': chapter_info['channel']['name'],
+ }
+ return [info]