2020-01-05 10:32:43 -05:00
|
|
|
|
import functools
|
2016-11-03 05:37:07 -04:00
|
|
|
|
import hashlib
|
|
|
|
|
import json
|
2018-03-03 11:07:29 -05:00
|
|
|
|
import random
|
2020-01-05 10:32:43 -05:00
|
|
|
|
import time
|
2016-03-13 07:22:23 -04:00
|
|
|
|
|
2016-11-03 05:37:07 -04:00
|
|
|
|
from .adobepass import AdobePassIE
|
2014-11-06 15:44:07 -05:00
|
|
|
|
from .common import InfoExtractor
|
2020-01-05 10:32:43 -05:00
|
|
|
|
from .youtube import YoutubeIE
|
2023-07-09 03:53:02 -04:00
|
|
|
|
from ..compat import compat_str
|
|
|
|
|
from ..networking.exceptions import HTTPError
|
2016-11-03 05:37:07 -04:00
|
|
|
|
from ..utils import (
|
2020-01-05 10:32:43 -05:00
|
|
|
|
clean_html,
|
2018-03-03 11:07:29 -05:00
|
|
|
|
ExtractorError,
|
2016-11-03 05:37:07 -04:00
|
|
|
|
int_or_none,
|
2020-01-05 10:32:43 -05:00
|
|
|
|
OnDemandPagedList,
|
2016-11-03 05:37:07 -04:00
|
|
|
|
parse_age_limit,
|
|
|
|
|
str_or_none,
|
2018-03-03 11:07:29 -05:00
|
|
|
|
try_get,
|
2016-11-03 05:37:07 -04:00
|
|
|
|
)
|
2014-11-06 15:44:07 -05:00
|
|
|
|
|
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
class ViceBaseIE(InfoExtractor):
|
|
|
|
|
def _call_api(self, resource, resource_key, resource_id, locale, fields, args=''):
|
|
|
|
|
return self._download_json(
|
|
|
|
|
'https://video.vice.com/api/v1/graphql', resource_id, query={
|
|
|
|
|
'query': '''{
|
|
|
|
|
%s(locale: "%s", %s: "%s"%s) {
|
|
|
|
|
%s
|
|
|
|
|
}
|
|
|
|
|
}''' % (resource, locale, resource_key, resource_id, args, fields),
|
|
|
|
|
})['data'][resource]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ViceIE(ViceBaseIE, AdobePassIE):
|
2018-03-03 11:07:29 -05:00
|
|
|
|
IE_NAME = 'vice'
|
2020-01-05 10:32:43 -05:00
|
|
|
|
_VALID_URL = r'https?://(?:(?:video|vms)\.vice|(?:www\.)?vice(?:land|tv))\.com/(?P<locale>[^/]+)/(?:video/[^/]+|embed)/(?P<id>[\da-f]{24})'
|
2022-07-31 21:23:25 -04:00
|
|
|
|
_EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=["\'](?P<url>(?:https?:)?//video\.vice\.com/[^/]+/embed/[\da-f]{24})']
|
2018-03-03 11:07:29 -05:00
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://video.vice.com/en_us/video/pet-cremator/58c69e38a55424f1227dc3f7',
|
|
|
|
|
'info_dict': {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'id': '58c69e38a55424f1227dc3f7',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '10 Questions You Always Wanted To Ask: Pet Cremator',
|
|
|
|
|
'description': 'md5:fe856caacf61fe0e74fab15ce2b07ca5',
|
|
|
|
|
'uploader': 'vice',
|
|
|
|
|
'uploader_id': '57a204088cb727dec794c67b',
|
|
|
|
|
'timestamp': 1489664942,
|
|
|
|
|
'upload_date': '20170316',
|
|
|
|
|
'age_limit': 14,
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
# geo restricted to US
|
|
|
|
|
'url': 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56',
|
|
|
|
|
'info_dict': {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'id': '5816510690b70e6c5fd39a56',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'ext': 'mp4',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'uploader': 'vice',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'title': 'The Signal From Tölva',
|
|
|
|
|
'description': 'md5:3927e3c79f9e8094606a2b3c5b5e55d5',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'uploader_id': '57a204088cb727dec794c67b',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'timestamp': 1477941983,
|
|
|
|
|
'upload_date': '20161031',
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://video.vice.com/alps/video/ulfs-wien-beruchtigste-grafitti-crew-part-1/581b12b60a0e1f4c0fb6ea2f',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '581b12b60a0e1f4c0fb6ea2f',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'ULFs - Wien berüchtigste Grafitti Crew - Part 1',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'description': 'Zwischen Hinterzimmer-Tattoos und U-Bahnschächten erzählen uns die Ulfs, wie es ist, "süchtig nach Sachbeschädigung" zu sein.',
|
|
|
|
|
'uploader': 'vice',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'uploader_id': '57a204088cb727dec794c67b',
|
|
|
|
|
'timestamp': 1485368119,
|
|
|
|
|
'upload_date': '20170125',
|
|
|
|
|
'age_limit': 14,
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# AES-encrypted m3u8
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://video.vice.com/en_us/video/pizza-show-trailer/56d8c9a54d286ed92f7f30e4',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://video.vice.com/en_us/embed/57f41d3556a0a80f54726060',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://vms.vice.com/en_us/video/preplay/58c69e38a55424f1227dc3f7',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.viceland.com/en_us/video/thursday-march-1-2018/5a8f2d7ff1cdb332dd446ec1',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
locale, video_id = self._match_valid_url(url).groups()
|
2018-03-03 11:07:29 -05:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
video = self._call_api('videos', 'id', video_id, locale, '''body
|
|
|
|
|
locked
|
|
|
|
|
rating
|
|
|
|
|
thumbnail_url
|
|
|
|
|
title''')[0]
|
|
|
|
|
title = video['title'].strip()
|
2018-03-03 11:07:29 -05:00
|
|
|
|
rating = video.get('rating')
|
2016-11-03 05:37:07 -04:00
|
|
|
|
|
|
|
|
|
query = {}
|
2020-01-05 10:32:43 -05:00
|
|
|
|
if video.get('locked'):
|
2016-11-03 05:37:07 -04:00
|
|
|
|
resource = self._get_mvpd_resource(
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'VICELAND', title, video_id, rating)
|
2017-05-05 11:12:40 -04:00
|
|
|
|
query['tvetoken'] = self._extract_mvpd_auth(
|
|
|
|
|
url, video_id, 'VICELAND', resource)
|
2016-11-03 05:37:07 -04:00
|
|
|
|
|
|
|
|
|
# signature generation algorithm is reverse engineered from signatureGenerator in
|
|
|
|
|
# webpack:///../shared/~/vice-player/dist/js/vice-player.js in
|
|
|
|
|
# https://www.viceland.com/assets/common/js/web.vendor.bundle.js
|
2018-03-03 11:07:29 -05:00
|
|
|
|
# new JS is located here https://vice-web-statics-cdn.vice.com/vice-player/player-embed.js
|
|
|
|
|
exp = int(time.time()) + 1440
|
|
|
|
|
|
2016-11-03 05:37:07 -04:00
|
|
|
|
query.update({
|
|
|
|
|
'exp': exp,
|
|
|
|
|
'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(),
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'skipadstitching': 1,
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'platform': 'desktop',
|
|
|
|
|
'rn': random.randint(10000, 100000),
|
2016-11-03 05:37:07 -04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try:
|
2017-05-05 11:12:40 -04:00
|
|
|
|
preplay = self._download_json(
|
2019-01-27 04:53:38 -05:00
|
|
|
|
'https://vms.vice.com/%s/video/preplay/%s' % (locale, video_id),
|
2017-05-05 11:12:40 -04:00
|
|
|
|
video_id, query=query)
|
2016-11-03 05:37:07 -04:00
|
|
|
|
except ExtractorError as e:
|
2023-07-09 03:53:02 -04:00
|
|
|
|
if isinstance(e.cause, HTTPError) and e.cause.status in (400, 401):
|
|
|
|
|
error = json.loads(e.cause.response.read().decode())
|
2018-03-03 11:07:29 -05:00
|
|
|
|
error_message = error.get('error_description') or error['details']
|
2017-05-05 11:12:40 -04:00
|
|
|
|
raise ExtractorError('%s said: %s' % (
|
2018-03-03 11:07:29 -05:00
|
|
|
|
self.IE_NAME, error_message), expected=True)
|
2016-11-03 05:37:07 -04:00
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
video_data = preplay['video']
|
2020-01-05 10:32:43 -05:00
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
|
preplay['playURL'], video_id, 'mp4', 'm3u8_native')
|
|
|
|
|
episode = video_data.get('episode') or {}
|
|
|
|
|
channel = video_data.get('channel') or {}
|
|
|
|
|
season = video_data.get('season') or {}
|
2016-11-03 05:37:07 -04:00
|
|
|
|
|
|
|
|
|
subtitles = {}
|
2020-01-05 10:32:43 -05:00
|
|
|
|
for subtitle in preplay.get('subtitleURLs', []):
|
|
|
|
|
cc_url = subtitle.get('url')
|
|
|
|
|
if not cc_url:
|
|
|
|
|
continue
|
|
|
|
|
language_code = try_get(subtitle, lambda x: x['languages'][0]['language_code'], compat_str) or 'en'
|
|
|
|
|
subtitles.setdefault(language_code, []).append({
|
2016-11-03 05:37:07 -04:00
|
|
|
|
'url': cc_url,
|
2020-01-05 10:32:43 -05:00
|
|
|
|
})
|
2016-11-03 05:37:07 -04:00
|
|
|
|
|
|
|
|
|
return {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'formats': formats,
|
2016-11-03 05:37:07 -04:00
|
|
|
|
'id': video_id,
|
|
|
|
|
'title': title,
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'description': clean_html(video.get('body')),
|
|
|
|
|
'thumbnail': video.get('thumbnail_url'),
|
|
|
|
|
'duration': int_or_none(video_data.get('video_duration')),
|
2017-02-18 03:52:43 -05:00
|
|
|
|
'timestamp': int_or_none(video_data.get('created_at'), 1000),
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'age_limit': parse_age_limit(video_data.get('video_rating') or rating),
|
|
|
|
|
'series': try_get(video_data, lambda x: x['show']['base']['display_title'], compat_str),
|
|
|
|
|
'episode_number': int_or_none(episode.get('episode_number')),
|
2016-11-03 05:37:07 -04:00
|
|
|
|
'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')),
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'season_number': int_or_none(season.get('season_number')),
|
|
|
|
|
'season_id': str_or_none(season.get('id') or video_data.get('season_id')),
|
|
|
|
|
'uploader': channel.get('name'),
|
2016-11-03 05:37:07 -04:00
|
|
|
|
'uploader_id': str_or_none(channel.get('id')),
|
|
|
|
|
'subtitles': subtitles,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
class ViceShowIE(ViceBaseIE):
|
2017-05-05 11:12:40 -04:00
|
|
|
|
IE_NAME = 'vice:show'
|
2020-01-05 10:32:43 -05:00
|
|
|
|
_VALID_URL = r'https?://(?:video\.vice|(?:www\.)?vice(?:land|tv))\.com/(?P<locale>[^/]+)/show/(?P<id>[^/?#&]+)'
|
|
|
|
|
_PAGE_SIZE = 25
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://video.vice.com/en_us/show/fck-thats-delicious',
|
2016-03-13 07:22:23 -04:00
|
|
|
|
'info_dict': {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'id': '57a2040c8cb727dec794c901',
|
|
|
|
|
'title': 'F*ck, That’s Delicious',
|
|
|
|
|
'description': 'The life and eating habits of rap’s greatest bon vivant, Action Bronson.',
|
2016-03-13 07:22:23 -04:00
|
|
|
|
},
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'playlist_mincount': 64,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.vicetv.com/en_us/show/fck-thats-delicious',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
2016-03-13 07:22:23 -04:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
def _fetch_page(self, locale, show_id, page):
|
|
|
|
|
videos = self._call_api('videos', 'show_id', show_id, locale, '''body
|
|
|
|
|
id
|
|
|
|
|
url''', ', page: %d, per_page: %d' % (page + 1, self._PAGE_SIZE))
|
|
|
|
|
for video in videos:
|
|
|
|
|
yield self.url_result(
|
|
|
|
|
video['url'], ViceIE.ie_key(), video.get('id'))
|
2016-03-13 07:22:23 -04:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
locale, display_id = self._match_valid_url(url).groups()
|
2020-01-05 10:32:43 -05:00
|
|
|
|
show = self._call_api('shows', 'slug', display_id, locale, '''dek
|
|
|
|
|
id
|
|
|
|
|
title''')[0]
|
|
|
|
|
show_id = show['id']
|
2016-03-13 07:22:23 -04:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
entries = OnDemandPagedList(
|
|
|
|
|
functools.partial(self._fetch_page, locale, show_id),
|
|
|
|
|
self._PAGE_SIZE)
|
2016-03-13 07:22:23 -04:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
return self.playlist_result(
|
|
|
|
|
entries, show_id, show.get('title'), show.get('dek'))
|
2017-05-05 08:26:51 -04:00
|
|
|
|
|
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
class ViceArticleIE(ViceBaseIE):
|
2017-05-05 11:12:40 -04:00
|
|
|
|
IE_NAME = 'vice:article'
|
2024-02-01 13:38:42 -05:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?vice\.com/(?P<locale>[^/]+)/article/(?:[0-9a-z]{6}/)?(?P<id>[^?#]+)'
|
2017-05-05 08:26:51 -04:00
|
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://www.vice.com/en_us/article/on-set-with-the-woman-making-mormon-porn-in-utah',
|
|
|
|
|
'info_dict': {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'id': '58dc0a3dee202d2a0ccfcbd8',
|
2017-05-05 08:26:51 -04:00
|
|
|
|
'ext': 'mp4',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'title': 'Mormon War on Porn',
|
|
|
|
|
'description': 'md5:1c5d91fe25fa8aa304f9def118b92dbf',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'uploader': 'vice',
|
|
|
|
|
'uploader_id': '57a204088cb727dec794c67b',
|
|
|
|
|
'timestamp': 1491883129,
|
|
|
|
|
'upload_date': '20170411',
|
|
|
|
|
'age_limit': 17,
|
2017-05-05 08:26:51 -04:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# AES-encrypted m3u8
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'add_ie': [ViceIE.ie_key()],
|
2017-05-05 08:26:51 -04:00
|
|
|
|
}, {
|
2017-05-05 11:12:40 -04:00
|
|
|
|
'url': 'https://www.vice.com/en_us/article/how-to-hack-a-car',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'md5': '13010ee0bc694ea87ec40724397c2349',
|
2017-05-05 08:26:51 -04:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '3jstaBeXgAs',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
|
|
|
|
|
'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
|
|
|
|
|
'uploader': 'Motherboard',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'uploader_id': 'MotherboardTV',
|
2017-05-05 08:26:51 -04:00
|
|
|
|
'upload_date': '20140529',
|
|
|
|
|
},
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'add_ie': [YoutubeIE.ie_key()],
|
2018-03-03 11:07:29 -05:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.vice.com/en_us/article/znm9dx/karley-sciortino-slutever-reloaded',
|
|
|
|
|
'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2',
|
|
|
|
|
'info_dict': {
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'id': '57f41d3556a0a80f54726060',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': "Making The World's First Male Sex Doll",
|
2020-01-05 10:32:43 -05:00
|
|
|
|
'description': 'md5:19b00b215b99961cf869c40fbe9df755',
|
2018-03-03 11:07:29 -05:00
|
|
|
|
'uploader': 'vice',
|
|
|
|
|
'uploader_id': '57a204088cb727dec794c67b',
|
|
|
|
|
'timestamp': 1476919911,
|
|
|
|
|
'upload_date': '20161019',
|
|
|
|
|
'age_limit': 17,
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
'add_ie': [ViceIE.ie_key()],
|
2017-05-05 11:12:40 -04:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.vice.com/en_us/article/cowboy-capitalists-part-1',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://www.vice.com/ru/article/big-night-out-ibiza-clive-martin-229',
|
|
|
|
|
'only_matching': True,
|
2017-05-05 08:26:51 -04:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-18 21:41:24 -04:00
|
|
|
|
locale, display_id = self._match_valid_url(url).groups()
|
2017-05-05 08:26:51 -04:00
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
article = self._call_api('articles', 'slug', display_id, locale, '''body
|
|
|
|
|
embed_code''')[0]
|
|
|
|
|
body = article['body']
|
2017-05-05 11:12:40 -04:00
|
|
|
|
|
|
|
|
|
def _url_res(video_url, ie_key):
|
2017-05-05 08:26:51 -04:00
|
|
|
|
return {
|
|
|
|
|
'_type': 'url_transparent',
|
2017-05-05 11:12:40 -04:00
|
|
|
|
'url': video_url,
|
2017-05-05 08:26:51 -04:00
|
|
|
|
'display_id': display_id,
|
2017-05-05 11:12:40 -04:00
|
|
|
|
'ie_key': ie_key,
|
2017-05-05 08:26:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 10:32:43 -05:00
|
|
|
|
vice_url = ViceIE._extract_url(body)
|
2018-03-03 11:07:29 -05:00
|
|
|
|
if vice_url:
|
|
|
|
|
return _url_res(vice_url, ViceIE.ie_key())
|
|
|
|
|
|
2017-09-05 13:50:25 -04:00
|
|
|
|
youtube_url = YoutubeIE._extract_url(body)
|
2017-05-05 11:12:40 -04:00
|
|
|
|
if youtube_url:
|
2017-09-05 13:50:25 -04:00
|
|
|
|
return _url_res(youtube_url, YoutubeIE.ie_key())
|
2017-05-05 11:12:40 -04:00
|
|
|
|
|
2017-05-05 08:26:51 -04:00
|
|
|
|
video_url = self._html_search_regex(
|
2017-05-05 11:12:40 -04:00
|
|
|
|
r'data-video-url="([^"]+)"',
|
2020-01-05 10:32:43 -05:00
|
|
|
|
article['embed_code'], 'video URL')
|
2017-05-05 08:26:51 -04:00
|
|
|
|
|
2017-05-05 11:12:40 -04:00
|
|
|
|
return _url_res(video_url, ViceIE.ie_key())
|