Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cli: support -t formatting vars in -o, -r and -R#3954

Closed
mkbloke wants to merge 1 commit into
streamlink:masterfrom
mkbloke:file-output-format-vars-3
Closed

cli: support -t formatting vars in -o, -r and -R#3954
mkbloke wants to merge 1 commit into
streamlink:masterfrom
mkbloke:file-output-format-vars-3

Conversation

@mkbloke

@mkbloke mkbloke commented Aug 28, 2021

Copy link
Copy Markdown
Member

Sorry for opening yet another PR, it wasn't my original intention.

Tests to come if this code looks reasonable...

closes #3898

@mkbloke mkbloke force-pushed the file-output-format-vars-3 branch 2 times, most recently from c501fac to 52aae4c Compare August 28, 2021 21:08
@mkbloke mkbloke force-pushed the file-output-format-vars-3 branch from 52aae4c to e0bb98c Compare August 28, 2021 21:36
@mkbloke

mkbloke commented Aug 28, 2021

Copy link
Copy Markdown
Member Author

I'm not sure if I've put the Formatter class file in the right place. Would it be better in src/streamlink_cli/utils/, or is src/streamlink/utils/ the right place?

@bastimeyer

Copy link
Copy Markdown
Member

I will take a look at this tomorrow as it's a bit late here. I can already tell you though that this belongs into streamlink_cli, if it makes sense having another formatter class, which I don't know yet.

@mkbloke

mkbloke commented Aug 29, 2021

Copy link
Copy Markdown
Member Author

Cool, I'll move it if the rest of it looks OK to you when you can properly look at it. I think it's worthwhile having the extra formatter class to do both title and filename formatting in a lazy/caching manner. If it wasn't for the use of LazyFormatter in hls.py I'd have been tempted to get rid of LazyFormatter completely (in other commits, I guess), but that's assuming this code looks acceptable to you overall...


def __missing__(self, k):
if k == "title":
v = self.plugin.get_title() or DEFAULT_STREAM_METADATA["title"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

all DEFAULT_STREAM_METADATA are pretty stupid, when it get used for a filename
for a player title it is like whatever, but when used for a file it will try to create files with the same name.

DEFAULT_STREAM_METADATA = {
"title": "Unknown Title",
"author": "Unknown Author",
"category": "No Category",
"game": "No Game/Category"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't really see how it's that much of a problem using these default strings in filenames when title/author/category/game cannot be retrieved via the plugin. They seem as good as any to me.

Potentially, yes, if a plugin does not implement any of the metadata methods then it's going to fall back to a filename that will possibly be a duplicate if Streamlink has been called before with a plugin where this has also happened, but the file will not be overwritten unless --force has been specified. I don't think this code should have to do anything to avoid that situation. Why should it need to do so?

self.cache = self.Cache(self.plugin)

def __missing__(self, k):
if k in ("title", "author", "category", "game", "url"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

seems hard coded, Formatter is not really reusable for other stuff

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That is true, but it was never intended to be a general reusable formatter. Its purpose is only to supply formatted title and filesystem-safe filename strings in a lazy manner and without multiple calls to the plugin.get_*() metadata methods. Perhaps I should rename it to better reflect that.

@bastimeyer

Copy link
Copy Markdown
Member

Here's a cleaned up version:

Changes from this PR:

  • no hardcoded variables in the Formatter class
  • no dependencies on the resolved plugin and CLI args in the Formatter class
  • no unnecessary nested Cache class
  • streamlink does not depend on streamlink_cli (the Formatter could instead also replace LazyFormatter and get moved back to streamlink with a slight modification... needs a decision)
  • default values are only applied to titles, but not file names
  • path character replacement has its own module that can be tested independently
  • unprintable chars get replaced on POSIX as well (why not?)
  • formatter initialization has been moved from handle_url to handle_stream

Tests are obviously still missing.

I'm not sure if I want to open a PR for this myself, because I don't want to shut down your efforts of implementing this feature, @mkbloke. What do you suggest should we do?

@mkbloke

mkbloke commented Aug 29, 2021

Copy link
Copy Markdown
Member Author

@bastimeyer, it's fine if you want to open the PR yourself with what you have done. It's substantially different from what I implemented, so I think it makes sense for you to do so. Cheers.

@mkbloke mkbloke closed this Aug 29, 2021
@mkbloke mkbloke deleted the file-output-format-vars-3 branch August 29, 2021 16:32
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

3 participants