Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@buchnema
Last active January 4, 2024 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save buchnema/f61f028630471429babacce6a3dd3abc to your computer and use it in GitHub Desktop.
Save buchnema/f61f028630471429babacce6a3dd3abc to your computer and use it in GitHub Desktop.
This drag-n-drop script for windows merges mp3 Files in multiple folders by dragging them onto this bat file. The result is one merged mp3 file per folder.
@echo off
chcp 1252
::===============================================================
:: This drag-n-drop script for windows merges all mp3 Files in a
:: folder by dragging it onto this bat file. It can be used for
:: multiple folders at once which outputs one merged mp3 file per
:: folder.
::
:: Installed ffmpeg is required. To use ffmpeg you need to install
:: it on your OS. Look here for instructions how to do this:
:: https://video.stackexchange.com/a/20496
::
:: Alternatively you can replace the ffmpeg command in this
:: script by the location of your ffmpeg executable.
:: e.g. C:\Programs\ffmpeg\bin\ffmpeg.exe
::===============================================================
SETLOCAL EnableExtensions EnableDelayedExpansion
pushd "%~dp1"
echo ### Merge mp3 files in folder ###
echo.
echo Current working directory (%%CD%%): %CD%
echo Directory of this script (%%~dp0): %~dp0
echo.
echo Folders will be processed in this order:
for %%z in (%*) do (
echo %%z
)
echo.
set back=%cd%
for /d %%i in (%*) do (
echo %%i >>folders.txt
)
for /f "tokens=*" %%i in (folders.txt) do (
rem echo %%i
echo Processing Folder: %%i
cd %%i
echo Files will be processed in this order:
for %%f in (*.mp3) do (
echo %%f
set "datei=%%~nxf"
set datei=!datei: =\ !
echo file !datei! >>confiles.txt
if not exist "metadata.txt" (
ffmpeg -i "%%~nxf" -v quiet -f ffmetadata "metadata.txt"
)
)
set "datei=%%~nxi"
echo using ffmpeg...
ffmpeg -f concat -safe "0" -i confiles.txt -i "metadata.txt" -v quiet -map_metadata 1 -id3v2_version 3 -write_id3v1 1 -c copy "!datei!_merged".mp3
echo !datei!_merged.mp3
move "!datei!_merged.mp3" %back%
del confiles.txt
del metadata.txt
echo.
)
cd %back%
del folders.txt
echo Exiting ...
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment