Skip to content

Add file path to progress output #4764

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

Conversation

bastimeyer
Copy link
Member

Resolves #4752

This refactors the progress module, removes the terminal module that was added in #4656, adds support for substitutions in format strings with dynamic/variable lengths, and finally adds a new format string that includes the file path. Paths now get truncated in a proper way, and the whole available space is used. Once not enough space is available for the path to be shown in a proper/usable way (at least 15 characters), then it'll fall back to the next format.

Didn't test on Windows. There's a special case when adding space characters to the output, where it removes one character. Since the non-space characters don't get covered by this special case, it's possible that the line will overflow. Need to check this later.

Also didn't test with paths that include CJK characters with widths larger than 1. After the changes of #4656, the whole character width calculation was unused, as there was no user-generated content in the progress output. Now that's obviously changed with the addition of the path, but the cut() method should still do its job according to the tests, so I don't think there will be an issue here.

@bastimeyer
Copy link
Member Author

This needs more work. As said, I didn't test on Windows before submitting this, so I didn't notice the test failure (the space character I was talking about), but there are other issues as well.

To no surprise, there are reflowing issues on Windows when changing the width of the terminal application(s), because lines don't get cleared properly (not an issue with the code - there's always the carriage return character), but there also appears to be an issue with how the path gets truncated. I will have to check later.

- Remove `streamlink_cli.utils.terminal` module again and move logic
  to the `Progress` and `ProgressFormatter` classes
- Replace `output` and `formatter` arguments of the `Progress` class
  with a simple `stream` argument
- Rewrite `ProgressFormatter.format()`
  - Pre-parse format strings via `string.Formatter.parse()`
    and store the parsing results
  - Add support for substitutions with dynamic/variable lengths
- Update tests
@bastimeyer bastimeyer force-pushed the cli/progress/refactor-and-add-path branch from 7b39396 to 8b50c7b Compare August 23, 2022 10:32
- Add `path` argument to the `Progress` class
- Update formats and add path variable with a min-width of 15
- Truncate paths according to the available space
- Add and update tests
@bastimeyer bastimeyer force-pushed the cli/progress/refactor-and-add-path branch from 8b50c7b to 89b439f Compare August 23, 2022 10:45
@bastimeyer
Copy link
Member Author

Everything should be working as intended now.

If there are any text duplication issues when resizing the terminal application, then it's because of the terminal application not respecting carriage return characters on the line that's getting updated by the progress output. All standard terminals on Windows as well as the one on macOS have this issue, which is quite ridiculous. Konsole for example works beautifully. Not an issue with this implementation or the ones before though.

streamlink.mp4

@gravyboat
Copy link
Member

Thanks for the helpful comments, it made reviewing this easier.

@gravyboat gravyboat merged commit b5df8aa into streamlink:master Aug 24, 2022
@bastimeyer bastimeyer deleted the cli/progress/refactor-and-add-path branch August 24, 2022 17:31
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.

No filename displayed in HLS livestream downloading since 4.3.0
2 participants