]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vice.py
8a00c8fee17ee84ae0d8d0e1e7360ca67befc8b0
   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
, 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/en_us/preplay/%s' % (host
, 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'), 
  74             'thumbnail': watch_hub_data
.get('cover-image') or watch_hub_data
.get('thumbnail'), 
  75             'duration': parse_duration(video_data
.get('video_duration') or watch_hub_data
.get('video-duration')), 
  76             'timestamp': int_or_none(video_data
.get('created_at')), 
  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/(?:[^/]+/)?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': 'http://www.vice.com/video/how-to-hack-a-car', 
 105         'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2', 
 109             'title': 'How to Hack a Car: Phreaked Out (Episode 2)', 
 110             'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30', 
 111             'uploader_id': 'MotherboardTV', 
 112             'uploader': 'Motherboard', 
 113             'upload_date': '20140529', 
 115         'add_ie': ['Youtube'], 
 117         'url': 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56', 
 120             'id': '5816510690b70e6c5fd39a56', 
 122             'uploader': 'Waypoint', 
 123             'title': 'The Signal From Tölva', 
 124             'uploader_id': '57f7d621e05ca860fa9ccaf9', 
 125             'timestamp': 1477941983938, 
 129             'skip_download': True, 
 131         'add_ie': ['UplynkPreplay'], 
 133         'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab', 
 134         'only_matching': True, 
 136         'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229', 
 137         'only_matching': True, 
 139         'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show', 
 140         'only_matching': True, 
 142     _PREPLAY_HOST 
= 'video.vice' 
 144     def _real_extract(self
, url
): 
 145         video_id 
= self
._match
_id
(url
) 
 146         webpage
, urlh 
= self
._download
_webpage
_handle
(url
, video_id
) 
 147         embed_code 
= self
._search
_regex
( 
 148             r
'embedCode=([^&\'"]+)', webpage, 
 149             'ooyala embed code', default=None) 
 151             return self.url_result('ooyala:%s' % embed_code, 'Ooyala') 
 152         youtube_id = self._search_regex( 
 153             r'data-youtube-id="([^
"]+)"', webpage, 'youtube 
id', default=None) 
 155             return self.url_result(youtube_id, 'Youtube
') 
 156         return self._extract_preplay_video(urlh.geturl(), webpage) 
 159 class ViceShowIE(InfoExtractor): 
 160     _VALID_URL = r'https?
://(?
:.+?\
.)?vice\
.com
/(?
:[^
/]+/)?show
/(?P
<id>[^
/?
#&]+)' 
 163         'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2', 
 165             'id': 'fuck-thats-delicious-2', 
 166             'title': "Fuck, That's Delicious", 
 167             'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.', 
 169         'playlist_count': 17, 
 172     def _real_extract(self
, url
): 
 173         show_id 
= self
._match
_id
(url
) 
 174         webpage 
= self
._download
_webpage
(url
, show_id
) 
 177             self
.url_result(video_url
, ViceIE
.ie_key()) 
 178             for video_url
, _ 
in re
.findall( 
 179                 r
'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"' 
 180                 % ViceIE
._VALID
_URL
, webpage
)] 
 182         title 
= self
._search
_regex
( 
 183             r
'<title>(.+?)</title>', webpage
, 'title', default
=None) 
 185             title 
= re
.sub(r
'(.+)\s*\|\s*.+$', r
'\1', title
).strip() 
 186         description 
= self
._html
_search
_meta
('description', webpage
, 'description') 
 188         return self
.playlist_result(entries
, show_id
, title
, description
)