Skip to content

cli: add --show-matchers argument #6287

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

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Nov 10, 2024

This adds the --show-matchers CLI argument for listing a plugin's matchers. Regular text and JSON output is supported.

While the JSON output contains all data (excluding the redundant re.UNICODE flag), the regular text output uses yaml-like syntax, skips missing matcher names and default priorities/flags, uses text for priority constants and flags (human readable), and it puts verbose regex patterns on the next line with a secondary indentation level. As said, it's not valid yaml, as it would require quoting+escaping the single-line regex patterns or adding yaml block-style indicators, which would make reading more difficult.

Plugin sideloading is of course supported.

Examples

$ streamlink --show-matchers twitch
- name: player
  pattern: https?://player\.twitch\.tv/\?.+
- name: clip
  pattern: https?://(?:clips\.twitch\.tv|(?:[\w-]+\.)?twitch\.tv/(?:[\w-]+/)?clip)/(?P<clip_id>[^/?]+)
- name: vod
  pattern: https?://(?:[\w-]+\.)?twitch\.tv/(?:[\w-]+/)?v(?:ideos?)?/(?P<video_id>\d+)
- name: live
  pattern: https?://(?:(?!clips\.)[\w-]+\.)?twitch\.tv/(?P<channel>(?!v(?:ideos?)?/|clip/)[^/?]+)/?(?:\?|$)
$ streamlink --show-matchers twitch --json
[
  {
    "name": "player",
    "priority": 20,
    "flags": 0,
    "pattern": "https?://player\\.twitch\\.tv/\\?.+"
  },
  {
    "name": "clip",
    "priority": 20,
    "flags": 0,
    "pattern": "https?://(?:clips\\.twitch\\.tv|(?:[\\w-]+\\.)?twitch\\.tv/(?:[\\w-]+/)?clip)/(?P<clip_id>[^/?]+)"
  },
  {
    "name": "vod",
    "priority": 20,
    "flags": 0,
    "pattern": "https?://(?:[\\w-]+\\.)?twitch\\.tv/(?:[\\w-]+/)?v(?:ideos?)?/(?P<video_id>\\d+)"
  },
  {
    "name": "live",
    "priority": 20,
    "flags": 0,
    "pattern": "https?://(?:(?!clips\\.)[\\w-]+\\.)?twitch\\.tv/(?P<channel>(?!v(?:ideos?)?/|clip/)[^/?]+)/?(?:\\?|$)"
  }
]
$ streamlink --show-matchers hls
- pattern: hls(?:variant)?://(?P<url>\S+)(?:\s(?P<params>.+))?$
- priority: LOW
  flags: IGNORECASE
  pattern: (?P<url>[^/]+/\S+\.m3u8(?:\?\S*)?)(?:\s(?P<params>.+))?$
$ streamlink --show-matchers steam
- pattern: https?://steamcommunity\.com/broadcast/watch/(\d+)
- pattern: https?://steam\.tv/(\w+)
$ streamlink --show-matchers ustreamtv
- flags: VERBOSE
  pattern:
    https?://(?:(?:www\.)?ustream\.tv|video\.ibm\.com)
    (?:
        /combined-embed
        /(?P<combined_channel_id>\d+)
        (?:/video/(?P<combined_video_id>\d+))?
        |
        (?:(?:/embed/|/channel/(?:id/)?)(?P<channel_id>\d+))?
        (?:(?:/embed)?/recorded/(?P<video_id>\d+))?
    )
$ streamlink --show-matchers ustreamtv --json
[
  {
    "name": null,
    "priority": 20,
    "flags": 64,
    "pattern": "https?://(?:(?:www\\.)?ustream\\.tv|video\\.ibm\\.com)\n(?:\n    /combined-embed\n    /(?P<combined_channel_id>\\d+)\n    (?:/video/(?P<combined_video_id>\\d+))?\n    |\n    (?:(?:/embed/|/channel/(?:id/)?)(?P<channel_id>\\d+))?\n    (?:(?:/embed)?/recorded/(?P<video_id>\\d+))?\n)"
  }
]
$ streamlink --show-matchers doesnotexist; echo $?
error: Plugin not found
1

$ streamlink --show-matchers doesnotexist --json; echo $?
{
  "error": "Plugin not found"
}
1

@bastimeyer bastimeyer merged commit 710f87b into streamlink:master Nov 11, 2024
16 checks passed
@bastimeyer bastimeyer deleted the cli/show-matchers branch November 11, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant