]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rutube.py
2 from __future__
import unicode_literals
7 from . common
import InfoExtractor
17 class RutubeIE ( InfoExtractor
):
19 IE_DESC
= 'Rutube videos'
20 _VALID_URL
= r
'https?://rutube\.ru/video/(?P<id>[\da-z] {32} )'
23 'url' : 'http://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/' ,
25 'id' : '3eac3b4561676c17df9132a9a1e62e3e' ,
27 'title' : 'Раненный кенгуру забежал в аптеку' ,
28 'description' : 'http://www.ntdtv.ru ' ,
30 'uploader' : 'NTDRussian' ,
31 'uploader_id' : '29790' ,
32 'upload_date' : '20131016' ,
36 # It requires ffmpeg (m3u8 download)
37 'skip_download' : True ,
41 def _real_extract ( self
, url
):
42 video_id
= self
._ match
_ id
( url
)
43 video
= self
._ download
_ json
(
44 'http://rutube.ru/api/video/ %s /?format=json' % video_id
,
45 video_id
, 'Downloading video JSON' )
47 # Some videos don't have the author field
48 author
= video
. get ( 'author' ) or {}
50 options
= self
._ download
_ json
(
51 'http://rutube.ru/api/play/options/ %s /?format=json' % video_id
,
52 video_id
, 'Downloading options JSON' )
54 m3u8_url
= options
[ 'video_balancer' ]. get ( 'm3u8' )
56 raise ExtractorError ( 'Couldn \' t find m3u8 manifest url' )
57 formats
= self
._ extract
_ m
3u8_ formats
( m3u8_url
, video_id
, ext
= 'mp4' )
61 'title' : video
[ 'title' ],
62 'description' : video
[ 'description' ],
63 'duration' : video
[ 'duration' ],
64 'view_count' : video
[ 'hits' ],
66 'thumbnail' : video
[ 'thumbnail_url' ],
67 'uploader' : author
. get ( 'name' ),
68 'uploader_id' : compat_str ( author
[ 'id' ]) if author
else None ,
69 'upload_date' : unified_strdate ( video
[ 'created_ts' ]),
70 'age_limit' : 18 if video
[ 'is_adult' ] else 0 ,
74 class RutubeEmbedIE ( InfoExtractor
):
75 IE_NAME
= 'rutube:embed'
76 IE_DESC
= 'Rutube embedded videos'
77 _VALID_URL
= 'https?://rutube\.ru/video/embed/(?P<id>[0-9]+)'
80 'url' : 'http://rutube.ru/video/embed/6722881?vk_puid37=&vk_puid38=' ,
82 'id' : 'a10e53b86e8f349080f718582ce4c661' ,
84 'upload_date' : '20131223' ,
85 'uploader_id' : '297833' ,
86 'description' : 'Видео группы ★http://vk.com/foxkidsreset★ музей Fox Kids и Jetix<br/><br/> восстановлено и сделано в шикоформате subziro89 http://vk.com/subziro89' ,
87 'uploader' : 'subziro89 ILya' ,
88 'title' : 'Мистический городок Эйри в Индиан 5 серия озвучка subziro89' ,
91 'skip_download' : 'Requires ffmpeg' ,
95 def _real_extract ( self
, url
):
96 embed_id
= self
._ match
_ id
( url
)
97 webpage
= self
._ download
_ webpage
( url
, embed_id
)
99 canonical_url
= self
._ html
_ search
_ regex
(
100 r
'<link\s+rel="canonical"\s+href="([^"]+?)"' , webpage
,
102 return self
. url_result ( canonical_url
, 'Rutube' )
105 class RutubeChannelIE ( InfoExtractor
):
106 IE_NAME
= 'rutube:channel'
107 IE_DESC
= 'Rutube channels'
108 _VALID_URL
= r
'http://rutube\.ru/tags/video/(?P<id>\d+)'
110 'url' : 'http://rutube.ru/tags/video/1800/' ,
114 'playlist_mincount' : 68 ,
117 _PAGE_TEMPLATE
= 'http://rutube.ru/api/tags/video/ %s /?page= %s &format=json'
119 def _extract_videos ( self
, channel_id
, channel_title
= None ):
121 for pagenum
in itertools
. count ( 1 ):
122 page
= self
._ download
_ json
(
123 self
._ PAGE
_ TEMPLATE
% ( channel_id
, pagenum
),
124 channel_id
, 'Downloading page %s ' % pagenum
)
125 results
= page
[ 'results' ]
128 entries
. extend ( self
. url_result ( result
[ 'video_url' ], 'Rutube' ) for result
in results
)
129 if not page
[ 'has_next' ]:
131 return self
. playlist_result ( entries
, channel_id
, channel_title
)
133 def _real_extract ( self
, url
):
134 mobj
= re
. match ( self
._ VALID
_U RL
, url
)
135 channel_id
= mobj
. group ( 'id' )
136 return self
._ extract
_ videos
( channel_id
)
139 class RutubeMovieIE ( RutubeChannelIE
):
140 IE_NAME
= 'rutube:movie'
141 IE_DESC
= 'Rutube movies'
142 _VALID_URL
= r
'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
145 _MOVIE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/ %s /?format=json'
146 _PAGE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/ %s /video?page= %s &format=json'
148 def _real_extract ( self
, url
):
149 movie_id
= self
._ match
_ id
( url
)
150 movie
= self
._ download
_ json
(
151 self
._ MOVIE
_ TEMPLATE
% movie_id
, movie_id
,
152 'Downloading movie JSON' )
153 movie_name
= movie
[ 'name' ]
154 return self
._ extract
_ videos
( movie_id
, movie_name
)
157 class RutubePersonIE ( RutubeChannelIE
):
158 IE_NAME
= 'rutube:person'
159 IE_DESC
= 'Rutube person videos'
160 _VALID_URL
= r
'http://rutube\.ru/video/person/(?P<id>\d+)'
162 'url' : 'http://rutube.ru/video/person/313878/' ,
166 'playlist_mincount' : 37 ,
169 _PAGE_TEMPLATE
= 'http://rutube.ru/api/video/person/ %s /?page= %s &format=json'