]>
Commit | Line | Data |
---|---|---|
704df56d PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | compat_urllib_request, | |
9 | parse_iso8601, | |
10 | ) | |
11 | ||
12 | ||
13 | class SportDeutschlandIE(InfoExtractor): | |
14 | _VALID_URL = r'https?://sportdeutschland\.tv/(?P<sport>[^/?#]+)/(?P<id>[^?#/]+)(?:$|[?#])' | |
3524cc25 | 15 | _TESTS = [{ |
704df56d PH |
16 | 'url': 'http://sportdeutschland.tv/badminton/live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen', |
17 | 'info_dict': { | |
18 | 'id': 'live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen', | |
19 | 'ext': 'mp4', | |
8ff14175 | 20 | 'title': 're:Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen', |
704df56d PH |
21 | 'categories': ['Badminton'], |
22 | 'view_count': int, | |
3524cc25 | 23 | 'thumbnail': 're:^https?://.*\.jpg$', |
8ff14175 | 24 | 'description': 're:Die Badminton-WM 2014 aus Kopenhagen bei Sportdeutschland\.TV', |
3524cc25 PH |
25 | 'timestamp': int, |
26 | 'upload_date': 're:^201408[23][0-9]$', | |
704df56d PH |
27 | }, |
28 | 'params': { | |
29 | 'skip_download': 'Live stream', | |
30 | }, | |
3524cc25 PH |
31 | }, { |
32 | 'url': 'http://sportdeutschland.tv/li-ning-badminton-wm-2014/lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs', | |
33 | 'info_dict': { | |
34 | 'id': 'lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs', | |
35 | 'ext': 'mp4', | |
36 | 'upload_date': '20140825', | |
37 | 'description': 'md5:60a20536b57cee7d9a4ec005e8687504', | |
38 | 'timestamp': 1408976060, | |
39 | 'title': 'Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen: Herren Einzel, Wei Lee vs. Keun Lee', | |
40 | 'thumbnail': 're:^https?://.*\.jpg$', | |
41 | 'view_count': int, | |
42 | 'categories': ['Li-Ning Badminton WM 2014'], | |
43 | } | |
44 | }] | |
704df56d PH |
45 | |
46 | def _real_extract(self, url): | |
47 | mobj = re.match(self._VALID_URL, url) | |
48 | video_id = mobj.group('id') | |
49 | sport_id = mobj.group('sport') | |
50 | ||
51 | api_url = 'http://splink.tv/api/permalinks/%s/%s' % ( | |
52 | sport_id, video_id) | |
53 | req = compat_urllib_request.Request(api_url, headers={ | |
54 | 'Accept': 'application/vnd.vidibus.v2.html+json', | |
55 | 'Referer': url, | |
56 | }) | |
57 | data = self._download_json(req, video_id) | |
58 | ||
59 | categories = list(data.get('section', {}).get('tags', {}).values()) | |
60 | asset = data['asset'] | |
61 | ||
3524cc25 | 62 | formats = [] |
704df56d | 63 | smil_url = asset['video'] |
3524cc25 PH |
64 | if '.smil' in smil_url: |
65 | m3u8_url = smil_url.replace('.smil', '.m3u8') | |
66 | formats.extend( | |
67 | self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')) | |
68 | ||
69 | smil_doc = self._download_xml( | |
70 | smil_url, video_id, note='Downloading SMIL metadata') | |
71 | base_url = smil_doc.find('./head/meta').attrib['base'] | |
72 | formats.extend([{ | |
73 | 'format_id': 'rmtp', | |
74 | 'url': base_url, | |
75 | 'play_path': n.attrib['src'], | |
76 | 'ext': 'flv', | |
77 | 'preference': -100, | |
78 | 'format_note': 'Seems to fail at example stream', | |
79 | } for n in smil_doc.findall('./body/video')]) | |
80 | else: | |
81 | formats.append({'url': smil_url}) | |
704df56d | 82 | |
704df56d PH |
83 | self._sort_formats(formats) |
84 | ||
85 | return { | |
86 | 'id': video_id, | |
87 | 'formats': formats, | |
88 | 'title': asset['title'], | |
89 | 'thumbnail': asset.get('image'), | |
90 | 'description': asset.get('teaser'), | |
91 | 'categories': categories, | |
92 | 'view_count': asset.get('views'), | |
3524cc25 | 93 | 'rtmp_live': asset.get('live'), |
704df56d PH |
94 | 'timestamp': parse_iso8601(asset.get('date')), |
95 | } |