如何在youtube-dl中设置默认下载位置,以便我使用youtube-dl下载的所有内容都进入该默认目录?
答案 0 :(得分:17)
-o
开关与配置文件 youtube-dl
上的输出由--output
或-o
开关处理;将其作为选项传递,然后将要下载的目标保存到:
youtube-dl -o 'C:\Users\User\Downloads\%(title)s.%(ext)s' www.youtube.com/video
请注意,此命令具有双重功能,因为它还使用变量设置输出文件命名方式的模板。在此示例中,它将输出原始下载视频的标题,后跟文件扩展名,这是我个人的偏好。对于可以在文件名中使用的所有变量,请查看the youtube-dl documentation here。
youtube-dl
还允许使用配置文件 - 一个可用于配置您最常使用的交换机的文件,以便程序可以从那里取出它们,从而节省您每次运行它时都必须显式调用它们。 这是您正在寻找的默认下载位置所需的内容。配置文件可用于设置默认输出目标,以便您不必再次显式设置输出。
要设置youtube-dl的配置文件,假设你有Windows:
在%APPDATA%\Roaming
中,创建一个youtube-dl
文件夹(如果尚不存在)。
在该文件夹中,创建一个名为config.txt
的纯文本文件。
将youtube-dl
个选项放在文件中,因为您通常在youtube-dl
的命令行中使用它们,将每个选项放在一个新行上。例如,对于输出开关,您可以使用:-o C:\Users\User\Destination
。有关配置文件的更多信息,请阅读the documentation on it here。
即使在配置文件中配置了选项,也可以通过从命令行显式调用它来覆盖它。因此,如果您在配置文件中设置-o
作为下载的默认位置,但希望将下载保存到当前作业的其他位置,则只需在命令行上调用-o
即可覆盖仅用于当前程序运行的配置文件。
答案 1 :(得分:3)
根据configuration documentation,您可以使用全局或特定于用户的配置文件来配置useEffect(() => {
AppState.addEventListener('change', handleChange);
return () => {
AppState.removeEventListener('change', handleChange);
}
}, []);
const handleChange = (newState) => {
if (newState === "active") {
getFromClipboard();
}
}
:
您可以通过将任何受支持的命令行选项放置到配置文件中来配置youtube-dl。在Linux和macOS上,系统范围的配置文件位于
youtube-dl
,用户范围的配置文件位于/etc/youtube-dl.conf
。在Windows上,用户范围的配置文件位置为~/.config/youtube-dl/config
或%APPDATA%\youtube-dl\config.txt
。请注意,默认情况下配置文件可能不存在,因此您可能需要自己创建它。
在linux上,这将是您的用户配置文件:
C:\Users\<user name>\youtube-dl.conf
答案 2 :(得分:2)
根据您的需要,我认为之后移动文件也同样有用:
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
创建一个移动文件的功能
答案 3 :(得分:0)
在我的youtube-dl.conf文件中我有一个sais的声明
# Save all videos under Movies directory in your home directory
-o C:/TV/Done/%(title)s.%(ext)
答案 4 :(得分:0)
我找到了一种直接在Downloads文件夹中下载文件的方法。我搜索了很长时间。我复制了我的整个函数,那么您就可以了解周围的情况。这是我的代码,可能对某人有用:
import os
def download_audio(request):
SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
}
link = request.GET.get('video_url')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v="+link])
如果有问题请告诉我。
答案 5 :(得分:0)
这是我使用的完整解决方案:
from youtube_dl import YoutubeDL
ydl_opts = {
'format': 'best',
'outtmpl': 'DIR-PATH-HERE%(title)s'+'.mp4',
'noplaylist': True,
'extract-audio': True,
}
video = "https://www.youtube.com/watch?v=SlPhMPnQ58k"
with YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video, download=True)
video_url = info_dict.get("url", None)
video_id = info_dict.get("id", None)
video_title = info_dict.get('title', None)
video_length = info_dict.get('duration')
# print(video_title)
答案 6 :(得分:0)
这是 EXACT 另一个有用的方法,用于 将视频下载到所需的目录 ,并且保留本地文件名< / strong>。
这是您在下面的配置文件:
-o%userprofile%/ Desktop / DL /%(title)s-%(id)s。%(ext)s
批处理文件设置:
::Variables: Set program="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\youtube-dl.exe" Set option=best SET MYPATH="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\config" SET MYCONFIG="--config-location" SET MYDLDIR="%USERPROFILE%\Desktop\DL" SET INSTR='%%(title)s-%%(id)s.%%(ext)s' MKDIR "%USERPROFILE%\Desktop\DL" ::Ask user for input. Set /P youtubelink=[Past Link]: :: For use of config file, for default download location. %program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%" :: There are many ways to accomplish this: :: For Batch File, NOTE extra (%) character needed. :: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%%(title)s-%%(id)s.%%(ext)s %youtubelink% :: or this use of variable :: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%INSTR% %youtubelink%
注意:变量选项中有空格时,请使用“引号”。
最终消息:
创建配置文件,将其放在您要引用的文件夹(目录)中。转到youtube-dl.exe文件,然后使用CMD或批处理文件将上面列出的“参数”传递给它。做完了(贡献和友善)
答案 7 :(得分:0)
在男人身上,这个问题有一个具体的答案(man youtube-dl
):
How do I put downloads into a specific folder?
Use the -o to specify an output template, for example -o "/home/user/videos/%(title)s-%(id)s.%(ext)s". If you want this for all of your downloads, put the option into your configuration file.
此外,该文件名模式是默认的,根据 man 的说法:
The current default template is %(title)s-%(id)s.%(ext)s.
我同意将输出文件夹与默认模板分离会很好,以防有一天默认更改,但我猜作者一定有理由这样做。