mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-13 15:04:14 +09:00
Compare commits
5 Commits
6c9b8a93b3
...
7fdddeefaf
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7fdddeefaf | ||
![]() |
da7223d4aa | ||
![]() |
37c2440d6a | ||
![]() |
fed9c8d17b | ||
![]() |
876d9b8f49 |
@ -232,8 +232,32 @@ _NSIG_TESTS = [
|
||||
'W9HJZKktxuYoDTqW', 'jHbbkcaxm54',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/91201489/player_ias_tce.vflset/en_US/base.js',
|
||||
'W9HJZKktxuYoDTqW', 'U48vOZHaeYS6vO',
|
||||
'https://www.youtube.com/s/player/643afba4/player_ias.vflset/en_US/base.js',
|
||||
'W9HJZKktxuYoDTqW', 'larxUlagTRAcSw',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/e7567ecf/player_ias_tce.vflset/en_US/base.js',
|
||||
'Sy4aDGc0VpYRR9ew_', '5UPOT1VhoZxNLQ',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/d50f54ef/player_ias_tce.vflset/en_US/base.js',
|
||||
'Ha7507LzRmH3Utygtj', 'XFTb2HoeOE5MHg',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/074a8365/player_ias_tce.vflset/en_US/base.js',
|
||||
'Ha7507LzRmH3Utygtj', 'ufTsrE0IVYrkl8v',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/643afba4/player_ias.vflset/en_US/base.js',
|
||||
'N5uAlLqm0eg1GyHO', 'dCBQOejdq5s-ww',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/69f581a5/tv-player-ias.vflset/tv-player-ias.js',
|
||||
'-qIP447rVlTTwaZjY', 'KNcGOksBAvwqQg',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/643afba4/tv-player-ias.vflset/tv-player-ias.js',
|
||||
'ir9-V6cdbCiyKxhr', '2PL7ZDYAALMfmA',
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -1242,6 +1242,10 @@ from .tagesschau import (
|
||||
TagesschauPlayerIE,
|
||||
TagesschauIE,
|
||||
)
|
||||
from .talktv import (
|
||||
TalkTVIE,
|
||||
TalkTVSeriesIE,
|
||||
)
|
||||
from .tass import TassIE
|
||||
from .tbs import TBSIE
|
||||
from .tdslifeway import TDSLifewayIE
|
||||
|
178
youtube_dl/extractor/talktv.py
Normal file
178
youtube_dl/extractor/talktv.py
Normal file
@ -0,0 +1,178 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import calendar
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
from .common import InfoExtractor
|
||||
|
||||
from ..compat import compat_str
|
||||
from ..utils import (
|
||||
clean_html,
|
||||
determine_ext,
|
||||
extract_attributes,
|
||||
ExtractorError,
|
||||
get_elements_by_class,
|
||||
HEADRequest,
|
||||
parse_duration,
|
||||
try_get,
|
||||
unified_timestamp,
|
||||
url_or_none,
|
||||
urljoin,
|
||||
)
|
||||
|
||||
|
||||
class TalkTVIE(InfoExtractor):
|
||||
IE_NAME = 'talk.tv'
|
||||
IE_DESC = 'TalkTV UK catch-up and live shows'
|
||||
_VALID_URL = r'https?://watch\.talk\.tv/(?P<id>watch/(?:vod|replay)/\d+|live)'
|
||||
_TESTS = [{
|
||||
'url': 'https://watch.talk.tv/watch/replay/12216792',
|
||||
'md5': 'dc9071f7d26f48ce4057a98425894eb3',
|
||||
'info_dict': {
|
||||
'id': '12216792',
|
||||
'ext': 'mp4',
|
||||
'title': 'Piers Morgan Uncensored',
|
||||
'description': 'The host interviews former US President Donald Trump',
|
||||
'timestamp': 1650917390,
|
||||
'upload_date': '20220425',
|
||||
'duration': float,
|
||||
},
|
||||
'params': {
|
||||
'skip_download': True, # adaptive download
|
||||
},
|
||||
}, {
|
||||
'url': 'https://watch.talk.tv/live',
|
||||
'info_dict': {
|
||||
'id': 'live',
|
||||
'ext': 'mp4',
|
||||
'title': 'Piers Morgan Uncensored',
|
||||
'description': compat_str,
|
||||
'timestamp': int,
|
||||
# needs core fix to force compat_str type
|
||||
'upload_date': r're:\d{8}',
|
||||
'duration': float,
|
||||
},
|
||||
'params': {
|
||||
'skip_download': True,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url).rsplit('/', 1)[-1]
|
||||
is_live = (video_id == 'live')
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
title = self._html_search_regex(r'(?is)<h1\b[^>]+>\s*(.+?)\s*</h1', webpage, 'title')
|
||||
player = self._search_regex(r'''(<[dD][iI][vV]\b[^>]+?\bid\s*=\s*(?P<q>"|')player(?P=q)[^>]*>)''', webpage, video_id)
|
||||
player = extract_attributes(player)
|
||||
expiry = player.get('expiry')
|
||||
if expiry is not None and expiry < time.time():
|
||||
raise ExtractorError('Video has expired', expected=True)
|
||||
api_info = self._download_json(
|
||||
'https://mm-v2.simplestream.com/ssmp/api.php?id=%(data-id)s&env=%(data-env)s' % player,
|
||||
video_id, note='Downloading API info', fatal=False)
|
||||
player['api_url'] = (
|
||||
url_or_none(try_get(api_info, lambda x: x['response']['api_hostname']))
|
||||
or 'https://v2-streams-elb.simplestreamcdn.com')
|
||||
headers = {'Referer': url, }
|
||||
for item in ('uvid', 'token', ('expiry', 'Token-Expiry')):
|
||||
if isinstance(item, compat_str):
|
||||
name = item.capitalize()
|
||||
else:
|
||||
item, name = item
|
||||
val = player.get('data-' + item)
|
||||
if val is not None:
|
||||
headers[name] = val
|
||||
|
||||
stream_info = self._download_json(
|
||||
'%(api_url)s/api/%(data-type)s/stream/%(data-uvid)s?key=%(data-key)s&platform=firefox&cc=%(data-country)s' % player,
|
||||
video_id, headers=headers)
|
||||
error = try_get(stream_info, lambda x: x['response']['error'])
|
||||
if error:
|
||||
raise ExtractorError('Streaming API reported: ' + error, expected=True)
|
||||
fmt_url = (stream_info['response'].get('drm') in (None, False)) and stream_info['response']['stream']
|
||||
formats = []
|
||||
duration = None
|
||||
description = None
|
||||
timestamp = None
|
||||
if fmt_url:
|
||||
ext = determine_ext(fmt_url)
|
||||
if ext == 'm3u8':
|
||||
formats.extend(self._extract_m3u8_formats(
|
||||
fmt_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
||||
m3u8_id='hls', live=is_live, fatal=False))
|
||||
elif ext == 'mpd':
|
||||
formats.extend(self._extract_mpd_formats(
|
||||
fmt_url, video_id, mpd_id='dash', live=is_live, fatal=False))
|
||||
else:
|
||||
formats.append({
|
||||
'url': fmt_url,
|
||||
})
|
||||
if not is_live:
|
||||
res = self._request_webpage(HEADRequest(fmt_url), video_id, note='Checking date', fatal=False)
|
||||
if res is not False:
|
||||
timestamp = unified_timestamp(res.info().getheader('last-modified'))
|
||||
|
||||
self._sort_formats(formats)
|
||||
|
||||
text_fields = get_elements_by_class('text-start', webpage)
|
||||
for text in text_fields:
|
||||
text = clean_html(text)
|
||||
if text.startswith('EPISODE'):
|
||||
duration = parse_duration(
|
||||
self._html_search_regex(r'^EPISODE\b\W*(\w[\w\s]*?)\s*$', text, 'duration', default=None))
|
||||
elif text.startswith('Live'):
|
||||
duration = self._html_search_regex(r'^Live\b(?:<[^>]+>|\W)*([0-2]?\d:\d{2}\s*-\s*[0-2]?\d:\d{2})\s*$', text, 'duration', default=None)
|
||||
duration = list(map(lambda x: datetime.strptime(x, '%H:%M'), re.split(r'\s*-\s*', duration)))
|
||||
if None not in duration and len(duration) == 2:
|
||||
timestamp = datetime.now().replace(hour=duration[0].hour, minute=duration[0].minute, second=0, microsecond=0)
|
||||
timestamp = calendar.timegm(timestamp.timetuple())
|
||||
duration = duration[1] - duration[0]
|
||||
try:
|
||||
duration = duration.total_seconds()
|
||||
except AttributeError:
|
||||
# Py 2.6
|
||||
duration = duration.td_seconds
|
||||
if duration is not None and duration < 0:
|
||||
duration += 24 * 3600
|
||||
else:
|
||||
description = text
|
||||
|
||||
return {
|
||||
# ensure live has a fixed ID
|
||||
'id': player['data-uvid'] if not is_live else video_id,
|
||||
'title': title,
|
||||
'display_id': video_id if not is_live else player['data-uvid'],
|
||||
'formats': formats,
|
||||
'thumbnail': player.get('data-poster'),
|
||||
'duration': duration,
|
||||
'timestamp': timestamp,
|
||||
'description': description,
|
||||
'is_live': is_live,
|
||||
}
|
||||
|
||||
|
||||
class TalkTVSeriesIE(InfoExtractor):
|
||||
IE_NAME = 'talk.tv:series'
|
||||
IE_DESC = 'TalkTV UK series catch-up'
|
||||
_VALID_URL = r'https?://(?:watch\.|www\.)?talk\.tv/shows/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
|
||||
_TESTS = [{
|
||||
'url': 'https://watch.talk.tv/shows/86dadc3e-c4d2-11ec-b4c6-0af62ebc70d1',
|
||||
'info_dict': {
|
||||
'id': '86dadc3e-c4d2-11ec-b4c6-0af62ebc70d1',
|
||||
},
|
||||
'playlist_mincount': 4,
|
||||
},
|
||||
]
|
||||
|
||||
def _real_extract(self, url):
|
||||
playlist_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, playlist_id)
|
||||
episodes = re.finditer(
|
||||
r'''(?i)<a\b[^>]+?\bhref\s*=\s*(?P<q>"|')(?P<href>/watch/(?:(?!(?P=q)).)+)(?P=q)''',
|
||||
webpage)
|
||||
return self.playlist_from_matches(
|
||||
episodes, playlist_id, getter=lambda x: urljoin(url, x.group('href')), ie='TalkTV')
|
@ -91,12 +91,12 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'INNERTUBE_CONTEXT': {
|
||||
'client': {
|
||||
'clientName': 'IOS',
|
||||
'clientVersion': '19.45.4',
|
||||
'clientVersion': '20.10.4',
|
||||
'deviceMake': 'Apple',
|
||||
'deviceModel': 'iPhone16,2',
|
||||
'userAgent': 'com.google.ios.youtube/19.45.4 (iPhone16,2; U; CPU iOS 18_1_0 like Mac OS X;)',
|
||||
'userAgent': 'com.google.ios.youtube/20.10.4 (iPhone16,2; U; CPU iOS 18_3_2 like Mac OS X;)',
|
||||
'osName': 'iPhone',
|
||||
'osVersion': '18.1.0.22B83',
|
||||
'osVersion': '18.3.2.22D82',
|
||||
},
|
||||
},
|
||||
'INNERTUBE_CONTEXT_CLIENT_NAME': 5,
|
||||
@ -109,7 +109,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'INNERTUBE_CONTEXT': {
|
||||
'client': {
|
||||
'clientName': 'MWEB',
|
||||
'clientVersion': '2.20241202.07.00',
|
||||
'clientVersion': '2.20250311.03.00',
|
||||
# mweb previously did not require PO Token with this UA
|
||||
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 16_7_10 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1,gzip(gfe)',
|
||||
},
|
||||
@ -122,7 +122,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'INNERTUBE_CONTEXT': {
|
||||
'client': {
|
||||
'clientName': 'TVHTML5',
|
||||
'clientVersion': '7.20250120.19.00',
|
||||
'clientVersion': '7.20250312.16.00',
|
||||
'userAgent': 'Mozilla/5.0 (ChromiumStylePlatform) Cobalt/Version',
|
||||
},
|
||||
},
|
||||
@ -133,7 +133,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
'INNERTUBE_CONTEXT': {
|
||||
'client': {
|
||||
'clientName': 'WEB',
|
||||
'clientVersion': '2.20241126.01.00',
|
||||
'clientVersion': '2.20250312.04.00',
|
||||
},
|
||||
},
|
||||
'INNERTUBE_CONTEXT_CLIENT_NAME': 1,
|
||||
@ -692,7 +692,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'invidious': '|'.join(_INVIDIOUS_SITES),
|
||||
}
|
||||
_PLAYER_INFO_RE = (
|
||||
r'/s/player/(?P<id>[a-zA-Z0-9_-]{8,})/player',
|
||||
r'/s/player/(?P<id>[a-zA-Z0-9_-]{8,})//(?:tv-)?player',
|
||||
r'/(?P<id>[a-zA-Z0-9_-]{8,})/player(?:_ias\.vflset(?:/[a-zA-Z]{2,3}_[a-zA-Z]{2,3})?|-plasma-ias-(?:phone|tablet)-[a-z]{2}_[A-Z]{2}\.vflset)/base\.js$',
|
||||
r'\b(?P<id>vfl[a-zA-Z0-9_-]+)\b.*?\.js$',
|
||||
)
|
||||
@ -1857,7 +1857,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
def _extract_n_function_code_jsi(self, video_id, jsi, player_id=None):
|
||||
|
||||
var_ay = self._search_regex(
|
||||
r'(?:[;\s]|^)\s*(var\s*[\w$]+\s*=\s*"[^"]+"\s*\.\s*split\("\{"\))(?=\s*[,;])',
|
||||
r'(?:[;\s]|^)\s*(var\s*[\w$]+\s*=\s*"(?:\\"|[^"])+"\s*\.\s*split\("\W+"\))(?=\s*[,;])',
|
||||
jsi.code, 'useful values', default='')
|
||||
|
||||
func_name = self._extract_n_function_name(jsi.code)
|
||||
|
Loading…
x
Reference in New Issue
Block a user