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!

  • "A:/..." - is this on Windows? – ashvatthama Jun 18 at 12:04

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))
| improve this answer | |

Your Answer

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