Can I create a playlist with a script?
#1
I am writing a script that will play a couple of random trailers before playing a movie. I had planned to pick a couple of trailers from a dynamically generated list and then add them to a playlist and then add the selected movie to the end of the playlist. I am unable to figure out how to make a playlist with a script, or if this is even possible. Alternatively, I can make a list of trailers (using a python data structure) and just play them from that list. Unfortunately, when I do that I can't figure out how to wait on one trailer to finish before the other one starts. The result is that the last trailer in the list is the one that gets played. Also, with this method, I don't think I can easily skip to the next trailer.

Here is my code to illustrate what I am trying to do...

Code:
MOVIE_PATH = 'D:/Movies/'
for root, dirs, files in os.walk(MOVIE_PATH):
  for directory in dirs:
    dirstring = MOVIE_PATH + directory
      for files in os.listdir(dirstring):
        if "-trailer" in files:
          trailer = dirstring + '/' + files
          xbmc.executebuiltin('XBMC.PlayMedia(' + trailer + ')')


Thanks,

Andy
Reply
#2
http://mirrors.xbmc.org/docs/python-docs...l#PlayList
Use the example provided in the docs, but you can call .add() multiple times. Then pass the playlist object to Player.play()
Reply
#3
(2013-06-10, 15:40)Bstrdsmkr Wrote: http://mirrors.xbmc.org/docs/python-docs...l#PlayList
Use the example provided in the docs, but you can call .add() multiple times. Then pass the playlist object to Player.play()

Thanks for the reply. After some more searching I found a code snippet that helped. Here is my working code for playing all my trailers in order.

Code:
MOVIE_PATH = 'D:/Movies/'

pl=xbmc.PlayList(1)
pl.clear()

for root, dirs, files in os.walk(MOVIE_PATH):
      for directory in dirs:
            dirstring = MOVIE_PATH + directory
            for files in os.listdir(dirstring):
                  if "-trailer" in files:
                        trailer = dirstring + '/' + files
                        listitem = xbmcgui.ListItem()
                        path = trailer
                        xbmc.PlayList(1).add(path, listitem)

xbmc.Player().play(pl)

It should be fairly trivial now to play a couple of random trailers before a movie.

Thanks again!
Reply

Logout Mark Read Team Forum Stats Members Help
Can I create a playlist with a script?0