mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-25 11:41:52 +00:00
[fox] add support for locked videos using cookies(closes #19060)
This commit is contained in:
parent
41c2c254d3
commit
6df196f32e
3 changed files with 51 additions and 26 deletions
|
@ -692,7 +692,10 @@ from .myvi import (
|
||||||
MyviEmbedIE,
|
MyviEmbedIE,
|
||||||
)
|
)
|
||||||
from .myvidster import MyVidsterIE
|
from .myvidster import MyVidsterIE
|
||||||
from .nationalgeographic import NationalGeographicVideoIE
|
from .nationalgeographic import (
|
||||||
|
NationalGeographicVideoIE,
|
||||||
|
NationalGeographicTVIE,
|
||||||
|
)
|
||||||
from .naver import NaverIE
|
from .naver import NaverIE
|
||||||
from .nba import NBAIE
|
from .nba import NBAIE
|
||||||
from .nbc import (
|
from .nbc import (
|
||||||
|
|
|
@ -5,19 +5,23 @@ import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from .adobepass import AdobePassIE
|
from .adobepass import AdobePassIE
|
||||||
from ..compat import compat_str
|
from ..compat import (
|
||||||
|
compat_HTTPError,
|
||||||
|
compat_str,
|
||||||
|
compat_urllib_parse_unquote,
|
||||||
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
parse_age_limit,
|
parse_age_limit,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
update_url_query,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class FOXIE(AdobePassIE):
|
class FOXIE(AdobePassIE):
|
||||||
_VALID_URL = r'https?://(?:www\.)?(?:fox\.com|nationalgeographic\.com/tv)/watch/(?P<id>[\da-fA-F]+)'
|
_VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[\da-fA-F]+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# clip
|
# clip
|
||||||
'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
|
'url': 'https://www.fox.com/watch/4b765a60490325103ea69888fb2bd4e8/',
|
||||||
|
@ -32,6 +36,7 @@ class FOXIE(AdobePassIE):
|
||||||
'upload_date': '20170901',
|
'upload_date': '20170901',
|
||||||
'creator': 'FOX',
|
'creator': 'FOX',
|
||||||
'series': 'Gotham',
|
'series': 'Gotham',
|
||||||
|
'age_limit': 14,
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
|
@ -44,15 +49,14 @@ class FOXIE(AdobePassIE):
|
||||||
# episode, geo-restricted, tv provided required
|
# episode, geo-restricted, tv provided required
|
||||||
'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
|
'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}, {
|
|
||||||
'url': 'https://www.nationalgeographic.com/tv/watch/f690e05ebbe23ab79747becd0cc223d1/',
|
|
||||||
'only_matching': True,
|
|
||||||
}]
|
}]
|
||||||
|
_HOME_PAGE_URL = 'https://www.fox.com/'
|
||||||
|
_API_KEY = 'abdcbed02c124d393b39e818a4312055'
|
||||||
_access_token = None
|
_access_token = None
|
||||||
|
|
||||||
def _call_api(self, path, video_id, data=None):
|
def _call_api(self, path, video_id, data=None):
|
||||||
headers = {
|
headers = {
|
||||||
'X-Api-Key': '238bb0a0c2aba67922c48709ce0c06fd',
|
'X-Api-Key': self._API_KEY,
|
||||||
}
|
}
|
||||||
if self._access_token:
|
if self._access_token:
|
||||||
headers['Authorization'] = 'Bearer ' + self._access_token
|
headers['Authorization'] = 'Bearer ' + self._access_token
|
||||||
|
@ -61,10 +65,16 @@ class FOXIE(AdobePassIE):
|
||||||
video_id, data=data, headers=headers)
|
video_id, data=data, headers=headers)
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
self._access_token = self._call_api(
|
if not self._access_token:
|
||||||
'login', None, json.dumps({
|
mvpd_auth = self._get_cookies(self._HOME_PAGE_URL).get('mvpd-auth')
|
||||||
'deviceId': compat_str(uuid.uuid4()),
|
if mvpd_auth:
|
||||||
}).encode())['accessToken']
|
self._access_token = (self._parse_json(compat_urllib_parse_unquote(
|
||||||
|
mvpd_auth.value), None, fatal=False) or {}).get('accessToken')
|
||||||
|
if not self._access_token:
|
||||||
|
self._access_token = self._call_api(
|
||||||
|
'login', None, json.dumps({
|
||||||
|
'deviceId': compat_str(uuid.uuid4()),
|
||||||
|
}).encode())['accessToken']
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
@ -73,25 +83,15 @@ class FOXIE(AdobePassIE):
|
||||||
|
|
||||||
title = video['name']
|
title = video['name']
|
||||||
release_url = video['url']
|
release_url = video['url']
|
||||||
|
|
||||||
data = try_get(
|
|
||||||
video, lambda x: x['trackingData']['properties'], dict) or {}
|
|
||||||
|
|
||||||
rating = video.get('contentRating')
|
|
||||||
if data.get('authRequired'):
|
|
||||||
resource = self._get_mvpd_resource(
|
|
||||||
'fbc-fox', title, video.get('guid'), rating)
|
|
||||||
release_url = update_url_query(
|
|
||||||
release_url, {
|
|
||||||
'auth': self._extract_mvpd_auth(
|
|
||||||
url, video_id, 'fbc-fox', resource)
|
|
||||||
})
|
|
||||||
m3u8_url = self._download_json(release_url, video_id)['playURL']
|
m3u8_url = self._download_json(release_url, video_id)['playURL']
|
||||||
formats = self._extract_m3u8_formats(
|
formats = self._extract_m3u8_formats(
|
||||||
m3u8_url, video_id, 'mp4',
|
m3u8_url, video_id, 'mp4',
|
||||||
entry_protocol='m3u8_native', m3u8_id='hls')
|
entry_protocol='m3u8_native', m3u8_id='hls')
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
data = try_get(
|
||||||
|
video, lambda x: x['trackingData']['properties'], dict) or {}
|
||||||
|
|
||||||
duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
|
duration = int_or_none(video.get('durationInSeconds')) or int_or_none(
|
||||||
video.get('duration')) or parse_duration(video.get('duration'))
|
video.get('duration')) or parse_duration(video.get('duration'))
|
||||||
timestamp = unified_timestamp(video.get('datePublished'))
|
timestamp = unified_timestamp(video.get('datePublished'))
|
||||||
|
@ -117,7 +117,7 @@ class FOXIE(AdobePassIE):
|
||||||
'description': video.get('description'),
|
'description': video.get('description'),
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'age_limit': parse_age_limit(rating),
|
'age_limit': parse_age_limit(video.get('contentRating')),
|
||||||
'creator': creator,
|
'creator': creator,
|
||||||
'series': series,
|
'series': series,
|
||||||
'season_number': int_or_none(video.get('seasonNumber')),
|
'season_number': int_or_none(video.get('seasonNumber')),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from .fox import FOXIE
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
url_basename,
|
url_basename,
|
||||||
|
@ -58,3 +59,24 @@ class NationalGeographicVideoIE(InfoExtractor):
|
||||||
{'force_smil_url': True}),
|
{'force_smil_url': True}),
|
||||||
'id': guid,
|
'id': guid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class NationalGeographicTVIE(FOXIE):
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?nationalgeographic\.com/tv/watch/(?P<id>[\da-fA-F]+)'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.nationalgeographic.com/tv/watch/6a875e6e734b479beda26438c9f21138/',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '6a875e6e734b479beda26438c9f21138',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Why Nat Geo? Valley of the Boom',
|
||||||
|
'description': 'The lives of prominent figures in the tech world, including their friendships, rivalries, victories and failures.',
|
||||||
|
'timestamp': 1542662458,
|
||||||
|
'upload_date': '20181119',
|
||||||
|
'age_limit': 14,
|
||||||
|
},
|
||||||
|
'params': {
|
||||||
|
'skip_download': True,
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
_HOME_PAGE_URL = 'https://www.nationalgeographic.com/tv/'
|
||||||
|
_API_KEY = '238bb0a0c2aba67922c48709ce0c06fd'
|
||||||
|
|
Loading…
Reference in a new issue