-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3_merge-files.bat
70 lines (61 loc) · 1.65 KB
/
mp3_merge-files.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
:fix_input
@echo off
chcp 65001>nul
::Remove "!" characters:
setlocal
for %%a in (*!*.mp3) do call :remove "%%~a"
::Remove "'" characters:
setlocal EnableDelayedExpansion
for %%a in ("*'*.mp3") do (
set "fileName=%%~NXa"
ren "%%a" "!filename:'=!"
)
::This calls the filelist generator function below
call :generate_filelist > filelist.txt
:: This copies metadata from the first input file, using temporary files to get formatting correct
SetLocal EnableDelayedExpansion
set inputfix=filelist.txt
set outputfix=inputmeta1.txt
set "substr='"
(
FOR /F "usebackq delims=" %%G IN ("%inputfix%") DO (
set line=%%G
echo !line:%substr%="!
)
) > "%outputfix%"
set inputfix=inputmeta1.txt
set outputfix=inputmeta2.txt
set "substr2=file"
(
FOR /F "usebackq delims=" %%G IN ("%inputfix%") DO (
set line=%%G
echo !line:%substr2%=!
)
) > "%outputfix%"
EndLocal
set /p inputmetadata=< inputmeta2.txt
ffmpeg -i %inputmetadata% -f ffmetadata metadatatemp.txt
del inputmeta1.txt >nul 2>&1
del inputmeta2.txt >nul 2>&1
::This merges the mp3 to a single file with metadata from first input file
:merge_mp3
ffmpeg -f concat -safe 0 -i filelist.txt -i metadatatemp.txt -map 0 -map_metadata 1 -c copy input.mp3
pause
::This deletes temporary files
:cleanup
del filelist.txt >nul 2>&1
del metadatatemp.txt >nul 2>&1
exit
::This generates the filelist
:generate_filelist
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%f in ('dir /b *.mp3') do (
echo file '%%f'
)
endlocal
EXIT /B 0
:remove
set "FROM=%~1"
set "TO=%FROM:!=%"
ren "%FROM%" "%TO%"