Solved play a random video just once in a folder on winxp?

July 12, 2015 at 18:57:41
Specs: Windows XP
I'm searching in the web and i'm finding this post here:

http://www.computing.net/answers/pr...

I'm doing the batch file and i don't get to work, i'm change the path file to the folder where i have my video files and nothing, the only thing i get is a .m3u file with this line: "#EXTM3U", i'm doing something wrong or this script don't work well like in win7 and i need to change something to get work in winxp?

Thanks and sorry for my bad english, my native speak is spanish :)


See More: play a random video just once in a folder on winxp?

Report •


✔ Best Answer
July 24, 2015 at 19:49:43
Ok, now that the thirteenth shoe has dropped, posting the (hopefully) final version still including info-mercial echos but no pauses:
::========= begin batchscript
@echo off & setlocal enabledelayedexpansion
SET extensionList=avi mp4 mkv
:: if you want flexibility, you can read from a text or use commandline
:: parameters. F/e: set /p extensionlist=<extlst -- or --
:: set extensionlist=%* -- respectively.
for %%a in (%extensionlist%) do call set searchlist=%%searchlist%% *.%%a
echo included extensions qualifying for random playlist: %extensionlist%
echo taken from all descending directories, but not the root directory.
:: first, reset all files' Archive attribute ON
for %%a in (%extensionlist%) do attrib /s +a *.%%a
>out.m3u echo #EXTM3U
:1
set flag=
for /d %%d in (*) do (
echo dir: "%%d"
:: get count of A attribute files in current directory to get limit
pushd "%%d"
set c=
set r=-1
call :aa
:: now random-pick from any un-playlisted files in this current directory
if defined c (
:: repeat-flag: set for another loop repetition
set flag=1
echo count for "%%d": !c!
:: randomize limit to r:
set /a r=%random% "%%" c+1
set c=
call :aa
:: now disqualify the selected file from subsequent loops selection by turning A attrib OFF
attrib -a "!this!"
:: output info to screen and to target M3U playlist
echo random pick from "%%d" #!r!, selected file: "!this!"
>>..\out.m3u echo #EXTINF:-1,!nameonly!
>> ..\out.m3u echo "%%d\!this!"
)
popd
)
if defined flag goto :1
start "" "C:\archivos de programa\mpui hcb\mpui.exe" -fs -playlist out.m3u
goto :eof

:aa
for /f "tokens=*" %%a in ('dir /b /aa %searchlist% 2^>nul') do (
set /a c+=1
set this=%%a
set nameonly="%%~na"
if !c! equ %r% goto :eof
)
goto :eof
::===== end batch script

message edited by nbrane



#1
July 13, 2015 at 21:24:25
It looks like you want a random selection from a single directory? This script is designed to start from a root directory and forage vid files from all descending folders. It does not include the root folder vids-files contents. If this is the case, you can change this line:
FOR /D %%a IN (c:\somePath\*) DO CALL :PickFile "%%a"

to:
CALL :Pickfile "%cd%"
(if you're working from the current directory) or:
DO CALL :PickFile "some-videos-directory")
(if you want to submit the directory-name explicitly).


Report •

#2
July 14, 2015 at 14:00:28
nbrane, thanks to answer my question but, i'm explain better my situation:

I have 1 folder with the name "test" in D:\, inside this folder i have 2 more folders, one with the name "One" and other with the name "Two", in the folder "One" i have 2 video files in .mp4 and in the folder "Two" i have 2 video files in .mp4, i'm change the script in the line:

FOR /D %%a IN (c:\somePath\*) DO CALL :PickFile "%%a"

to:

FOR /D %%a IN (d:\test\*) DO CALL :PickFile "%%a"

But the script only make me a m3u file with only one line:

#EXTM3U

when i'm open the batch file in CMD window i have this error in the line:

SET /A fileNum=(23256 %% limit) + 1
Error division by zero

I don't know what i'm doing wrong, i think this script maybe don't work well in winxp and only work fine in win7

I hope you can help me to fix it, thanks :)


Report •

#3
July 14, 2015 at 20:24:55
Razor's script worked in my limiited tests. Here is the regurgitated script with a few "debugging snares". Mainly, it looks like the return value for "liimit" is coming back undefined, which means there were no qualifying files in the given directory. You'll see when you run this:

@echo off & setlocal
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:\hp_pav\vids\*) DO CALL :PickFile "%%a"
GOTO :EOF

:PickFile
:: here debugging starts
echo directory %1
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% "%~1\*.%%b"
echo searchlist: %searchlist%
pause
set limit=
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b
echo limit of %1: %limit%
:: here I modified to eject if limit is not defined ie no qual. files found
if not defined limit echo fail no qualifying files in %1&goto :eof
pause
:: the rest is "history" - no changes
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


Report •

Related Solutions

#4
July 14, 2015 at 20:44:39
Ok, testing the new batch file this is what i get in the CMD window:

directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Press any key to continue . . .
limit of "d:\test\Dos":
fail no qualifying files in "d:\test\Dos"
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Press any key to continue . . .

And again a .m3u file with only "#EXTM3U" line :(

Here's the problem what you saying if i'm run this script, any suggestion ?

message edited by tvjpn


Report •

#5
July 14, 2015 at 21:50:23
Could you post the output from this command:
dir "d:\test\dos\*.mp4"

Report •

#6
July 14, 2015 at 21:56:05
Here's the Output:

C:\>dir d:\test\dos\*.mp4

Directory of d:\test\dos

14/09/2014 02:32 a.m. 483,919,391 AA.mp4
28/08/2014 06:59 p.m. 387,188,404 AB.mp4
2 Files 871,107,795 bytes
0 dirs 16,037,937,152 Free Bytes

C:\>


Report •

#7
July 14, 2015 at 22:11:56
Ah HA!, i think:
2 Files 871,107,795 bytes
(your output) versus:

"File(s)"

FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b

So, if you change that line, it might work. Change it to match your output:
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "Files") DO SET limit=%%b

This might circumvent the problem entirely:

fOR /F "tokens=1 delims=[]" %%b IN ('DIR /b /A-D-H-S %searchList% ^| FIND /n /v ""') DO set limit=%%b

message edited by nbrane


Report •

#8
July 15, 2015 at 01:14:34
ok, my winxp is in spanish so some commands are in spanish and i'm translate to you from spanish to english that you can understand, so this is exactly CMD Words from "dir d:\test\dos\*.mp4":

Directorio de d:\test\Dos

13/07/2015 08:48 p.m. <DIR> .
13/07/2015 08:48 p.m. <DIR> ..
14/09/2014 02:32 a.m. 483,919,391 AA.mp4
28/08/2014 06:59 p.m. 387,188,404 AB.mp4
2 archivos 871,107,795 bytes
2 dirs 13,821,952,000 bytes libres


now, changing the line:

FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b

to:

FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "Files"') DO SET limit=%%b

I have the same results, but if i change "Files" to "archivos", the batch send me:

directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Presione una tecla para continuar . . .
El sistema no puede encontrar el archivo 'DIR /A-D-H-S "d:\test\Dos\*.avi" "d:\t
est\Dos\*.mp4" "d:\test\Dos\*.mkv" | FIND "archivos".
limit of "d:\test\Dos":
fail no qualifying files in "d:\test\Dos"
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Presione una tecla para continuar . . .
El sistema no puede encontrar el archivo 'DIR /A-D-H-S "d:\test\Uno\*.avi" "d:\t
est\Uno\*.mp4" "d:\test\Uno\*.mkv" | FIND "Archivos".
limit of "d:\test\Uno":
fail no qualifying files in "d:\test\Uno"


Translating:

- Presione una tecla para continuar = Press any key to continue...
- El sistema no puede encontrar el archivo = The system can't find the file...


and if i change the line:

FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b

to

FOR /F "tokens=1 delims=[]" %%b IN ('DIR /b /A-D-H-S %searchList% ^| FIND /n /v ""') DO set limit=%%b


I have the same result and errors :(

Thank you very much to help me and i hope this lines can help you to find where exactly is the problem.

Thanks :)

message edited by tvjpn


Report •

#9
July 15, 2015 at 17:27:00
First, you need to observe case. From what you've reported, this:
FIND "archivos".
won't find this: "Archivos".

but that's not the whole problem. Something in your script makes the CMD think you're looking for a file in this statement:
El sistema no puede encontrar el archivo 'DIR /A-D-H-S "d:\test\Dos\*.avi" "d:\t
est\Dos\*.mp4" "d:\test\Dos\*.mkv" | FIND "archivos".

Fix that first item Archivos, then post your whole script untranslated. My spanish is limited, but sometimes I can get the gist. I need to see exactly what's going on...


Report •

#10
July 15, 2015 at 21:01:12
This is the script i'm using:

@echo off & setlocal
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 (d:\test\*) DO CALL :PickFile "%%a"
GOTO :EOF

:PickFile
:: here debugging starts
echo directory %1
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% "%~1\*.%%b"
echo searchlist: %searchlist%
pause
set limit=
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b
echo limit of %1: %limit%
:: here I modified to eject if limit is not defined ie no qual. files found
if not defined limit echo fail no qualifying files in %1&goto :eof
pause
:: the rest is "history" - no changes
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

And there it is the CMD Windows step by step without translate:

- First "dir d:\test\dos"

Directorio de d:\test\Dos

13/07/2015 08:48 p.m. <DIR> .
13/07/2015 08:48 p.m. <DIR> ..
14/09/2014 02:32 a.m. 483,919,391 AA.mp4
28/08/2014 06:59 p.m. 387,188,404 AB.mp4
2 archivos 871,107,795 bytes
2 dirs 10,183,577,600 bytes libres


- Runing the script on CMD Window without changing "File(s)" in the line:
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b

directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Dos":
fail no qualifying files in "d:\test\Dos"
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Uno":
fail no qualifying files in "d:\test\Uno"

- Runing the script on CMD Window changing "File(s)" to "Files" in the line:
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "Files"') DO SET limit=%%b

directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Dos": El
Presione una tecla para continuar . . .
Error de división por cero.
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Uno": El
Presione una tecla para continuar . . .
Error de división por cero.

- Runing the script on CMD Window changing "Files" to "archivos" in the line:
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "archivos"') DO SET limit=%%b


directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Dos": 2
Presione una tecla para continuar . . .
" " no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Uno": 2
Presione una tecla para continuar . . .
" " no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

and..
- Runing the script on CMD Window changing "archivos" to "Archivos" in the line:
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "Archivos"') DO SET limit=%%b

directory "d:\test\Dos"
searchlist: "d:\test\Dos\*.avi" "d:\test\Dos\*.mp4" "d:\test\Dos\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Dos":
fail no qualifying files in "d:\test\Dos"
directory "d:\test\Uno"
searchlist: "d:\test\Uno\*.avi" "d:\test\Uno\*.mp4" "d:\test\Uno\*.mkv"
Presione una tecla para continuar . . .
limit of "d:\test\Uno":
fail no qualifying files in "d:\test\Uno"


Well there it is, i hope this help you to fix this problem, thanks again

message edited by tvjpn


Report •

#11
July 21, 2015 at 14:01:35
nbrane, are you there ?

Report •

#12
July 21, 2015 at 19:29:51
Yes, still here. aplogies.
You almost had it working till you changed "archivos" to "Archivos". Change that back. You got the correct file count: "limit of "d:\test\Dos": 2"
then it says "unrecognized command" referring to subsequent commands.
That narrows it down to everything "downstream" after getting the correct file-count - starting here:

:: the rest is "history" - no changes
:: this picks a random file between 1 and the number of qualifying files in the current
:: directory - in this case: two.
SET /A fileNum=(%random% %% limit) + 1
echo random picked: %filenum%
pause
FOR /F "tokens=2 delims=:" %%b IN ('2^>NUL DIR /A-D-H-S/B %searchList% ^| FINDSTR /N ".*" ^| FINDSTR "^%fileNum%:"') DO ^
echo call :addlist %1 "%%b"
pause
CALL :AddList %1 "%%b" >>%cnt%.m3u
GOTO :EOF

:AddList
@ECHO.#EXTINF:-1,%~n2
@ECHO.%~f1\%~2
@GOTO :EOF

::====== end test/debug script
We need to see where the "unrecognized command" is occuring, so try running this "debugging" version to see where things hang up, and what the values are.

ps: it's not a win version problem, since all we're doing is creating a textfile based on standard basic CMD commands inside a batchscript.


message edited by nbrane


Report •

#13
July 21, 2015 at 20:38:18
Ok, here are the results:

In this script:

@echo off & setlocal
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 (d:\test\*) DO CALL :PickFile "%%a"
GOTO :EOF

:PickFile
:: here debugging starts
echo directory %1
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% "%~1\*.%%b"
echo searchlist: %searchlist%
pause
set limit=
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "archivos"') DO SET limit=%%b
echo limit of %1: %limit%
:: here I modified to eject if limit is not defined ie no qual. files found
if not defined limit echo fail no qualifying files in %1&goto :eof
pause
:: the rest is "history" - no changes
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

Is working now and i have this playlist:

#EXTM3U
#EXTINF:-1,AB
d:\test\dos\AB.mp4
#EXTINF:-1,A
d:\test\uno\A.mp4


And in this script:

@echo off & setlocal
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 (d:\test\*) DO CALL :PickFile "%%a"
GOTO :EOF

:PickFile
:: here debugging starts
echo directory %1
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% "%~1\*.%%b"
echo searchlist: %searchlist%
pause
set limit=
FOR /F "tokens=1*" %%b IN ('DIR /A-D-H-S %searchList% ^| FIND "archivos"') DO SET limit=%%b
echo limit of %1: %limit%
:: here I modified to eject if limit is not defined ie no qual. files found
if not defined limit echo fail no qualifying files in %1&goto :eof
pause
:: the rest is "history" - no changes
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


Is working and i have this playlist:

#EXTM3U
#EXTINF:-1,b
d:\test\dos\b
#EXTINF:-1,b
d:\test\uno\b

So, the playlist made with the first script is working fine in a player, the playlist made with the second script is not working in a player, and now i have these question:

This script is only make a playlist with one file for each folder, or the script is randomize every file for each folder to put all the files of each folder in the playlist?

Example:

#EXTM3U
#EXTINF:-1,AA
d:\test\dos\AA.mp4
#EXTINF:-1,A
d:\test\uno\A.mp4

(Here is only one file per folder, and i dont have the file B for folder Uno, and the file AB for folder Dos)

I suppose the script is make me something like this:

#EXTM3U
#EXTINF:-1,AB
d:\test\dos\AB.mp4
#EXTINF:-1,A
d:\test\uno\A.mp4
#EXTINF:-1,AA
d:\test\dos\AA.mp4
#EXTINF:-1,B
d:\test\uno\B.mp4


if the script is not doing this, is hard to do the script make random for all the files for all the folders once and every i'm run the script is random again the files in other playlist?


Thanks again for you help nbrane

message edited by tvjpn


Report •

#14
July 21, 2015 at 23:56:56
Yes, this is what the script does:
"This script is only make a playlist with one file for each folder:"

"In the end, I want to know if there's a way to play one single random video in 1 folder, then move on to the next folder and play 1 single random video and just go like that and cycle through so basically I never see the same show again until all 22 shows are shown"

which is not what you want, from what I understand so far.
So now, it's "what do you exactly want"? (I know there's a language challenge here, mostly on my part!). My understanding so far: you want ALL the files from all the folders randomly mixed, but taken from each folder successively? For example:
folder "A" has files A1, A2, A3...
folder "B" has files B1,B2, B3...
And you want list result like:
A3, B2, A1, B1, A2, B3
Into one playlist.
But of course with any number of folders and any number of files in each folder? And of course with no duplicates in any one play-list. Each time you run the batch, it builds a new list of randoms all files from all folders. Does this sound close?



Report •

#15
July 22, 2015 at 10:55:08
yes nbrane, this is exactly what i want:

I want ALL the files from all the folders randomly mixed, but taken from each folder successively.

- For example:
folder "A" has files A1, A2, A3...
folder "B" has files B1,B2, B3...
And you want list result like:
A3, B2, A1, B1, A2, B3
Into one playlist.

But of course with any number of folders and any number of files in each folder, and of course with no duplicates in any one play-list. Each time you run the batch, it builds a new list of randoms all files from all folders.

is difficult to modify the actually script to do this ?

message edited by tvjpn


Report •

#16
July 22, 2015 at 22:14:55
Here's a working prototype for you to test. It worked ok on my small testing layout (3 directories with different numbers of files):
::========= begin test batch
@echo off & setlocal enabledelayedexpansion
:: first, reset all files' Archive attribute ON
attrib /s +a *.mp4
>out.m3u echo #EXTM3U
:1
set flag=
for /d %%d in (*) do (
echo dir: %%d
:: get count of A attribute files in current directory to get limit
pushd %%d
set c=
set r=-1
call :aa
:: now random-pick from any un-playlisted files in this current directory
if defined c (
:: repeat-flag: set for another loop repetition
set flag=1
echo count for %%d: !c!

:: randomize limit to r:
set /a r=%random% "%%" c+1
set c=
call :aa
:: now disqualify the selected file from subsequent loops selection by turning A attrib OFF
attrib -a !this!
:: output info to screen and to target M3U playlist
echo random pick from %%d #!r!, selected file: !this!
>>..\out.m3u echo #EXTINF:-1,!nameonly!
>> ..\out.m3u echo %%d\!this!
)
popd
)
if defined flag goto :1
start "" "C:\archivos de programa\mpui hcb\mpui.exe" -fs -playlist out.m3u
goto :eof

:aa
for /f %%a in ('dir /b /aa *.mp4 2^>nul') do (
set /a c+=1
set this=%%a
set nameonly=%%~na
if !c! equ %r% goto :eof
)
::===== end batch script PROTOTYPE ONLY
You may need to fully qualify pathnames etc (I get SOOOO tired of dealing with local BS issues like paths and funky filenames! Rant not directed at you, just in general Ha ha!)

message edited by nbrane


Report •

#17
July 22, 2015 at 23:16:13
This is what i get using your prototype script in my test folder with 2 subfolders named "uno" with files A.mp4 and B.mp4 and "dos" with the files AA.mp4 and AB.mp4

in the folder name "test" i have a file named "X" without asociation and inside the file i get:

dos\AB.mp4
uno\B.mp4
dos\AA.mp4
uno\A.mp4

I suppose the prototype scripts is working well, so we need to export to a playlist structure and make playable in a video player, other thing i need is the script not make me pauses between folders (any press key to continue), because i need something more automatized.

In the other scripts i put a extra line to make start a player named "MPUI" inmediately the script finished the playlist structure and inmediately play the playlist, this is the line i put there:

start "" "C:\archivos de programa\mpui hcb\mpui.exe" -fs -playlist out.m3u

with this line, the player starts inmediately and play the playlist in fullscreen mode.

Again, thank you very much to help me with this :)


message edited by tvjpn


Report •

#18
July 22, 2015 at 23:50:34
Ok, try #16 again (modified to suit).

Report •

#19
July 23, 2015 at 01:13:36
very good nbrane, the prototype scripts is work very well but... it's still no compatible in the players, this script send me now a file with name "out.m3u" and inside the file is like this:

dos\AB.mp4
uno\B.mp4
dos\AA.mp4
uno\A.mp4


so, in the anothers scripts the m3u file are like this:

#EXTM3U
#EXTINF:-1,AA
d:\test\dos\AA.mp4
#EXTINF:-1,B
d:\test\uno\B.mp4

this m3u structure is totally compatible with players, so, we need the new script make the m3u files with this structure to make compatible with players and mpui.

if the problem is with the pathnames in the script, please only tell me where i need to change it.


Thanks again for your work :)


message edited by tvjpn


Report •

#20
July 23, 2015 at 18:33:18
Ok, try #16 again (modified to suit per request #19).



Report •

#21
July 24, 2015 at 00:05:38
nbrane thank you very much for your help with this script, is working really good and great and the mpui player is recognize the files on the playlist, and now i have only two more question:

Is possible the script recognize mkv, mpg, avi and more type of videos in the folders?, because analyzing the script it's only recognize .mp4 files

And the script no detect files and folders with spaces in the name

thanks again. :)



message edited by tvjpn


Report •

#22
July 24, 2015 at 19:49:43
✔ Best Answer
Ok, now that the thirteenth shoe has dropped, posting the (hopefully) final version still including info-mercial echos but no pauses:
::========= begin batchscript
@echo off & setlocal enabledelayedexpansion
SET extensionList=avi mp4 mkv
:: if you want flexibility, you can read from a text or use commandline
:: parameters. F/e: set /p extensionlist=<extlst -- or --
:: set extensionlist=%* -- respectively.
for %%a in (%extensionlist%) do call set searchlist=%%searchlist%% *.%%a
echo included extensions qualifying for random playlist: %extensionlist%
echo taken from all descending directories, but not the root directory.
:: first, reset all files' Archive attribute ON
for %%a in (%extensionlist%) do attrib /s +a *.%%a
>out.m3u echo #EXTM3U
:1
set flag=
for /d %%d in (*) do (
echo dir: "%%d"
:: get count of A attribute files in current directory to get limit
pushd "%%d"
set c=
set r=-1
call :aa
:: now random-pick from any un-playlisted files in this current directory
if defined c (
:: repeat-flag: set for another loop repetition
set flag=1
echo count for "%%d": !c!
:: randomize limit to r:
set /a r=%random% "%%" c+1
set c=
call :aa
:: now disqualify the selected file from subsequent loops selection by turning A attrib OFF
attrib -a "!this!"
:: output info to screen and to target M3U playlist
echo random pick from "%%d" #!r!, selected file: "!this!"
>>..\out.m3u echo #EXTINF:-1,!nameonly!
>> ..\out.m3u echo "%%d\!this!"
)
popd
)
if defined flag goto :1
start "" "C:\archivos de programa\mpui hcb\mpui.exe" -fs -playlist out.m3u
goto :eof

:aa
for /f "tokens=*" %%a in ('dir /b /aa %searchlist% 2^>nul') do (
set /a c+=1
set this=%%a
set nameonly="%%~na"
if !c! equ %r% goto :eof
)
goto :eof
::===== end batch script

message edited by nbrane


Report •

#23
July 25, 2015 at 09:58:26
Ok nbrane the script is progressing, now i have more extensions than mp4 on the m3u file, but the filenames with spaces is still no recognize and now the mpui is no start at the end of the progress

Sorry for bother you, buy i'm very apreciated with your help and thanks again.


Report •

#24
July 25, 2015 at 19:13:34
revised #22: added the quotes needed for those blessed spaces-in-filenames and re-activated your player-launcher. Not tested with spaces-in-filenames. I'll leave that up to you!

Report •

#25
July 25, 2015 at 21:58:06
nbrane, i'm tested the changes you do it in the script and finally i can say the script is working very good, i need to make a little changes to work fine for example in the m3u files the path of the videos are show like this:

before:

#EXTM3U
#EXTINF:-1,"AB"
"dos\AB.mp4"
#EXTINF:-1,"B"
"uno\B.mp4"
#EXTINF:-1,"AA"
"dos\AA.mp4"
#EXTINF:-1,"A"
"uno\A.mp4"

In this mode the player is not recognized me the files, so i'm searching and compared between the new and the old scripts and changed some lines so now the m3u file is show like this:

after :

#EXTM3U
#EXTINF:-1,AB
d:\test\dos\AB.mp4
#EXTINF:-1,B
d:\test\uno\B.mp4
#EXTINF:-1,AA
d:\test\dos\AA.mp4
#EXTINF:-1,A
d:\test\uno\A.mp4

And now the player is recognized me the video files, about the filenames without space now is work perfect, the script is recognize the filenames with spaces and run perfect.

i'm post here the final batch to show you the changes i made:

::========= begin batchscript
@echo off & setlocal enabledelayedexpansion
SET extensionList=avi mp4 mkv
:: if you want flexibility, you can read from a text or use commandline
:: parameters. F/e: set /p extensionlist=<extlst -- or --
:: set extensionlist=%* -- respectively.
for %%a in (%extensionlist%) do call set searchlist=%%searchlist%% *.%%a
echo included extensions qualifying for random playlist: %extensionlist%
echo taken from all descending directories, but not the root directory.
:: first, reset all files' Archive attribute ON
for %%a in (%extensionlist%) do attrib /s +a *.%%a
>out.m3u echo #EXTM3U
:1
set flag=
for /d %%d in (d:\test\*) do (
echo dir: %%d
:: get count of A attribute files in current directory to get limit
pushd %%d
set c=
set r=-1
call :aa
:: now random-pick from any un-playlisted files in this current directory
if defined c (
:: repeat-flag: set for another loop repetition
set flag=1
echo count for %%d: !c!
:: randomize limit to r:
set /a r=%random% "%%" c+1
set c=
call :aa
:: now disqualify the selected file from subsequent loops selection by turning A attrib OFF
attrib -a "!this!"
:: output info to screen and to target M3U playlist
echo random pick from %%d #!r!, selected file: !this!
>>..\out.m3u echo #EXTINF:-1,!nameonly!
>> ..\out.m3u echo %%d\!this!
)
popd
)
if defined flag goto :1
start "" "C:\archivos de programa\mpui hcb\mpui.exe" -fs -playlist out.m3u
goto :eof

:aa
for /f "tokens=*" %%a in ('dir /b /aa %searchlist% 2^>nul') do (
set /a c+=1
set this=%%a
set nameonly="%%~na"
if !c! equ %r% goto :eof
)
goto :eof
::===== end batch script


Thank you very much to help me with this script, so now i can make the automatization i need.


PD: This is not a prority but i think we can do it, using the actual script and searching my needs i see a new issue thay maybe can do it, i'm explain:

I have 4 folders:

- Promos
- TV program 1
- TV program 2
- TV program 3

well, my need is to play like the actual script but i want to play one file for folder "TV Program 1", after this play a file for folder "Promos", after this play a file from folder "TV Program 2", again after this play another file for folder "Promos", and now go to play a file from folder "TV Program 3" and after this play another file for folder "promos" and after this again play a file in the folder "TV Program 1", etc...

Example

- Promos
- TV Program 1
- Promos
- TV Program 2
- Promos
- TV Program 3
- Promos
- TV Program 1
...etc


The actual script is working fine to me, i'm only need to do is to repeat the folder "promos" with another files after the folders "TV Program 1", "TV Program 2", TV Program 3", etc...

Example:

- TV Program 1
- Promos 01
- TV Program 2
- Promos 02
- TV Program 3
- Promos 03

but if we can do the another example with this or another script, for me is more flexible to make the automation with the promo video files in one folder than one "promos" folder per "TV Program" folder.

Thanks :)


Report •

Ask Question