Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Upload year in youtube-dl output template

Writer Emily Wong

This is my current output template:-o "A:/YouTube/%(uploader)s/%(upload_date)s/%(title)s-%(id)s.%(ext)s"

But instead of %(upload_date)s which is formatted as YYYYMMDD I want the folder to be named after the upload year only. I can't seem to figure out how that works, please help me out!

1

1 Answer

youtube-dl doesn't have an year option (except for music videos, where it is %(release_year)s).

so what we can do instead is let youtube-dl save the files with YYYYMMDD, and we can modify it later:

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))

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy