Compare commits

...

5 Commits

Author SHA1 Message Date
sukkerstjernen
1a63519242
Merge 2358117d39 into f2a4983df7 2024-11-13 01:47:10 +01:00
Jackson Humphrey
f2a4983df7
[ie/archive.org] Fix comments extraction (#11527)
Closes #11526
Authored by: jshumphrey
2024-11-12 23:26:18 +00:00
bashonly
bacc31b05a
[ie/facebook] Fix formats extraction (#11513)
Closes #11497
Authored by: bashonly
2024-11-12 23:23:10 +00:00
sukkerstjernen
2358117d39
Merge branch 'yt-dlp:master' into master 2024-10-16 13:10:36 +02:00
sukkerstjernen
9ef3e8aaa3 draft for ctc.ru extractor 2024-10-14 16:09:01 +02:00
4 changed files with 220 additions and 6 deletions

View File

@ -446,6 +446,11 @@ from .cspan import (
CSpanCongressIE,
CSpanIE,
)
from .ctc import (
CTCIE,
CTCSeasonIE,
CTCSeriesIE,
)
from .ctsnews import CtsNewsIE
from .ctv import CTVIE
from .ctvnews import CTVNewsIE

View File

@ -205,6 +205,26 @@ class ArchiveOrgIE(InfoExtractor):
},
},
],
}, {
# The reviewbody is None for one of the reviews; just need to extract data without crashing
'url': 'https://archive.org/details/gd95-04-02.sbd.11622.sbeok.shnf/gd95-04-02d1t04.shn',
'info_dict': {
'id': 'gd95-04-02.sbd.11622.sbeok.shnf/gd95-04-02d1t04.shn',
'ext': 'mp3',
'title': 'Stuck Inside of Mobile with the Memphis Blues Again',
'creators': ['Grateful Dead'],
'duration': 338.31,
'track': 'Stuck Inside of Mobile with the Memphis Blues Again',
'description': 'md5:764348a470b986f1217ffd38d6ac7b72',
'display_id': 'gd95-04-02d1t04.shn',
'location': 'Pyramid Arena',
'uploader': 'jon@archive.org',
'album': '1995-04-02 - Pyramid Arena',
'upload_date': '20040519',
'track_number': 4,
'release_date': '19950402',
'timestamp': 1084927901,
},
}]
@staticmethod
@ -335,7 +355,7 @@ class ArchiveOrgIE(InfoExtractor):
info['comments'].append({
'id': review.get('review_id'),
'author': review.get('reviewer'),
'text': str_or_none(review.get('reviewtitle'), '') + '\n\n' + review.get('reviewbody'),
'text': join_nonempty('reviewtitle', 'reviewbody', from_dict=review, delim='\n\n'),
'timestamp': unified_timestamp(review.get('createdate')),
'parent': 'root'})

164
yt_dlp/extractor/ctc.py Normal file
View File

@ -0,0 +1,164 @@
from .common import InfoExtractor
from ..utils import (
traverse_obj,
int_or_none
)
class CTCIE(InfoExtractor):
IE_NAME = 'ctc'
_VALID_URL = (
r'https?://ctc\.ru/projects/filmi/(?P<project_name>[^/]+)/?(?:video/?)?$'
r'|https?://ctc\.ru/projects/(?P<category>show|multiki|serials)/(?P<project_name2>[^/]+)/video/'
r'(?:$'
r'|(?P<season_number>\d+)-sezon/(?P<episode_number>\d+)-(?:vypusk|serija)/?$'
r'|promo/[^/]+/?$'
r')'
)
_GEO_COUNTRIES = ['RU']
def _real_extract(self, url):
url_slug = url.split("https://ctc.ru/")[1]
item_response = self._download_json(
f'https://ctc.ru/api/page/v1/{url_slug}', url_slug,
note='Downloading item data', headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0"
}
)
track_hub_id = str(traverse_obj(item_response, ('content', 0, 'trackHubId'), expected_type=int))
if not track_hub_id:
self.raise_no_formats('trackHubId not found')
video_url = traverse_obj(
item_response, ('content', 0, 'videoUrl'), get_all=False
) or traverse_obj(
item_response, ('content', 0, 'trackUrl'), get_all=False
)
stream_response = self._download_json(
video_url.replace("/player/", "/playlist/"),
track_hub_id,
note='Downloading stream data', headers={
'X-Referer': 'https://ctc.ru',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0',
}
)
if traverse_obj(stream_response, ('playlist', 'items', 0, 'errors', 0, 'code')) == 102:
self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
elif traverse_obj(stream_response, ('playlist', 'items', 0, 'errors', 0, 'code')) == 103:
self.raise_login_required(msg='This video is only available for registered users with the required subscription')
formats = []
for stream in traverse_obj(stream_response, ('playlist', 'items', 0, 'streams')):
protocol = stream.get('protocol')
video_id = traverse_obj(stream_response, ('playlist', 'items', 0, 'track_id'))
fmts = []
if protocol == 'HLS':
fmts, _ = self._extract_m3u8_formats_and_subtitles(
stream.get('url'), video_id, ext='mp4', preference=1, m3u8_id="video/hls", fatal=False)
formats.extend(fmts)
return {
'formats': formats,
'id': track_hub_id,
'title': ": ".join(filter(None, [
traverse_obj(stream_response, ('playlist', 'items', 0, 'project_name')),
traverse_obj(stream_response, ('playlist', 'items', 0, 'episode_name'))
])),
**traverse_obj(item_response, {
'description': ('content', 0, 'description'),
}),
**traverse_obj(stream_response, {
'episode': ('playlist', 'items', 0, 'episode_name'),
'duration': ('playlist', 'items', 0, 'duration'),
'thumbnail': ('playlist', 'items', 0, 'thumbnail_url'),
'season': ('playlist', 'items', 0, 'season_name'),
'age_limit': ('playlist', 'items', 0, 'min_age'),
}),
'season_number': int_or_none(self._match_valid_url(url).group('season_number')),
'episode_number': int_or_none(self._match_valid_url(url).group('episode_number')),
}
class CTCSeasonIE(InfoExtractor):
IE_NAME = 'ctc:season'
_VALID_URL = (
r'https?://ctc\.ru/projects/(?P<category>show|multiki|serials)/'
r'(?P<project_name>[^/]+)/video/(?P<season_number>\d+)-sezon/?$'
)
_GEO_COUNTRIES = ['RU']
def _real_extract(self, url):
url_slug = url.split("https://ctc.ru/")[1]
season_data = self._download_json(f'https://ctc.ru/api/page/v1/{url_slug}', url_slug)
entries = [{
'_type': 'url',
'title': episode.get('title'),
'url': f"https://ctc.ru{episode.get('popupUrl')}",
'ie_key': CTCIE.ie_key(),
'season_number': self._match_valid_url(url).group('season_number'),
'episode_number': self._search_regex(
r'/(?P<episode>\d+)-(vypusk|serija)/',
episode.get('popupUrl'),
'episode number',
)
} for episode in traverse_obj(season_data, ('content', 1, 'widgets')) if episode.get('popupUrl')]
return {
'_type': 'playlist',
'entries': entries,
**traverse_obj(season_data, {
'id': ('content', 9, 'entityId'),
'title': ('content', 0, 'widgets', 1, 'title'),
'season_number': self._match_valid_url(url).group('season_number'),
'series': ('content', 0, 'widgets', 1, 'title'),
'description': ('content', 0, 'widgets', 1, 'description'),
}),
}
class CTCSeriesIE(InfoExtractor):
IE_NAME = 'ctc:series'
_VALID_URL = (
r'https?://ctc\.ru/projects/(?P<category>show|multiki|serials)/'
r'(?P<slug>[^/]+)/?$'
)
_GEO_COUNTRIES = ['RU']
def _real_extract(self, url):
url_slug = url.split("https://ctc.ru/")[1]
series_data = self._download_json(f'https://ctc.ru/api/page/v1/{url_slug}', url_slug)
# cartoons doesn't indicate in the url what type it is, so
# if it's a movie, then redirect it to CTCIE
if traverse_obj(series_data, ('content', 5, 'tabs')) == []:
return self.url_result(f'https://ctc.ru/{url_slug}/video')
entries = [{
'_type': 'url',
'title': season.get('title'),
'url': f'https://ctc.ru{season.get("url")}',
'ie_key': CTCSeasonIE.ie_key(),
'season_number': self._search_regex(
r'/(?P<episode>\d+)-sezon/',
season.get("url"),
'season number',
),
'series': season.get('title'),
} for season in traverse_obj(series_data, ('content', 1, 'tabs')) if season.get("url").endswith("sezon/")]
return {
'_type': 'playlist',
'entries': entries,
**traverse_obj(series_data, {
'id': ('content', 0, 'projectId'),
'title': ('content', 0, 'widgets', 1, 'title'),
'series': ('content', 0, 'widgets', 1, 'title'),
'description': ('content', 0, 'widgets', 1, 'description')
}),
}

View File

@ -563,13 +563,13 @@ class FacebookIE(InfoExtractor):
return extract_video_data(try_get(
js_data, lambda x: x['jsmods']['instances'], list) or [])
def extract_dash_manifest(video, formats):
def extract_dash_manifest(vid_data, formats, mpd_url=None):
dash_manifest = traverse_obj(
video, 'dash_manifest', 'playlist', 'dash_manifest_xml_string', expected_type=str)
vid_data, 'dash_manifest', 'playlist', 'dash_manifest_xml_string', 'manifest_xml', expected_type=str)
if dash_manifest:
formats.extend(self._parse_mpd_formats(
compat_etree_fromstring(urllib.parse.unquote_plus(dash_manifest)),
mpd_url=url_or_none(video.get('dash_manifest_url'))))
mpd_url=url_or_none(video.get('dash_manifest_url')) or mpd_url))
def process_formats(info):
# Downloads with browser's User-Agent are rate limited. Working around
@ -619,9 +619,12 @@ class FacebookIE(InfoExtractor):
video = video['creation_story']
video['owner'] = traverse_obj(video, ('short_form_video_context', 'video_owner'))
video.update(reel_info)
fmt_data = traverse_obj(video, ('videoDeliveryLegacyFields', {dict})) or video
formats = []
q = qualities(['sd', 'hd'])
# Legacy formats extraction
fmt_data = traverse_obj(video, ('videoDeliveryLegacyFields', {dict})) or video
for key, format_id in (('playable_url', 'sd'), ('playable_url_quality_hd', 'hd'),
('playable_url_dash', ''), ('browser_native_hd_url', 'hd'),
('browser_native_sd_url', 'sd')):
@ -629,7 +632,7 @@ class FacebookIE(InfoExtractor):
if not playable_url:
continue
if determine_ext(playable_url) == 'mpd':
formats.extend(self._extract_mpd_formats(playable_url, video_id))
formats.extend(self._extract_mpd_formats(playable_url, video_id, fatal=False))
else:
formats.append({
'format_id': format_id,
@ -638,6 +641,28 @@ class FacebookIE(InfoExtractor):
'url': playable_url,
})
extract_dash_manifest(fmt_data, formats)
# New videoDeliveryResponse formats extraction
fmt_data = traverse_obj(video, ('videoDeliveryResponseFragment', 'videoDeliveryResponseResult'))
mpd_urls = traverse_obj(fmt_data, ('dash_manifest_urls', ..., 'manifest_url', {url_or_none}))
dash_manifests = traverse_obj(fmt_data, ('dash_manifests', lambda _, v: v['manifest_xml']))
for idx, dash_manifest in enumerate(dash_manifests):
extract_dash_manifest(dash_manifest, formats, mpd_url=traverse_obj(mpd_urls, idx))
if not dash_manifests:
# Only extract from MPD URLs if the manifests are not already provided
for mpd_url in mpd_urls:
formats.extend(self._extract_mpd_formats(mpd_url, video_id, fatal=False))
for prog_fmt in traverse_obj(fmt_data, ('progressive_urls', lambda _, v: v['progressive_url'])):
format_id = traverse_obj(prog_fmt, ('metadata', 'quality', {str.lower}))
formats.append({
'format_id': format_id,
# sd, hd formats w/o resolution info should be deprioritized below DASH
'quality': q(format_id) - 3,
'url': prog_fmt['progressive_url'],
})
for m3u8_url in traverse_obj(fmt_data, ('hls_playlist_urls', ..., 'hls_playlist_url', {url_or_none})):
formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', fatal=False, m3u8_id='hls'))
if not formats:
# Do not append false positive entry w/o any formats
return