Skip to content

Commit

Permalink
abematv: convert onair_channels traversing to traverse_obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesmiscore committed Apr 9, 2022
1 parent 7cb6b0c commit 5396ed0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
5 changes: 2 additions & 3 deletions yt_dlp/downloader/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import threading
import typing
import http.server
import inspect

if typing.TYPE_CHECKING:
from .common import FileDownloader
Expand Down Expand Up @@ -210,10 +209,10 @@ def chain(callbacks, handler):
def wrapper(handler):
assert struct(handler)

if not inspect.isfunction(struct):
if not callable(struct):
route_callbacks = []
for r in struct['routes']:
if inspect.isfunction(r):
if callable(r):
route_callbacks.append(r)
continue
if 'data' in r:
Expand Down
15 changes: 4 additions & 11 deletions yt_dlp/extractor/abematv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
random_uuidv4,
request_to_url,
time_seconds,
update_url_query,
traverse_obj,
intlist_to_bytes,
bytes_to_intlist,
Expand Down Expand Up @@ -443,15 +442,10 @@ def _real_extract(self, url):
is_live, m3u8_url = False, None
if video_type == 'now-on-air':
is_live = True
channel_url = 'https://api.abema.io/v1/channels'
if video_id == 'news-global':
channel_url = update_url_query(channel_url, {'division': '1'})
onair_channels = self._download_json(channel_url, video_id)
for ch in onair_channels['channels']:
if video_id == ch['id']:
m3u8_url = ch['playback']['hls']
break
else:
onair_channels = self._download_json(
'https://api.abema.io/v1/channels', video_id)
m3u8_url = traverse_obj(onair_channels, ('channels', lambda _, v: v['id'] == video_id, 'playback', 'hls'), get_all=False)
if not m3u8_url:
raise ExtractorError(f'Cannot find on-air {video_id} channel.', expected=True)
elif video_type == 'episode':
api_response = self._download_json(
Expand All @@ -460,7 +454,6 @@ def _real_extract(self, url):
headers=headers)
ondemand_types = traverse_obj(api_response, ('terms', ..., 'onDemandType'), default=[])
if 3 not in ondemand_types:
# cannot acquire decryption key for these streams
self.report_warning('This is a premium-only stream')

m3u8_url = f'https://vod-abematv.akamaized.net/program/{video_id}/playlist.m3u8'
Expand Down

0 comments on commit 5396ed0

Please sign in to comment.