-
Notifications
You must be signed in to change notification settings - Fork 0
/
m4b_export-cue.bat
84 lines (68 loc) · 1.83 KB
/
m4b_export-cue.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
FOR %%i IN (*.m4b) DO (
rename "%%i" "export.m4b"
)
@echo off
:check1
if exist "export.m4b" (
goto :check2
) else goto :stop1
:check2
if exist "export-cue.py" (
goto :embedded2cue
) else goto :stop2
:embedded2cue
ffprobe -print_format compact=print_section=0:nokey=1:escape=csv -show_chapters "export.m4b" > metadata_chapters.txt
::This inverts the metadata_chapters file because the final chapter time base sometimes does not match the time base of the earlier chapters
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "filename1=metadata_chapters.txt"
SET "outfile=metadata_chapters_inverted.txt"
SET /a count=0
FOR /f "delims=" %%a IN (%filename1%) DO (
SET /a count+=1
SET "line[!count!]=%%a"
)
(
FOR /L %%a IN (%count%,-1,1) DO ECHO(!line[%%a]!
)>"%outfile%"
::This fetches the timebase of the first chapter
Set "File=.\metadata_chapters_inverted.txt"
Set "Match=1"
Set "Tokens=2"
Set "Delimitter=|"
For /F "Tokens=%Tokens% Delims=%Delimitter%" %%# in (
'Type "%File%"^|FIND /I "%Match%"'
) Do (
Set "Value=%%#"
)
Echo %VALUE% > timebase.txt
:: This removes the numerator of the timebase
:timebase
@echo off
SetLocal EnableDelayedExpansion
set input=timebase.txt
set output=timebase1.txt
set "substr=1/"
(
FOR /F "usebackq delims=" %%G IN ("%input%") DO (
set line=%%G
echo. !line:%substr%=!
)
) > "%output%"
EndLocal
::This executes export-cue.py on the metadata_chapters.txt, which also uses the fetched timebase in calculation
py export-cue.py metadata_chapters.txt --audio-file="export.m4b" --output-file="cuesheet.cue"
del timebase.txt
del timebase1.txt
del metadata_chapters.txt
del metadata_chapters_inverted.txt
rename export.m4b input.mp4
exit
:stop1
echo MISSING export.m4b
pause
exit
:stop2
echo MISSING export-cue.py
pause
exit