Skip to content

stream.dash: fix LookupError on period selection #6518

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

Conversation

bastimeyer
Copy link
Member

Ref #5058 (comment)

A LookupError should not be raised when selecting a specific DASH period. Instead, raise a PluginError with a better error message.

This PR also adds support for selecting DASH periods by their id attribute, which is an optional value. This requires quotation when using the DASH plugin (streamlink 'dash://URL period="ID"'), as it's parsing Python literals, and IDs are string values. Probably not ideal that Streamlink doesn't log what's available, but that's not the goal of this PR.

Example on a random DASH stream from steamcommunity.com:

IndexError/LookupError (master):

$ streamlink 'dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=123' best
[cli][info] Found matching plugin dash for URL dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=123
Traceback (most recent call last):
  File "/home/basti/venv/streamlink-313/bin/streamlink", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 1011, in main
    exit_code = run(parser)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 994, in run
    exit_code = handle_url_wrapper()
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 582, in handle_url_wrapper
    handle_url()
    ~~~~~~~~~~^^
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 630, in handle_url
    streams = fetch_streams(plugin)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 500, in fetch_streams
    return plugin.streams(
           ~~~~~~~~~~~~~~^
        stream_types=args.stream_types,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        sorting_excludes=args.stream_sorting_excludes,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/basti/repos/streamlink/src/streamlink/plugin/plugin.py", line 401, in streams
    ostreams = self._get_streams()
  File "/home/basti/repos/streamlink/src/streamlink/plugins/dash.py", line 43, in _get_streams
    return DASHStream.parse_manifest(self.session, url, **params)
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/basti/repos/streamlink/src/streamlink/stream/dash/dash.py", line 296, in parse_manifest
    for aset in mpd.periods[period].adaptationSets:
                ~~~~~~~~~~~^^^^^^^^
IndexError: list index out of range

IndexError/LookupError (PR):

$ streamlink 'dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=does-not-exist' best
[cli][info] Found matching plugin dash for URL dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=does-not-exist
error: DASH period 123 not found. Select a valid period by index or by id attribute value.

by index and id attr:

$ streamlink 'dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=0'
[cli][info] Found matching plugin dash for URL dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period=0
Available streams: 1080p (worst, best)

$ streamlink 'dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period="1"'
[cli][info] Found matching plugin dash for URL dash://https://cache11-ams1.steamcontent.com/broadcast/76561198074710428/5461257622813668676/manifest/0/cache11-ams1.steamcontent.com/?broadcast_origin=ext2-fra1.steamserver.net period="1"
Available streams: 1080p (worst, best)

@bastimeyer bastimeyer force-pushed the stream/dash/period-selection-lookuperror branch from e1e7b08 to 46e76eb Compare May 3, 2025 20:16
@bastimeyer bastimeyer force-pushed the stream/dash/period-selection-lookuperror branch from 46e76eb to 6401b0b Compare May 3, 2025 20:17
@bastimeyer bastimeyer merged commit b9c4cc7 into streamlink:master May 3, 2025
23 checks passed
@bastimeyer bastimeyer deleted the stream/dash/period-selection-lookuperror branch May 3, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant