[Restudy] Add new extractor for restudy.dk
[youtube-dl] / youtube_dl / extractor / restudy.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class RestudyIE(InfoExtractor):
8     _VALID_URL = r'https://www.restudy.dk/video/play/id/(?P<id>[0-9]+)'
9     _TEST = {
10         'url': 'https://www.restudy.dk/video/play/id/1637',
11         # MD5 sum of first 10241 bytes of the video file, as reported by
12         # head -c 10241 Leiden-frosteffekt-1637.mp4 | md5sum
13         'md5': '4e755c4287f292a1fe5363834a683818',
14         'info_dict': {
15             'id': '1637',
16             'ext': 'mp4',
17             'title': 'Leiden-frosteffekt',
18         }
19     }
20
21     def _real_extract(self, url):
22         video_id = self._match_id(url)
23         webpage = self._download_webpage(url, video_id)
24         xml_url = (
25             'https://www.restudy.dk/awsmedia/SmilDirectory/video_%s.xml'
26             % video_id)
27         xml = self._download_webpage(xml_url, video_id)
28
29         base = self._search_regex(
30             r'<meta base="([^"]+)', xml, 'meta base')
31         # TODO: Provide multiple video qualities instead of forcing highest
32         filename = self._search_regex(
33             r'<video src="mp4:([^"]+_high\.mp4)', xml, 'filename')
34         url = '%s%s' % (base, filename)
35         title = self._og_search_title(webpage)
36         return {
37             'id': video_id,
38             'title': title,
39             'url': url,
40             'protocol': 'rtmp',
41         }