Compare commits

..

4 Commits

Author SHA1 Message Date
garret
cb875582a7 i should have actually tested, apologies 2023-10-03 19:11:22 +01:00
garret
41b3f01fbb fix indent 2023-10-03 19:08:43 +01:00
garret
455fd3107b apply code review suggestions
Co-Authored-By: bashonly <bashonly@bashonly.com>
2023-10-03 17:05:07 +01:00
garret
9de8f42411 Revert "use aSmartPhone7a stream API"
This reverts commit e9117f0bab.
2023-10-03 17:02:05 +01:00

View File

@ -1,5 +1,5 @@
import base64
import secrets
import random
import urllib.parse
from .common import InfoExtractor
@ -70,9 +70,9 @@ class RadikoBaseIE(InfoExtractor):
def _auth_client(self):
cachedata = self.cache.load('radiko', 'auth_data')
if cachedata is not None:
response = self._download_webpage('https://radiko.jp/v2/api/auth_check', None,
'Checking cached token', expected_status=401,
headers={'X-Radiko-AuthToken': cachedata[0], 'X-Radiko-AreaId': cachedata[1]})
response = self._download_webpage(
'https://radiko.jp/v2/api/auth_check', None, 'Checking cached token', expected_status=401,
headers={'X-Radiko-AuthToken': cachedata[0], 'X-Radiko-AreaId': cachedata[1]})
if response == 'OK':
return cachedata
return self._negotiate_token()
@ -116,7 +116,7 @@ class RadikoBaseIE(InfoExtractor):
def _extract_formats(self, video_id, station, is_onair, ft, cursor, auth_token, area_id, query):
m3u8_playlist_data = self._download_xml(
f'https://radiko.jp/v3/station/stream/aSmartPhone7a/{station}.xml', video_id,
f'https://radiko.jp/v3/station/stream/pc_html5/{station}.xml', video_id,
note='Downloading stream information')
formats = []
@ -128,13 +128,12 @@ class RadikoBaseIE(InfoExtractor):
pcu = element.text
if pcu in found:
continue
else:
found.add(pcu)
found.add(pcu)
playlist_url = update_url_query(pcu, {
'station_id': station,
**query,
'l': '15',
'lsid': secrets.token_hex(16),
'lsid': ''.join(random.choices('0123456789abcdef', k=32)),
'type': 'b',
})
@ -143,7 +142,7 @@ class RadikoBaseIE(InfoExtractor):
domain = urllib.parse.urlparse(playlist_url).netloc
subformats = self._extract_m3u8_formats(
playlist_url, video_id, ext='m4a',
fatal=False, m3u8_id=domain,
live=True, fatal=False, m3u8_id=domain,
note=f'Downloading m3u8 information from {domain}',
headers={
'X-Radiko-AreaId': area_id,
@ -183,6 +182,7 @@ class RadikoIE(RadikoBaseIE):
prog, station_program, ft, radio_begin, radio_end = self._find_program(video_id, station, vid_int)
auth_token, area_id = self._auth_client()
return {
'id': video_id,
'title': try_call(lambda: prog.find('title').text),
@ -190,7 +190,7 @@ class RadikoIE(RadikoBaseIE):
'uploader': try_call(lambda: station_program.find('.//name').text),
'uploader_id': station,
'timestamp': vid_int,
'live_status': 'was_live',
'is_live': True,
'formats': self._extract_formats(
video_id=video_id, station=station, is_onair=False,
ft=ft, cursor=vid_int, auth_token=auth_token, area_id=area_id,