]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
0f6ed94a S |
2 | from __future__ import unicode_literals |
3 | ||
0f6ed94a | 4 | from .common import InfoExtractor |
9b5288c9 S |
5 | from ..compat import ( |
6 | compat_str, | |
7 | compat_urlparse, | |
8 | ) | |
61dd350a S |
9 | from ..utils import ( |
10 | int_or_none, | |
11 | qualities, | |
12 | unified_strdate, | |
61dd350a | 13 | ) |
0f6ed94a S |
14 | |
15 | ||
16 | class FirstTVIE(InfoExtractor): | |
9347fddb S |
17 | IE_NAME = '1tv' |
18 | IE_DESC = 'Первый канал' | |
9b8c554e | 19 | _VALID_URL = r'https?://(?:www\.)?1tv\.ru/(?:[^/]+/)+(?P<id>[^/?#]+)' |
0f6ed94a | 20 | |
9347fddb | 21 | _TESTS = [{ |
d0fa172e | 22 | # single format |
9b8c554e RA |
23 | 'url': 'http://www.1tv.ru/shows/naedine-so-vsemi/vypuski/gost-lyudmila-senchina-naedine-so-vsemi-vypusk-ot-12-02-2015', |
24 | 'md5': 'a1b6b60d530ebcf8daacf4565762bbaf', | |
0f6ed94a | 25 | 'info_dict': { |
9b8c554e | 26 | 'id': '40049', |
0f6ed94a | 27 | 'ext': 'mp4', |
9b5288c9 | 28 | 'title': 'Гость Людмила Сенчина. Наедине со всеми. Выпуск от 12.02.2015', |
ec85ded8 | 29 | 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$', |
61dd350a S |
30 | 'upload_date': '20150212', |
31 | 'duration': 2694, | |
cb389289 | 32 | }, |
9347fddb | 33 | }, { |
d0fa172e | 34 | # multiple formats |
9b8c554e | 35 | 'url': 'http://www.1tv.ru/shows/dobroe-utro/pro-zdorove/vesennyaya-allergiya-dobroe-utro-fragment-vypuska-ot-07042016', |
d0fa172e RA |
36 | 'info_dict': { |
37 | 'id': '364746', | |
38 | 'ext': 'mp4', | |
9b5288c9 | 39 | 'title': 'Весенняя аллергия. Доброе утро. Фрагмент выпуска от 07.04.2016', |
ec85ded8 | 40 | 'thumbnail': r're:^https?://.*\.(?:jpg|JPG)$', |
d0fa172e RA |
41 | 'upload_date': '20160407', |
42 | 'duration': 179, | |
43 | 'formats': 'mincount:3', | |
44 | }, | |
45 | 'params': { | |
46 | 'skip_download': True, | |
47 | }, | |
9b5288c9 S |
48 | }, { |
49 | 'url': 'http://www.1tv.ru/news/issue/2016-12-01/14:00', | |
50 | 'info_dict': { | |
51 | 'id': '14:00', | |
52 | 'title': 'Выпуск новостей в 14:00 1 декабря 2016 года. Новости. Первый канал', | |
53 | 'description': 'md5:2e921b948f8c1ff93901da78ebdb1dfd', | |
54 | }, | |
55 | 'playlist_count': 13, | |
56 | }, { | |
57 | 'url': 'http://www.1tv.ru/shows/tochvtoch-supersezon/vystupleniya/evgeniy-dyatlov-vladimir-vysockiy-koni-priveredlivye-toch-v-toch-supersezon-fragment-vypuska-ot-06-11-2016', | |
58 | 'only_matching': True, | |
9347fddb | 59 | }] |
0f6ed94a S |
60 | |
61 | def _real_extract(self, url): | |
9b8c554e | 62 | display_id = self._match_id(url) |
0f6ed94a | 63 | |
9b8c554e RA |
64 | webpage = self._download_webpage(url, display_id) |
65 | playlist_url = compat_urlparse.urljoin(url, self._search_regex( | |
9b5288c9 S |
66 | r'data-playlist-url=(["\'])(?P<url>(?:(?!\1).)+)\1', |
67 | webpage, 'playlist url', group='url')) | |
68 | ||
69 | parsed_url = compat_urlparse.urlparse(playlist_url) | |
70 | qs = compat_urlparse.parse_qs(parsed_url.query) | |
71 | item_ids = qs.get('videos_ids[]') or qs.get('news_ids[]') | |
72 | ||
73 | items = self._download_json(playlist_url, display_id) | |
74 | ||
75 | if item_ids: | |
76 | items = [ | |
77 | item for item in items | |
78 | if item.get('uid') and compat_str(item['uid']) in item_ids] | |
79 | else: | |
80 | items = [items[0]] | |
81 | ||
82 | entries = [] | |
83 | QUALITIES = ('ld', 'sd', 'hd', ) | |
84 | ||
85 | for item in items: | |
86 | title = item['title'] | |
87 | quality = qualities(QUALITIES) | |
88 | formats = [] | |
1fe84be0 | 89 | path = None |
9b5288c9 S |
90 | for f in item.get('mbr', []): |
91 | src = f.get('src') | |
92 | if not src or not isinstance(src, compat_str): | |
93 | continue | |
94 | tbr = int_or_none(self._search_regex( | |
95 | r'_(\d{3,})\.mp4', src, 'tbr', default=None)) | |
1fe84be0 S |
96 | if not path: |
97 | path = self._search_regex( | |
98 | r'//[^/]+/(.+?)_\d+\.mp4', src, | |
99 | 'm3u8 path', default=None) | |
9b5288c9 S |
100 | formats.append({ |
101 | 'url': src, | |
102 | 'format_id': f.get('name'), | |
103 | 'tbr': tbr, | |
1fe84be0 | 104 | 'source_preference': quality(f.get('name')), |
f7a747ce S |
105 | # quality metadata of http formats may be incorrect |
106 | 'preference': -1, | |
9b5288c9 | 107 | }) |
1fe84be0 S |
108 | # m3u8 URL format is reverse engineered from [1] (search for |
109 | # master.m3u8). dashEdges (that is currently balancer-vod.1tv.ru) | |
110 | # is taken from [2]. | |
111 | # 1. http://static.1tv.ru/player/eump1tv-current/eump-1tv.all.min.js?rnd=9097422834:formatted | |
112 | # 2. http://static.1tv.ru/player/eump1tv-config/config-main.js?rnd=9097422834 | |
113 | if not path and len(formats) == 1: | |
114 | path = self._search_regex( | |
115 | r'//[^/]+/(.+?$)', formats[0]['url'], | |
116 | 'm3u8 path', default=None) | |
117 | if path: | |
118 | if len(formats) == 1: | |
119 | m3u8_path = ',' | |
120 | else: | |
121 | tbrs = [compat_str(t) for t in sorted(f['tbr'] for f in formats)] | |
122 | m3u8_path = '_,%s,%s' % (','.join(tbrs), '.mp4') | |
123 | formats.extend(self._extract_m3u8_formats( | |
124 | 'http://balancer-vod.1tv.ru/%s%s.urlset/master.m3u8' | |
125 | % (path, m3u8_path), | |
126 | display_id, 'mp4', | |
127 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) | |
9b5288c9 S |
128 | self._sort_formats(formats) |
129 | ||
130 | thumbnail = item.get('poster') or self._og_search_thumbnail(webpage) | |
131 | duration = int_or_none(item.get('duration') or self._html_search_meta( | |
132 | 'video:duration', webpage, 'video duration', fatal=False)) | |
133 | upload_date = unified_strdate(self._html_search_meta( | |
134 | 'ya:ovs:upload_date', webpage, 'upload date', default=None)) | |
0f6ed94a | 135 | |
9b5288c9 | 136 | entries.append({ |
4afa4ff2 | 137 | 'id': compat_str(item.get('id') or item['uid']), |
9b5288c9 S |
138 | 'thumbnail': thumbnail, |
139 | 'title': title, | |
140 | 'upload_date': upload_date, | |
141 | 'duration': int_or_none(duration), | |
142 | 'formats': formats | |
9b8c554e | 143 | }) |
61dd350a | 144 | |
9b8c554e RA |
145 | title = self._html_search_regex( |
146 | (r'<div class="tv_translation">\s*<h1><a href="[^"]+">([^<]*)</a>', | |
147 | r"'title'\s*:\s*'([^']+)'"), | |
9b5288c9 S |
148 | webpage, 'title', default=None) or self._og_search_title( |
149 | webpage, default=None) | |
9b8c554e RA |
150 | description = self._html_search_regex( |
151 | r'<div class="descr">\s*<div> </div>\s*<p>([^<]*)</p></div>', | |
152 | webpage, 'description', default=None) or self._html_search_meta( | |
9b5288c9 | 153 | 'description', webpage, 'description', default=None) |
0f6ed94a | 154 | |
9b5288c9 | 155 | return self.playlist_result(entries, display_id, title, description) |