Question Details

No question body available.

Tags

python python-3.x windows character-encoding yt-dlp

Answers (1)

Accepted Answer Available
Accepted Answer
June 21, 2025 Score: 2 Rep: 14,423 Quality: High Completeness: 60%

The redirection operator > is converting the text to the console's code page.
On wineconsole

Z:\home\lmc\tmp>chcp
Active code page: 437

Z:\home\lmc\tmp>echo 철갑혹성 철갑혹성

Z:\home\lmc\tmp>echo 철갑혹성 > k.out

Z:\home\lmc\tmp>type k.out ????

Z:\home\lmc\tmp>chcp 949 Active code page: 949

Z:\home\lmc\tmp>echo 철갑혹성 > k.out

Z:\home\lmc\tmp>type k.out 철갑혹성

Note: international characters appear as an small empty rectangle but correctly displayed by this site). Kind of:

echo -e '\u2BD1\u2BD1\u2BD1\u2BD1'

⯑⯑⯑⯑

Making subprocess to write to a file and setting encoding on ytl-dlp could work (don't have python on Wine to test)

import subprocess

enc = 'cp949' f = open('out.txt', 'wb') p = subprocess.run(f"yt-dlp --encoding '{enc}' --flat-playlist -i --print title PLySOINx0fqvYr6s8aGdqaK9j8CAWcP5U".split(), stdout=f, encoding=enc)

Output on wineconsole (cmd.exe)

wineconsole 2>/dev/null

Microsoft Windows 10.0.2600

Z:\home\lmc\tmp>chcp 949 Active code page: 949

Z:\home\lmc\tmp>type out.txt Vague (feat. Hey) 새벽 한 시 천 개의 태양 Wish ...

Additionally, yt-dlp can be used as a python module to avoid using subprocess

import json
import ytdlp

URL = 'https://www.youtube.com/playlist?list=PLySOINx0fqvYr6s8aGdqaK9j8CAWcP5U' enc = 'cp949' f = open('out.txt', 'wb')

list
out = ''

See help(ytdlp.YoutubeDL) for a list of available options and public functions

ydlopts = { 'extractflat': True, 'playlistitems': '1-5', 'encoding': enc } with ytdlp.YoutubeDL(ydlopts) as ydl: info = ydl.extractinfo(URL, download=False) #print(json.dumps(ydl.sanitizeinfo(info))) for v in info['entries']: listout += f"{v['title']}\n"

f.write(list
out.encode(enc))