From 1a14d26b1b673685f1c70f92a420a1af591005aa Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Tue, 8 May 2018 22:48:55 +0200 Subject: [PATCH] Return empty dict instead of None --- lib/svtplay_dl/fetcher/dash.py | 8 +++----- lib/svtplay_dl/fetcher/hds.py | 2 +- lib/svtplay_dl/service/aftonbladet.py | 12 +++++------- lib/svtplay_dl/service/atg.py | 2 -- lib/svtplay_dl/service/bigbrother.py | 5 ++--- lib/svtplay_dl/service/cmore.py | 5 ++--- lib/svtplay_dl/service/dplay.py | 5 ++--- lib/svtplay_dl/service/efn.py | 5 ++--- lib/svtplay_dl/service/eurosport.py | 5 ++--- lib/svtplay_dl/service/lemonwhale.py | 5 ++--- lib/svtplay_dl/service/mtvnn.py | 11 ++++------- lib/svtplay_dl/service/nhl.py | 5 ++--- lib/svtplay_dl/service/picsearch.py | 5 ++--- lib/svtplay_dl/service/riksdagen.py | 5 ++--- lib/svtplay_dl/service/sportlib.py | 5 ++--- lib/svtplay_dl/service/tv4play.py | 10 ++++------ lib/svtplay_dl/service/vg.py | 5 ++--- lib/svtplay_dl/service/viaplay.py | 10 ++++------ lib/svtplay_dl/service/viasatsport.py | 5 ++--- 19 files changed, 45 insertions(+), 70 deletions(-) diff --git a/lib/svtplay_dl/fetcher/dash.py b/lib/svtplay_dl/fetcher/dash.py index e7390a2..2780be4 100644 --- a/lib/svtplay_dl/fetcher/dash.py +++ b/lib/svtplay_dl/fetcher/dash.py @@ -135,14 +135,14 @@ def dashparse(config, res, url, output=None): duration_sec = None if not res: - return None + return streams if res.status_code >= 400: streams[0] = ServiceError("Can't read DASH playlist. {0}".format(res.status_code)) return streams if len(res.text) < 1: streams[0] = ServiceError("Can't read DASH playlist. {0}, size: {1}".format(res.status_code, len(res.text))) - return + return streams xml = ET.XML(res.text) if xml.find("./{urn:mpeg:dash:schema:mpd:2011}BaseURL") is not None: @@ -168,9 +168,7 @@ def dashparse(config, res, url, output=None): if not audiofiles or not videofiles: streams[0] = ServiceError("Found no Audiofiles or Videofiles to download.") - return - - options.set("other", "mp4") + return streams for i in videofiles.keys(): bitrate = i + list(audiofiles.keys())[0] diff --git a/lib/svtplay_dl/fetcher/hds.py b/lib/svtplay_dl/fetcher/hds.py index 7d46567..7010316 100644 --- a/lib/svtplay_dl/fetcher/hds.py +++ b/lib/svtplay_dl/fetcher/hds.py @@ -39,7 +39,7 @@ def hdsparse(config, res, manifest, output=None): bootstrap = {} if not res: - return None + return streams if res.status_code >= 400: streams[0] = ServiceError("Can't read HDS playlist. {0}".format(res.status_code)) diff --git a/lib/svtplay_dl/service/aftonbladet.py b/lib/svtplay_dl/service/aftonbladet.py index fcf296d..f726035 100644 --- a/lib/svtplay_dl/service/aftonbladet.py +++ b/lib/svtplay_dl/service/aftonbladet.py @@ -35,9 +35,8 @@ class Aftonbladettv(Service): data = json.loads(data) streams = hlsparse(self.config, self.http.request("get", data["streamUrls"]["hls"]), data["streamUrls"]["hls"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] class Aftonbladet(Service): @@ -89,7 +88,6 @@ class Aftonbladet(Service): params={"hdcore": "3.7.0"}), streamUrls["hds"])) - if streams: - for s in streams: - for key in list(s.keys()): - yield s[key] + for s in streams: + for key in list(s.keys()): + yield s[key] diff --git a/lib/svtplay_dl/service/atg.py b/lib/svtplay_dl/service/atg.py index 064caf9..f3862fc 100644 --- a/lib/svtplay_dl/service/atg.py +++ b/lib/svtplay_dl/service/atg.py @@ -37,10 +37,8 @@ class Atg(Service): if "urls" in janson: for i in janson["urls"]: - stream = None if "m3u" == i: stream = hlsparse(self.config, self.http.request("get", janson["urls"]["m3u"]), janson["urls"]["m3u"]) - if stream: for key in list(stream.keys()): yield stream[key] diff --git a/lib/svtplay_dl/service/bigbrother.py b/lib/svtplay_dl/service/bigbrother.py index 0be75eb..8a0c216 100644 --- a/lib/svtplay_dl/service/bigbrother.py +++ b/lib/svtplay_dl/service/bigbrother.py @@ -64,9 +64,8 @@ class Bigbrother(Service, OpenGraphThumbMixin): if i["defaultURL"].endswith("f4m"): streams = hdsparse(copy.copy(self.config), self.http.request("get", i["defaultURL"], params={"hdcore": "3.7.0"}), i["defaultURL"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] if i["defaultURL"].endswith("m3u8"): streams = hlsparse(self.config, self.http.request("get", i["defaultURL"]), i["defaultURL"]) diff --git a/lib/svtplay_dl/service/cmore.py b/lib/svtplay_dl/service/cmore.py index 740bbe4..f68a60c 100644 --- a/lib/svtplay_dl/service/cmore.py +++ b/lib/svtplay_dl/service/cmore.py @@ -61,9 +61,8 @@ class Cmore(Service): i = janson["playback"]["items"]["item"] if i["mediaFormat"] == "ism": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def _autoname(self, vid): url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}.json?expand=metadata".format(self._gettld(), vid) diff --git a/lib/svtplay_dl/service/dplay.py b/lib/svtplay_dl/service/dplay.py index 3d6f59f..00b0f46 100644 --- a/lib/svtplay_dl/service/dplay.py +++ b/lib/svtplay_dl/service/dplay.py @@ -81,9 +81,8 @@ class Dplay(Service): return streams = hlsparse(self.config, self.http.request("get", res.json()["data"]["attributes"]["streaming"]["hls"]["url"]), res.json()["data"]["attributes"]["streaming"]["hls"]["url"], httpobject=self.http) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def _autoname(self, jsondata): match = re.search('^([^/]+)/', jsondata["data"]["attributes"]["path"]) diff --git a/lib/svtplay_dl/service/efn.py b/lib/svtplay_dl/service/efn.py index c558151..5fa8f38 100644 --- a/lib/svtplay_dl/service/efn.py +++ b/lib/svtplay_dl/service/efn.py @@ -16,6 +16,5 @@ class Efn(Service, OpenGraphThumbMixin): return streams = hlsparse(self.config, self.http.request("get", match.group(1)), match.group(1)) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] diff --git a/lib/svtplay_dl/service/eurosport.py b/lib/svtplay_dl/service/eurosport.py index 1fa96ad..2c7b765 100644 --- a/lib/svtplay_dl/service/eurosport.py +++ b/lib/svtplay_dl/service/eurosport.py @@ -98,6 +98,5 @@ class Eurosport(Service): hls_url = res.json()["stream"]["complete"] streams = hlsparse(self.config, self.http.request("get", hls_url), hls_url, authorization=access_token) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] diff --git a/lib/svtplay_dl/service/lemonwhale.py b/lib/svtplay_dl/service/lemonwhale.py index 02ef5dd..b5ed385 100644 --- a/lib/svtplay_dl/service/lemonwhale.py +++ b/lib/svtplay_dl/service/lemonwhale.py @@ -34,9 +34,8 @@ class Lemonwhale(Service): jdata = json.loads(data) if "videos" in jdata: streams = self.get_video(jdata) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def get_vid(self): match = re.search(r'video url-([^"]+)', self.get_urldata()) diff --git a/lib/svtplay_dl/service/mtvnn.py b/lib/svtplay_dl/service/mtvnn.py index d0cadef..052d661 100644 --- a/lib/svtplay_dl/service/mtvnn.py +++ b/lib/svtplay_dl/service/mtvnn.py @@ -53,10 +53,8 @@ class Mtvnn(Service, OpenGraphThumbMixin): hls_url = xml.find("./video").find("item").find("rendition").find("src").text stream = hlsparse(self.config, self.http.request("get", hls_url), hls_url) - if stream: - - for key in list(stream.keys()): - yield stream[key] + for key in list(stream.keys()): + yield stream[key] return match = re.search(r'data-mrss=[\'"](http://gakusei-cluster.mtvnn.com/v2/mrss.xml[^\'"]+)[\'"]', data) @@ -96,9 +94,8 @@ class Mtvnn(Service, OpenGraphThumbMixin): dataj = json.loads(data) for i in dataj["local_playlist_videos"]: streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def find_all_episodes(self, config): match = re.search(r"data-franchise='([^']+)'", self.get_urldata()) diff --git a/lib/svtplay_dl/service/nhl.py b/lib/svtplay_dl/service/nhl.py index fb30be0..c377e2a 100644 --- a/lib/svtplay_dl/service/nhl.py +++ b/lib/svtplay_dl/service/nhl.py @@ -46,6 +46,5 @@ class NHL(Service, OpenGraphThumbMixin): janson = res.json() for i in janson["user_verified_event"][0]["user_verified_content"][0]["user_verified_media_item"]: streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] diff --git a/lib/svtplay_dl/service/picsearch.py b/lib/svtplay_dl/service/picsearch.py index 7fe2f10..6ae31a9 100644 --- a/lib/svtplay_dl/service/picsearch.py +++ b/lib/svtplay_dl/service/picsearch.py @@ -55,9 +55,8 @@ class Picsearch(Service, OpenGraphThumbMixin): for i in jansson["media"]["playerconfig"]["playlist"]: if "provider" in i and i["provider"] == "httpstreaming": streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def get_auth(self): match = re.search(r"picsearch_ajax_auth[ ]*=[ ]*['\"]([^'\"]+)['\"]", self.get_urldata()) diff --git a/lib/svtplay_dl/service/riksdagen.py b/lib/svtplay_dl/service/riksdagen.py index 53aad79..4dcd75d 100644 --- a/lib/svtplay_dl/service/riksdagen.py +++ b/lib/svtplay_dl/service/riksdagen.py @@ -30,6 +30,5 @@ class Riksdagen(Service, OpenGraphThumbMixin): if i["mimetype"] == "application/x-mpegurl": data2 = self.http.get(i["url"]).json() streams = hlsparse(self.config, self.http.request("get", data2["url"]), data2["url"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] diff --git a/lib/svtplay_dl/service/sportlib.py b/lib/svtplay_dl/service/sportlib.py index c47b986..b0562fc 100644 --- a/lib/svtplay_dl/service/sportlib.py +++ b/lib/svtplay_dl/service/sportlib.py @@ -67,6 +67,5 @@ class Sportlib(Service, OpenGraphThumbMixin): res = self.http.post("https://playlist.oz.com/cookie", json=postjson) cookies = res.cookies streams = hlsparse(self.config, self.http.request("get", hlsplaylist), hlsplaylist, keycookie=cookies) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] diff --git a/lib/svtplay_dl/service/tv4play.py b/lib/svtplay_dl/service/tv4play.py index 4eaa27b..4964f98 100644 --- a/lib/svtplay_dl/service/tv4play.py +++ b/lib/svtplay_dl/service/tv4play.py @@ -33,10 +33,9 @@ class Tv4play(Service, OpenGraphThumbMixin): self.config.set("live", True) self.options.hls_time_stamp = True - if streams: - for n in list(streams.keys()): - yield streams[n] streams = hlsparse(self.config, self.http.request("get", url), url) + for n in list(streams.keys()): + yield streams[n] return data = self.get_urldata() @@ -110,10 +109,9 @@ class Tv4play(Service, OpenGraphThumbMixin): if i.find("mediaFormat").text == "mp4": parse = urlparse(i.find("url").text) if parse.path.endswith("m3u8"): - if streams: - for n in list(streams.keys()): - yield streams[n] streams = hlsparse(self.config, self.http.request("get", i.find("url").text), i.find("url").text) + for n in list(streams.keys()): + yield streams[n] def _get_show_info(self): show = self._get_showname() diff --git a/lib/svtplay_dl/service/vg.py b/lib/svtplay_dl/service/vg.py index 3e0eacd..d3cfabc 100644 --- a/lib/svtplay_dl/service/vg.py +++ b/lib/svtplay_dl/service/vg.py @@ -31,9 +31,8 @@ class Vg(Service, OpenGraphThumbMixin): if "hds" in jsondata["streamUrls"]: streams = hdsparse(self.config, self.http.request("get", jsondata["streamUrls"]["hds"], params={"hdcore": "3.7.0"}), jsondata["streamUrls"]["hds"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] if "hls" in jsondata["streamUrls"]: streams = hlsparse(self.config, self.http.request("get", jsondata["streamUrls"]["hls"]), jsondata["streamUrls"]["hls"]) for n in list(streams.keys()): diff --git a/lib/svtplay_dl/service/viaplay.py b/lib/svtplay_dl/service/viaplay.py index 230d469..dd80b61 100644 --- a/lib/svtplay_dl/service/viaplay.py +++ b/lib/svtplay_dl/service/viaplay.py @@ -164,9 +164,8 @@ class Viaplay(Service, OpenGraphThumbMixin): filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse(self.config, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] else: parse = urlparse(filename) match = re.search("^(/[^/]+)/(.*)", parse.path) @@ -180,9 +179,8 @@ class Viaplay(Service, OpenGraphThumbMixin): if streamj["streams"]["hls"]: streams = hlsparse(self.config, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"]) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n] def find_all_episodes(self, options): seasons = [] diff --git a/lib/svtplay_dl/service/viasatsport.py b/lib/svtplay_dl/service/viasatsport.py index 37a9fb6..e592d03 100644 --- a/lib/svtplay_dl/service/viasatsport.py +++ b/lib/svtplay_dl/service/viasatsport.py @@ -26,6 +26,5 @@ class Viasatsport(Service, OpenGraphThumbMixin): if re.search("/live/", hls): self.config.set("live", True) streams = hlsparse(self.config, self.http.request("get", hls), hls) - if streams: - for n in list(streams.keys()): - yield streams[n] + for n in list(streams.keys()): + yield streams[n]