这是我当前的输出模板:
-o "A:/YouTube/%(uploader)s/%(upload_date)s/%(title)s-%(id)s.%(ext)s"
但我希望文件夹仅以上传年份命名,而不是以 %(upload_date)s(格式为 YYYYMMDD)。我似乎无法弄清楚这是如何工作的,请帮帮我!
答案1
youtube-dl 没有年份选项(音乐视频除外%(release_year)s
)。
所以我们可以做的是让 youtube-dl 使用 YYYYMMDD 保存文件,然后我们可以稍后修改它:
import os
YOUTUBE_DIR = "/path/to/youtube/videos"
uploaders = os.path.listdir(YOUTUBE_DIR)
for uploader in uploaders:
videofile = os.path.listdir(os.path.join(YOUTUBE_DIR, uploader))
yyyy = videofile[:4]
newname = yyyy + videofile[8:]
print("old path is: ", os.path.join(YOUTUBE_DIR, uploader, videofile))
print("new path is: ", os.path.join(YOUTUBE_DIR, uploader, newname))
# first run the script as-is, and if you're okay with the new names, uncomment the next line and run again to actually rename the files
#os.rename(os.path.join(YOUTUBE_DIR, uploader, videofile), os.path.join(YOUTUBE_DIR, uploader, newname))