I am trying to make an audio downloader with youtube-dl and ffmpeg which will:
- Download the best format of audio available on YouTube
- Embed thumbnail in the file.
- Convert the file to mp3.
- Delete everything from the folder except the converted mp3 file.
Below is the code I've come up with:
@echo off
cls
set /p playlist="Enter YouTube Link: "
youtube-dl -f bestaudio[ext=m4a] -i --write-thumbnail --embed-thumbnail -o "%%(title)s.%%(ext)s" %playlist% --exec "ffmpeg -i {} -codec:a libmp3lame -qscale:a 0 {}.mp3 && del {}"The issues I've been facing with my code:
- The converted file is not renamed correctly. It's named
Filename.m4a.mp3where I want it to be namedFilename.mp3 - Video thumbnail is saved as
Filename.jpgand youtube-dl creates a file namedcookies.txt. Those are not deleted automatically. - Lastly, this error shows up:
[swscaler @ 00000143e0a4ffc0] deprecated pixel format used, make sure you did set range correctly [mp3 @ 00000143e09f0340] Frame rate very high for a muxer not efficiently supporting it. Please consider specifying a lower framerate, a different muxer or -vsync 2
I'd really appreciate it if you helped me fix those issues. Thanks!
1 Answer
Here's the code which is currently doing everything I need it to do:
@echo off
cls
set /p playlist="Enter YouTube Link: "
youtube-dl -f bestaudio[ext=m4a] --extract-audio --write-thumbnail --embed-thumbnail -o "%%(title)s.%%(ext)s" %playlist% --exec "ffmpeg -i {} -codec:a libmp3lame -qscale:a 0 {}.mp3 && del {}"
@For /R %%f in (*) Do (if not "%%~xf"==".mp3" Del "%%~f")
@For %%G In (*.m4a.mp3) Do @For %%H In ("%%~nG") Do @Ren "%%G" "%%~nH%%~xG"