Skip to content

Conversation

@bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Oct 22, 2018

Add special stream synonyms "best-unfiltered" and "worst-unfiltered" in
cases when all available streams have been filtered out by the
--stream-sorting-excludes parameter and the "best" and "worst" stream
synonyms don't exist. These new synonyms point towards the respective
streams of the unfiltered streams list so that the user is able to
select a fallback stream.

Example:
streamlink --stream-sorting-excludes '>=480p' URL best,best-unfiltered
Will try to open the best stream below 480p, but if none is available
will continue with the best of all streams as a fallback selection.

Resolves #1055

@bastimeyer
Copy link
Member Author

Something on GH seems to be broken right now, oh boy... https://status.github.com/messages 😕

@bastimeyer bastimeyer force-pushed the feature/fallback-synonyms branch from 5643884 to 0aad083 Compare October 22, 2018 15:36
@bastimeyer bastimeyer changed the title feature: add synonyms for empty filtered streams feature: {best,worst}-unfiltered stream synonyms Oct 22, 2018
@codecov
Copy link

codecov bot commented Oct 22, 2018

Codecov Report

Merging #2127 into master will decrease coverage by 0.27%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2127      +/-   ##
==========================================
- Coverage   51.31%   51.04%   -0.28%     
==========================================
  Files         232      232              
  Lines       14184    14189       +5     
==========================================
- Hits         7279     7243      -36     
- Misses       6905     6946      +41

@gravyboat
Copy link
Member

Talk about an edge case. This looks good to me @bastimeyer. I'll leave it open for a bit longer in case anyone else wants to weigh in, but if not we'll get it merged.

@bastimeyer
Copy link
Member Author

Let's tag it as enhancement...

edge case

The main problem and motivation for this change is that people who are using the Twitch GUI can set different stream quality selections which filter out unwanted streams by using the stream-sorting-excludes parameter. This has to be done because Twitch doesn't provide an API for knowing the available qualities, so you have to define the selection beforehand (or manually parse the HLS playlist in a couple of redundant requests, which is kinda stupid when using Streamlink).
Now If a user has selected a medium quality and thus filters out everything above the specified medium qualities and a streamer on Twitch doesn't have a full partnership and only a certain quality above "medium" is available, this stream-sorting-excludes filter fails. By having fallback stream name synonyms, this won't happen.

final_sorted_streams["worst"] = streams[worst]
final_sorted_streams["best"] = streams[best]
else:
best = unfiltered_sorted_streams[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current behavior without this PR

error: The specified stream(s) 'best' could not be found.
       Available streams: vod, vod_alt, vod_alt2

with this PR

as vod is not a valid sorted stream name for Streamlink,
sorted_streams (unfiltered_sorted_streams) is empty here and it will error

Traceback (most recent call last):
  File "venv/bin/streamlink", line 11, in <module>
    load_entry_point('streamlink', 'console_scripts', 'streamlink')()
  File "src/streamlink_cli/main.py", line 1007, in main
    handle_url()
  File "src/streamlink_cli/main.py", line 557, in handle_url
    streams = fetch_streams(plugin)
  File "src/streamlink_cli/main.py", line 437, in fetch_streams
    sorting_excludes=args.stream_sorting_excludes)
  File "src/streamlink/plugin/plugin.py", line 407, in streams
    best = unfiltered_sorted_streams[-1]
IndexError: list index out of range

it shouldn't error and it should return the same as before or handle it with some unfiltered worst/best


this can be used to test it without a valid URL / Plugin

--- a/src/streamlink/plugin/plugin.py
+++ b/src/streamlink/plugin/plugin.py
@@ -382,9 +382,11 @@ class Plugin(object):
             return (self.stream_weight(s)[0] or
                     (len(streams) == 1 and 1))
 
+        streams = {'vod': '', 'vod_alt': '', 'vod_alt2': ''}
         stream_names = filter(stream_weight_only, streams.keys())
         sorted_streams = sorted(stream_names, **key=stream_weight_only)**

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now with a simple len(unfiltered_sorted_streams) > 0 check.
Test here:

@bastimeyer bastimeyer force-pushed the feature/fallback-synonyms branch from 0aad083 to e5898db Compare October 24, 2018 13:23
@bastimeyer
Copy link
Member Author

Interesting... There's something going on with parsing the vod_alt stream name on Python<=3.5. This is unrelated to the PR because I was using the suggested stream names by @back-to.

if "UnsortableStreamNames" in self.url:
return {
"vod": HTTPStream(self.session, "http://test.se/stream"),
"vod_alt": HTTPStream(self.session, "http://test.se/stream"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the _alt tag is to early

you are here

ostreams = self._get_streams()

and they are all called vod here

it will be added later

if name in streams:
name = "{0}_alt".format(name)
num_alts = len(list(filter(lambda n: n.startswith(name), streams.keys())))
# We shouldn't need more than 2 alt streams
if num_alts >= 2:
continue
elif num_alts > 0:
name = "{0}{1}".format(name, num_alts + 1)


you might use a generator instead of a dict here

        if "UnsortableStreamNames" in self.url:
            def gen():
                for i in range(3):
                    yield "vod", HTTPStream(self.session, "http://test.se/stream")
            return gen()

Add special stream synonyms "best-unfiltered" and "worst-unfiltered" in
cases when all available streams have been filtered out by the
`--stream-sorting-excludes` parameter and the "best" and "worst" stream
synonyms don't exist. These new synonyms point towards the respective
streams of the unfiltered streams list so that the user is able to
select a fallback stream.

Example:
streamlink --stream-sorting-excludes '>=480p' URL best,best-unfiltered
Will try to open the best stream below 480p, but if none is available
will continue with the best of all streams as a fallback selection.

Resolves streamlink#1055
@bastimeyer bastimeyer force-pushed the feature/fallback-synonyms branch from e5898db to 5c03dbf Compare October 24, 2018 15:37
@back-to back-to merged commit 056978c into streamlink:master Oct 26, 2018
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Apr 1, 2020
streamlink 1.3.1 (2020-01-27)

A small patch release that addresses the removal of MPV's legacy option syntax, also with fixes of several plugins, the addition of the --twitch-disable-reruns parameter and dropped support for Python 3.4.

streamlink 1.3.0 (2019-11-22)

A new release with plugin updates and fixes, including Twitch.tv (see #2680), which had to be delayed due to back and forth API changes.

The Twitch.tv workarounds mentioned in #2680 don't have to be applied anymore, but authenticating via --twitch-oauth-token has been disabled, regardless of the origin of the OAuth token (via --twitch-oauth-authenticate or the Twitch website). In order to not introduce breaking changes, both parameters have been kept in this release and the user name will still be logged when using an OAuth token, but receiving item drops or accessing restricted streams is not possible anymore.

Plugins for the following sites have also been added:

    albavision
    news.now.com
    twitcasting.tv
    viu.tv
    vlive.tv
    willax.tv

streamlink 1.2.0 (2019-08-18)

Here are the changes for this month's release

    Multiple plugin fixes
    Fixed single hyphen params at the beginning of --player-args (#2333)
    --http-proxy will set the default value of --https-proxy to same as --http-proxy. (#2536)
    DASH Streams will handle headers correctly (#2545)
    the timestamp for FFMPEGMuxer streams will start with zero (#2559)

streamlink 1.1.1 (2019-04-02)

This is just a small patch release which fixes a build/deploy issue with the new special wheels for Windows on PyPI. (#2392)

streamlink 1.0.0 (2019-01-30)

The celebratory release of Streamlink 1.0.0!

A lot of hard work has gone into getting Streamlink to where it is. Not only is Streamlink used across multiple applications and platforms, but companies as well.

Streamlink started from the inaugural fork of Livestreamer on September 17th, 2016.

Since then, We've hit multiple milestones:

    Over 886 PRs
    Hit 3,000 commits in Streamlink
    Obtaining our first sponsors as well as backers of the project
    The creation of our own logo (streamlink/streamlink#1123)

Thanks to everyone who has contributed to Streamlink (and our backers)! Without you, we wouldn't be where we are today.

Without further ado, here are the changes in release 1.0.0:

    We have a new icon / logo for Streamlink! (streamlink/streamlink#2165)
    Updated dependencies (streamlink/streamlink#2230)
    A ton of plugin updates. Have a look at this search query for all the recent updates.
    You can now provide a custom key URI to override HLS streams (streamlink/streamlink#2139). For example: --hls-segment-key-uri <URI>
    User agents for API communication have been updated (streamlink/streamlink#2194)
    Special synonyms have been added to sort "best" and "worst" streams (streamlink/streamlink#2127). For example: streamlink --stream-sorting-excludes '>=480p' URL best,best-unfiltered
    Process output will no longer show if tty is unavailable (streamlink/streamlink#2090)
    We've removed BountySource in favour of our OpenCollective page. If you have any features you'd like to request, please open up an issue with the request and possibly consider backing us!
    Improved terminal progress display for wide characters (streamlink/streamlink#2032)
    Fixed a bug with dynamic playlists on playback (streamlink/streamlink#2096)
    Fixed makeinstaller.sh (streamlink/streamlink#2098)
    Old Livestreamer deprecations and API references were removed (streamlink/streamlink#1987)
    Dependencies have been updated for Python (streamlink/streamlink#1975)
    Newer and more common User-Agents are now used (streamlink/streamlink#1974)
    DASH stream bitrates now round-up to the nearest 10, 100, 1000, etc. (streamlink/streamlink#1995)
    Updated documentation on issue templates (streamlink/streamlink#1996)
    URL have been added for better processing of HTML tags (streamlink/streamlink#1675)
    Fixed sort and prog issue (streamlink/streamlink#1964)
    Reformatted issue templates (streamlink/streamlink#1966)
    Fixed crashing bug with player-continuous-http option (streamlink/streamlink#2234)
    Make sure all dev dependencies (streamlink/streamlink#2235)
    -r parameter has been replaced for --rtmp-rtmpdump (streamlink/streamlink#2152)

Breaking changes:

    A large number of unmaintained or NSFW plugins have been removed. You can find the PR that implemented that change here: streamlink/streamlink#2003 . See our CONTRIBUTING.md documentation for plugin policy.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Apr 6, 2020
streamlink 1.3.1 (2020-01-27)

A small patch release that addresses the removal of MPV's legacy option syntax, also with fixes of several plugins, the addition of the --twitch-disable-reruns parameter and dropped support for Python 3.4.

streamlink 1.3.0 (2019-11-22)

A new release with plugin updates and fixes, including Twitch.tv (see #2680), which had to be delayed due to back and forth API changes.

The Twitch.tv workarounds mentioned in #2680 don't have to be applied anymore, but authenticating via --twitch-oauth-token has been disabled, regardless of the origin of the OAuth token (via --twitch-oauth-authenticate or the Twitch website). In order to not introduce breaking changes, both parameters have been kept in this release and the user name will still be logged when using an OAuth token, but receiving item drops or accessing restricted streams is not possible anymore.

Plugins for the following sites have also been added:

    albavision
    news.now.com
    twitcasting.tv
    viu.tv
    vlive.tv
    willax.tv

streamlink 1.2.0 (2019-08-18)

Here are the changes for this month's release

    Multiple plugin fixes
    Fixed single hyphen params at the beginning of --player-args (#2333)
    --http-proxy will set the default value of --https-proxy to same as --http-proxy. (#2536)
    DASH Streams will handle headers correctly (#2545)
    the timestamp for FFMPEGMuxer streams will start with zero (#2559)

streamlink 1.1.1 (2019-04-02)

This is just a small patch release which fixes a build/deploy issue with the new special wheels for Windows on PyPI. (#2392)

streamlink 1.0.0 (2019-01-30)

The celebratory release of Streamlink 1.0.0!

A lot of hard work has gone into getting Streamlink to where it is. Not only is Streamlink used across multiple applications and platforms, but companies as well.

Streamlink started from the inaugural fork of Livestreamer on September 17th, 2016.

Since then, We've hit multiple milestones:

    Over 886 PRs
    Hit 3,000 commits in Streamlink
    Obtaining our first sponsors as well as backers of the project
    The creation of our own logo (streamlink/streamlink#1123)

Thanks to everyone who has contributed to Streamlink (and our backers)! Without you, we wouldn't be where we are today.

Without further ado, here are the changes in release 1.0.0:

    We have a new icon / logo for Streamlink! (streamlink/streamlink#2165)
    Updated dependencies (streamlink/streamlink#2230)
    A ton of plugin updates. Have a look at this search query for all the recent updates.
    You can now provide a custom key URI to override HLS streams (streamlink/streamlink#2139). For example: --hls-segment-key-uri <URI>
    User agents for API communication have been updated (streamlink/streamlink#2194)
    Special synonyms have been added to sort "best" and "worst" streams (streamlink/streamlink#2127). For example: streamlink --stream-sorting-excludes '>=480p' URL best,best-unfiltered
    Process output will no longer show if tty is unavailable (streamlink/streamlink#2090)
    We've removed BountySource in favour of our OpenCollective page. If you have any features you'd like to request, please open up an issue with the request and possibly consider backing us!
    Improved terminal progress display for wide characters (streamlink/streamlink#2032)
    Fixed a bug with dynamic playlists on playback (streamlink/streamlink#2096)
    Fixed makeinstaller.sh (streamlink/streamlink#2098)
    Old Livestreamer deprecations and API references were removed (streamlink/streamlink#1987)
    Dependencies have been updated for Python (streamlink/streamlink#1975)
    Newer and more common User-Agents are now used (streamlink/streamlink#1974)
    DASH stream bitrates now round-up to the nearest 10, 100, 1000, etc. (streamlink/streamlink#1995)
    Updated documentation on issue templates (streamlink/streamlink#1996)
    URL have been added for better processing of HTML tags (streamlink/streamlink#1675)
    Fixed sort and prog issue (streamlink/streamlink#1964)
    Reformatted issue templates (streamlink/streamlink#1966)
    Fixed crashing bug with player-continuous-http option (streamlink/streamlink#2234)
    Make sure all dev dependencies (streamlink/streamlink#2235)
    -r parameter has been replaced for --rtmp-rtmpdump (streamlink/streamlink#2152)

Breaking changes:

    A large number of unmaintained or NSFW plugins have been removed. You can find the PR that implemented that change here: streamlink/streamlink#2003 . See our CONTRIBUTING.md documentation for plugin policy.
mkbloke pushed a commit to mkbloke/streamlink that referenced this pull request Aug 18, 2020
…ynonyms

feature: {best,worst}-unfiltered stream synonyms
@bastimeyer bastimeyer deleted the feature/fallback-synonyms branch January 19, 2021 23:23
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.

3 participants