Saturday, May 15, 2010

Podcast manipulatie script


Al sinds 2005 gebruik ik Juice, nu al een paar jaar versie 2.2. Waar ik die versie vandaan heb weet ik niet meer maar op sourceforge staat nog steeds versie 2.0.
Maar goed, nadat de bestanden gedownload zijn wil ik ze eerst uniform maken.
Sommige MP3's hebben namen van meer dan 100 karakters lang.

Zoals deze van meer dan 150 tekens, waarbij de tekens in rood tracking tekens zijn:

dailysourcecode-231472-05-15-2010_pshow_352992_dopvhost_media_podshow
_com_doppl_0f98d82d4477dccd4427dc9d013759b3d0f252c2_dopsig_e2705c144
ee77c66df70c7a296d17c94.mp3

Dat vinden mijn iRivers niet zo fijn, dus breng ik die bestandsnamen terug naar maximaal 60 tekens.
Daarna maak ik de bestanden kleiner door ze naar 32kb/s mono te converteren.
De Podcasts waar ik naar luister zijn toch alleen maar gesproken woord (m.u.v. de DSC)...
Omdat Lame (bij het converteren) niet zo'n goede job doet om de podcasts allemaal even luid te laten klinken gooi ik de gekrompen bestanden door mp3gain heen. Hierdoor klinken de Podcasts allemaal even luid en hoef ik niet steeds aan de volume knopjes te zitten...
Lame verliest bij de conversie de ID3 tags, daarom kopieer ik, na de conversie, de ID3 tag van het oorspronkelijke bestand naar het nieuwe gecomprimeerde bestand.

Ik heb de programma's allemaal in "C:\Program Files\MyPrograms\" staan.
De programma's zijn:
id3.exe http://home.wanadoo.nl/squell/id3.html
lame.exe http://lame.sourceforge.net
mp3gain.exe http://mp3gain.sourceforge.net/

Processing mp3 files after downloading them with Juice.
I listen to podcasts and I want all files to be small, so I can carry many of them on my iRiver. For that reason, I reduce the file lengths to a maximum of 60 characters, then I have lame convert the files to 32kb/s mono.
In the process the ID3 tags are lost, so I resolve this by copying the ID3 tags from the original files to the reduced files. (The message from Lame.exe is: Be aware that the ID3 tag is currently lost when transcoding.)
In order to make them all sound equally loud I run them through mp3gain.

=====START PodcastScript.bat =====
@ECHO OFF

REM Move all files in TempDirectories to Temp0 directory, this can be done in Juice, but did not work for the ARGOS podcast under Win-XP as there is a >> in the path. Under Win-7, this works just fine.
REM Juice is configured to place all downloaded files in subdirectories under C:\2Podcasts\TempDirectories

REM Copy all files from the Juice temp directories to one single directory TempZero
cd C:\2Podcasts\TempDirectories
FOR /R %1 %%G IN (*.*) DO (
move "%%G" C:\2Podcasts\Temp0\
)

REM rename partially downloaded files from .mp3.partial to .mp3
REM Most partial files are actually fully downloaded, just not renamed
cd C:\2Podcasts\Temp0
FOR /R %1 %%G IN (*.partial) DO (
ren "%%G" "%%~nG"
)

REM Move mp3 files to Temp1 and then move remaining files to RemainingFiles directory
Move /Y C:\2Podcasts\Temp0\*.mp3 C:\2Podcasts\Temp1\
Move /Y C:\2Podcasts\Temp0\*.* C:\2Podcasts\RemainingFiles\

REM All active files are now in Temp1

REM Truncate filenames longer than 60 characters
setlocal EnableDelayedExpansion
cd "C:\2Podcasts\Temp1"
REM loop over all files in the cwd
for /f %%a in ('dir /a-d /b') do (
REM store this filename in a variable so we can do substringing
set ThisFileName=%%a
REM Set a filename without the extension
set ThisFileNameNOEXT=%%~na
REM now take a substring after removing the extension
set ThisShortFileName=!ThisFileNameNOEXT:~0,60!
REM finally, the rename. I use the shortfilename with an * to handle spaces in he filenames
ren !ThisShortFileName!* !ThisShortFileName!.mp3
)
:EOF
endlocal

REM All active shortnamed files are in Temp1

REM Re-encode all files to 32kbs at 32kHz sample rate from Temp1 to Temp2
REM Copy the lost ID3 Tags from the original file back to the re-encoded file.
REM ID3 is located on: http://home.wanadoo.nl/squell/id3.html
cd C:\2Podcasts\Temp1
FOR /R "C:\2Podcasts\Temp1" %1 %%G IN (*.mp3) DO (
"C:\Program Files\MyPrograms\lame.exe" -f -a -b 32 --resample 32 "%%G" "C:\2Podcasts\Temp2\%%~nxG"
"C:\Program Files\MyPrograms\id3" -D "%%G" -1 -2 "C:\2Podcasts\Temp2\%%~nxG"
)
Move /Y C:\2Podcasts\Temp1\*.mp3 C:\2Podcasts\Backup2\

REM All original shortnamed files are in Backup2
REM All reduced shortnamed files are in Temp2

REM Ensure that all mp3's sound equally loud, files will remain in Temp2
"C:\Program Files\MyPrograms\mp3gain.exe" /r /d -4 /c /p C:\2Podcasts\Temp2\*.mp3

REM All reduced shortnamed files are still in Temp2

REM Move original files to Backup2 and the re-encoded files to LeveledFiles
Move /Y C:\2Podcasts\Temp2\*.mp3 C:\2Podcasts\LevelledFiles
Move /Y C:\2Podcasts\Temp2\*.* C:\2Podcasts\Backup2\

REM Turn the system to sleep
REM echo "Puting system to sleep"

REM pause
REM ping 127.0.0.1 -n 2 -w 1000 > nul
REM %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState
REM echo "Shutting system down"
REM shutdown.exe -s -f

=====END DOS Script voor Podcasts van Juice=====


=====Start of Copy ID3 tag script=====
REM I only needed this once to catch up with previously converted mp3's.
REM Copy the ID3 tag from the original files over to the re-encoded files that lost their ID3 tag.
REM Original files: "C:\2Podcasts\Backup2"
REM Re-encoded files: "C:\2Podcasts\LevelledFiles"

cd "C:\2Podcasts\Backup2"
FOR /R "C:\2Podcasts\LevelledFiles" %1 %%G IN (*.mp3) DO (
"C:\Program Files\MyPrograms\id3" -D "C:\2Podcasts\Backup2\%%~nxG" -1 -2 "C:\2Podcasts\LevelledFiles\%%~nxG"
)

=====End of copy ID3 Tag script=====

No comments:

Post a Comment