Skip to content

Commit

Permalink
Handle Areena redirecting to /audio/
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Mar 3, 2022
1 parent 339032a commit 9ebf9f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion yledl/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
from .streamprobe import FullHDFlavorProber
from .timestamp import parse_areena_timestamp
from .subtitles import Subtitle
from .http import Redirected


logger = logging.getLogger('yledl')


class PlaylistRedirected(Exception):
def __init__(self, message: str, suggested_url: str) -> None:
super().__init__(message)
self.suggested_url = suggested_url


def extractor_factory(url, filters, language_chooser, httpclient):
if re.match(r'^https?://yle\.fi/aihe/', url) or \
re.match(r'^https?://svenska\.yle\.fi/artikel/', url) or \
Expand Down Expand Up @@ -205,10 +212,21 @@ def __init__(self, httpclient):
self.httpclient = httpclient

def extract(self, url, latest_only, title_formatter, ffprobe):
playlist = self.get_playlist(url, latest_only)
playlist = self.guarded_get_playlist(url, latest_only)
return (self.extract_clip(clipurl, title_formatter, ffprobe)
for clipurl in playlist)

def guarded_get_playlist(self, url, latest_only=False):
# get_playlist, but with a guard to turn a http Redirected error to a PlaylistRedirected
# for upstream handling
try:
return self.get_playlist(url, latest_only)
except Redirected as r:
raise PlaylistRedirected(
f"Redirected while retrieving playlist: please try {r.response.url!r} instead",
suggested_url=r.response.url,
) from r

def get_playlist(self, url, latest_only=False):
raise NotImplementedError("get_playlist must be overridden")

Expand Down
2 changes: 1 addition & 1 deletion yledl/yledl.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def clips():
title_formatter, io.ffprobe())

if action == StreamAction.PRINT_EPISODE_PAGES:
print_lines(extractor.get_playlist(url))
print_lines(extractor.guarded_get_playlist(url))
return RD_SUCCESS
elif action == StreamAction.PRINT_STREAM_URL:
print_lines(dl.get_urls(clips(), stream_filters))
Expand Down

0 comments on commit 9ebf9f2

Please sign in to comment.