aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2017-07-14 00:40:54 +0700
committerSergey M․ <dstftw@gmail.com>2017-07-14 00:42:12 +0700
commit15da37c7dc8cf14ba5ce880aa1805fceaa71fc44 (patch)
tree24395c40d915db748a220f0868304f1e540b7cc8 /youtube_dl/YoutubeDL.py
parent9a0942ad55bba714d6eaeb9ee4f66a138ec85e17 (diff)
downloadyoutube-dl-15da37c7dc8cf14ba5ce880aa1805fceaa71fc44.zip
youtube-dl-15da37c7dc8cf14ba5ce880aa1805fceaa71fc44.tar.gz
youtube-dl-15da37c7dc8cf14ba5ce880aa1805fceaa71fc44.tar.bz2
[YoutubeDL] Don't expand env variables in meta fields (closes #13637)
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-xyoutube_dl/YoutubeDL.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index 60ee4b7..8730d32 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -20,6 +20,7 @@ import re
import shutil
import subprocess
import socket
+import string
import sys
import time
import tokenize
@@ -674,7 +675,19 @@ class YoutubeDL(object):
FORMAT_RE.format(numeric_field),
r'%({0})s'.format(numeric_field), outtmpl)
- filename = expand_path(outtmpl % template_dict)
+ # expand_path translates '%%' into '%' and '$$' into '$'
+ # correspondingly that is not what we want since we need to keep
+ # '%%' intact for template dict substitution step. Working around
+ # with boundary-alike separator hack.
+ sep = ''.join([random.choice(string.ascii_letters) for _ in range(32)])
+ outtmpl = outtmpl.replace('%%', '%{0}%'.format(sep)).replace('$$', '${0}$'.format(sep))
+
+ # outtmpl should be expand_path'ed before template dict substitution
+ # because meta fields may contain env variables we don't want to
+ # be expanded. For example, for outtmpl "%(title)s.%(ext)s" and
+ # title "Hello $PATH", we don't want `$PATH` to be expanded.
+ filename = expand_path(outtmpl).replace(sep, '') % template_dict
+
# Temporary fix for #4787
# 'Treat' all problem characters by passing filename through preferredencoding
# to workaround encoding issues with subprocess on python2 @ Windows