]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/yandexvideo.py
Annotate changelog with bug being closed.
[youtubedl] / youtube_dl / extractor / yandexvideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 url_or_none,
8 )
9
10
11 class YandexVideoIE(InfoExtractor):
12 _VALID_URL = r'''(?x)
13 https?://
14 (?:
15 yandex\.ru(?:/portal/(?:video|efir))?/?\?.*?stream_id=|
16 frontend\.vh\.yandex\.ru/player/
17 )
18 (?P<id>[\da-f]+)
19 '''
20 _TESTS = [{
21 'url': 'https://yandex.ru/portal/video?stream_id=4dbb262b4fe5cf15a215de4f34eee34d',
22 'md5': '33955d7ae052f15853dc41f35f17581c',
23 'info_dict': {
24 'id': '4dbb262b4fe5cf15a215de4f34eee34d',
25 'ext': 'mp4',
26 'title': 'В Нью-Йорке баржи и теплоход оторвались от причала и расплылись по Гудзону',
27 'description': '',
28 'thumbnail': r're:^https?://.*\.jpg$',
29 'timestamp': 0,
30 'duration': 30,
31 'age_limit': 18,
32 },
33 }, {
34 'url': 'https://yandex.ru/portal/efir?stream_id=4dbb36ec4e0526d58f9f2dc8f0ecf374&from=morda',
35 'only_matching': True,
36 }, {
37 'url': 'https://yandex.ru/?stream_id=4dbb262b4fe5cf15a215de4f34eee34d',
38 'only_matching': True,
39 }, {
40 'url': 'https://frontend.vh.yandex.ru/player/4dbb262b4fe5cf15a215de4f34eee34d?from=morda',
41 'only_matching': True,
42 }, {
43 # vod-episode, series episode
44 'url': 'https://yandex.ru/portal/video?stream_id=45b11db6e4b68797919c93751a938cee',
45 'only_matching': True,
46 }, {
47 # episode, sports
48 'url': 'https://yandex.ru/?stream_channel=1538487871&stream_id=4132a07f71fb0396be93d74b3477131d',
49 'only_matching': True,
50 }]
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54
55 content = self._download_json(
56 'https://frontend.vh.yandex.ru/v22/player/%s.json' % video_id,
57 video_id, query={
58 'stream_options': 'hires',
59 'disable_trackings': 1,
60 })['content']
61
62 m3u8_url = url_or_none(content.get('content_url')) or url_or_none(
63 content['streams'][0]['url'])
64 title = content.get('title') or content.get('computed_title')
65
66 formats = self._extract_m3u8_formats(
67 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
68 m3u8_id='hls')
69 self._sort_formats(formats)
70
71 description = content.get('description')
72 thumbnail = content.get('thumbnail')
73 timestamp = (int_or_none(content.get('release_date'))
74 or int_or_none(content.get('release_date_ut'))
75 or int_or_none(content.get('start_time')))
76 duration = int_or_none(content.get('duration'))
77 series = content.get('program_title')
78 age_limit = int_or_none(content.get('restriction_age'))
79
80 return {
81 'id': video_id,
82 'title': title,
83 'description': description,
84 'thumbnail': thumbnail,
85 'timestamp': timestamp,
86 'duration': duration,
87 'series': series,
88 'age_limit': age_limit,
89 'formats': formats,
90 }