Extractor for non-password protected GDC Vault videos
[youtube-dl] / youtube_dl / extractor / gdcvault.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5 import xml.etree.ElementTree
6
7 from .common import InfoExtractor
8 from ..utils import unified_strdate
9
10
11 class GDCVaultIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)/(?P<name>(\w|-)+)'
13
14     _TEST = {
15         u'url': u'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
16         u'md5': u'7ce8388f544c88b7ac11c7ab1b593704',
17         u'info_dict': {
18             u"id": u"1019721",
19             u"ext": u"mp4",
20             u"title": u"Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)"
21         }
22     }
23
24     def _real_extract(self, url):
25         mobj = re.match(self._VALID_URL, url)
26
27         video_id = mobj.group('id')
28         webpage_url = 'http://www.gdcvault.com/play/' + video_id
29
30         start_page = self._download_webpage(webpage_url, video_id)
31
32         self.report_extraction(video_id)
33
34         xml_root = self._html_search_regex(r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>', start_page, 'xml root')
35         xml_name = self._html_search_regex(r'<iframe src=".*?\?xml=(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename')
36         xml_decription_url = xml_root + 'xml/' + xml_name
37
38         xml_description = self._download_xml(xml_decription_url, video_id)
39
40         video_title = xml_description.find('./metadata/title').text
41
42         mp4_video = xml_description.find('./metadata/mp4video').text
43         mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video)
44         video_root = mobj.group('root')
45
46         formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
47         video_formats = []
48         for format in formats:
49             mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
50             url = video_root + mobj.group('path')
51             vbr = format.find('bitrate').text
52             video_formats.append({
53                 'url': url,
54                 'vbr': int(vbr),
55             })
56
57         return [{
58             'id': video_id,
59             'formats': video_formats,
60             'title': video_title,
61         }]