mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-05-01 21:16:13 +00:00
improvements/cleanup
Authored by: bashonly
This commit is contained in:
parent
e242c884a8
commit
b7e8d0cf48
@ -637,6 +637,10 @@ class TwitchPlaylistBaseIE(TwitchBaseIE):
|
|||||||
_PAGE_LIMIT = 100
|
_PAGE_LIMIT = 100
|
||||||
|
|
||||||
def _entries(self, channel_name, *args):
|
def _entries(self, channel_name, *args):
|
||||||
|
"""
|
||||||
|
Subclasses must define _make_variables() and _extract_entry(),
|
||||||
|
as well as set _OPERATION_NAME, _ENTRY_KIND, _EDGE_KIND, and _NODE_KIND
|
||||||
|
"""
|
||||||
cursor = None
|
cursor = None
|
||||||
variables_common = self._make_variables(channel_name, *args)
|
variables_common = self._make_variables(channel_name, *args)
|
||||||
entries_key = f'{self._ENTRY_KIND}s'
|
entries_key = f'{self._ENTRY_KIND}s'
|
||||||
@ -676,7 +680,22 @@ class TwitchPlaylistBaseIE(TwitchBaseIE):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
class TwitchVideosIE(TwitchPlaylistBaseIE):
|
class TwitchVideosBaseIE(TwitchPlaylistBaseIE):
|
||||||
|
_OPERATION_NAME = 'FilterableVideoTower_Videos'
|
||||||
|
_ENTRY_KIND = 'video'
|
||||||
|
_EDGE_KIND = 'VideoEdge'
|
||||||
|
_NODE_KIND = 'Video'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _make_variables(channel_name, broadcast_type, sort):
|
||||||
|
return {
|
||||||
|
'channelOwnerLogin': channel_name,
|
||||||
|
'broadcastType': broadcast_type,
|
||||||
|
'videoSort': sort.upper(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TwitchVideosIE(TwitchVideosBaseIE):
|
||||||
_VALID_URL = r'https?://(?:(?:www|go|m)\.)?twitch\.tv/(?P<id>[^/]+)/(?:videos|profile)'
|
_VALID_URL = r'https?://(?:(?:www|go|m)\.)?twitch\.tv/(?P<id>[^/]+)/(?:videos|profile)'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
@ -755,11 +774,6 @@ class TwitchVideosIE(TwitchPlaylistBaseIE):
|
|||||||
'views': 'Popular',
|
'views': 'Popular',
|
||||||
}
|
}
|
||||||
|
|
||||||
_OPERATION_NAME = 'FilterableVideoTower_Videos'
|
|
||||||
_ENTRY_KIND = 'video'
|
|
||||||
_EDGE_KIND = 'VideoEdge'
|
|
||||||
_NODE_KIND = 'Video'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suitable(cls, url):
|
def suitable(cls, url):
|
||||||
return (False
|
return (False
|
||||||
@ -768,14 +782,6 @@ class TwitchVideosIE(TwitchPlaylistBaseIE):
|
|||||||
TwitchVideosCollectionsIE))
|
TwitchVideosCollectionsIE))
|
||||||
else super().suitable(url))
|
else super().suitable(url))
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _make_variables(channel_name, broadcast_type, sort):
|
|
||||||
return {
|
|
||||||
'channelOwnerLogin': channel_name,
|
|
||||||
'broadcastType': broadcast_type,
|
|
||||||
'videoSort': sort.upper(),
|
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_entry(node):
|
def _extract_entry(node):
|
||||||
return _make_video_result(node)
|
return _make_video_result(node)
|
||||||
@ -923,7 +929,7 @@ class TwitchVideosCollectionsIE(TwitchPlaylistBaseIE):
|
|||||||
playlist_title=f'{channel_name} - Collections')
|
playlist_title=f'{channel_name} - Collections')
|
||||||
|
|
||||||
|
|
||||||
class TwitchStreamIE(TwitchPlaylistBaseIE):
|
class TwitchStreamIE(TwitchVideosBaseIE):
|
||||||
IE_NAME = 'twitch:stream'
|
IE_NAME = 'twitch:stream'
|
||||||
_VALID_URL = r'''(?x)
|
_VALID_URL = r'''(?x)
|
||||||
https?://
|
https?://
|
||||||
@ -987,10 +993,6 @@ class TwitchStreamIE(TwitchPlaylistBaseIE):
|
|||||||
},
|
},
|
||||||
}]
|
}]
|
||||||
_PAGE_LIMIT = 1
|
_PAGE_LIMIT = 1
|
||||||
_OPERATION_NAME = 'FilterableVideoTower_Videos'
|
|
||||||
_ENTRY_KIND = 'video'
|
|
||||||
_EDGE_KIND = 'VideoEdge'
|
|
||||||
_NODE_KIND = 'Video'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def suitable(cls, url):
|
def suitable(cls, url):
|
||||||
@ -1004,14 +1006,6 @@ class TwitchStreamIE(TwitchPlaylistBaseIE):
|
|||||||
TwitchClipsIE))
|
TwitchClipsIE))
|
||||||
else super().suitable(url))
|
else super().suitable(url))
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _make_variables(channel_name, broadcast_type, sort):
|
|
||||||
return {
|
|
||||||
'channelOwnerLogin': channel_name,
|
|
||||||
'broadcastType': broadcast_type,
|
|
||||||
'videoSort': sort.upper(),
|
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_entry(node):
|
def _extract_entry(node):
|
||||||
if not isinstance(node, dict) or not node.get('id'):
|
if not isinstance(node, dict) or not node.get('id'):
|
||||||
@ -1065,7 +1059,7 @@ class TwitchStreamIE(TwitchPlaylistBaseIE):
|
|||||||
if self.get_param('live_from_start'):
|
if self.get_param('live_from_start'):
|
||||||
self.to_screen(f'{channel_name}: Extracting VOD to download live from start')
|
self.to_screen(f'{channel_name}: Extracting VOD to download live from start')
|
||||||
entry = next(self._entries(channel_name, None, 'time'), None)
|
entry = next(self._entries(channel_name, None, 'time'), None)
|
||||||
if entry and entry['timestamp'] >= timestamp:
|
if entry and entry['timestamp'] >= (timestamp or float('inf')):
|
||||||
return entry
|
return entry
|
||||||
self.report_warning(
|
self.report_warning(
|
||||||
'Unable to extract the VOD associated with this livestream', video_id=channel_name)
|
'Unable to extract the VOD associated with this livestream', video_id=channel_name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user