mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-16 00:14:17 +09:00
Compare commits
7 Commits
0cc2acc917
...
2763ea228a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2763ea228a | ||
![]() |
da7223d4aa | ||
![]() |
37c2440d6a | ||
![]() |
96a0ad4778 | ||
![]() |
28fddc1758 | ||
![]() |
a5ec30e106 | ||
![]() |
34c3b06402 |
@ -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',
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -1078,6 +1078,10 @@ from .rutube import (
|
||||
RutubePersonIE,
|
||||
RutubePlaylistIE,
|
||||
)
|
||||
from .megatvcom import (
|
||||
MegaTVComIE,
|
||||
MegaTVComEmbedIE,
|
||||
)
|
||||
from .rutv import RUTVIE
|
||||
from .ruutu import RuutuIE
|
||||
from .ruv import RuvIE
|
||||
|
@ -102,6 +102,7 @@ from .ustream import UstreamIE
|
||||
from .arte import ArteTVEmbedIE
|
||||
from .videopress import VideoPressIE
|
||||
from .rutube import RutubeIE
|
||||
from .megatvcom import MegaTVComEmbedIE
|
||||
from .limelight import LimelightBaseIE
|
||||
from .anvato import AnvatoIE
|
||||
from .washingtonpost import WashingtonPostIE
|
||||
@ -3400,6 +3401,12 @@ class GenericIE(InfoExtractor):
|
||||
return self.playlist_from_matches(
|
||||
rutube_urls, video_id, video_title, ie=RutubeIE.ie_key())
|
||||
|
||||
# Look for megatv.com embeds
|
||||
megatvcom_urls = list(MegaTVComEmbedIE._extract_urls(webpage, url))
|
||||
if megatvcom_urls:
|
||||
return self.playlist_from_matches(
|
||||
megatvcom_urls, video_id, video_title, ie=MegaTVComEmbedIE.ie_key())
|
||||
|
||||
# Look for WashingtonPost embeds
|
||||
wapo_urls = WashingtonPostIE._extract_urls(webpage)
|
||||
if wapo_urls:
|
||||
|
203
youtube_dl/extractor/megatvcom.py
Normal file
203
youtube_dl/extractor/megatvcom.py
Normal file
@ -0,0 +1,203 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import (
|
||||
compat_str,
|
||||
compat_parse_qs,
|
||||
compat_urllib_parse_urlparse,
|
||||
)
|
||||
from ..utils import (
|
||||
HEADRequest,
|
||||
ExtractorError,
|
||||
determine_ext,
|
||||
get_element_by_class,
|
||||
unified_timestamp,
|
||||
extract_attributes,
|
||||
clean_html,
|
||||
unescapeHTML,
|
||||
)
|
||||
|
||||
|
||||
class MegaTVComBaseIE(InfoExtractor):
|
||||
_PLAYER_DIV_ID = 'player_div_id'
|
||||
|
||||
def _extract_player_attrs(self, webpage):
|
||||
PLAYER_DIV_RE = r'''(?x)
|
||||
<div(?:
|
||||
id=(?P<_q1>["'])(?P<%(pdi)s>%(pdi)s)(?P=_q1)|
|
||||
[^>]*?
|
||||
)+>
|
||||
''' % {'pdi': self._PLAYER_DIV_ID}
|
||||
for mobj in re.finditer(PLAYER_DIV_RE, webpage):
|
||||
if mobj.group(self._PLAYER_DIV_ID):
|
||||
player_el = mobj.group(0)
|
||||
break
|
||||
else:
|
||||
raise ExtractorError('no <div id="%s"> element found in webpage' %
|
||||
self._PLAYER_DIV_ID)
|
||||
return {
|
||||
re.sub(r'^data-(?:kwik_)?', '', k): v
|
||||
for k, v in extract_attributes(player_el).items()
|
||||
if k not in ('id',)
|
||||
}
|
||||
|
||||
|
||||
class MegaTVComIE(MegaTVComBaseIE):
|
||||
IE_NAME = 'megatvcom'
|
||||
IE_DESC = 'megatv.com videos'
|
||||
_VALID_URL = r'https?://(?:www\.)?megatv\.com/(?:(?!\d{4})[^/]+/(?P<id>\d+)/[^/]+|\d{4}/\d{2}/\d{2}/.+)'
|
||||
|
||||
_TESTS = [{
|
||||
'url': 'https://www.megatv.com/2021/10/23/egkainia-gia-ti-nea-skini-omega-tou-dimotikou-theatrou-peiraia/',
|
||||
'md5': '2ebe96661cb81854889053cebb661068',
|
||||
'info_dict': {
|
||||
'id': '520979',
|
||||
'ext': 'mp4',
|
||||
'title': 'md5:70eef71a9cd2c1ecff7ee428354dded2',
|
||||
'description': 'md5:0209fa8d318128569c0d256a5c404db1',
|
||||
'timestamp': 1634975747,
|
||||
'upload_date': '20211023',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.megatv.com/tvshows/527800/epeisodio-65-12/',
|
||||
'md5': '8ab0c9d664cea11678670202b87bb2b1',
|
||||
'info_dict': {
|
||||
'id': '527800',
|
||||
'ext': 'mp4',
|
||||
'title': 'md5:fc322cb51f682eecfe2f54cd5ab3a157',
|
||||
'description': 'md5:b2b7ed3690a78f2a0156eb790fdc00df',
|
||||
'timestamp': 1636048859,
|
||||
'upload_date': '20211104',
|
||||
},
|
||||
}]
|
||||
|
||||
def _match_article_id(self, webpage):
|
||||
ART_RE = r'''(?x)
|
||||
<article(?:
|
||||
id=(?P<_q2>["'])Article_(?P<article>\d+)(?P=_q2)|
|
||||
[^>]*?
|
||||
)+>
|
||||
'''
|
||||
return compat_str(self._search_regex(ART_RE, webpage, 'article_id',
|
||||
group='article'))
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
_is_article = video_id == 'None'
|
||||
webpage = self._download_webpage(url,
|
||||
'N/A' if _is_article else
|
||||
video_id)
|
||||
if _is_article:
|
||||
video_id = self._match_article_id(webpage)
|
||||
player_attrs = self._extract_player_attrs(webpage)
|
||||
title = player_attrs.get('label') or self._og_search_title(webpage)
|
||||
description = clean_html(get_element_by_class(
|
||||
'article-wrapper' if _is_article else 'story_content',
|
||||
webpage))
|
||||
if not description:
|
||||
description = self._og_search_description(webpage)
|
||||
thumbnail = player_attrs.get('image') or \
|
||||
self._og_search_thumbnail(webpage)
|
||||
timestamp = unified_timestamp(self._html_search_meta(
|
||||
'article:published_time', webpage))
|
||||
try:
|
||||
source = player_attrs['source']
|
||||
except KeyError:
|
||||
raise ExtractorError('no source found for %s' % video_id)
|
||||
formats = self._extract_m3u8_formats(source, video_id, 'mp4') \
|
||||
if determine_ext(source) == 'm3u8' else [source]
|
||||
self._sort_formats(formats)
|
||||
return {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'thumbnail': thumbnail,
|
||||
'timestamp': timestamp,
|
||||
'formats': formats,
|
||||
}
|
||||
|
||||
|
||||
class MegaTVComEmbedIE(MegaTVComBaseIE):
|
||||
IE_NAME = 'megatvcom:embed'
|
||||
IE_DESC = 'megatv.com embedded videos'
|
||||
_VALID_URL = r'https?://(?:www\.)?megatv\.com/embed/?\?p=\d+'
|
||||
|
||||
_TESTS = [{
|
||||
'url': 'https://www.megatv.com/embed/?p=2020520979',
|
||||
'md5': '2ebe96661cb81854889053cebb661068',
|
||||
'info_dict': {
|
||||
'id': '520979',
|
||||
'ext': 'mp4',
|
||||
'title': 'md5:70eef71a9cd2c1ecff7ee428354dded2',
|
||||
'description': 'md5:0209fa8d318128569c0d256a5c404db1',
|
||||
'timestamp': 1634975747,
|
||||
'upload_date': '20211023',
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.megatv.com/embed/?p=2020534081',
|
||||
'md5': 'f9a15e315acbf01b128e8efa3f75aab3',
|
||||
'info_dict': {
|
||||
'id': '534081',
|
||||
'ext': 'mp4',
|
||||
'title': 'md5:062e9d5976ef854d8bdc1f5724d9b2d0',
|
||||
'description': 'md5:36dbe4c3762d2ede9513eea8d07f6d52',
|
||||
'timestamp': 1636376351,
|
||||
'upload_date': '20211108',
|
||||
},
|
||||
}]
|
||||
|
||||
@classmethod
|
||||
def _extract_urls(cls, webpage, origin_url=None):
|
||||
# make the scheme in _VALID_URL optional
|
||||
_URL_RE = r'(?:https?:)?//' + cls._VALID_URL.split('://', 1)[1]
|
||||
EMBED_RE = r'''(?x)
|
||||
<iframe[^>]+?src=(?P<_q1>%(quot_re)s)
|
||||
(?P<url>%(url_re)s)(?P=_q1)
|
||||
''' % {'quot_re': r'["\']', 'url_re': _URL_RE}
|
||||
for mobj in re.finditer(EMBED_RE, webpage):
|
||||
url = unescapeHTML(mobj.group('url'))
|
||||
if url.startswith('//'):
|
||||
scheme = compat_urllib_parse_urlparse(origin_url).scheme \
|
||||
if origin_url else 'https'
|
||||
url = '%s:%s' % (scheme, url)
|
||||
yield url
|
||||
|
||||
def _match_canonical_url(self, webpage):
|
||||
LINK_RE = r'''(?x)
|
||||
<link(?:
|
||||
rel=(?P<_q1>%(quot_re)s)(?P<canonical>canonical)(?P=_q1)|
|
||||
href=(?P<_q2>%(quot_re)s)(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
|
||||
[^>]*?
|
||||
)+>
|
||||
''' % {'quot_re': r'["\']'}
|
||||
for mobj in re.finditer(LINK_RE, webpage):
|
||||
canonical, href = mobj.group('canonical', 'href')
|
||||
if canonical and href:
|
||||
return unescapeHTML(href)
|
||||
|
||||
def _real_extract(self, url):
|
||||
webpage = self._download_webpage(url, 'N/A')
|
||||
player_attrs = self._extract_player_attrs(webpage)
|
||||
canonical_url = player_attrs.get('share_url') or \
|
||||
self._match_canonical_url(webpage)
|
||||
if not canonical_url:
|
||||
raise ExtractorError('canonical URL not found')
|
||||
video_id = compat_parse_qs(compat_urllib_parse_urlparse(
|
||||
canonical_url).query)['p'][0]
|
||||
|
||||
# Resolve the canonical URL, following redirects, and defer to
|
||||
# megatvcom, as the metadata extracted from the embeddable page some
|
||||
# times are slightly different, for the same video
|
||||
canonical_url = self._request_webpage(
|
||||
HEADRequest(canonical_url), video_id,
|
||||
note='Resolve canonical URL',
|
||||
errnote='Could not resolve canonical URL').geturl()
|
||||
return self.url_result(
|
||||
canonical_url,
|
||||
MegaTVComIE.ie_key(),
|
||||
video_id
|
||||
)
|
@ -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