Skip to content

cli: player title and file output metadata vars #3962

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
Aug 31, 2021

Conversation

bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Aug 29, 2021

  • support the same plugin metadata variables in --output, --record
    and --record-and-pipe like they already exist in --title:
    {url}, {author}, {category}/{game} and {title}
  • substitute unsupported file name characters on specific OS-types
  • add --fs-safe-rules CLI argument for overriding substitution logic
  • add new Formatter class with caching and parameter translation
  • create formatter instance in handle_stream and pass it to output
    methods where player titles or file names need to be formatted
  • rewrite test_cli_main tests

Co-Authored-By: Ian Cameron 1661072+mkbloke@users.noreply.github.com


Resolves #3898
Related #3954, #3933, #3913


  • The critical code path where the formatter gets initialized is currently not tested because there weren't any test prior to these changes. I will try to add some tests tomorrow or so. This requires setting up ton of mocks, which is ugly.
  • The new Formatter could be moved to the streamlink package and replace the LazyFormatter which is currently only used in the HLSWriter for the HLS key URI override stuff.
  • There's currently no variable for the output stream's file container, which makes these variables not that useful IMO, but whatever.

@bastimeyer bastimeyer added the CLI label Aug 29, 2021
@bastimeyer bastimeyer force-pushed the cli/output-variables branch from 4e6fbff to f545a60 Compare August 30, 2021 16:31
- support the same plugin metadata variables in `--output`, `--record`
  and `--record-and-pipe` like they already exist in `--title`:
  `{url}`, `{author}`, `{category}`/`{game}` and `{title}`
- substitute unsupported file name characters on specific OS-types
- add `--fs-safe-rules` CLI argument for overriding substitution logic
- add new Formatter class with caching and parameter translation
- create formatter instance in `handle_stream` and pass it to output
  methods where player titles or file names need to be formatted
- rewrite test_cli_main tests

Co-Authored-By: Ian Cameron <1661072+mkbloke@users.noreply.github.com>
@bastimeyer bastimeyer force-pushed the cli/output-variables branch from f545a60 to 158cdb4 Compare August 30, 2021 16:41
@bastimeyer
Copy link
Member Author

I've added a new test which checks the formatter's initialization and the correct metadata variable defintions. This still doesn't test every change in the main CLI module, but I don't care, because adding more and more tests with 100s of mocks for this aged module doesn't make sense when the design isn't good to begin with. As said, a complete rewrite is needed.
https://app.codecov.io/gh/streamlink/streamlink/compare/3962/diff

Also just noticed that my test changes fix a mistake which was present since several years where it always created an HTTPServer instance when running file output tests:

@bastimeyer
Copy link
Member Author

A future PR could add more vars to the formatter, with optional custom format specifiers (if that's possible):

  • time: {date}, {time}, etc.
  • stream container: {filetype}, {ending}, etc.

@back-to back-to merged commit 89b51a9 into streamlink:master Aug 31, 2021
@bastimeyer bastimeyer deleted the cli/output-variables branch August 31, 2021 15:35
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.

Option to add formatting variables for output filename
2 participants