__init__.py -> new --output format + warn if old
- Edited __init__.py so that it uses the new {NAME} rather than the old %(NAME)s --output format - Moved the backwards compatibility code from YoutubeDL.py to __init__.py - Display a warning if the old format is used (using sys.stderr.write(); this is probably not the way to go...)
This commit is contained in:
parent
588f7f8d6d
commit
95d9e48547
@ -9,6 +9,7 @@ import codecs
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -189,18 +190,25 @@ def _real_main(argv=None):
|
|||||||
if opts.allsubtitles and not opts.writeautomaticsub:
|
if opts.allsubtitles and not opts.writeautomaticsub:
|
||||||
opts.writesubtitles = True
|
opts.writesubtitles = True
|
||||||
|
|
||||||
outtmpl = ((opts.outtmpl is not None and opts.outtmpl) or
|
outtmpl = (opts.outtmpl if opts.outtmpl is not None
|
||||||
(opts.format == '-1' and opts.usetitle and '%(title)s-%(id)s-%(format)s.%(ext)s') or
|
else '{title}-{id}-{format}.{ext}' if opts.format == '-1' and opts.usetitle
|
||||||
(opts.format == '-1' and '%(id)s-%(format)s.%(ext)s') or
|
else '{id}-{format}.{ext}' if opts.format == '-1'
|
||||||
(opts.usetitle and opts.autonumber and '%(autonumber)s-%(title)s-%(id)s.%(ext)s') or
|
else '{autonumber}-{title}-{id}.{ext}' if opts.usetitle and opts.autonumber
|
||||||
(opts.usetitle and '%(title)s-%(id)s.%(ext)s') or
|
else '{autonumber}-{title}-{id}.{ext}' if opts.usetitle
|
||||||
(opts.useid and '%(id)s.%(ext)s') or
|
else '{id}.{ext}' if opts.useid
|
||||||
(opts.autonumber and '%(autonumber)s-%(id)s.%(ext)s') or
|
else '{autonumber}-{id}.{ext}' if opts.autonumber
|
||||||
DEFAULT_OUTTMPL)
|
else DEFAULT_OUTTMPL)
|
||||||
if not os.path.splitext(outtmpl)[1] and opts.extractaudio:
|
# Backwards compatibility fix (deprecated): %(foo)s -> {foo}, %% -> %
|
||||||
|
outtmpl2 = re.sub(r'(?<!%)((?:%)*)\1%\(([^)]*)\)s', r'\1{\2}', outtmpl)
|
||||||
|
if outtmpl2 != outtmpl:
|
||||||
|
sys.stderr.write('WARNING: Format "{0}" is deprecated; use "{1}" instead\n'
|
||||||
|
.format(outtmpl, outtmpl2))
|
||||||
|
outtmpl = outtmpl2.replace('%%','%') # do the %% replacement AFTER the warning
|
||||||
|
if opts.extractaudio and not os.path.splitext(outtmpl)[1]:
|
||||||
parser.error('Cannot download a video and extract audio into the same'
|
parser.error('Cannot download a video and extract audio into the same'
|
||||||
' file! Use "{0}.%(ext)s" instead of "{0}" as the output'
|
' file! Use "{0}.{{ext}}" instead of "{0}" as the output'
|
||||||
' template'.format(outtmpl))
|
' template'.format(outtmpl))
|
||||||
|
outtmpl = compat_expanduser(outtmpl)
|
||||||
|
|
||||||
any_getting = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
|
any_getting = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
|
||||||
any_printing = opts.print_json
|
any_printing = opts.print_json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user