]>
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/',
24 'id': '3eac3b4561676c17df9132a9a1e62e3e',
26 'title': 'Раненный кенгуру забежал в аптеку',
27 'description': 'http://www.ntdtv.ru ',
29 'uploader': 'NTDRussian',
30 'uploader_id': '29790',
31 'upload_date': '20131016',
34 # It requires ffmpeg (m3u8 download)
35 'skip_download': True,
39 def _real_extract(self
, url
):
40 mobj
= re
.match(self
._VALID
_URL
, url
)
41 video_id
= mobj
.group('id')
43 api_response
= self
._download
_webpage
(
44 'http://rutube.ru/api/video/%s/?format=json' % video_id
,
45 video_id
, 'Downloading video JSON')
46 video
= json
.loads(api_response
)
48 api_response
= self
._download
_webpage
(
49 'http://rutube.ru/api/play/trackinfo/%s/?format=json' % video_id
,
50 video_id
, 'Downloading trackinfo JSON')
51 trackinfo
= json
.loads(api_response
)
53 # Some videos don't have the author field
54 author
= trackinfo
.get('author') or {}
55 m3u8_url
= trackinfo
['video_balancer'].get('m3u8')
57 raise ExtractorError('Couldn\'t find m3u8 manifest url')
61 'title': video
['title'],
62 'description': video
['description'],
63 'duration': video
['duration'],
64 'view_count': video
['hits'],
67 'thumbnail': video
['thumbnail_url'],
68 'uploader': author
.get('name'),
69 'uploader_id': compat_str(author
['id']) if author
else None,
70 'upload_date': unified_strdate(video
['created_ts']),
71 'age_limit': 18 if video
['is_adult'] else 0,
75 class RutubeChannelIE(InfoExtractor
):
76 IE_NAME
= 'rutube:channel'
77 IE_DESC
= 'Rutube channels'
78 _VALID_URL
= r
'http://rutube\.ru/tags/video/(?P<id>\d+)'
80 _PAGE_TEMPLATE
= 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json'
82 def _extract_videos(self
, channel_id
, channel_title
=None):
84 for pagenum
in itertools
.count(1):
85 api_response
= self
._download
_webpage
(
86 self
._PAGE
_TEMPLATE
% (channel_id
, pagenum
),
87 channel_id
, 'Downloading page %s' % pagenum
)
88 page
= json
.loads(api_response
)
89 results
= page
['results']
92 entries
.extend(self
.url_result(result
['video_url'], 'Rutube') for result
in results
)
93 if not page
['has_next']:
95 return self
.playlist_result(entries
, channel_id
, channel_title
)
97 def _real_extract(self
, url
):
98 mobj
= re
.match(self
._VALID
_URL
, url
)
99 channel_id
= mobj
.group('id')
100 return self
._extract
_videos
(channel_id
)
103 class RutubeMovieIE(RutubeChannelIE
):
104 IE_NAME
= 'rutube:movie'
105 IE_DESC
= 'Rutube movies'
106 _VALID_URL
= r
'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
108 _MOVIE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/?format=json'
109 _PAGE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json'
111 def _real_extract(self
, url
):
112 mobj
= re
.match(self
._VALID
_URL
, url
)
113 movie_id
= mobj
.group('id')
114 api_response
= self
._download
_webpage
(
115 self
._MOVIE
_TEMPLATE
% movie_id
, movie_id
,
116 'Downloading movie JSON')
117 movie
= json
.loads(api_response
)
118 movie_name
= movie
['name']
119 return self
._extract
_videos
(movie_id
, movie_name
)
122 class RutubePersonIE(RutubeChannelIE
):
123 IE_NAME
= 'rutube:person'
124 IE_DESC
= 'Rutube person videos'
125 _VALID_URL
= r
'http://rutube\.ru/video/person/(?P<id>\d+)'
127 _PAGE_TEMPLATE
= 'http://rutube.ru/api/video/person/%s/?page=%s&format=json'