Hello, couple of months ago, a very helpful person by the name of Razor2.3 helped me with a batch that when executed, it will look into each folder of my shows, and from those shows randomly choose a video and then continue with the next folder and randomly pick a show and so forth.
The batch would output an m3u playlist file and all I would have to do is to click the batch X amount of times and generates X amount of m3u playlists and all I would have to do is play that in my Windows media player without having to manually pick each episode for each show. (btw, I am using windows 7 PC).
The final script was done and it looks like this:
SET extensionList=avi mp4 mkv
SET cnt=0
:Loop
SET /A cnt+=1
IF EXIST %cnt%.m3u GOTO Loop
>%cnt%.m3u ECHO.#EXTM3U
FOR /D %%a IN (c:\somePath\*) DO CALL :PickFile “%%a”
GOTO :EOF
:PickFile
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% “%~1\*.%%b”
FOR /F %%b IN (‘2^>NUL DIR /A-D-H-S %searchList% ^| FIND “File(s)”‘) DO SET limit=%%b
SET /A fileNum=(%random% %% limit) + 1
FOR /F “tokens=2 delims=:” %%b IN (‘2^>NUL DIR /A-D-H-S/B %searchList% ^| FINDSTR /N “.*” ^| FINDSTR “^%fileNum%:”‘) DO ^
CALL :AddList %1 “%%b” >>%cnt%.m3u
GOTO :EOF
:AddList
@ECHO.#EXTINF:-1,%~n2
@ECHO.%~f1\%~2
@GOTO :EOF
After weeks of testing, I found out that more often than not, it seems to repeat some episodes of my shows from my last playlist. (I would generate this playlist X amount of times)
Is there a way to edit this so that I can make sure I don’t see a repeated episode from the last playlist? Or to make it even more random? I hope that makes sense, I can clarify even more on the next post. Thank you~
BTW, the original post is here (https://computing.net/answers/programming/is-there-a-way-to-play-a-random-video-just-once-in-a-folder/28683.html#xtor=EPR-2)
Yeah, I think my post got all crossed up somehow, so heeding Razor’s sound advice, I’ll put what I thought would solve the problem of “repeat performances” (this is Razor’s code, btw, with only the two mods I planted):
:Start
SET extensionList=avi mp4 mkv
SET cnt=0
:Loop
SET /A cnt+=1
IF EXIST %cnt%.m3u GOTO Loop
>%cnt%.m3u ECHO.#EXTM3U
FOR /D %%a IN (c:\somePath\*) DO CALL :PickFile “%%a”
GOTO :EOF
:PickFile
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% “%~1\*.%%b”
:: modification one: count only files with archive attribute turned ON
set limit=0
FOR /F %%b IN (‘2^>NUL DIR /A-D-H-SA %searchList% ^| FIND “File(s)”‘) DO SET limit=%%b
IF %limit% gtr 0 goto :randsel
ECHO No more unplayed files, reset all files?
choice
if %errorlevel% equ 2 goto :eof
cd \somePath
attrib /s +a *.*
:: ===== OPTIONAL: remove old playlists.
del /s *.m3u
goto :start
:randsel
SET /A fileNum=(%random% %% limit) + 1
:: modification 2: include only files with archive attribute turned ON
FOR /F “tokens=2 delims=:” %%b IN (‘2^>NUL DIR /A-D-H-SA/B %searchList% ^| FINDSTR /N “.*” ^| FINDSTR “^%fileNum%:”‘) DO ^
CALL :AddList %1 “%%b” >>%cnt%.m3u
GOTO :EOF
:AddList
@ECHO.#EXTINF:-1,%~n2
@ECHO.%~f1\%~2
:: modification three: “disable” or otherwise “switch off” this file from future inclusions
@ATTRIB -A %~f1\%2
@GOTO :EOF
::====== end
@a11: the other short batch was just a “reset” to turn all the files back on, it was just put there to confuse you! 😉
Anyway, with any given set of items, any random generator will randomly duplicate values unless those values are somehow removed from the lineup – otherwise it’s not “random” for that set. What you want is random plus unique, which means the set must be reduced somehow. It doesn’t matter how, you could delete the files, rename the files, move the files to foreign directories, maintain a list, etc. etc. I chose to use the archive-bit, since it’s fairly easy to implement using minimal modifications to Razor’s working code. As far as I know, there is no random generator that is designed to never duplicate a value, because then it is no longer definable as truly random: it has an agenda, like God: “God does not play dice with the universe” (Albert Einsten)