将文件路径传递给python

时间:2016-09-09 13:34:06

标签: python python-3.x github subprocess youtube-dl

我使用python subprocess.call()来调用[youtube-dl.exe][1]并传递参数

downloadLocation = "-o " + "C:/Users/username/Documents/Youtube/%(title)s.%(ext)s"

subprocess.call(["youtube-dl",
                 "-f" "bestvideo[ext=mp4, height=1080]+bestaudio[ext=m4a]/best[ext=mp4, height=1080]/best",
                 downloadLocation,
                 url])

但结果是(在python控制台上):[download] Destination: C#\Users\username\Documents\Youtube\myVideoFile.mp4

文件将被下载到进行python调用的当前目录中。

示例:"C:\Users\username\PycharmProjects\pytest\ C#\Users\username\Documents\Youtube"

在我看来,它无法转义文件路径中的“:”字符。

请帮忙

1 个答案:

答案 0 :(得分:0)

更新:以下是我如何开始工作

subprocess.call(["youtube-dl",
                 "-f" "bestvideo[ext=mp4, height=1080]+bestaudio[ext=m4a]/best[ext=mp4, height=1080]/best",
                 "-o" "%s" %downloadLocation,
                 "--ignore-errors",
                 url])