Skip to content

Instantly share code, notes, and snippets.

@jesterjunk
Last active December 8, 2024 07:27
Show Gist options
  • Select an option

  • Save jesterjunk/adb8bb8a809415ff0270c46e7e9b6ec4 to your computer and use it in GitHub Desktop.

Select an option

Save jesterjunk/adb8bb8a809415ff0270c46e7e9b6ec4 to your computer and use it in GitHub Desktop.
yt-dlp.conf

yt-dlp.conf


yt-dlp automatically reads the yt-dlp.conf file from the following directory path:

C:\Users\YourUserName\yt-dlp.conf

-U

--output 'D:\Various Videos\%(extractor_key)s\%(id)s\%(title)s (%(extractor_key)s, %(id)s, %(width)sx%(height)s, %(fps)s).%(ext)s'

--downloader aria2c

--ignore-errors

--sub-lang en

--write-auto-sub

--sub-format vtt

--add-metadata

--write-info-json

--write-description

--write-annotation

--write-all-thumbnails

--user-agent 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'

--exec "organize_yt-dlp_downloaded_thumbnails.bat {}"
Argument Description
-U Update yt-dlp to the latest version.
--output '...' Set the output directory and filename format for downloaded files.
--downloader aria2c Use aria2c as the external downloader.
--ignore-errors Continue on download errors.
--sub-lang en Download English subtitles.
--write-auto-sub Download automatically generated subtitles.
--sub-format vtt Specify the subtitle format as VTT.
--add-metadata Embed video metadata into the file.
--write-info-json Write video metadata to a separate JSON file.
--write-description Save the video description to a file.
--write-annotation Download video annotations.
--write-all-thumbnails Download all available thumbnails of the video.
--user-agent '...' Set a specific user agent for the downloader.
--exec "..." Execute a specified batch file after the download is complete.



organize_yt-dlp_downloaded_thumbnails.bat

Add the directory path for this file to the Windows Path,
so that it can be accessed via command line for yt-dlp to
find it when it is called in the yt-dlp.conf file.


@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

REM The first argument is the full path of the downloaded video
SET "downloadPath=%~1"

REM Get the directory of the downloaded video without the filename
FOR %%i IN ("%downloadPath%") DO SET "downloadDir=%%~dpi"

REM Remove trailing backslash
SET "downloadDir=!downloadDir:~0,-1!"

REM Define the jpg and webp directories
SET "jpgDir=!downloadDir!\img\jpg"
SET "webpDir=!downloadDir!\img\webp"

REM Create jpg and webp directories if they don't exist
IF NOT EXIST "!jpgDir!" MKDIR "!jpgDir!"
IF NOT EXIST "!webpDir!" MKDIR "!webpDir!"

REM Use robocopy to move the .jpg and .webpfiles.
robocopy "!downloadDir!" "!jpgDir!" *.jpg /MOV /NJH /NJS /NDL /NFL
robocopy "!downloadDir!" "!webpDir!" *.webp /MOV /NJH /NJS /NDL /NFL

ENDLOCAL
Line of Code Explanation
@echo off Disables the echoing of commands in the console, making the script output cleaner.
SETLOCAL ENABLEDELAYEDEXPANSION Enables delayed expansion, which allows for the dynamic use of variables within loops or code blocks.
SET "downloadPath=%~1" Assigns the first script argument (the full path of the downloaded video) to the variable downloadPath.
FOR %%i IN ("%downloadPath%") DO SET "downloadDir=%%~dpi" Extracts and sets the directory path of the downloaded video, without the filename, to downloadDir.
SET "downloadDir=!downloadDir:~0,-1!" Removes the trailing backslash from the downloadDir path.
SET "jpgDir=!downloadDir!\img\jpg" Sets the path for the jpg directory, adding \img\jpg to the downloadDir path.
SET "webpDir=!downloadDir!\img\webp" Sets the path for the webp directory, adding \img\webp to the downloadDir path.
IF NOT EXIST "!jpgDir!" MKDIR "!jpgDir!" Creates the jpg directory if it doesn't already exist.
IF NOT EXIST "!webpDir!" MKDIR "!webpDir!" Creates the webp directory if it doesn't already exist.
robocopy "!downloadDir!" "!jpgDir!" *.jpg /MOV /NJH /NJS /NDL /NFL Moves all jpg files from downloadDir to jpgDir, suppressing various output messages.
robocopy "!downloadDir!" "!webpDir!" *.webp /MOV /NJH /NJS /NDL /NFL Moves all webp files from downloadDir to webpDir, suppressing various output messages.
ENDLOCAL Ends the local environment changes, restoring any changes made to the environment variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment