import functools
-import urllib
+import urllib.parse
from .common import InfoExtractor
-from ..compat import compat_parse_qs
+from ..networking.exceptions import HTTPError
from ..utils import (
ExtractorError,
+ OnDemandPagedList,
int_or_none,
qualities,
try_get,
- OnDemandPagedList,
)
'height': height,
'quality': quality(format_id),
})
- self._sort_formats(formats)
return {
'id': video_id,
raise ExtractorError('Unable to get temporary token')
self._API_HEADERS['authorization'] = f'Bearer {auth["token"]}'
- def _call_api(self, ep, video_id, *args, **kwargs):
- for attempt in range(2):
+ def _call_api(self, ep, video_id, **kwargs):
+ for first_attempt in True, False:
if 'authorization' not in self._API_HEADERS:
self._fetch_oauth_token(video_id)
try:
headers = dict(self._API_HEADERS)
headers['x-customheader'] = f'https://www.redgifs.com/watch/{video_id}'
data = self._download_json(
- f'https://api.redgifs.com/v2/{ep}', video_id, headers=headers, *args, **kwargs)
+ f'https://api.redgifs.com/v2/{ep}', video_id, headers=headers, **kwargs)
break
except ExtractorError as e:
- if not attempt and isinstance(e.cause, urllib.error.HTTPError) and e.cause.code == 401:
+ if first_attempt and isinstance(e.cause, HTTPError) and e.cause.status == 401:
del self._API_HEADERS['authorization'] # refresh the token
+ continue
raise
if 'error' in data:
'categories': list,
'age_limit': 18,
'tags': list,
- }
+ },
}, {
'url': 'https://thumbs2.redgifs.com/SqueakyHelplessWisent-mobile.mp4#t=0',
'info_dict': {
'categories': list,
'age_limit': 18,
'tags': list,
- }
+ },
}]
def _real_extract(self, url):
'info_dict': {
'id': 'tags=Lesbian',
'title': 'Lesbian',
- 'description': 'RedGifs search for Lesbian, ordered by trending'
+ 'description': 'RedGifs search for Lesbian, ordered by trending',
},
'playlist_mincount': 100,
},
'info_dict': {
'id': 'type=g&order=latest&tags=Lesbian',
'title': 'Lesbian',
- 'description': 'RedGifs search for Lesbian, ordered by latest'
+ 'description': 'RedGifs search for Lesbian, ordered by latest',
},
'playlist_mincount': 100,
},
'info_dict': {
'id': 'type=g&order=latest&tags=Lesbian&page=2',
'title': 'Lesbian',
- 'description': 'RedGifs search for Lesbian, ordered by latest'
+ 'description': 'RedGifs search for Lesbian, ordered by latest',
},
'playlist_count': 80,
- }
+ },
]
def _real_extract(self, url):
query_str = self._match_valid_url(url).group('query')
- query = compat_parse_qs(query_str)
+ query = urllib.parse.parse_qs(query_str)
if not query.get('tags'):
raise ExtractorError('Invalid query tags', expected=True)
'info_dict': {
'id': 'lamsinka89',
'title': 'lamsinka89',
- 'description': 'RedGifs user lamsinka89, ordered by recent'
+ 'description': 'RedGifs user lamsinka89, ordered by recent',
},
'playlist_mincount': 100,
},
'info_dict': {
'id': 'lamsinka89?page=3',
'title': 'lamsinka89',
- 'description': 'RedGifs user lamsinka89, ordered by recent'
+ 'description': 'RedGifs user lamsinka89, ordered by recent',
},
'playlist_count': 30,
},
'info_dict': {
'id': 'lamsinka89?order=best&type=g',
'title': 'lamsinka89',
- 'description': 'RedGifs user lamsinka89, ordered by best'
+ 'description': 'RedGifs user lamsinka89, ordered by best',
},
'playlist_mincount': 100,
- }
+ },
]
def _real_extract(self, url):
username, query_str = self._match_valid_url(url).group('username', 'query')
playlist_id = f'{username}?{query_str}' if query_str else username
- query = compat_parse_qs(query_str)
+ query = urllib.parse.parse_qs(query_str)
order = query.get('order', ('recent',))[0]
entries = self._paged_entries(f'users/{username}/search', playlist_id, query, {