From 95d9e485470f5637835326ef0667fece663b8097 Mon Sep 17 00:00:00 2001 From: cousteau Date: Sun, 18 Oct 2015 20:05:37 +0200 Subject: [PATCH] __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...) --- youtube_dl/__init__.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 55b22c889..54c0058a4 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -9,6 +9,7 @@ import codecs import io import os import random +import re import shlex import sys @@ -189,18 +190,25 @@ def _real_main(argv=None): if opts.allsubtitles and not opts.writeautomaticsub: opts.writesubtitles = True - outtmpl = ((opts.outtmpl is not None and opts.outtmpl) or - (opts.format == '-1' and opts.usetitle and '%(title)s-%(id)s-%(format)s.%(ext)s') or - (opts.format == '-1' and '%(id)s-%(format)s.%(ext)s') or - (opts.usetitle and opts.autonumber and '%(autonumber)s-%(title)s-%(id)s.%(ext)s') or - (opts.usetitle and '%(title)s-%(id)s.%(ext)s') or - (opts.useid and '%(id)s.%(ext)s') or - (opts.autonumber and '%(autonumber)s-%(id)s.%(ext)s') or - DEFAULT_OUTTMPL) - if not os.path.splitext(outtmpl)[1] and opts.extractaudio: + outtmpl = (opts.outtmpl if opts.outtmpl is not None + else '{title}-{id}-{format}.{ext}' if opts.format == '-1' and opts.usetitle + else '{id}-{format}.{ext}' if opts.format == '-1' + else '{autonumber}-{title}-{id}.{ext}' if opts.usetitle and opts.autonumber + else '{autonumber}-{title}-{id}.{ext}' if opts.usetitle + else '{id}.{ext}' if opts.useid + else '{autonumber}-{id}.{ext}' if opts.autonumber + else DEFAULT_OUTTMPL) + # Backwards compatibility fix (deprecated): %(foo)s -> {foo}, %% -> % + outtmpl2 = re.sub(r'(?