From 8eb59a1862d2bf509b95e139ac01e018b68d97c3 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 28 Jul 2024 16:25:57 +0200 Subject: [PATCH] sr: fix support for music files via language argument --- lib/svtplay_dl/service/sr.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/svtplay_dl/service/sr.py b/lib/svtplay_dl/service/sr.py index 62f67e83..af458726 100644 --- a/lib/svtplay_dl/service/sr.py +++ b/lib/svtplay_dl/service/sr.py @@ -1,7 +1,6 @@ # ex:ts=4:sw=4:sts=4:et # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- import copy -import json import re from svtplay_dl.error import ServiceError @@ -17,15 +16,21 @@ def get(self): data = self.get_urldata() match = re.search(r'data-audio-id="(\d+)"', data) - match2 = re.search(r'data-audio-type="(\w+)"', data) + match2 = re.search(r'data-publication-id="(\w+)"', data) if match and match2: aid = match.group(1) - type = match2.group(1) + pubid = match2.group(1) else: yield ServiceError("Can't find audio info") return - dataurl = f"https://sverigesradio.se/sida/playerajax/getaudiourl?id={aid}&type={type}&quality=high&format=iis" - data = self.http.request("get", dataurl).text - playerinfo = json.loads(data) - yield HTTP(copy.copy(self.config), playerinfo["audioUrl"], 128, output=self.output) + for what in ["episode", "secondary"]: + language = "" + apiurl = f"https://sverigesradio.se/playerajax/audio?id={aid}&type={what}&publicationid={pubid}&quality=high" + resp = self.http.request("get", apiurl) + if resp.status_code > 400: + continue + playerinfo = resp.json() + if what == "secondary": + language = "musik" + yield HTTP(copy.copy(self.config), playerinfo["audioUrl"], 128, output=self.output, language=language)