mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-06-12 13:54:28 +00:00
parent
70050a6262
commit
bc90c36b13
@ -21,6 +21,7 @@ class OnsenIE(InfoExtractor):
|
|||||||
IE_NAME = 'onsen'
|
IE_NAME = 'onsen'
|
||||||
IE_DESC = 'インターネットラジオステーション<音泉>'
|
IE_DESC = 'インターネットラジオステーション<音泉>'
|
||||||
|
|
||||||
|
_API_HEADERS = {'X-Client': 'onsen-web'}
|
||||||
_BASE_URL = 'https://www.onsen.ag'
|
_BASE_URL = 'https://www.onsen.ag'
|
||||||
_HEADERS = {'Referer': f'{_BASE_URL}/'}
|
_HEADERS = {'Referer': f'{_BASE_URL}/'}
|
||||||
_NETRC_MACHINE = 'onsen'
|
_NETRC_MACHINE = 'onsen'
|
||||||
@ -71,6 +72,15 @@ class OnsenIE(InfoExtractor):
|
|||||||
'playlist_mincount': 35,
|
'playlist_mincount': 35,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_temp_id(cls, url):
|
||||||
|
import base64
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
if c := urllib.parse.parse_qs(urllib.parse.urlparse(url).query).get('c'):
|
||||||
|
return base64.urlsafe_b64decode(f'{c[-1]}===').decode()
|
||||||
|
return super().get_temp_id(url)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_encoded_id(program):
|
def _get_encoded_id(program):
|
||||||
return base64.urlsafe_b64encode(str(program['id']).encode()).decode()
|
return base64.urlsafe_b64encode(str(program['id']).encode()).decode()
|
||||||
@ -80,6 +90,7 @@ class OnsenIE(InfoExtractor):
|
|||||||
f'{self._BASE_URL}/web_api/signin', None, 'Logging in', headers={
|
f'{self._BASE_URL}/web_api/signin', None, 'Logging in', headers={
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
**self._API_HEADERS,
|
||||||
}, data=json.dumps({
|
}, data=json.dumps({
|
||||||
'session': {
|
'session': {
|
||||||
'email': username,
|
'email': username,
|
||||||
@ -94,7 +105,8 @@ class OnsenIE(InfoExtractor):
|
|||||||
program_id = self._match_id(url)
|
program_id = self._match_id(url)
|
||||||
try:
|
try:
|
||||||
programs = self._download_json(
|
programs = self._download_json(
|
||||||
f'{self._BASE_URL}/web_api/programs/{program_id}', program_id)
|
f'{self._BASE_URL}/web_api/programs/{program_id}',
|
||||||
|
program_id, headers=self._API_HEADERS)
|
||||||
except ExtractorError as e:
|
except ExtractorError as e:
|
||||||
if isinstance(e.cause, HTTPError) and e.cause.status == 404:
|
if isinstance(e.cause, HTTPError) and e.cause.status == 404:
|
||||||
raise ExtractorError('Invalid URL', expected=True)
|
raise ExtractorError('Invalid URL', expected=True)
|
||||||
@ -103,8 +115,10 @@ class OnsenIE(InfoExtractor):
|
|||||||
query = {k: v[-1] for k, v in parse_qs(url).items() if v}
|
query = {k: v[-1] for k, v in parse_qs(url).items() if v}
|
||||||
if 'c' not in query:
|
if 'c' not in query:
|
||||||
entries = [
|
entries = [
|
||||||
self.url_result(update_url_query(url, {'c': self._get_encoded_id(program)}), OnsenIE)
|
self.url_result(
|
||||||
for program in traverse_obj(programs, ('contents', lambda _, v: v['id']))
|
update_url_query(url, {'c': self._get_encoded_id(program)}),
|
||||||
|
OnsenIE, str_or_none(program['id']),
|
||||||
|
) for program in traverse_obj(programs, ('contents', lambda _, v: v['id']))
|
||||||
]
|
]
|
||||||
|
|
||||||
return self.playlist_result(
|
return self.playlist_result(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user