]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/rutube.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
16 class RutubeIE(InfoExtractor
):
18 IE_DESC
= 'Rutube videos'
19 _VALID_URL
= r
'https?://rutube\.ru/video/(?P<id>[\da-z]{32})'
22 'url': 'http://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/',
23 'file': '3eac3b4561676c17df9132a9a1e62e3e.mp4',
25 'title': 'Раненный кенгуру забежал в аптеку',
26 'uploader': 'NTDRussian',
27 'uploader_id': '29790',
30 # It requires ffmpeg (m3u8 download)
31 'skip_download': True,
35 def _real_extract(self
, url
):
36 mobj
= re
.match(self
._VALID
_URL
, url
)
37 video_id
= mobj
.group('id')
39 api_response
= self
._download
_webpage
('http://rutube.ru/api/video/%s/?format=json' % video_id
,
40 video_id
, 'Downloading video JSON')
41 video
= json
.loads(api_response
)
43 api_response
= self
._download
_webpage
('http://rutube.ru/api/play/trackinfo/%s/?format=json' % video_id
,
44 video_id
, 'Downloading trackinfo JSON')
45 trackinfo
= json
.loads(api_response
)
47 # Some videos don't have the author field
48 author
= trackinfo
.get('author') or {}
49 m3u8_url
= trackinfo
['video_balancer'].get('m3u8')
51 raise ExtractorError('Couldn\'t find m3u8 manifest url')
55 'title': video
['title'],
56 'description': video
['description'],
57 'duration': video
['duration'],
58 'view_count': video
['hits'],
61 'thumbnail': video
['thumbnail_url'],
62 'uploader': author
.get('name'),
63 'uploader_id': compat_str(author
['id']) if author
else None,
64 'upload_date': unified_strdate(video
['created_ts']),
65 'age_limit': 18 if video
['is_adult'] else 0,
69 class RutubeChannelIE(InfoExtractor
):
70 IE_NAME
= 'rutube:channel'
71 IE_DESC
= 'Rutube channels'
72 _VALID_URL
= r
'http://rutube\.ru/tags/video/(?P<id>\d+)'
74 _PAGE_TEMPLATE
= 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json'
76 def _extract_videos(self
, channel_id
, channel_title
=None):
78 for pagenum
in itertools
.count(1):
79 api_response
= self
._download
_webpage
(
80 self
._PAGE
_TEMPLATE
% (channel_id
, pagenum
),
81 channel_id
, 'Downloading page %s' % pagenum
)
82 page
= json
.loads(api_response
)
83 results
= page
['results']
86 entries
.extend(self
.url_result(result
['video_url'], 'Rutube') for result
in results
)
87 if not page
['has_next']:
89 return self
.playlist_result(entries
, channel_id
, channel_title
)
91 def _real_extract(self
, url
):
92 mobj
= re
.match(self
._VALID
_URL
, url
)
93 channel_id
= mobj
.group('id')
94 return self
._extract
_videos
(channel_id
)
97 class RutubeMovieIE(RutubeChannelIE
):
98 IE_NAME
= 'rutube:movie'
99 IE_DESC
= 'Rutube movies'
100 _VALID_URL
= r
'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
102 _MOVIE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/?format=json'
103 _PAGE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json'
105 def _real_extract(self
, url
):
106 mobj
= re
.match(self
._VALID
_URL
, url
)
107 movie_id
= mobj
.group('id')
108 api_response
= self
._download
_webpage
(
109 self
._MOVIE
_TEMPLATE
% movie_id
, movie_id
,
110 'Downloading movie JSON')
111 movie
= json
.loads(api_response
)
112 movie_name
= movie
['name']
113 return self
._extract
_videos
(movie_id
, movie_name
)
116 class RutubePersonIE(RutubeChannelIE
):
117 IE_NAME
= 'rutube:person'
118 IE_DESC
= 'Rutube person videos'
119 _VALID_URL
= r
'http://rutube\.ru/video/person/(?P<id>\d+)'
121 _PAGE_TEMPLATE
= 'http://rutube.ru/api/video/person/%s/?page=%s&format=json'