Merge branch 'unistra_hd' of https://github.com/Rudloff/youtube-dl into Rudloff-unist...
[youtube-dl] / youtube_dl / extractor / unistra.py
1 import re
2
3 from .common import InfoExtractor
4
5 class UnistraIE(InfoExtractor):
6     _VALID_URL = r'http://utv\.unistra\.fr/(?:index|video)\.php\?id_video\=(\d+)'
7
8     _TEST = {
9         u'url': u'http://utv.unistra.fr/video.php?id_video=154',
10         u'file': u'154.mp4',
11         u'md5': u'736f605cfdc96724d55bb543ab3ced24',
12         u'info_dict': {
13             u'title': u'M!ss Yella',
14             u'description': u'md5:104892c71bd48e55d70b902736b81bbf',
15         },
16     }
17
18     def _real_extract(self, url):
19         video_id = re.match(self._VALID_URL, url).group(1)
20         webpage = self._download_webpage(url, video_id)
21         width = re.search(r'width: "(\d*?)",', webpage).group(1)
22         height = re.search(r'height: "(\d*?)",', webpage).group(1)
23         files = re.findall(r'file: "(.*?)"', webpage)
24         video_url = 'http://vod-flash.u-strasbg.fr:8080'
25         formats = [{
26             'format_id': 'SD',
27             'url': video_url + files[0],
28             'ext': 'mp4',
29             'resolution': width + 'x' + height
30             }]
31         if files[1] != files[0]:
32             formats.append({
33             'format_id': 'HD',
34             'url': video_url + files[1],
35             'ext': 'mp4'
36             })
37         title = self._html_search_regex(r'<title>UTV - (.*?)</', webpage, u'title')
38
39         return {'id': video_id,
40                 'title': title,
41                 'description': self._html_search_regex(r'<meta name="Description" content="(.*?)"', webpage, u'description', flags=re.DOTALL),
42                 'thumbnail': self._search_regex(r'image: "(.*?)"', webpage, u'thumbnail'),
43                 'formats': formats
44                 }