mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 01:01:25 +01:00
Compare commits
3 Commits
9fa8a8c094
...
cb9c6af548
Author | SHA1 | Date | |
---|---|---|---|
|
cb9c6af548 | ||
|
39d79c9b9c | ||
|
05b4b30206 |
|
@ -525,7 +525,7 @@ class TestTraversalHelpers:
|
||||||
def test_unpack(self):
|
def test_unpack(self):
|
||||||
assert unpack(lambda *x: ''.join(map(str, x)))([1, 2, 3]) == '123'
|
assert unpack(lambda *x: ''.join(map(str, x)))([1, 2, 3]) == '123'
|
||||||
assert unpack(join_nonempty)([1, 2, 3]) == '1-2-3'
|
assert unpack(join_nonempty)([1, 2, 3]) == '1-2-3'
|
||||||
assert unpack(join_nonempty(delim=' '))([1, 2, 3]) == '1 2 3'
|
assert unpack(join_nonempty, delim=' ')([1, 2, 3]) == '1 2 3'
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
unpack(join_nonempty)()
|
unpack(join_nonempty)()
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
|
|
@ -72,7 +72,6 @@ from yt_dlp.utils import (
|
||||||
intlist_to_bytes,
|
intlist_to_bytes,
|
||||||
iri_to_uri,
|
iri_to_uri,
|
||||||
is_html,
|
is_html,
|
||||||
join_nonempty,
|
|
||||||
js_to_json,
|
js_to_json,
|
||||||
limit_length,
|
limit_length,
|
||||||
locked_file,
|
locked_file,
|
||||||
|
@ -2158,10 +2157,6 @@ Line 1
|
||||||
assert int_or_none(v=10) == 10, 'keyword passed positional should call function'
|
assert int_or_none(v=10) == 10, 'keyword passed positional should call function'
|
||||||
assert int_or_none(scale=0.1)(10) == 100, 'call after partial application should call the function'
|
assert int_or_none(scale=0.1)(10) == 100, 'call after partial application should call the function'
|
||||||
|
|
||||||
assert callable(join_nonempty(delim=', ')), 'varargs positional should apply partially'
|
|
||||||
assert callable(join_nonempty()), 'varargs positional should apply partially'
|
|
||||||
assert join_nonempty(None, delim=', ') == '', 'passed varargs should call the function'
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -158,56 +158,59 @@ class RedGifsIE(RedGifsBaseInfoExtractor):
|
||||||
|
|
||||||
class RedGifsSearchIE(RedGifsBaseInfoExtractor):
|
class RedGifsSearchIE(RedGifsBaseInfoExtractor):
|
||||||
IE_DESC = 'Redgifs search'
|
IE_DESC = 'Redgifs search'
|
||||||
_VALID_URL = r'https?://(?:www\.)?redgifs\.com/browse\?(?P<query>[^#]+)'
|
_VALID_URL = r'https?://(?:www\.)?redgifs\.com/gifs/(?P<tags>[^?/]+)(\?(?P<query>[^#]+))?'
|
||||||
_PAGE_SIZE = 80
|
_PAGE_SIZE = 80
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
{
|
{
|
||||||
'url': 'https://www.redgifs.com/browse?tags=Lesbian',
|
'url': 'https://www.redgifs.com/gifs/lesbian?tab=gifs',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'tags=Lesbian',
|
'id': 'search_text=lesbian&order=trending&type=g',
|
||||||
'title': 'Lesbian',
|
'title': 'lesbian',
|
||||||
'description': 'RedGifs search for Lesbian, ordered by trending',
|
'description': 'RedGifs search for lesbian, ordered by trending',
|
||||||
},
|
},
|
||||||
'playlist_mincount': 100,
|
'playlist_mincount': 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'url': 'https://www.redgifs.com/browse?type=g&order=latest&tags=Lesbian',
|
'url': 'https://www.redgifs.com/gifs/lesbian?order=new&tab=gifs',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'type=g&order=latest&tags=Lesbian',
|
'id': 'search_text=lesbian&order=new&type=g',
|
||||||
'title': 'Lesbian',
|
'title': 'lesbian',
|
||||||
'description': 'RedGifs search for Lesbian, ordered by latest',
|
'description': 'RedGifs search for lesbian, ordered by latest',
|
||||||
},
|
},
|
||||||
'playlist_mincount': 100,
|
'playlist_mincount': 100,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'url': 'https://www.redgifs.com/browse?type=g&order=latest&tags=Lesbian&page=2',
|
|
||||||
'info_dict': {
|
|
||||||
'id': 'type=g&order=latest&tags=Lesbian&page=2',
|
|
||||||
'title': 'Lesbian',
|
|
||||||
'description': 'RedGifs search for Lesbian, ordered by latest',
|
|
||||||
},
|
|
||||||
'playlist_count': 80,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
query_str = self._match_valid_url(url).group('query')
|
match = self._match_valid_url(url)
|
||||||
|
tags = match.group('tags')
|
||||||
|
query_str = match.group('query')
|
||||||
query = urllib.parse.parse_qs(query_str)
|
query = urllib.parse.parse_qs(query_str)
|
||||||
if not query.get('tags'):
|
|
||||||
raise ExtractorError('Invalid query tags', expected=True)
|
|
||||||
|
|
||||||
tags = query.get('tags')[0]
|
|
||||||
order = query.get('order', ('trending',))[0]
|
order = query.get('order', ('trending',))[0]
|
||||||
|
|
||||||
query['search_text'] = [tags]
|
tab = query.get('tab', (None,))[0]
|
||||||
entries = self._paged_entries('gifs/search', query_str, query, {
|
# TODO: Can we support creators / niches tabs?
|
||||||
|
tab_to_type = {
|
||||||
|
'gifs': 'g',
|
||||||
|
'images': 'i',
|
||||||
|
}
|
||||||
|
if tab not in tab_to_type:
|
||||||
|
raise ExtractorError('Only "See all" search pages for gifs/images are supported.', expected=True)
|
||||||
|
|
||||||
|
search_query = {
|
||||||
|
'search_text': [tags],
|
||||||
|
'order': [order],
|
||||||
|
'type': [tab_to_type[tab]],
|
||||||
|
}
|
||||||
|
playlist_id = urllib.parse.urlencode(search_query, doseq=True)
|
||||||
|
entries = self._paged_entries('gifs/search', playlist_id, search_query, {
|
||||||
'search_text': None,
|
'search_text': None,
|
||||||
'order': 'trending',
|
'order': 'trending',
|
||||||
'type': None,
|
'type': None,
|
||||||
})
|
})
|
||||||
|
|
||||||
return self.playlist_result(
|
return self.playlist_result(
|
||||||
entries, query_str, tags, f'RedGifs search for {tags}, ordered by {order}')
|
entries, playlist_id, tags, f'RedGifs search for {tags}, ordered by {order}')
|
||||||
|
|
||||||
|
|
||||||
class RedGifsUserIE(RedGifsBaseInfoExtractor):
|
class RedGifsUserIE(RedGifsBaseInfoExtractor):
|
||||||
|
|
|
@ -216,7 +216,7 @@ def partial_application(func):
|
||||||
sig = inspect.signature(func)
|
sig = inspect.signature(func)
|
||||||
required_args = [
|
required_args = [
|
||||||
param.name for param in sig.parameters.values()
|
param.name for param in sig.parameters.values()
|
||||||
if param.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.VAR_POSITIONAL)
|
if param.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)
|
||||||
if param.default is inspect.Parameter.empty
|
if param.default is inspect.Parameter.empty
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4837,7 +4837,6 @@ def number_of_digits(number):
|
||||||
return len('%d' % number)
|
return len('%d' % number)
|
||||||
|
|
||||||
|
|
||||||
@partial_application
|
|
||||||
def join_nonempty(*values, delim='-', from_dict=None):
|
def join_nonempty(*values, delim='-', from_dict=None):
|
||||||
if from_dict is not None:
|
if from_dict is not None:
|
||||||
values = (traversal.traverse_obj(from_dict, variadic(v)) for v in values)
|
values = (traversal.traverse_obj(from_dict, variadic(v)) for v in values)
|
||||||
|
|
|
@ -452,9 +452,9 @@ def trim_str(*, start=None, end=None):
|
||||||
return trim
|
return trim
|
||||||
|
|
||||||
|
|
||||||
def unpack(func):
|
def unpack(func, **kwargs):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def inner(items, **kwargs):
|
def inner(items):
|
||||||
return func(*items, **kwargs)
|
return func(*items, **kwargs)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
Loading…
Reference in New Issue
Block a user