[RELEASE] Autoplay directory (script)
#1
This simple script automatically plays all videofiles in a directory. The path of the directory can be set in the scriptfile.

I was in need of such a script myself, so decided to learn some python and script it myself.

The script also shuffles the order of the videos, so the order of the videofiles is different every time. (you can turn this option off by adding a # in front of the videoList.shuffle() command)

It also puts all of your videos on repeat, so when the last video has been played; it starts over again. (turn this option off by adding a # in front of the xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)") command)

Very simple script, but I noticed some requests for a function like this in the past.

Code:
# Autoplay videodirectory
import os, xbmc

# set path to dir you want to play
path="E:\\videos"

dirList=os.listdir(path)

videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()

for fname in dirList:
    videoList.add(path + "\\" + fname)

# shuffle playlist
videoList.shuffle()

# put playlist on repeat
xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)")

# play playlist
xbmc.Player().play(videoList)

Copy the above code, paste it in notepad and save it as autoplaydir.py (or something similar). Put the file in your xbmc/scripts/ directory.

Add the script to your autoexec.py file to make it automatically play your videos at startup.

Have fun with it Smile
Reply
#2
Can this be done, not at startup, but when I press play on a video?
Reply
#3
I am running the OpenELEC 1.0.2 on my Asus Eee Box B202. I've tried the script but it doesn't seem to run. Can someone help me with this? Thanks!

autoplaydir.py in \var\media\DATA\Download\WaitingRoom

Code:
# Autoplay videodirectory
import os, xbmc

# set path to dir you want to play
path="\var\media\DATA\Download\WaitingRoom"

dirList=os.listdir(path)

videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()

for fname in dirList:
    videoList.add(path + "\\" + fname)

# shuffle playlist
videoList.shuffle()

# put playlist on repeat
xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)")

# play playlist
xbmc.Player().play(videoList)

autoexec.py in \var\userdata\

Code:
import xbmc
xbmc.executescript('\\var\\media\\DATA\\Download\\WaitingRoom\\autoplaydir.py')
Reply
#4
this script is a great idea because there are some skins that don't play playlists automatically. they list them first.

could this be added as a shortcut?
Reply
#5
This is EXACTLY what I need to do!
Now, it seems like there is no autoexec.py anywhere on my system partition.
How could i do it?
I really need to be able to randomly play the videos on repeat, so it can play videos all day long in no particular order.
Help me someone, please, I need this to be ready in 5 hours time... or less!

thank you!
Reply
#6
Hello!
How hard is it to change your script to play a certain video_playlist.m3u ?
Reply
#7
(2013-02-12, 19:36)simon_kloyns Wrote: Hello!
How hard is it to change your script to play a certain video_playlist.m3u ?

you just have to replace the loop listdir/for fname with
videoList.load("/path/to/yourplaylist.m3u")
Reply
#8
Wink 
so true?

Code:
# Autoplay videodirectory
import os, xbmc

videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()

videoList.load("/home/playlist.m3u")

# shuffle playlist
videoList.shuffle()

# put playlist on repeat
xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)")

# play playlist
xbmc.Player().play(videoList)

Quote:I'm sorry for my English !
Reply
#9
Thank you! it works!
Reply
#10
I am having some trouble with this script. I am a competent Python guy and I found the documentation for the xbmc python module http://xbmc.sourceforge.net/python-docs/xbmc.html which definitely suggests that this script should work.

However, I am getting an error like this:

Code:
Traceback (most recent call last):
  File "./autoplaydir.py", line 12, in <module>
    videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
AttributeError: 'module' object has no attribute 'PlayList'

This suggests that the xbmc module has changed. I played around a little more and couldn't find *any* of the methods that I might need for this sort of script in my version of the python libs.

I am using Frodo (12.0) running on openElec on a Raspberry Pi.

I would appreciate any guidance on newer python docs, or a better approach for this.

Thanks.
Reply
#11
After much digging, I determined the problem. I was attempting to run this from the command line, assuming that because the module "xbmc" imported ok, that these things were available. But it turns out you can *only* run this from the "internal" context.

So now the script runs, and I get the infinite loop at startup. In my case, I just want to play a loop of videos in a particular directory, so I omitted the separate autoplaydir.py and simply made autoexec.py look like this:

Code:
import xbmc
xbmc.executebuiltin('xbmc.PlayerControl(RepeatAll)')
xbmc.executebuiltin('xbmc.PlayMedia("/storage/loop","isdir")')

Thanks for the help in this thread.
Reply
#12
Hi there,

The script is working on Raspbmc but it doesn't repeat the videos tho...

Any idea why?
Reply
#13
Mostly for reference to new readers:

(2013-12-03, 17:39)dudumomo Wrote: Hi there,

The script is working on Raspbmc but it doesn't repeat the videos tho...

Any idea why?

You need to start the playback first, then set the RepeatAll, as no playlist is active before the directory has been queued. Maybe this is unique for Raspbmc, I don't know.

Code:
import xbmc
xbmc.executebuiltin('xbmc.PlayMedia("/storage/loop","isdir")')
xbmc.executebuiltin('xbmc.PlayerControl(RepeatAll)')

Thanks for the tip though, just what I need for using Raspbmc for exhibits.
Reply
#14
Hi everybody,

I use this script in Xbmc from Geexbox V3 (embed XBMC 11).

Work fine, but playlist generated is shuffle, wether comment line #videoList.shuffle()


Quote: for fname in dirList:
videoList.add(path + "\\" + fname)

Can i order a list by filename ?


thx !
Reply
#15
found solution:

Quote:# Autoplay videodirectory
import os, xbmc

# set path to dir you want to play
path="/mnt/SATA Disk #1 GeeXboX (0)/media/"

dirList=os.listdir(path)

dirList.sort()

videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
videoList.clear()

for fname in dirList:
videoList.add(path + "\\" + fname)

# shuffle playlist
#videoList.unshuffle()

# put playlist on repeat
xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)")

# play playlist
xbmc.Player().play(videoList)
Reply

Logout Mark Read Team Forum Stats Members Help
[RELEASE] Autoplay directory (script)1