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