mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-01-05 11:01:49 +01:00
[nrk] Accidentally removed login function
This commit is contained in:
parent
670ac229d9
commit
38746cb1af
1 changed files with 33 additions and 0 deletions
|
@ -1,8 +1,10 @@
|
||||||
import itertools
|
import itertools
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..networking.exceptions import HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
|
@ -12,6 +14,7 @@ from ..utils import (
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
|
try_get,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urljoin,
|
urljoin,
|
||||||
)
|
)
|
||||||
|
@ -324,6 +327,36 @@ class NRKIE(NRKBaseIE):
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
def _perform_login(self, username, password):
|
||||||
|
try:
|
||||||
|
self._download_json(
|
||||||
|
self._LOGIN_URL, None, headers={'Content-Type': 'application/json; charset=UTF-8', 'accept': 'application/json; charset=utf-8'},
|
||||||
|
data=json.dumps({
|
||||||
|
'clientId': '',
|
||||||
|
'hashedPassword': {'current': {
|
||||||
|
'hash': password,
|
||||||
|
'recipe': {
|
||||||
|
'algorithm': 'cleartext',
|
||||||
|
'salt': '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'password': password,
|
||||||
|
'username': username,
|
||||||
|
}).encode())
|
||||||
|
|
||||||
|
self._download_webpage('https://tv.nrk.no/auth/web/login/opsession', None)
|
||||||
|
response = self._download_json('https://tv.nrk.no/auth/session/tokenforsub/_', None)
|
||||||
|
self._AUTH_TOKEN = traverse_obj(response, ('session', 'accessToken'))
|
||||||
|
self._API_CALL_HEADERS['authorization'] = f'Bearer {self._AUTH_TOKEN}'
|
||||||
|
except ExtractorError as e:
|
||||||
|
message = None
|
||||||
|
if isinstance(e.cause, HTTPError) and e.cause.status in (401, 400):
|
||||||
|
resp = self._parse_json(
|
||||||
|
e.cause.response.read().decode(), None, fatal=False) or {}
|
||||||
|
message = next((error['message'] for error in resp['errors'] if error['field'] == 'Password'), None)
|
||||||
|
self.report_warning(message or 'Unable to log in')
|
||||||
|
|
||||||
|
|
||||||
class NRKTVIE(NRKBaseIE):
|
class NRKTVIE(NRKBaseIE):
|
||||||
IE_DESC = 'NRK TV and NRK Radio'
|
IE_DESC = 'NRK TV and NRK Radio'
|
||||||
|
|
Loading…
Reference in a new issue