It uses m3ugen.ini file, which can be freely customized.
That INI file syntax is:
Item1_name=Text to be displayed
Item1_data=semicolon-separated file extensions to be matched
...
Item2147483647_name=Text to be displayed #2147483646
Item2147483647_data=extensions...
This script demonstrates the usage of my dynamic choice algorithm, which bases on the content of its INI file; the choice list is created dynamically, count is not fixed in batch file itself.
It's just a simple file lister matching files of chosen extension(s).
The script:
@echo off setlocal EnableDelayedExpansion echo. echo M3UGen v1.00 (c)2012 Michal Hanebach echo. call:ValidateIni||( :inicorrupted echo INI file corrupted. goto end ) set/a itemcount=( %linecount% / 2 ) for /l %%A in (1,1,%itemcount%) do ( call:GetNextItemFromIniFile %%A ) for /l %%A in (1,1,%itemcount%) do ( call:PrintNameOfItemOfIndex %%A ) echo. echo [x] exit :WaitForUserInput echo. set ch= set /p ch=úChoose one of the three if defined ch ( set ch=%ch:"=% ) else ( goto WaitForUserInput ) if /i "%ch%"=="x" exit call:IsInteger %ch%||( echo [%ch%] is not a positive integer value goto WaitForUserInput ) call:TranslateMessage %ch% if "%errorlevel%"=="2" (echo.&echo Out of range [1..%itemcount%]) if "%errorlevel%"=="3" (goto inicorrupted) if not "%errorlevel%"=="0" (goto WaitForUserInput) set itemcount= set linecount= :loop0 echo. set ch=&set/p ch=úDrag directory here or press ENTER for the current folder if not defined ch ( set source=%~dp0 set source=!source:~0,-1! ) else ( if exist "!ch!" ( set source=!ch! ) else ( goto loop0 ) ) set source=!source:"=! :loop1 echo. set ch=&set/p ch=úType in playlist file name if not defined ch (goto loop1) set fname=!ch! if /i "!fname:~-4!"==".m3u" (set fname=!fname:~0,-4!) set ch= for %%A in (%fextpat%) do (call:BuildUpTheList %%A&&echo Added files of type: %%A&&set/a succ_cnt+=1) if not defined succ_cnt (echo None files added&goto end) set succ_cnt= sort queue.$$$ /O !fname!.m3u goto end :BuildUpTheList dir/b "!source!\*.%1">nul 2>&1||( call:ThrowErrorLevel dummy 1 goto BuildUpTheList_procend ) for /f "tokens=*" %%A in ('dir/b "%source%\*.%1"') do (echo !source!\%%A>>queue.$$$) call:ThrowErrorLevel dummy 0 :BuildUpTheList_procend exit/b%errorlevel% :ThrowErrorLevel if defined %1 set %1= exit/b%2 :ValidateIni for /f %%G in ('type m3ugen.ini') do (set/a linecount+=1) set/a remainder=( %linecount% %% 2 ) if not "%remainder%"=="0" (call:ThrowErrorLevel remainder 1) else (call:ThrowErrorLevel remainder 0) exit/b%errorlevel% :GetNextItemFromIniFile for %%A in ( Item%1_name Item%1_data ) do (for /f "tokens=1,* delims=,=" %%G in (m3ugen.ini) do (if "%%G"=="%%A" (set %%A=%%H))) exit/b0 :PrintNameOfItemOfIndex for /f "tokens=1,* delims=,=" %%G in ('set Item%1_name') do (echo %1 %%H) exit/b0 :TranslateMessage if %1 GTR %itemcount% exit/b2 if %1 LSS 1 exit/b2 set Item%1_name>nul 2>&1||exit/b3 set Item%1_data>nul 2>&1||exit/b3 for /f "tokens=2* delims=,=" %%G in ('set Item%1_data') do (set fextpat=%%G %%H) exit/b0 :IsInteger set tempvar=%1 :iilp set firstchar=%tempvar:~0,1% call:CheckIfDigit||( call:IsInteger_flushvars /failure||( exit/b1 ) ) set tempvar=%tempvar:~1% if "%tempvar%"=="" goto IsInteger_eol goto iilp :IsInteger_eol call:IsInteger_flushvars exit/b0 :CheckIfDigit if "%firstchar%"=="0" ( exit/b0 ) if "%firstchar%"=="1" ( exit/b0 ) if "%firstchar%"=="2" ( exit/b0 ) if "%firstchar%"=="3" ( exit/b0 ) if "%firstchar%"=="4" ( exit/b0 ) if "%firstchar%"=="5" ( exit/b0 ) if "%firstchar%"=="6" ( exit/b0 ) if "%firstchar%"=="7" ( exit/b0 ) if "%firstchar%"=="8" ( exit/b0 ) if "%firstchar%"=="9" ( exit/b0 ) exit/b1 :IsInteger_flushvars for %%A in ( tempvar firstchar ) do (if defined %%A (set %%A=)) if "%1"=="/failure" (exit/b1) exit/b0 :end if exist queue.$$$ del queue.$$$ set source= set fextpat= echo. echo ^< Any key to exit ^> pause>nul 2>&1 endlocalExample INI file (has to be called m3ugen.ini):
Item1_name=MP3 only Item1_data=mp3 Item2_name=FLAC only Item2_data=flac Item3_name=all audio formats possible Item3_data=aac;asf;cda;flac;kar;mid;midi;miz;mp1;mp2;mp3;nsa;ogg;rmi;vlb;wav;wma
No comments:
Post a Comment