@echo off
setlocal EnableDelayedExpansion
IF "%1"=="" (goto syntax) ELSE (set wavfiles=%1)
IF "%2"=="" (goto syntax) ELSE (set csvfile=%2)
IF "%3"=="" (goto syntax) ELSE (set ftpserver=%3)
IF "%4"=="" (goto syntax) ELSE (set ftpuser=%4)
IF "%5"=="" (goto syntax) ELSE (set ftppass=%5)
IF "%6"=="" (goto syntax) ELSE (set ftpdir=%6)
IF "%7"=="" (goto syntax) ELSE (set /a maxfiles=%7)
IF "%8"=="" (goto syntax) ELSE (set rssbase=%8)
IF "%9"=="" (goto syntax) ELSE (set rsslink=%9)
type %rssbase% > %rssbase%.xml
set dtim=%TIME:~0,8%
IF "%dtim:~0,1%"==" " set dtim=0%dtim:~1%
echo ^%DATE:~4% %dtim% +1000^ >> %rssbase%.xml
REM --- Now loop for each file and check what processing it requires ---
set /a fc=0
for /F "tokens=1-8 delims=," %%i in (%csvfile%) do (
for %%f in (%wavfiles%) do (
set c=%%f
set d=!c:~0,10!
set yr=!c:~0,4!
set dy=!c:~8,2!
set mt=!c:~5,2!
set month=!mt!
if "!month!"=="01" set month=Jan
if "!month!"=="02" set month=Feb
if "!month!"=="03" set month=Mar
if "!month!"=="04" set month=Apr
if "!month!"=="05" set month=May
if "!month!"=="06" set month=Jun
if "!month!"=="07" set month=Jul
if "!month!"=="08" set month=Aug
if "!month!"=="09" set month=Sep
if "!month!"=="10" set month=Oct
if "!month!"=="11" set month=Nov
if "!month!"=="12" set month=Dec
IF !d!==%%i (
set /a fc+=1
REM --- Only process if we've haven't processed passed the maximum ---
IF !fc! LEQ %maxfiles% (
echo %%~nf: Processing
IF "%%l"=="One-off" (
set fn=%%i %%j %%k
) ELSE (
set fn=%%l Part %%m %%j
)
set fn=!fn: =_!
set fn=!fn:^&=and!
set ft=%%k
set ft=!ft:^&=and!
REM --- MP3 Conversion ---
IF EXIST "!fn!.mp3" (
echo %%~nf: Already converted to mp3
) ELSE (
echo %%~nf: Converting .wav to !fn!.mp3
lame --nohist --vbr-old -V 7 -q 0 -a -m m -c --resample 44.1 --tt "%%~k" --ta "%%~j" --tl "%%~l" --ty !yr! --tc "%%~o" --tn %%~m --tg "%%~n" --ti "%%~p" %%f "!fn!.mp3" 2> "%%~nf.enc"
IF EXIST "%%~nf.log" DEL "%%~nf.log"
)
REM --- MP3 Transfer ---
IF EXIST "%%~nf.log" (
echo %%~nf: Already transferred via FTP
) ELSE (
echo %%~nf: Posting via FTP
echo OPEN %ftpserver% > postmp3.ftp
echo %ftpuser%>> postmp3.ftp
echo %ftppass%>> postmp3.ftp
echo BIN >> postmp3.ftp
echo HASH >> postmp3.ftp
echo PROMPT >> postmp3.ftp
echo CD %ftpdir% >> postmp3.ftp
echo PUT "!fn!.mp3" >> postmp3.ftp
echo DIR >> postmp3.ftp
echo BYE >> postmp3.ftp
IF EXIST "%%~nf.err" DEL "%%~ndf.err"
ftp -s:postmp3.ftp > "%%~nf.log"
find "File successfully transferred" "%%~nf.log" > nul
IF ERRORLEVEL 1 (
REN "%%~nf.log" "%%~nf.err"
echo %%~nf: File transfer failed, see %%~nf.err
) ELSE (
echo %%~nf: File transfer successful
)
)
REM --- RSS Build ---
IF NOT "%rssbase%"=="" (
echo %%~nf: Adding to RSS file
REM -- Retrieve the file size --
for %%a in ("!fn!.mp3") do set fs=%%~za
REM -- Calculate the mp3 duration --
for /f "usebackq tokens=1-10 delims=|/(" %%q in ("%%~nf.enc") do (if not "%%z"=="" set fd=%%z)
set /a fsec="((fd*100)/3828)"
set /a fhour="(fsec/3600)"
set /a fsec="(fsec-(fhour*3600))"
set /a fmin="(fsec/60)"
set /a fsec="(fsec-(fmin*60))"
IF !fhour! LSS 10 set fhour=0!fhour!
IF !fmin! LSS 10 set fmin=0!fmin!
IF !fsec! LSS 10 set fsec=0!fsec!
REM -- Write out an RSS item
echo ^ >> %rssbase%.xml
echo ^!ft!^ >> %rssbase%.xml
echo ^%rsslink%!fn!.mp3^ >> %rssbase%.xml
echo ^^<^^![CDATA[%%~o]]^>^ >> %rssbase%.xml
echo ^%%~l^ >> %rssbase%.xml
echo ^!dy! !month! !yr! 10:30:00 +1000!^ >> %rssbase%.xml
echo ^%rsslink%!fn!.mp3^ >> %rssbase%.xml
echo ^ >> %rssbase%.xml
echo ^!fhour!:!fmin!:!fsec!^ >> %rssbase%.xml
echo ^%%~l^ >> %rssbase%.xml
echo ^%%~j^ >> %rssbase%.xml
echo ^Clean^ >> %rssbase%.xml
echo ^ >> %rssbase%.xml
)
)
)
)
)
REM --- RSS Transfer ---
IF NOT "%rssbase%"=="" (
echo ^^ >> %rssbase%.xml
echo Posting RSS file via FTP
echo OPEN %ftpserver% > postmp3.ftp
echo %ftpuser%>> postmp3.ftp
echo %ftppass%>> postmp3.ftp
echo BIN >> postmp3.ftp
echo HASH >> postmp3.ftp
echo PROMPT >> postmp3.ftp
echo CD %ftpdir% >> postmp3.ftp
echo PUT %rssbase%.xml >> postmp3.ftp
echo DIR >> postmp3.ftp
echo BYE >> postmp3.ftp
IF EXIST "%rssbase%.err" DEL "%rssbase%.err"
ftp -s:postmp3.ftp > "%rssbase%.log"
find "File successfully transferred" "%rssbase%.log" > nul
IF ERRORLEVEL 1 (
REN "%rssbase%.log" "%rssbase%.err"
echo RSS File transfer failed, see %rssbase%.err
) ELSE (
echo RSS File transfer successful
)
)
REM --- Cleanup ---
rem IF EXIST postmp3.ftp DEL postmp3.ftp
goto end
:syntax
echo PostMP3 v1.0: Converts .wav files to .mp3 and posts to an FTP server
echo Scripted by Jon Guyer - http://www.jagtech.biz
echo Requires LAME mp3 encoder - http://www.mp3dev.org
echo.
echo POSTMP3 wavfiles csvfile ftpserver ftpuser ftppass ftpdir maxfiles rssbase rsslink
echo.
echo wavfiles A filename (wildcards allowed), or list of filenames within quotes
echo csvfile A comma-delimited file in the format:
echo yyyy-mm-dd,artist,title,album,track,genre,comments,picture
echo The first field is used to match the first 10 characters of a file
echo to match filenames with csv records, the rest are used as id3 tags
echo as well as for the output file: "album part track title artist.mp3"
echo ftpserver Server where the .mp3 files are posted
echo ftpuser Username on that server
echo ftppass Password for that user
echo ftpdir Relative path on the server where the files are posted
echo maxfiles Maximum number of files to transfer, starting with the last file
echo in csvfile for which a wavfile exists, counting back from there.
echo This limit also affects rss items below. The default is 10 files.
echo rssbase Header portion of RSS file on which to build item entries for mp3s
echo rsslink Link to public location of files being uploaded (end with a slash)
echo.
:end