Merge remote-tracking branch 'gabeos/crunchyroll-show-playlist'
[youtube-dl] / youtube_dl / extractor / sportbox.py
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     parse_duration,
9     parse_iso8601,
10     int_or_none,
11 )
12
13
14 class SportBoxIE(InfoExtractor):
15     _VALID_URL = r'https?://news\.sportbox\.ru/Vidy_sporta/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
16     _TESTS = [
17         {
18             'url': 'http://news.sportbox.ru/Vidy_sporta/Avtosport/Rossijskij/spbvideo_NI483529_Gonka-2-zaezd-Obyedinenniy-2000-klassi-Turing-i-S',
19             'md5': 'ff56a598c2cf411a9a38a69709e97079',
20             'info_dict': {
21                 'id': '80822',
22                 'ext': 'mp4',
23                 'title': 'Гонка 2  заезд ««Объединенный 2000»: классы Туринг и Супер-продакшн',
24                 'description': 'md5:81715fa9c4ea3d9e7915dc8180c778ed',
25                 'thumbnail': 're:^https?://.*\.jpg$',
26                 'timestamp': 1411896237,
27                 'upload_date': '20140928',
28                 'duration': 4846,
29             },
30             'params': {
31                 # m3u8 download
32                 'skip_download': True,
33             },
34         }, {
35             'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
36             'only_matching': True,
37         }
38     ]
39
40     def _real_extract(self, url):
41         mobj = re.match(self._VALID_URL, url)
42         display_id = mobj.group('display_id')
43
44         webpage = self._download_webpage(url, display_id)
45
46         video_id = self._search_regex(
47             r'src="/vdl/player/media/(\d+)"', webpage, 'video id')
48
49         player = self._download_webpage(
50             'http://news.sportbox.ru/vdl/player/media/%s' % video_id,
51             display_id, 'Downloading player webpage')
52
53         hls = self._search_regex(
54             r"var\s+original_hls_file\s*=\s*'([^']+)'", player, 'hls file')
55
56         formats = self._extract_m3u8_formats(hls, display_id, 'mp4')
57
58         title = self._html_search_regex(
59             r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
60         description = self._html_search_regex(
61             r'(?s)<div itemprop="description">(.+?)</div>', webpage, 'description', fatal=False)
62         thumbnail = self._og_search_thumbnail(webpage)
63         timestamp = parse_iso8601(self._search_regex(
64             r'<span itemprop="uploadDate">([^<]+)</span>', webpage, 'timestamp', fatal=False))
65         duration = parse_duration(self._html_search_regex(
66             r'<meta itemprop="duration" content="PT([^"]+)">', webpage, 'duration', fatal=False))
67
68         return {
69             'id': video_id,
70             'display_id': display_id,
71             'title': title,
72             'description': description,
73             'thumbnail': thumbnail,
74             'timestamp': timestamp,
75             'duration': duration,
76             'formats': formats,
77         }