Randomiziation script request.

Discuss your Lua playlist, album art and interface scripts.
Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Randomiziation script request.

Postby Chromatic » 02 Jul 2013 23:41

I don't know how to script in LUA,.. but this seems like a simple task that would just require a randomizer, and tracking of each filename played.

I basically need a way so I can put the player on a random and loop all (never-ending) -- where it plays truly randomly BUT never plays the same filename twice UNTIL it has gone through every video (file) in the playlist.

With the current random, it will play a video two, three, or more times before it gets to some other random video that it still hasn't played. My purposes are that I broadcast to an audience and truly need all the playlist to be played just one time a piece, randomly , before it starts over in random.. so there aren't repeats until the whole list has been played one time.



In code, I would figure a randomizer would be really easy to code/script -- Then just read the filename that is played and store it in a file somewhere, (or memory) and then it ranomizes and goes to the NEXT random filename in the playlist (it first checks if that filename = ANY of the filenames in this file that is keeping track of what HAS been played,.. and if it DOES NOT = any filename in that list.. it get the go ahead to play. Thus, with this logic it would go through the entire list, at random, until all of the files have been played.

When all the files in playlist have been played,.. the program would RE-randomize the list in a new order.. and play it, again checking.. and loop.

Can anyone do this ? (Again, I use Loop ALL and Random -- but it repeats videos often before it gets to other videos that have not been played 1 time..) I have about 150 files/videos in the playlist.

Thanks!

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 03 Jul 2013 13:32

Attempt for Shuffle is here: VLC Extension: Playlist randomizer
So you do not need to see the random order. You just need to play playlist items in random order, each item only once, then new randomization after all items were already played. Just better/proper Random with Loop all. Right?
Probably modification/enhancement of Pause @ start - a simple extension script:

Code: Select all

... if state==4 then vlc.playlist.goto( id ) ...
I will see what I can do.

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 03 Jul 2013 20:17

So you do not need to see the random order. You just need to play playlist items in random order, each item only once, then new randomization after all items were already played. Just better/proper Random with Loop all. Right?
Exactly, couldn't have said it better myself.

I really appreciate your help.

Respectfully,

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 05 Jul 2013 14:10

If you turn off/on Random, you will get new random order. The only issue here is, that you better use also Loop all otherwise the playback will stop before all files have been already played. It would be very useful to see the random order so that you can play the complete playlist in random order and then stop (no Loop all).

10 files in the playlist, random, no loop:
#1: 8-10-4-3-5-9-2-7-1-6
#2: 6-2-1-7-9 | 4-8-10-5-3 => 4-8-10-5-3-6-2-1-7-9
#3: 9-8-4-7 | 5-10-2-3-6-1 => 5-10-2-3-6-1-9-8-4-7

Is it all right if the last file will be one of the first ones in the next (new) random order?

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 06 Jul 2013 07:56

For To Long, Didn't Read -- SEE: TL:DR at bottom of post (will save you some time if you don't want to read the mess of text I ended up writing).

I'm reading and re-reading your post.. Maybe I'm dense. :)

Anyhow -- This is a live stream that never goes offline.. with several hundred viewers at any given time. Around 150 or so 45minute videos in the playlist. So the goal here is to randomize so those watching (and they watch literally for 3-4 hours or more at a time) to not see the same episode of the series I'm playing until all the others have been played.

I always have *Loop All* on,.. and *DID* have random on,.. but everyone complained that the same episodes were showing up time and time again..

For example.. 150 episodes/files -- It might play file 50, then 80, then 104, then 116, then 53, then 50 again, and so on.. For all 150 files to play it takes 4+ days.. With random on , in those 4 days there would be tons of repeats and not all series/episodes would have been played..

This wouldn't be an issue if it just occasionally played an episode it had just played a few hours before.. but for whatever reason it played them so often that people would notice,.. including myself. The simple goal is to have it NOT play an episode it has played until all the others have been played 1 time. Then it can reset the random order, and do so again.

To your question.. "Is it all right if the last file will be one of the first ones in the next (new) random order?" -- Well, preferably it would be one of the last .. if it must be placed at a certain position I suppose placing it in the middle of the random order would be just fine.

Also, I don't know if you are intending for it to be this way -- but it seems that maybe you are saying I will need to turn random off and then back on to get a new random order --

A few issues with that, if it is the case. This is a live video stream, and while I try to attend to it as much as possible, I obviously am not around all the time,.. so it would be nearly impossible to be at the computer at the exact time to reset the random order. Is there no way this can be automated?

Again my logic would be this:

Let's use 100 files for ease of math.

Set script (or playlist on Random and Loop-All) -- (I was kind of thinking this script/extension would replace the random feature of VLC as I don't know how it would modify the built in Random feature that is giving me issues) -- But however it works is fine.

Anyhow -- Set playlist on Loop-All (so that it can function , in theory, indefinitely, without any input from me after I press play the first time.)

The code does something like this:

Take all files in playlist (I DO play a a saved playlist) -- and generate a random order -- and then play that entire order like it was a set playlist NOT on random... since it randomized the playlist (sort of like if you pressed randomize in Winamp (if you are familiar) and then pressed play. -- THEN, at file 100 (the last file),.. it would automatically Re-randomize all the files, create new playlist order and play them.. and it goes on and on like this.

Or -- perhaps:

It is easier with code/script to eliminate using VLC's random and loop-all function all together on the command bar. (Essentially I suppose I would be using this extension to run my playlist, instead of the command bar's loopall/random) -- Anyhow, if so -- The script/extension would have a little easy menu in it that I could pull down and load my playlist file into, and then press GO -- (If I had to enter all the files manually one time into this script menu for it to work properly, I would be happy to do so.)

Then the script had the logic of:

1)Take all files entered (pseudo playlist) and generate a number correlation to each file. --
2) Script then uses Random Number Generator to mix up the order of the total number (say 50,13,99,4,33,76,21,5,... and so on till it has a complete random order of all files).
3) Script plays first Random file.
4) At end of the video playing, the script stores this number (or filename) and writes it to a text file on the hard drive (or into a memory address)
5) Script then queues up next file (video) to play, and does a check -- Does number correlated to this queued video = number stored at Step (4)? If yes, then =! do not play, queue next video and repeat the Does this filename (or number correlated to filename) = any number stored (obviously these stored names or numbers would be videos/files already played once) -- If no, then play file.
6) Somewhere in this logic would need to be a check of does Total Played files = Total Number of Files stored in list (file/memory)? If yes, then Go back to Step 1, which would re-randomize the list, and erase the stored played files in memory/file, and start over again with a New random order, and a clean memory of files already played.

Sheesh, Looking at that logic is bound to be confusing -- but I've done some basic scripting in other scripting languages but it has been a while.. but I know how code works on a very basic level.. so if that is too confusing just ignore it --

Code: Select all

From some simple scripting languages (and general bullshit) I've used I would do something like: $totalfiles = all videos in playlist. $file = current file (video about to be played). $playedfiles = all videos that have been played once and stored. $totalnumber = Total Number of Files (assigned a number) in playlist. $playednumber = Total Number of Files that have been played. #MENU Insert Code to build menu with options that are applicable to this extension. #BEGIN Open playlist.xspf *Insert Code For Randomizing the files in this list* (ie: Something using the RNG) Save playlist.xspf > randomplaylist.xspf $totalnumber = findstr /R /N "^" randomplaylist | find /C ":" GOTO #FILE_CHECK #FILE_CHECK If $file != $playedfiles THEN GOTO #FILE_VIDEO_PLAY ELSE GOTO #NEXT_FILE ENDIF #NEXT_FILE IF $playednumber = totalnumber GOTO #BEGIN ELSE Open randomplaylist.xspf Select.Next.File // Code to open the randomly generated playlist file and select the next file on the list. $file = Next.File // Setting variable of the selected next filename. CALL #FILE_CHECK #FILE_VIDEO_PLAY Play filename // The action of playing the file (video) $playednumber = $playednumber + 1 // To set variable adding 1, so once it reaches the total $playednumber it starts the process all over. GOTO #NEXTFILE
Ok, I am by no means a coder -- as is painfully obvious.. but the basic idea is to run a loop to take my playlist... randomize it,.. then perhaps write it to another filename (ie: Randomplaylist.txt) -- Then the code can use this new playlist file the code made,.. and filter through the file until EOF (end of file.. or with the use of $playednumber = $totalnumber) then Go back to the begining of the code. At the beginning of the code it would erase the randomplaylist.txt (or whatever extension) if it exists, and randomize the existing playlist.xspf file and write it to randomplaylist.txt for the code to work through until EOF, or the +1 counter on $playednumber equals the total lines in the file -- Which should equate to the total number of videos in the playlist.

Of course, some simple menu with a box to enter the name/path of my playlist file,.. and a START or GO button. (And any other options you think are needed on the menu). Obviously if the script/extension code is playing the files/videos then it wouldn't matter what I did with the loop and random buttons on the VLC command menu.

But, I know nothing of how the lua extensions integrate with the command line -- but maybe this fuzzy logic will give you some sort of idea of what I'm trying to accomplish.

I think a bit of smart thinking and it wouldn't take a huge amount of lines of code/script.

I remember scripting things years back in something called Vscript for a BBS and then while going to sleep thinking of another way to take 1000 lines of code and perform the same function with 10 lines of code. But, neat or bloated I care not!

Yes, I know the above example "code" is not real code.. it wouldn't work in any way, shape, or form! Maybe, it shows you just how much I need your help, lol.

TL:DR -- Basically to answer you question, I need something that can be left alone without any input from me after I start it that will take my playlist, randomize it,.. play all the files ONE time, then once it has played them all once, starts over -- re-randomizes them, and plays the new random order 1 time per file.. it won't work if I have to press a button after it plays each file 1 time. It literally needs to be on autopilot mode randomizing, playing all 150 files, then re-randomizing, playing all 150 files, re-randomizing, playing all 150 files.. ad infinitum.


Thank you so much for helping with this!

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 07 Jul 2013 20:01

>> New Random with Loop all
Please test the extension and share your experience.

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 07 Jul 2013 23:13

Here is another attempt:

Code: Select all

-- "New Random with Loop all.lua" -- VLC Extension first_ID = 6 items = 10 random_order={3,5,8,2,9,4,7,1,10,6} function descriptor() return { title = "New Random with Loop all", capabilities = {"input-listener", "meta-listener"} } end function activate() create_dialog() end function deactivate() end function close() vlc.deactivate() end k=0 function input_changed() state = vlc.var.get(vlc.object.input(), "state") --vlc.msg.info("["..descriptor().title.."] Input state = "..state) if state==4 then k=k+1 if k>#random_order then k=1 New_Random() end vlc.playlist.goto(random_order[k]+first_ID-2) --vlc.msg.info("["..descriptor().title.."] ".. k ": goto(" .. random_order[k] .. "+"..first_ID.."-2)") order="" for ix, vx in ipairs(random_order) do if ix==k then vx="<b>["..vx.."]</b>" end order=order..vx..", " end w8:set_text(order) w:update() end end function meta_changed() end ----- Dialog box: ----- function create_dialog() w = vlc.dialog(descriptor().title) w1 = w:add_label("ID of the first item:", 1, 1) w2 = w:add_text_input(first_ID, 2, 1) w3 = w:add_button("Check ID:",click_CheckID, 3, 1) w4 = w:add_label("Number of items:", 1, 2) w5 = w:add_text_input(items, 2, 2) w6 = w:add_label("Random order", 1, 3, 2) w7 = w:add_button("START",click_Start, 3, 3) w8 = w:add_html("", 1, 4, 3) end function click_CheckID() w3:set_text("Check ID: " .. vlc.playlist.current()) end function click_Start() k=0 -- playback reset New_Random() order = "" for _, v in ipairs(random_order) do order = order..v..", " end w8:set_text(order) end ----- Generator of random order: ----- i=0 function New_Random() i=i+1 first_ID = w2:get_text() items = w5:get_text() random_order = {} for j=1,items do random_order[j] = j end -- Initialize the pseudo random number generator math.randomseed( os.time() ) math.random(); math.random(); math.random() -- done. :-) random_order = shuffle(random_order) w6:set_text("Random order #"..i) end function shuffle(t) local n = #t while n > 2 do -- n is now the last pertinent index local m = math.random(n) -- 1 <= m <= n -- Quick swap t[n], t[m] = t[m], t[n] n = n - 1 end return t end
INSTRUCTIONS:
* feed VLC playlist with files;
* VLC Random is off, Loop is off, start to play the first file;
* activate the extension in VLC menu;
* press [Check ID:] button;
* write the ID in the text input field (usually value 5 or 6);
* how many files are there in the playlist (you can activate ID column in VLC playlist (right-click on the header) in Detailed View);
* press [START] button;
* stop the playback of the first file in the playlist;
=> playback continues in random order :)
A new random order will be automatically generated at the end of the last file in current random order or you can press [START] button again anytime.
Starting VLC with --play-and-stop CLI parameter could help (desktop shortcut icon or batch file). Appropriate setting in VLC preferences: Tools > Preferences > ( Show settings = All ) > Playlist: [v] Play and stop >> Save changes, restart VLC.
Thanks! I will be testing and if any issues, or non issues I will report back.

Just a little clarification on the instructions.

You say press "check ID" button, and it will usually be 5 or 6.. I've heard this before, but in my detailed view of my playlist the first file's ID is 1.. is this going to change to 5 or 6 on launching this script/extension?

To be clear -- I press the extensions Start button, and then press the Square STOP button in VLC of that file playing, yet it will continue to play another file and repeat forever?

Also, do I put VLC's random and Loop-All features on? Or just loop-all? Or does the script handle all of that?

Thanks again!

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 08 Jul 2013 00:33

Internal IDs are different from IDs you can see in the playlist (1-2-3-... is actually 5-6-7-...). Also do not do any changes like moving or deleting files in the playlist! Just open new VLC and enque files or simply open one playlist file (.xspf).
Yes, the stop of playback (manual Stop playback square button or "s" hotkey or automatically when an item is over) triggers an action. Stop again to play next item.
You do not need to use VLC's Random and Loop. Do not turn them on (probably does not matter), because the script handles all of that.

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 08 Jul 2013 01:17

Roger..

So get ID from script.. plug it in.. I assume your instructions meant to also input the total number of files in playlist (This doesn't mean 5 + total actual number I hope). Press start on extension,.. press stop of current file playing -- and the script will run indefinitely from there without any further input from user.

Again I appreciate you coding this!

If you could only make a simple script to make my marquee On Screen Display text that has the Filename/Playtime displayed on video during playback stay the same text size and not get illegibly tiny on high resolution videos and super large on low resolution videos I'd have all issues worked out! Wonder why the marquee text is in pixels and not relative in percent to screen?

Thanks again!

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 11 Jul 2013 03:52

Tried out the random script -- and it causes VLC (the latest version) for windows to crash.

Any ideas?

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 11 Jul 2013 04:19

I did press the >> Next track button to watch how the randomizer worked.. and after a few clicks of this button it just went to "Program not responding" and locked up VLC.

I tested the VLC random,.. and it took 11 rotations of the entire playlist to play some of the files just one time.

There must be an easy work around with this.

Would it be easier or possible to just randomize the playlist file that it is playing off of after a manually inputted number of the total files in the playlist?

IE: What are total files in playlist? I put in 150.

It then randomizes the order of the playlist file itself -- and plays the playlistfile in order.. then at the end of 150 plays.. it re-randomizes the playlistfile?

Even a button to 'shuffle' the playlist file order in the actual playlist would be an option that would work, although I would have to manually re-randomize after each full play of the playlist file.

This can't be that difficult I wouldn't imagine to simply randomize files and not play the same file but one time until all files in playlist have been played?.

I truly, truly appreciate your attempt at the script -- I am using VLC media player 2.0.7 Twoflower if that makes a difference (for windows).

Thanks so much!

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 11 Jul 2013 14:19

Please try it also with the suggested "play and stop" option and do not use the ">> Next track" button. Use "Stop" button instead, but better if you do not use it, too. Try to click on "time slider" right before the end of the video and wait, until it ends automatically. Perhaps it can work without any freeze of VLC if you do not touch it at all. That is why I have tried to make a script, that do not work with playlist except those jumps (goto item) and also you have to manually enter initial values rather than let the script to do it automatically by reading the loaded playlist.

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 12 Jul 2013 05:13

I did. No pressing of the controls of VLC,.. just used time slider a bit to test.. and after several videos.. maybe 8-10 or so videos it locked up VLC (unresponsive).

Any ideas on debugging the code?

Thanks

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 12 Jul 2013 08:28

Mederi:

I've further tested this with short 10 second video's.. and just put 10 of them in the playlist. So I didn't touch any controls.. it still would stop responding after 5-10 videos.

------ Thoughts--

I've taken a good look at the script. Would it make it easier, and perhaps more stable if the dialogue box didn't ask for the ID number, or how many files were in the playlist. But instead I would just go into the .lua script itself and modify the code and manually input the first "ID" .. which is going to be 5. And then manually input the total number of files (items) -- IE: 150.

If I added any files to my playlist, I would just go manually into the .lua script and change the values manually. I don't care for anything to be pretty. Just something I can set up and press Start and it will randomize all 150 videos, play each once before playing any other.. then re-randomize,.. and play the list again.. and continue this loop forever/indefinitely until I went to the script dialogue box and pressed "stop".

Perhaps some of the code could be taken out, reduced.. to where it is basically just a randomizer and would give the command to play each file.. and maybe in the script/code could add something like if n = 150 where n is the total files I manually inputed in the code,.. then it would goto or call the randomizer again.

Just as an aside:

Is it not possible to implement this into the VLC playlist controls? Where it would actually randomize the playlist.xspf file in the playlist and then just play in order.. and upon reaching the last file in playlist.. re-randomize and play the list again.. and so on indefinitely?

I notice the playlist.xspf files are simply XML files -- could anything be done with reading the xml files and changing the file around so VLC's controls would not bother the script ? As VLC would just be playing the playlist file (XML) as it reads.. the script would just be changing the order of the text in the playlist.xpsf (XML file).

I know I output the 127.0.0.1/requests/status.xml through the built in HTTP VLC webserver -- and then use an IRC script to pull data from this XML file to output to my channel. Different purposes, but it looks as if the playlists are just inherently XML metadata files that are in a specific format, so it would seem that scripting an extension to just modify the playlist XML file in a random way would effectively play nice with VLC.

I'm not trying to be difficult,.. just trying to get this figured out for me and all ;)

Thank you kind sir,

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Randomiziation script request.

Postby mederi » 15 Jul 2013 13:34

Please, feel free to adapt the script to your liking. You can play with it and learn, how to make your own scripts. To remove the dialog box simply delete function create_dialog() and also the call for it in function activate(). Delete all related wx:set_text() stuff. Replace wx:get_text() stuff with the appropriate values or some global variables, that you can define somewhere at the beginning of the script. Delete functions triggered by buttons, like function click_CheckID(). You can keep function click_Start(), rename it and call it in function activate(). This is a homework for you :)

I really do no know where the problem is. I think that only developers can identify a bug by using their tools. Perhaps there is some collision of different events trying to do different things at the same time.

You can try to open a ticket for your feature request: http://trac.videolan.org/vlc/newticket
Just briefly describe the problem and suggest a solution (randomize, play all only once, an option for rerandomization in next loop all, shuffle button, ... ).

You can read external file and parse the data, but you always need to feed VLC playlist with a media to be played. Yes, that is another way, how to try to do it and test the stability of VLC.
I know I output the 127.0.0.1/requests/status.xml through the built in HTTP VLC webserver ...
You know more than me. So all you need is to learn Lua. It is not that difficult for everybody with some programming experience. "Getting started?" forum topic, necessary functions, VLC Lua Readme document, Lua 5.1 reference manual is really all you need.

Chromatic
Blank Cone
Blank Cone
Posts: 28
Joined: 27 Jun 2013 16:03

Re: Randomiziation script request.

Postby Chromatic » 16 Jul 2013 03:10

Thanks for the help. I'm really lost in the programming language of this. The only problem I have with it, is it crashes. That is why I was suggesting maybe there is like a few lines of code that could be written in 10 mins or so to just have it randomize what I manually put in the lua code. What I mean is I can modify scripts/code halfway decently.. ie: If you were to make it randomize 150 files from playlist.xspf , then play that randomized list,.. at end of file 150, re-randomize, and play -- and that was absolutely it -- that would be fine. I have no problem jumping in the code and changing the manually inputted number of files -- the main thing is just that it will randomize, play.. re-randomize, and play.. -- two basic functions, with the 'play' part being a single line of code, so essentially it's just a randomization script.

Surely a script can randomize a playlist and not crash?

I've asked all over the forums about this -- and seen others ask over many years about this same problem of not true randomization and it is largely ignored. I understand it is a 'free' project, but it seems a bit difficult to really get any help.

I also understand you don't know me at all.. and I'm probably just wasting your time. It's just such an important function for what I do with VLC. If I could code I would certainly jump into the open source code and do it.. but , at best, I can modify pre-written scripts a little bit to fit my needs.. from scratch I'm lost. I can make about 30% sense of what I am looking at in the LUA code.. but not enough to rewrite it. Further, it crashes and I'm not real sure how to submit that to these guys who develop this software, give I really don't know how to explain what the script is about.

Could you submit a ticket sort of explaining it to them given you know the code aspect of it? You have been around a lot longer than I, and you can easily say .. Hey I wrote this.. it crashes after X.. and so on?

Have you tried it on your own VLC? Have you let it play through a few dozen files? Is it stable for you? I utilize Windows with 2.0.7 (twoflower).

Anyhow, thanks Mederi.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 3 guests