From 7ac9fcd99d9825b3af59d659e7d4585bf50bb3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E4=B8=BA?= <26770468+D-VR@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:32:39 +0100 Subject: [PATCH 1/4] Fix Json Parsing in getOpenCastRealURL This fixes json parsing, but does not handle multiple possible videos --- syncmymoodle/__main__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/syncmymoodle/__main__.py b/syncmymoodle/__main__.py index dadebc6..8ff42d1 100755 --- a/syncmymoodle/__main__.py +++ b/syncmymoodle/__main__.py @@ -961,17 +961,25 @@ def getOpenCastRealURL(self, additional_info, url): episodejson = f"https://engage.streaming.rwth-aachen.de/search/episode.json?id={linkid.groups()[0]}" episodejson = json.loads(self.session.get(episodejson).text) - tracks = episodejson["search-results"]["result"]["mediapackage"]["media"][ - "track" + # Collect tracks from all mediapackages + mediapackages = [ + track["mediapackage"]["media"]["track"] + for track in episodejson["result"] ] + + # TODO, handle multiple mediapackages (videos? could be seperate presenter and screencap) + tracks = mediapackages[0] + + # Filter and sort tracks by resolution (width) tracks = sorted( [ (t["url"], t["video"]["resolution"]) for t in tracks - if t["mimetype"] == "video/mp4" and "transport" not in t + if t["mimetype"] == "video/mp4" and "transport" not in t and "video" in t ], - key=(lambda x: int(x[1].split("x")[0])), + key=lambda x: int(x[1].split("x")[0]), # Sort by width (e.g., "1920x1080") ) + # only choose mp4s provided with plain https (no transport key), and use the one with the highest resolution (sorted by width) (could also use bitrate) finaltrack = tracks[-1] From e4117ce598551c2f73b714eada99ba94af447cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E4=B8=BA?= <26770468+D-VR@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:34:57 +0100 Subject: [PATCH 2/4] fix typo --- syncmymoodle/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncmymoodle/__main__.py b/syncmymoodle/__main__.py index 8ff42d1..4f160ca 100755 --- a/syncmymoodle/__main__.py +++ b/syncmymoodle/__main__.py @@ -975,7 +975,7 @@ def getOpenCastRealURL(self, additional_info, url): [ (t["url"], t["video"]["resolution"]) for t in tracks - if t["mimetype"] == "video/mp4" and "transport" not in t and "video" in t + if t["mimetype"] == "video/mp4" and "transport" not in t and "video" in t ], key=lambda x: int(x[1].split("x")[0]), # Sort by width (e.g., "1920x1080") ) From 607cac3d11ff6894c708acf70219f9095dd1ad77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E4=B8=BA?= <26770468+D-VR@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:38:01 +0100 Subject: [PATCH 3/4] Bump minor version so fix will get distributed --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 304c1bc..cb72544 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = syncMyMoodle -version = 0.2.1 +version = 0.2.2 author = Nils Kattenbeck author_email = nilskemail+pypi@gmail.com description = Synchronization client for RWTH Moodle From e51470bd163956c76fa242e7d7ea98c5c71f0849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E4=B8=BA?= <26770468+D-VR@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:42:21 +0100 Subject: [PATCH 4/4] Satisfy black --- syncmymoodle/__main__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/syncmymoodle/__main__.py b/syncmymoodle/__main__.py index 4f160ca..ecd4f61 100755 --- a/syncmymoodle/__main__.py +++ b/syncmymoodle/__main__.py @@ -963,8 +963,7 @@ def getOpenCastRealURL(self, additional_info, url): # Collect tracks from all mediapackages mediapackages = [ - track["mediapackage"]["media"]["track"] - for track in episodejson["result"] + track["mediapackage"]["media"]["track"] for track in episodejson["result"] ] # TODO, handle multiple mediapackages (videos? could be seperate presenter and screencap) @@ -975,7 +974,9 @@ def getOpenCastRealURL(self, additional_info, url): [ (t["url"], t["video"]["resolution"]) for t in tracks - if t["mimetype"] == "video/mp4" and "transport" not in t and "video" in t + if t["mimetype"] == "video/mp4" + and "transport" not in t + and "video" in t ], key=lambda x: int(x[1].split("x")[0]), # Sort by width (e.g., "1920x1080") )