Skip to content
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

garbled text occur when input Chinese text #779

Open
kejicjk opened this issue Jun 9, 2024 · 1 comment
Open

garbled text occur when input Chinese text #779

kejicjk opened this issue Jun 9, 2024 · 1 comment

Comments

@kejicjk
Copy link

kejicjk commented Jun 9, 2024

garbled text occur when input Chinese text, for example
input:
python3 videoTextGuessit.py 庆余年第二季/01.mp4

response is
{"title": "\u5e86\u4f59\u5e74\u7b2c\u4e8c\u5b63", "season": null, "episode": 1}

script detail is

import sys
import json
from guessit import guessit

def parse_video_info(file_path):
    guess = guessit(file_path)
    result = {
        'title': guess.get('title'),
        'season': guess.get('season'),
        'episode': guess.get('episode')
    }
    print(json.dumps(result))

if __name__ == "__main__":
    file_path = sys.argv[1]
    parse_video_info(file_path)
@chevignon93
Copy link

chevignon93 commented Jun 27, 2024

@kejicjk I don't know if you've solved your problem but I'd just like to point out that this has nothing to do with this library, this is how the json module works when it encounter non-ascii characters.

To "solve" it, just ensure that you add ensure_ascii=False when using json.dumps

import sys
import json
from guessit import guessit


def parse_video_info(file_path):
    guess = guessit(file_path)
    result = {
        "title": guess.get("title"),
        "season": guess.get("season"),
        "episode": guess.get("episode"),
    }
    print(json.dumps(result, ensure_ascii=False))
### Output: {"title": "庆余年第二季", "season": null, "episode": 1}


if __name__ == "__main__":
    file_path = sys.argv[1]
    parse_video_info(file_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants