]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/unistra.py
Imported Upstream version 2015.07.21
[youtubedl] / youtube_dl / extractor / unistra.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import qualities
7
8
9 class UnistraIE(InfoExtractor):
10 _VALID_URL = r'http://utv\.unistra\.fr/(?:index|video)\.php\?id_video\=(?P<id>\d+)'
11
12 _TESTS = [
13 {
14 'url': 'http://utv.unistra.fr/video.php?id_video=154',
15 'md5': '736f605cfdc96724d55bb543ab3ced24',
16 'info_dict': {
17 'id': '154',
18 'ext': 'mp4',
19 'title': 'M!ss Yella',
20 'description': 'md5:104892c71bd48e55d70b902736b81bbf',
21 },
22 },
23 {
24 'url': 'http://utv.unistra.fr/index.php?id_video=437',
25 'md5': '1ddddd6cccaae76f622ce29b8779636d',
26 'info_dict': {
27 'id': '437',
28 'ext': 'mp4',
29 'title': 'Prix Louise Weiss 2014',
30 'description': 'md5:cc3a8735f079f4fb6b0b570fc10c135a',
31 },
32 }
33 ]
34
35 def _real_extract(self, url):
36 mobj = re.match(self._VALID_URL, url)
37 video_id = mobj.group('id')
38
39 webpage = self._download_webpage(url, video_id)
40
41 files = set(re.findall(r'file\s*:\s*"([^"]+)"', webpage))
42
43 quality = qualities(['SD', 'HD'])
44 formats = []
45 for file_path in files:
46 format_id = 'HD' if file_path.endswith('-HD.mp4') else 'SD'
47 formats.append({
48 'url': 'http://vod-flash.u-strasbg.fr:8080%s' % file_path,
49 'format_id': format_id,
50 'quality': quality(format_id)
51 })
52
53 title = self._html_search_regex(
54 r'<title>UTV - (.*?)</', webpage, 'title')
55 description = self._html_search_regex(
56 r'<meta name="Description" content="(.*?)"', webpage, 'description', flags=re.DOTALL)
57 thumbnail = self._search_regex(
58 r'image: "(.*?)"', webpage, 'thumbnail')
59
60 return {
61 'id': video_id,
62 'title': title,
63 'description': description,
64 'thumbnail': thumbnail,
65 'formats': formats
66 }