Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError When Fetching Manifest #38

Open
justin025 opened this issue Jan 18, 2025 · 1 comment
Open

KeyError When Fetching Manifest #38

justin025 opened this issue Jan 18, 2025 · 1 comment

Comments

@justin025
Copy link

Traceback (most recent call last):
File "/home/j/test2.py", line 59, in
asyncio.run(main())
File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/j/test2.py", line 32, in main
manifest = await client.get_manifest(streams.url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/j/Desktop/venv/lib/python3.12/site-packages/crunpyroll/methods/get_manifest.py", line 24, in get_manifest
return types.Manifest.parse(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/j/Desktop/venv/lib/python3.12/site-packages/crunpyroll/types/manifest.py", line 47, in parse
template = aset["SegmentTemplate"]
~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'SegmentTemplate'

https://www.crunchyroll.com/watch/G7PU4VJEJ/asteroid-blues

Code:

def main():
...
    streams = await client.get_streams("G7PU4VJEJ")
    manifest = await client.get_manifest(streams.url)
...

I took a look at the response but I am not entirely sure what to make of it, any help would be appreciated.

@justin025
Copy link
Author

justin025 commented Jan 18, 2025

The call for this video returns a subtitle where the api assumes a video would be, in crunpyroll/types/manifest.py the comments below seems to fix the problem

    def parse(cls, obj: str):
        data = {}
        data["plain"] = obj
        data["video_streams"] = []
        data["audio_streams"] = []
        data["content_protection"] = {}
        manifest = xmltodict.parse(obj)
        for aset in manifest["MPD"]["Period"]["AdaptationSet"]:

            # Use get.("", {}) for asets that are not video or audio
            template = aset.get("SegmentTemplate", {})
            for drm in aset.get("ContentProtection", []):
                scheme_id_uri = drm.get("@schemeIdUri")

                if scheme_id_uri == WIDEVINE_UUID:
                    data["content_protection"]["widevine"] = {}
                    data["content_protection"]["widevine"]["pssh"] = drm["cenc:pssh"]
                    data["content_protection"]["widevine"]["key_id"] = drm["@cenc:default_KID"]
                if scheme_id_uri == PLAYREADY_UUID:
                    data["content_protection"]["playready"] = {}
                    data["content_protection"]["playready"]["pssh"] = drm["mspr:pro"]

            # Subtitles are returned as a list
            if isinstance(aset["Representation"], list):

                for repr in aset["Representation"]:
                    if repr.get("@mimeType").startswith("video"):
                        stream = ManifestVideoStream.parse(repr, template)
                        data["video_streams"].append(stream)
                    elif repr.get("@mimeType").startswith("audio"):
                        stream = ManifestAudioStream.parse(repr, template)
                        data["audio_streams"].append(stream)
        return cls(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant