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

Skip to content

cli.console: keep unicode chars in JSON output#6080

Merged
bastimeyer merged 1 commit into
streamlink:masterfrom
bastimeyer:cli/console/json-unicode
Jul 13, 2024
Merged

cli.console: keep unicode chars in JSON output#6080
bastimeyer merged 1 commit into
streamlink:masterfrom
bastimeyer:cli/console/json-unicode

Conversation

@bastimeyer

Copy link
Copy Markdown
Member

@bastimeyer bastimeyer added the CLI label Jul 13, 2024
@bastimeyer bastimeyer force-pushed the cli/console/json-unicode branch from 2235407 to 261680c Compare July 13, 2024 12:29
@bastimeyer

Copy link
Copy Markdown
Member Author

Force-push with an update which makes ensure_ascii conditional, based on the output stream's encoding. UTF8 is not guaranteed to be the output encoding.
https://docs.python.org/3/library/sys.html#sys.stdout


Prior commit:

$ PYTHONIOENCODING=ascii streamlink https://www.youtube.com/@Nuke73-Live best -j
Traceback (most recent call last):
  File "/home/basti/venv/streamlink-312/bin/streamlink", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 955, in main
    exit_code = run(parser)
                ^^^^^^^^^^^
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 927, in run
    handle_url()
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 564, in handle_url
    handle_stream(plugin, streams, stream_name)
  File "/home/basti/repos/streamlink/src/streamlink_cli/main.py", line 396, in handle_stream
    console.msg_json(
  File "/home/basti/repos/streamlink/src/streamlink_cli/console.py", line 83, in msg_json
    self.output.write(f"{msg}\n")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2058-2061: ordinal not in range(128)

Now:

$ PYTHONIOENCODING=ascii streamlink https://www.youtube.com/@Nuke73-Live best -j | grep title
    "title": "RGG-LAND \u041b\u0415\u0422\u041e 2024 \u2022 \u0414\u0435\u043d\u044c 16 \u2022 \u0427\u0430\u0441\u0442\u044c 2"
$ streamlink https://www.youtube.com/@Nuke73-Live best -j | grep title
    "title": "RGG-LAND ЛЕТО 2024 • День 16 • Часть 2"

@bastimeyer bastimeyer merged commit 09c19cf into streamlink:master Jul 13, 2024
@bastimeyer bastimeyer deleted the cli/console/json-unicode branch July 13, 2024 12:37
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