]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/myvi.py
debian/changelog: Reword for better consumption of users.
[youtubedl] / youtube_dl / extractor / myvi.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .vimple import SprutoBaseIE
8
9
10 class MyviIE(SprutoBaseIE):
11 _VALID_URL = r'''(?x)
12 (?:
13 https?://
14 (?:www\.)?
15 myvi\.
16 (?:
17 (?:ru/player|tv)/
18 (?:
19 (?:
20 embed/html|
21 flash|
22 api/Video/Get
23 )/|
24 content/preloader\.swf\?.*\bid=
25 )|
26 ru/watch/
27 )|
28 myvi:
29 )
30 (?P<id>[\da-zA-Z_-]+)
31 '''
32 _TESTS = [{
33 'url': 'http://myvi.ru/player/embed/html/oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wObeRTZaCATzucDQIDph8hQU0',
34 'md5': '571bbdfba9f9ed229dc6d34cc0f335bf',
35 'info_dict': {
36 'id': 'f16b2bbd-cde8-481c-a981-7cd48605df43',
37 'ext': 'mp4',
38 'title': 'хозяин жизни',
39 'thumbnail': r're:^https?://.*\.jpg$',
40 'duration': 25,
41 },
42 }, {
43 'url': 'http://myvi.ru/player/content/preloader.swf?id=oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wOYf1WFpPfc_bWTKGVf_Zafr0',
44 'only_matching': True,
45 }, {
46 'url': 'http://myvi.ru/player/api/Video/Get/oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wObeRTZaCATzucDQIDph8hQU0',
47 'only_matching': True,
48 }, {
49 'url': 'http://myvi.tv/embed/html/oTGTNWdyz4Zwy_u1nraolwZ1odenTd9WkTnRfIL9y8VOgHYqOHApE575x4_xxS9Vn0?ap=0',
50 'only_matching': True,
51 }, {
52 'url': 'http://myvi.ru/player/flash/ocp2qZrHI-eZnHKQBK4cZV60hslH8LALnk0uBfKsB-Q4WnY26SeGoYPi8HWHxu0O30',
53 'only_matching': True,
54 }, {
55 'url': 'https://www.myvi.ru/watch/YwbqszQynUaHPn_s82sx0Q2',
56 'only_matching': True,
57 }, {
58 'url': 'myvi:YwbqszQynUaHPn_s82sx0Q2',
59 'only_matching': True,
60 }]
61
62 @classmethod
63 def _extract_url(cls, webpage):
64 mobj = re.search(
65 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//myvi\.(?:ru/player|tv)/(?:embed/html|flash)/[^"]+)\1', webpage)
66 if mobj:
67 return mobj.group('url')
68
69 def _real_extract(self, url):
70 video_id = self._match_id(url)
71
72 spruto = self._download_json(
73 'http://myvi.ru/player/api/Video/Get/%s?sig' % video_id, video_id)['sprutoData']
74
75 return self._extract_spruto(spruto, video_id)
76
77
78 class MyviEmbedIE(InfoExtractor):
79 _VALID_URL = r'https?://(?:www\.)?myvi\.tv/(?:[^?]+\?.*?\bv=|embed/)(?P<id>[\da-z]+)'
80 _TESTS = [{
81 'url': 'https://www.myvi.tv/embed/ccdqic3wgkqwpb36x9sxg43t4r',
82 'info_dict': {
83 'id': 'b3ea0663-3234-469d-873e-7fecf36b31d1',
84 'ext': 'mp4',
85 'title': 'Твоя (original song).mp4',
86 'thumbnail': r're:^https?://.*\.jpg$',
87 'duration': 277,
88 },
89 'params': {
90 'skip_download': True,
91 },
92 }, {
93 'url': 'https://www.myvi.tv/idmi6o?v=ccdqic3wgkqwpb36x9sxg43t4r#watch',
94 'only_matching': True,
95 }]
96
97 @classmethod
98 def suitable(cls, url):
99 return False if MyviIE.suitable(url) else super(MyviEmbedIE, cls).suitable(url)
100
101 def _real_extract(self, url):
102 video_id = self._match_id(url)
103
104 webpage = self._download_webpage(
105 'https://www.myvi.tv/embed/%s' % video_id, video_id)
106
107 myvi_id = self._search_regex(
108 r'CreatePlayer\s*\(\s*["\'].*?\bv=([\da-zA-Z_]+)',
109 webpage, 'video id')
110
111 return self.url_result('myvi:%s' % myvi_id, ie=MyviIE.ie_key())