]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sportbox.py
54497c880ec2cc9cbfc5ff20756cbc19d4ee6c65
[youtubedl] / 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 determine_ext,
9 int_or_none,
10 js_to_json,
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': '211355',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'duration': 292,
24 'view_count': int,
25 },
26 'params': {
27 # m3u8 download
28 'skip_download': True,
29 },
30 }, {
31 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
32 'only_matching': True,
33 }, {
34 'url': 'https://news.sportbox.ru/vdl/player/media/193095',
35 'only_matching': True,
36 }]
37
38 @staticmethod
39 def _extract_urls(webpage):
40 return re.findall(
41 r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"',
42 webpage)
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 webpage = self._download_webpage(url, video_id)
48
49 wjplayer_data = self._parse_json(
50 self._search_regex(
51 r'(?s)wjplayer\(({.+?})\);', webpage, 'wjplayer settings'),
52 video_id, transform_source=js_to_json)
53
54 formats = []
55 for source in wjplayer_data['sources']:
56 src = source.get('src')
57 if not src:
58 continue
59 if determine_ext(src) == 'm3u8':
60 formats.extend(self._extract_m3u8_formats(
61 src, video_id, 'mp4', entry_protocol='m3u8_native',
62 m3u8_id='hls', fatal=False))
63 else:
64 formats.append({
65 'url': src,
66 })
67 self._sort_formats(formats)
68
69 view_count = int_or_none(self._search_regex(
70 r'Просмотров\s*:\s*(\d+)', webpage, 'view count', default=None))
71
72 return {
73 'id': video_id,
74 'title': video_id,
75 'thumbnail': wjplayer_data.get('poster'),
76 'duration': int_or_none(wjplayer_data.get('duration')),
77 'view_count': view_count,
78 'formats': formats,
79 }