]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/vice.py
2 from __future__
import unicode_literals
9 from . adobepass
import AdobePassIE
10 from . common
import InfoExtractor
11 from .. compat
import compat_HTTPError
22 class ViceBaseIE ( AdobePassIE
):
23 def _extract_preplay_video ( self
, url
, locale
, webpage
):
24 watch_hub_data
= extract_attributes ( self
._ search
_ regex
(
25 r
'(?s)(<watch-hub\s*.+?</watch-hub>)' , webpage
, 'watch hub' ))
26 video_id
= watch_hub_data
[ 'vms-id' ]
27 title
= watch_hub_data
[ 'video-title' ]
30 is_locked
= watch_hub_data
. get ( 'video-locked' ) == '1'
32 resource
= self
._ get
_ mvpd
_ resource
(
33 'VICELAND' , title
, video_id
,
34 watch_hub_data
. get ( 'video-rating' ))
35 query
[ 'tvetoken' ] = self
._ extract
_ mvpd
_ auth
( url
, video_id
, 'VICELAND' , resource
)
37 # signature generation algorithm is reverse engineered from signatureGenerator in
38 # webpack:///../shared/~/vice-player/dist/js/vice-player.js in
39 # https://www.viceland.com/assets/common/js/web.vendor.bundle.js
40 exp
= int ( time
. time ()) + 14400
43 'sign' : hashlib
. sha512 (( ' %s :GET: %d ' % ( video_id
, exp
)). encode ()). hexdigest (),
47 host
= 'www.viceland' if is_locked
else self
._ PREPLAY
_ HOST
48 preplay
= self
._ download
_ json
( 'https:// %s .com/ %s /preplay/ %s ' % ( host
, locale
, video_id
), video_id
, query
= query
)
49 except ExtractorError
as e
:
50 if isinstance ( e
. cause
, compat_HTTPError
) and e
. cause
. code
== 400 :
51 error
= json
. loads ( e
. cause
. read (). decode ())
52 raise ExtractorError ( ' %s said: %s ' % ( self
. IE_NAME
, error
[ 'details' ]), expected
= True )
55 video_data
= preplay
[ 'video' ]
56 base
= video_data
[ 'base' ]
57 uplynk_preplay_url
= preplay
[ 'preplayURL' ]
58 episode
= video_data
. get ( 'episode' , {})
59 channel
= video_data
. get ( 'channel' , {})
62 cc_url
= preplay
. get ( 'ccURL' )
69 '_type' : 'url_transparent' ,
70 'url' : uplynk_preplay_url
,
73 'description' : base
. get ( 'body' ) or base
. get ( 'display_body' ),
74 'thumbnail' : watch_hub_data
. get ( 'cover-image' ) or watch_hub_data
. get ( 'thumbnail' ),
75 'duration' : int_or_none ( video_data
. get ( 'video_duration' )) or parse_duration ( watch_hub_data
. get ( 'video-duration' )),
76 'timestamp' : int_or_none ( video_data
. get ( 'created_at' ), 1000 ),
77 'age_limit' : parse_age_limit ( video_data
. get ( 'video_rating' )),
78 'series' : video_data
. get ( 'show_title' ) or watch_hub_data
. get ( 'show-title' ),
79 'episode_number' : int_or_none ( episode
. get ( 'episode_number' ) or watch_hub_data
. get ( 'episode' )),
80 'episode_id' : str_or_none ( episode
. get ( 'id' ) or video_data
. get ( 'episode_id' )),
81 'season_number' : int_or_none ( watch_hub_data
. get ( 'season' )),
82 'season_id' : str_or_none ( episode
. get ( 'season_id' )),
83 'uploader' : channel
. get ( 'base' , {}). get ( 'title' ) or watch_hub_data
. get ( 'channel-title' ),
84 'uploader_id' : str_or_none ( channel
. get ( 'id' )),
85 'subtitles' : subtitles
,
86 'ie_key' : 'UplynkPreplay' ,
90 class ViceIE ( ViceBaseIE
):
91 _VALID_URL
= r
'https?://(?:.+?\.)?vice\.com/(?P<locale>[^/]+)/(?:[^/]+/)?videos?/(?P<id>[^/?#&]+)'
94 'url' : 'http://www.vice.com/video/cowboy-capitalists-part-1' ,
95 'md5' : 'e9d77741f9e42ba583e683cd170660f7' ,
97 'id' : '43cW1mYzpia9IlestBjVpd23Yu3afAfp' ,
99 'title' : 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov' ,
102 'add_ie' : [ 'Ooyala' ],
104 'url' : 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56' ,
106 'id' : '5816510690b70e6c5fd39a56' ,
108 'uploader' : 'Waypoint' ,
109 'title' : 'The Signal From Tölva' ,
110 'description' : 'md5:3927e3c79f9e8094606a2b3c5b5e55d5' ,
111 'uploader_id' : '57f7d621e05ca860fa9ccaf9' ,
112 'timestamp' : 1477941983 ,
113 'upload_date' : '20161031' ,
117 'skip_download' : True ,
119 'add_ie' : [ 'UplynkPreplay' ],
121 'url' : 'https://video.vice.com/alps/video/ulfs-wien-beruchtigste-grafitti-crew-part-1/581b12b60a0e1f4c0fb6ea2f' ,
123 'id' : '581b12b60a0e1f4c0fb6ea2f' ,
125 'title' : 'ULFs - Wien berüchtigste Grafitti Crew - Part 1' ,
126 'description' : '<p>Zwischen Hinterzimmer-Tattoos und U-Bahnschächten erzählen uns die Ulfs, wie es ist, "süchtig nach Sachbeschädigung" zu sein.</p>' ,
128 'uploader_id' : '57a204088cb727dec794c67b' ,
129 'timestamp' : 1485368119 ,
130 'upload_date' : '20170125' ,
135 'skip_download' : True ,
137 'add_ie' : [ 'UplynkPreplay' ],
139 'url' : 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab' ,
140 'only_matching' : True ,
142 'url' : 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229' ,
143 'only_matching' : True ,
145 'url' : 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show' ,
146 'only_matching' : True ,
148 _PREPLAY_HOST
= 'video.vice'
150 def _real_extract ( self
, url
):
151 mobj
= re
. match ( self
._ VALID
_U RL
, url
)
152 video_id
= mobj
. group ( 'id' )
153 locale
= mobj
. group ( 'locale' )
154 video_id
= self
._ match
_ id
( url
)
155 webpage
, urlh
= self
._ download
_ webpage
_ handle
( url
, video_id
)
156 embed_code
= self
._ search
_ regex
(
157 r
'embedCode=([^&\' "]+)', webpage,
158 'ooyala embed code', default=None)
160 return self.url_result('ooyala: %s ' % embed_code, 'Ooyala')
161 youtube_id = self._search_regex(
162 r'data-youtube-id=" ([ ^
"]+)" ', webpage, ' youtube
id ', default=None)
164 return self.url_result(youtube_id, ' Youtube
')
165 return self._extract_preplay_video(urlh.geturl(), locale, webpage)
168 class ViceShowIE(InfoExtractor):
169 _VALID_URL = r' https?
://( ?
:.+ ?\
.) ?vice\
. com
/( ?
:[ ^
/]+/) ?show
/( ?P
< id >[ ^
/ ?
#&]+)'
172 'url' : 'https://munchies.vice.com/en/show/fuck-thats-delicious-2' ,
174 'id' : 'fuck-thats-delicious-2' ,
175 'title' : "Fuck, That's Delicious" ,
176 'description' : 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.' ,
178 'playlist_count' : 17 ,
181 def _real_extract ( self
, url
):
182 show_id
= self
._ match
_ id
( url
)
183 webpage
= self
._ download
_ webpage
( url
, show_id
)
186 self
. url_result ( video_url
, ViceIE
. ie_key ())
187 for video_url
, _
in re
. findall (
188 r
'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="( %s .*?)"'
189 % ViceIE
._ VALID
_U RL
, webpage
)]
191 title
= self
._ search
_ regex
(
192 r
'<title>(.+?)</title>' , webpage
, 'title' , default
= None )
194 title
= re
. sub ( r
'(.+)\s*\|\s*.+$' , r
'\1' , title
). strip ()
195 description
= self
._ html
_ search
_ meta
( 'description' , webpage
, 'description' )
197 return self
. playlist_result ( entries
, show_id
, title
, description
)
200 class ViceArticleIE ( InfoExtractor
):
201 _VALID_URL
= r
'https://www.vice.com/[^/]+/article/(?P<id>[^?#]+)'
204 'url' : 'https://www.vice.com/en_us/article/on-set-with-the-woman-making-mormon-porn-in-utah' ,
206 'id' : '58dc0a3dee202d2a0ccfcbd8' ,
208 'title' : 'Mormon War on Porn ' ,
209 'description' : 'md5:ad396a2481e7f8afb5ed486878421090' ,
211 'uploader_id' : '57a204088cb727dec794c693' ,
212 'timestamp' : 1489160690 ,
213 'upload_date' : '20170310' ,
217 'skip_download' : True ,
220 'url' : 'http://www.vice.com/video/how-to-hack-a-car' ,
221 'md5' : 'a7ecf64ee4fa19b916c16f4b56184ae2' ,
225 'title' : 'How to Hack a Car: Phreaked Out (Episode 2)' ,
226 'description' : 'md5:ee95453f7ff495db8efe14ae8bf56f30' ,
227 'uploader_id' : 'MotherboardTV' ,
228 'uploader' : 'Motherboard' ,
229 'upload_date' : '20140529' ,
231 'add_ie' : [ 'Youtube' ],
234 def _real_extract ( self
, url
):
235 display_id
= self
._ match
_ id
( url
)
237 webpage
= self
._ download
_ webpage
( url
, display_id
)
239 prefetch_data
= self
._ parse
_ json
( self
._ search
_ regex
(
240 r
'window\.__PREFETCH_DATA\s*=\s*( {.*} );' ,
241 webpage
, 'prefetch data' ), display_id
)
242 body
= prefetch_data
[ 'body' ]
243 youtube_url
= self
._ html
_ search
_ regex
(
244 r
'<iframe[^>]+src="(.*youtube\.com/.*)"' , body
, 'YouTube URL' , default
= None )
247 '_type' : 'url_transparent' ,
249 'display_id' : display_id
,
253 video_url
= self
._ html
_ search
_ regex
(
254 r
'data-video-url="([^"]+)"' , prefetch_data
[ 'embed_code' ], 'video URL' )
257 '_type' : 'url_transparent' ,
259 'display_id' : display_id
,
260 'ie_key' : ViceIE
. ie_key (),