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

charmap coded can't encode character #6566

Closed
r0f1 opened this issue Aug 15, 2015 · 3 comments
Closed

charmap coded can't encode character #6566

r0f1 opened this issue Aug 15, 2015 · 3 comments

Comments

@r0f1
Copy link

@r0f1 r0f1 commented Aug 15, 2015

If I try downloading a video, that has special unicode chars in its title I get an exeception:

b"'charmap' codec can't encode character '\\u2014' in position 45: character maps to <undefined>"

Example: Try this video

 https://www.youtube.com/watch?v=kMgP0lFyVXA

which contains a special dash in its title. The options I am using are:

options = {
    "outtmpl": u"%(title)s.%(ext)s",
    "restrict_filenames": True
}

I there a way to tell the program (eg. via the output template parameter), that special chars in the title should be escaped?

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Aug 15, 2015

Post the full output of youtube-dl when run with --verbose option.

@r0f1
Copy link
Author

@r0f1 r0f1 commented Aug 15, 2015

Program:

import sys
from youtube_dl import YoutubeDL

def print_progress(d):
    k = dict(d)
    if d["status"] == "downloading":
        msg = "\r[%(status)s] %(_percent_str)s of %(_total_bytes_str)s %(filename)s"
    else:
        msg = "\n[%(status)s] %(filename)s" 

    sys.stdout.write(msg % k)
    sys.stdout.flush()


options = {
    "outtmpl": u"%(title)s.%(ext)s",
    "postprocessors": [{
        "key": "FFmpegExtractAudio",
        "preferredcodec": "mp3"
    }],
    "progress_hooks": [print_progress],
    "restrict_filenames": True,
    "verbose": True
}

with YoutubeDL(options) as ydl:
    ydl.download(["http://www.youtube.com/watch?v=kMgP0lFyVXA"])

Output: http://pastebin.com/Da5ECtML

I am using Windows 7 and Python Version: 3.4.1

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Aug 15, 2015

It fails in your code namely at this line:

sys.stdout.write(msg % k)

You have to use proper encoding that is supported by your terminal. If you don't want to deal with this yourself use ydl.to_stdout instead.

@dstftw dstftw closed this Aug 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.