I have created a BAT file to append the MP3 Track Number ID3 tag to the beginning of the title ID3 tag. I want this so that when the song is played in my car, the title that displays also shows the Track number.
Goal: Copy the Track Number ID3 tag and tack it on to the beginning of the Title ID3 tag with a separator.
Result I’m getting: is The Track Number AND the Artist tags tacked onto the beginning of the Title tag.
My Bat File Code:
@echo off
setlocal enabledelayedexpansion
set "SEPARATOR= - "
set "INPUT_FOLDER=."
set "OUTPUT_FOLDER=output"
if not exist "%OUTPUT_FOLDER%" mkdir "%OUTPUT_FOLDER%"
for %%f in ("%INPUT_FOLDER%*.mp3") do (
set "FILENAME=%%~nf"
set "TRACK_NUMBER=!FILENAME:~0,2!"
set "ORIGINAL_TITLE=!FILENAME:~3!"
echo Processing: "%%f"
ffmpeg -i "%%f" -metadata track="!TRACK_NUMBER!" -metadata title="!TRACK_NUMBER!!SEPARATOR!!ORIGINAL_TITLE!" -c:a copy "%OUTPUT_FOLDER%%%~nf.mp3"
)
echo Done.
pause
Alternate version with same result:
@echo off
setlocal enableDelayedExpansion
for %%f in (*.mp3) do (
echo Processing "%%f"...
rem Get current TITLE and TRACK number
for /f "tokens=*" %%a in ('ffmpeg -i "%%f" -hide_banner -loglevel error -show_entries format_tags=title,track -of default=noprint_wrappers=1:nokey=1') do (
if not defined current_title (
set "current_title=%%a"
) else (
set "track_number=%%a"
)
)
rem Remove leading/trailing spaces from track_number
for /f "tokens=*" %%t in ("!track_number!") do set "track_number=%%t"
rem Check if track_number is valid and not empty
if not "!track_number!"=="" (
rem Construct new title
set "new_title=!current_title! - !track_number!"
rem Update the ID3 tag using ffmpeg
ffmpeg -i "%%f" -metadata title="!new_title!" -codec copy "temp_%%f"
del "%%f"
ren "temp_%%f" "%%f"
echo Updated "%%f" with title: "!new_title!"
) else (
echo Warning: Track number not found for "%%f". Skipping update.
)
rem Reset variables for the next iteration
set "current_title="
set "track_number="
)
echo All MP3 files processed.
pause
It almost seems like it’s just putting the file name into the title tag, but I cannot see what in the code would do that.
Really want to solve this as asked and not interested in workarounds.