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

ERROR: Error in output template: unsupported format character #5006

Closed
pricejn2 opened this issue Feb 20, 2015 · 9 comments
Closed

ERROR: Error in output template: unsupported format character #5006

pricejn2 opened this issue Feb 20, 2015 · 9 comments

Comments

@pricejn2
Copy link

@pricejn2 pricejn2 commented Feb 20, 2015

Usage of % symbols in the output throw errors since they are being read as output templates. Is there a better check that could be added since all output templates utilize the form %(TEMPLATE)s?

youtube-dl --verbose 'https://soundcloud.com/esteban-chachalo-dj/mixer-al-100-original-in-the' -o 'MIXER AL 100%Original in the mix - ( Esteban Chachalo dJ ) DEMO.%(ext)s'
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['--verbose', 'https://soundcloud.com/esteban-chachalo-dj/mixer-al-100-original-in-the', '-o', 'MIXER AL 100%Original in the mix - ( Esteban Chachalo dJ ) DEMO.%(ext)s']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2015.02.19.3
[debug] Python version 2.7.3 - Linux-3.14.32-xxxx-grs-ipv6-64-x86_64-with-Debian-7
[debug] exe versions: avconv 1.2.12, avprobe 1.2.12, ffmpeg 1.2.12, ffprobe 1.2.12, rtmpdump 2.4
[debug] Proxy map: {}
[soundcloud] esteban-chachalo-dj/mixer-al-100-original-in-the: Resolving id
[soundcloud] esteban-chachalo-dj/mixer-al-100-original-in-the: Downloading info JSON
[soundcloud] 105246408: Downloading track url
ERROR: Error in output template: unsupported format character 'O' (0x4f) at index 13 (encoding: 'UTF-8')
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/youtube_dl/YoutubeDL.py", line 562, in prepare_filename
    filename = tmpl % template_dict
ValueError: unsupported format character 'O' (0x4f) at index 13
@phihag
Copy link
Contributor

@phihag phihag commented Feb 20, 2015

Not all output templates use the form %(TEMPLATE)s, although the documentation heavily favors them. Why are you specifying your own title in the first place instead of just -o "%(title)s.%(ext)s"?

In any case, if you are into setting your own title, simply double all percent signs in it.

@phihag phihag closed this Feb 20, 2015
@pricejn2
Copy link
Author

@pricejn2 pricejn2 commented Feb 20, 2015

Thanks for the quick response. I didn't see any other bugs on this particular issue so wanted to at least have it out there.

Manually specifying the title can be preferable in some use cases, but not worth re-inventing the wheel for.

Double %% works as expected. Thanks!

@snarfed
Copy link

@snarfed snarfed commented Jul 20, 2016

i see this occasionally too, with 2016.7.17, in a python webapp that uses youtube-dl as a library, http://huffduff-video.snarfed.org/. example video url: https://www.oreilly.com/ideas/applications-of-ai-technologies-peter-norvig-in-conversation-with-tim-oreilly

the app uses 'outtmpl': '/tmp/%(webpage_url).240s' in the options dict that it passes to download(). code is here, full stack trace below.

Traceback (most recent call last):
  File "/var/www/cgi-bin/app.py", line 142, in run
    youtube_dl.YoutubeDL(options).download([url])
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 1775, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 746, in process_ie_result
    extra_info=extra_info)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 693, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 739, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 1421, in process_video_result
    self.process_info(new_info)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 1499, in process_info
    info_dict['_filename'] = filename = self.prepare_filename(info_dict)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 605, in prepare_filename
    self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 556, in report_error
    self.trouble(error_message, tb)
  File "/usr/local/lib/python2.6/site-packages/youtube_dl/YoutubeDL.py", line 526, in trouble
    raise DownloadError(message, exc_info)
DownloadError: ERROR: Error in output template: unsupported format character 'B' (0x42) at index 53 (encoding: 'ANSI_X3.4-1968')
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jul 20, 2016

/tmp/%(webpage_url).240s is invalid output template.

@snarfed
Copy link

@snarfed snarfed commented Jul 20, 2016

...and yet it works almost all the time. :P

you're right that %(webpage_url)s isn't listed in the --output section of --help, but i need a globally unique string, and it's the best option i found, even though it's undocumented. sigh.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jul 20, 2016

In any case you override it here therefore it's your responsibility to escape % in filename_prefix.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jul 20, 2016

I'm not about not being listed. .240s is not guaranteed to work. There is no full support for string formatting operations in output template.

@snarfed
Copy link

@snarfed snarfed commented Jul 20, 2016

true, thank you! good points. escaping %s fixed it!

snarfed added a commit to snarfed/huffduff-video that referenced this issue Jul 20, 2016
@EngineeredJonas
Copy link

@EngineeredJonas EngineeredJonas commented Feb 13, 2020

Double % did work for me! Thanks.

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
5 participants
You can’t perform that action at this time.