]>
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' ,
35 # It requires ffmpeg (m3u8 download)
36 'skip_download' : True ,
40 def _real_extract ( self
, url
):
41 video_id
= self
._ match
_ id
( url
)
42 video
= self
._ download
_ json
(
43 'http://rutube.ru/api/video/ %s /?format=json' % video_id
,
44 video_id
, 'Downloading video JSON' )
46 # Some videos don't have the author field
47 author
= video
. get ( 'author' ) or {}
49 options
= self
._ download
_ json
(
50 'http://rutube.ru/api/play/options/ %s /?format=json' % video_id
,
51 video_id
, 'Downloading options JSON' )
53 m3u8_url
= options
[ 'video_balancer' ]. get ( 'm3u8' )
55 raise ExtractorError ( 'Couldn \' t find m3u8 manifest url' )
56 formats
= self
._ extract
_ m
3u8_ formats
( m3u8_url
, video_id
, ext
= 'mp4' )
60 'title' : video
[ 'title' ],
61 'description' : video
[ 'description' ],
62 'duration' : video
[ 'duration' ],
63 'view_count' : video
[ 'hits' ],
65 'thumbnail' : video
[ 'thumbnail_url' ],
66 'uploader' : author
. get ( 'name' ),
67 'uploader_id' : compat_str ( author
[ 'id' ]) if author
else None ,
68 'upload_date' : unified_strdate ( video
[ 'created_ts' ]),
69 'age_limit' : 18 if video
[ 'is_adult' ] else 0 ,
73 class RutubeEmbedIE ( InfoExtractor
):
74 IE_NAME
= 'rutube:embed'
75 IE_DESC
= 'Rutube embedded videos'
76 _VALID_URL
= 'https?://rutube\.ru/video/embed/(?P<id>[0-9]+)'
79 'url' : 'http://rutube.ru/video/embed/6722881?vk_puid37=&vk_puid38=' ,
81 'id' : 'a10e53b86e8f349080f718582ce4c661' ,
83 'upload_date' : '20131223' ,
84 'uploader_id' : '297833' ,
85 'description' : 'Видео группы ★http://vk.com/foxkidsreset★ музей Fox Kids и Jetix<br/><br/> восстановлено и сделано в шикоформате subziro89 http://vk.com/subziro89' ,
86 'uploader' : 'subziro89 ILya' ,
87 'title' : 'Мистический городок Эйри в Индиан 5 серия озвучка subziro89' ,
90 'skip_download' : 'Requires ffmpeg' ,
94 def _real_extract ( self
, url
):
95 embed_id
= self
._ match
_ id
( url
)
96 webpage
= self
._ download
_ webpage
( url
, embed_id
)
98 canonical_url
= self
._ html
_ search
_ regex
(
99 r
'<link\s+rel="canonical"\s+href="([^"]+?)"' , webpage
,
101 return self
. url_result ( canonical_url
, 'Rutube' )
104 class RutubeChannelIE ( InfoExtractor
):
105 IE_NAME
= 'rutube:channel'
106 IE_DESC
= 'Rutube channels'
107 _VALID_URL
= r
'http://rutube\.ru/tags/video/(?P<id>\d+)'
109 'url' : 'http://rutube.ru/tags/video/1800/' ,
113 'playlist_mincount' : 68 ,
116 _PAGE_TEMPLATE
= 'http://rutube.ru/api/tags/video/ %s /?page= %s &format=json'
118 def _extract_videos ( self
, channel_id
, channel_title
= None ):
120 for pagenum
in itertools
. count ( 1 ):
121 page
= self
._ download
_ json
(
122 self
._ PAGE
_ TEMPLATE
% ( channel_id
, pagenum
),
123 channel_id
, 'Downloading page %s ' % pagenum
)
124 results
= page
[ 'results' ]
127 entries
. extend ( self
. url_result ( result
[ 'video_url' ], 'Rutube' ) for result
in results
)
128 if not page
[ 'has_next' ]:
130 return self
. playlist_result ( entries
, channel_id
, channel_title
)
132 def _real_extract ( self
, url
):
133 mobj
= re
. match ( self
._ VALID
_U RL
, url
)
134 channel_id
= mobj
. group ( 'id' )
135 return self
._ extract
_ videos
( channel_id
)
138 class RutubeMovieIE ( RutubeChannelIE
):
139 IE_NAME
= 'rutube:movie'
140 IE_DESC
= 'Rutube movies'
141 _VALID_URL
= r
'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
144 _MOVIE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/ %s /?format=json'
145 _PAGE_TEMPLATE
= 'http://rutube.ru/api/metainfo/tv/ %s /video?page= %s &format=json'
147 def _real_extract ( self
, url
):
148 movie_id
= self
._ match
_ id
( url
)
149 movie
= self
._ download
_ json
(
150 self
._ MOVIE
_ TEMPLATE
% movie_id
, movie_id
,
151 'Downloading movie JSON' )
152 movie_name
= movie
[ 'name' ]
153 return self
._ extract
_ videos
( movie_id
, movie_name
)
156 class RutubePersonIE ( RutubeChannelIE
):
157 IE_NAME
= 'rutube:person'
158 IE_DESC
= 'Rutube person videos'
159 _VALID_URL
= r
'http://rutube\.ru/video/person/(?P<id>\d+)'
161 'url' : 'http://rutube.ru/video/person/313878/' ,
165 'playlist_mincount' : 37 ,
168 _PAGE_TEMPLATE
= 'http://rutube.ru/api/video/person/ %s /?page= %s &format=json'