1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-07-18 19:28:31 +00:00

[ie/locipo] Split single metadata traversal function

This commit is contained in:
gravesducking 2025-07-09 23:31:44 +09:00
parent 15b1211c21
commit 3cb5f1a953

View File

@ -56,6 +56,19 @@ class LocipoIE(InfoExtractor):
}, },
] ]
def _get_creative_metadata(self, creative_data):
return traverse_obj(creative_data, {
'id': ('id', {str}),
'duration': ('video', 'duration', {int_or_none}),
'title': ('title', {str}),
'description': ('description', {str}),
'uploader': ('station_cd', {str}),
'uploader_id': ('station_id', {str}),
'thumbnail': ('thumb', {url_or_none}),
'timestamp': ('broadcast_started_at', {parse_iso8601}),
'modified_timestamp': ('updated_at', {parse_iso8601}),
})
def _real_extract(self, url: str): def _real_extract(self, url: str):
creative_id, playlist_id = self._match_valid_url(url).group('creative_id', 'playlist_id') # type: ignore creative_id, playlist_id = self._match_valid_url(url).group('creative_id', 'playlist_id') # type: ignore
@ -73,19 +86,12 @@ def _real_extract(self, url: str):
return { return {
'formats': self._extract_m3u8_formats(m3u8_url=traverse_obj(creative_data, ('video', 'hls', {str})), video_id=creative_id), # type: ignore 'formats': self._extract_m3u8_formats(m3u8_url=traverse_obj(creative_data, ('video', 'hls', {str})), video_id=creative_id), # type: ignore
'id': creative_id, 'id': creative_id,
**self._get_creative_metadata(creative_data), # type: ignore
**traverse_obj( **traverse_obj(
creative_data, creative_data,
{ {
'series': ('playlist', 'title', {str}), 'series': ('playlist', 'title', {str}),
'series_id': ('playlist', 'id', {str}), 'series_id': ('playlist', 'id', {str}),
'duration': ('video', 'duration', {int_or_none}),
'title': ('title', {str}),
'description': ('description', {str}),
'uploader': ('station_cd', {str}),
'uploader_id': ('station_id', {str}),
'thumbnail': ('thumb', {url_or_none}),
'timestamp': ('broadcast_started_at', {parse_iso8601}),
'modified_timestamp': ('updated_at', {parse_iso8601}),
}, },
), # type: ignore ), # type: ignore
} }
@ -115,20 +121,11 @@ def _real_extract(self, url: str):
for creative in playlist_creatives_data.get('items', []): # type: ignore for creative in playlist_creatives_data.get('items', []): # type: ignore
entries.append( entries.append(
{ {
**traverse_obj( 'formats': self._extract_m3u8_formats(
creative, m3u8_url=traverse_obj(creative, ('video', 'hls', {str})), # type: ignore
{ video_id=traverse_obj(creative, ('id', {str})), # type: ignore
'id': ('id', {str}), ),
'duration': ('video', 'duration', {int_or_none}), **self._get_creative_metadata(creative), # type: ignore
'title': ('title', {str}),
'description': ('description', {str_or_none}),
'uploader': ('station_cd', {str_or_none}),
'uploader_id': ('station_id', {str_or_none}),
'thumbnail': ('thumb', {url_or_none}),
'timestamp': ('broadcast_started_at', {parse_iso8601}),
'modified_timestamp': ('updated_at', {parse_iso8601}),
},
), # type: ignore
**traverse_obj( **traverse_obj(
playlist_data, playlist_data,
{ {
@ -136,10 +133,6 @@ def _real_extract(self, url: str):
'series_id': ('id', {str}), 'series_id': ('id', {str}),
}, },
), # type: ignore ), # type: ignore
'formats': self._extract_m3u8_formats(
m3u8_url=traverse_obj(creative, ('video', 'hls', {str})), # type: ignore
video_id=traverse_obj(creative, ('id', {str})), # type: ignore
),
}, },
) )