]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/unistra.py
debian/control: Remove trailing whitespace at EOF.
[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'https?://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 self._sort_formats(formats)
53
54 title = self._html_search_regex(
55 r'<title>UTV - (.*?)</', webpage, 'title')
56 description = self._html_search_regex(
57 r'<meta name="Description" content="(.*?)"', webpage, 'description', flags=re.DOTALL)
58 thumbnail = self._search_regex(
59 r'image: "(.*?)"', webpage, 'thumbnail')
60
61 return {
62 'id': video_id,
63 'title': title,
64 'description': description,
65 'thumbnail': thumbnail,
66 'formats': formats
67 }