]>
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
(self
._PAGE
_TEMPLATE
% (channel_id
, pagenum
),
80 channel_id
, 'Downloading page %s' % pagenum
)
81 page
= json
.loads(api_response
)
82 results
= page
['results']
85 entries
.extend(self
.url_result(result
['video_url'], 'Rutube') for result
in results
)
86 if page
['has_next'] is False:
88 return self
.playlist_result(entries
, channel_id
, channel_title
)
90 def _real_extract(self
, url
):
91 mobj
= re
.match(self
._VALID
_URL
, url
)
92 channel_id
= mobj
.group('id')
93 return self
._extract
_videos
(channel_id
)
96 class RutubeMovieIE(RutubeChannelIE
):
97 IE_NAME
= 'rutube:movie'
98 IE_DESC
= 'Rutube movies'
99 _VALID_URL
= r
'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
101 _MOVIE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/?format=json'
102 _PAGE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json'
104 def _real_extract(self
, url
):
105 mobj
= re
.match(self
._VALID
_URL
, url
)
106 movie_id
= mobj
.group('id')
107 api_response
= self
._download
_webpage
(self
._MOVIE
_TEMPLATE
% movie_id
, movie_id
,
108 'Downloading movie JSON')
109 movie
= json
.loads(api_response
)
110 movie_name
= movie
['name']
111 return self
._extract
_videos
(movie_id
, movie_name
)
114 class RutubePersonIE(RutubeChannelIE
):
115 IE_NAME
= 'rutube:person'
116 IE_DESC
= 'Rutube person videos'
117 _VALID_URL
= r
'http://rutube\.ru/video/person/(?P<id>\d+)'
119 _PAGE_TEMPLATE
= 'http://rutube.ru/api/video/person/%s/?page=%s&format=json'