[sportbox] Remove extractor (closes #11954)
[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 ..compat import compat_urlparse
8 from ..utils import (
9     js_to_json,
10     unified_strdate,
11 )
12
13
14 class SportBoxEmbedIE(InfoExtractor):
15     _VALID_URL = r'https?://news\.sportbox\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
16     _TESTS = [{
17         'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
18         'info_dict': {
19             'id': '211355',
20             'ext': 'mp4',
21             'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
22             'thumbnail': r're:^https?://.*\.jpg$',
23         },
24         'params': {
25             # m3u8 download
26             'skip_download': True,
27         },
28     }, {
29         'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
30         'only_matching': True,
31     }]
32
33     @staticmethod
34     def _extract_urls(webpage):
35         return re.findall(
36             r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"',
37             webpage)
38
39     def _real_extract(self, url):
40         video_id = self._match_id(url)
41
42         webpage = self._download_webpage(url, video_id)
43
44         formats = []
45
46         def cleanup_js(code):
47             # desktop_advert_config contains complex Javascripts and we don't need it
48             return js_to_json(re.sub(r'desktop_advert_config.*', '', code))
49
50         jwplayer_data = self._parse_json(self._search_regex(
51             r'(?s)player\.setup\(({.+?})\);', webpage, 'jwplayer settings'), video_id,
52             transform_source=cleanup_js)
53
54         hls_url = jwplayer_data.get('hls_url')
55         if hls_url:
56             formats.extend(self._extract_m3u8_formats(
57                 hls_url, video_id, ext='mp4', m3u8_id='hls'))
58
59         rtsp_url = jwplayer_data.get('rtsp_url')
60         if rtsp_url:
61             formats.append({
62                 'url': rtsp_url,
63                 'format_id': 'rtsp',
64             })
65
66         self._sort_formats(formats)
67
68         title = jwplayer_data['node_title']
69         thumbnail = jwplayer_data.get('image_url')
70
71         return {
72             'id': video_id,
73             'title': title,
74             'thumbnail': thumbnail,
75             'formats': formats,
76         }