mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 06:27:21 +00:00
add login error handling
Authored by: bashonly
This commit is contained in:
parent
61007bb684
commit
4918dfd46b
|
@ -1,7 +1,9 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..networking.exceptions import HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
clean_html,
|
clean_html,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
join_nonempty,
|
join_nonempty,
|
||||||
|
@ -15,7 +17,6 @@
|
||||||
class GameDevTVDashboardIE(InfoExtractor):
|
class GameDevTVDashboardIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<id>\d+)'
|
||||||
_NETRC_MACHINE = 'gamedevtv'
|
_NETRC_MACHINE = 'gamedevtv'
|
||||||
_API_HEADERS = {}
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.gamedev.tv/dashboard/courses/25',
|
'url': 'https://www.gamedev.tv/dashboard/courses/25',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
|
@ -31,8 +32,10 @@ class GameDevTVDashboardIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
'playlist_count': 100,
|
'playlist_count': 100,
|
||||||
}]
|
}]
|
||||||
|
_API_HEADERS = {}
|
||||||
|
|
||||||
def _perform_login(self, username, password):
|
def _perform_login(self, username, password):
|
||||||
|
try:
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
|
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
|
||||||
headers={'Content-Type': 'application/json'},
|
headers={'Content-Type': 'application/json'},
|
||||||
|
@ -41,6 +44,11 @@ def _perform_login(self, username, password):
|
||||||
'password': password,
|
'password': password,
|
||||||
'cart_items': [],
|
'cart_items': [],
|
||||||
}).encode())
|
}).encode())
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
|
||||||
|
raise ExtractorError('Invalid username/password', expected=True)
|
||||||
|
raise
|
||||||
|
|
||||||
self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
|
self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
|
||||||
|
|
||||||
def _real_initialize(self):
|
def _real_initialize(self):
|
||||||
|
|
Loading…
Reference in a new issue