Playing smart playlists
#1
I'm new to Python and need some help. I don't know if this is right place to post. I will move this thread if necessary.

Ever since I discovered smart playlists I've wanted the option to play two or more smart playlists were one button press. First I tried it by combining smart playlists, but adding random to the playlist messes things up. Then I tried using a .strm file to cqall the playlists, but of course the file extension .xsp is not recognized as a playable file. Then I found that I could launch a smart playlist with python. I thought that would be the solution, but I cann't seem to get it to work, at least not like I'd like.

Using
Code:
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist1.xsp)")
I can launch one playlist. That's cool. The problems come when I try to launch another. I tried:

Code:
import xbmc

xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist1.xsp)")
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist2.xsp)")
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist3.xsp)")
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist4.xsp)")
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist5.xsp)")
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist6.xsp)")

And ran into problems right away. Of course, XBMC tries to launch each playlist right away (that's what I told it to do. I'm new to python, not programming). Checking the log, I figured out what went wrong, searched the forums, and came up with (borrowed) a partial solution:

Code:
import xbmc

xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist1.xsp)")

class MyPlayer(xbmc.Player) :

         def __init__ (self):
             xbmc.Player.__init__(self)

         def onPlayBackStarted(self):
             xbmc.log('********************************************************* CALLBACK: PLAY Item 2')

         def onPlayBackEnded(self):
             xbmc.sleep(1000)
             xbmc.log('********************************************************* CALLBACK: END Item 1')

         def onPlayBackStopped(self):
             xbmc.log('********************************************************* CALLBACK: STOP Item 1')
             xbmc.log('********************************************************* CALLBACK: PLAY Item 2')
             xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist2.xsp)")


player=MyPlayer()


while(1):
    xbmc.sleep(500)

That plays the first playlist, puts the entries in the log and then there's a problem. It will not play the second item.

I've spent more than 2 weeks search for an answer. Everything I've tried brings up the same problem. After playing the first smart playlist, XBMC can not open the second. In the log I see:

Error loading Smart playlist special://videoplaylists/playlist2.xsp (failed to read file)

every time it goes to load the second list. I even accidentally wrote a script that started a loop where XBMC tried opening the playlist many times, failing each time.

What am I doing wrong? Since a smart playlist is not an actual playlist, I don't think clearing the playlist will help. Is there some way to reset the player to it's original state, before the first playlist played?

I don't want to developed a long program to do such a simple set of tasks, but I will if I must. Just means lots of homework.

Any help would be appreciated. Thank You.
Reply
#2
Bump.

Since no one's answering, I thought I'd bump this.

I don't know if this smart playlist problem is a bug or not. When I began this journey weeks ago, I found a thread where someone was trying to play two smart music playlists and ran into the same problem. For the life of me I can not find that thread (I cann't remember the search parameters I used in Google) but when I do I'll post a link. After someone took the time to answer that person's question the problem was eventually revealed as a bug. I don't know if this is also a bug.

Also thought I'd update on my failures:

1. Tried using jsonrpc to clear the playlist in the "def onPlayBackStopped(self):" section because last night I noticed when I was playing a smart playlist that a playlist must exist somewhere, because I can view it by left clicking with the mouse while the smart playlist is playing.
The only effect of clearing the playlist in this fashion was that it somehow stopped the log messages from appearing. The second playlist still would not play.

2. Tried this:
Code:
import xbmc
import time

def PlayAndWait():
     xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist1.xsp)")
     while xbmc.Player().isPlaying():
         time.sleep(1.0)

PlayAndWait()
xbmc.executebuiltin("PlayMedia(special://videoplaylists/playlist2
.xsp)")
which I adapted from this thread. With no luck. If I remove the second PlayMedia it will play one smart playlist, but with both PlayMedias it will play nothing.

Again, Is this a Bug?
Reply
#3
What's the error given in the log with your first solution? Mind posting a Debug Log of it playing the first followed by the failing at the second?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
Thank you for taking the time to answer.

I don't mean to be dense, but what do you mean by "What's the error given in the log with your first solution?" I've tried so many different ways to do this. Do you mean when I tried using xbmc.executebuiltin one after the other (like the beginning of post 1) or trying to clear the playlist like post #2.

If it's the first failure, from post #1 I can do this: I've posted an old log from a different failure here. I'm sorry, it's on pastebin, but it's just an old log I kept for future reference. It's not from the actual script in post #1, but I get the same error EVERY time XBMC tries to play the second playlist (yes, I can play it normally. If I switch the order and play playlist #2 first using the 'builtin' call playlist #2 will play and then it will fail when it tries to play playlist #1). The log I posted is from a bad script, I accidentally set up a loop, but the result is the same without the loop. It's the same no matter what.

The first playlist is called and the log reads (line 197):

"ERROR: Error loading Smart playlist special://videoplaylists/playlist #1.xsp (failed to read file)"

but the next line reads:

"NOTICE: DVDPlayer: Opening: smb: .........."

as XBMC plays the file from the playlist. I only have the playlist set for one item (to make testing quicker) so when that file is done, playlist #2 should begin to play. Instead, when it begins playlist #2, it fails. The log reads:

"ERROR: Error loading Smart playlist special://videoplaylists/playlist #2.xsp (failed to read file)"

as it did the first time. The next few lines are where the problem comes in. Unlike the first time, the playlist seems to be passed on to the player as a file and not a smart playlist. The log reads:

"ERROR: Previous line repeats 1 times.
ERROR: XFILE::CDirectory::GetDirectory - Error getting special://videoplaylists/playlist #2.xsp
NOTICE: DVDPlayer: Opening: special://videoplaylists/playlist #2.xsp"
and a little later...
"ERROR: CDVDPlayer::OpenInputStream - error opening [special://videoplaylists/playlist #2.xsp]"
and
"ERROR: XBMC.PlayMedia could not play media: special://videoplaylists/playlist #2.xsp"

To me this makes it seem as if the second playlist is being treated like a file, not a smart playlist.

I don't know if that's what you're looking for. If you want, I'll post logs the official way, just please be a little clearer about which ones I'm supposed to post.

I'm still looking for the thread where the person had the same problem using other types of playlists (I think they were music). Like I said, the final outcome from that was the discovery of a bug. I hate to call this a bug, it was just the final outcome in that thread. Personally, I think it would be much easier if we could play multiple smart playlists using a .strm file or perhaps a .m3u8. Of course, that would mean a change in code, and that's way beyond me at this point.

Thank you for your time.
Reply
#5
What's the content of each of the playlist files "playlist #1.xsp" ? (i.e. the XML)

BTW: a full Debug Log will provide me more information to diagnose and fix the problem. I suspect there's a workaround available to you already, but won't know for sure until I see the Debug Log.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#6
OK Here goes...

My script:
Code:
import xbmc

xbmc.executebuiltin("PlayMedia(special://videoplaylists/Popeye the Sailor.xsp)")

class MyPlayer(xbmc.Player) :

         def __init__ (self):
             xbmc.Player.__init__(self)

         def onPlayBackStarted(self):
             xbmc.log('********************************************************* CALLBACK: PLAY Item 1')

         def onPlayBackEnded(self):
             xbmc.log('********************************************************* CALLBACK: END Item 1')

         def onPlayBackStopped(self):
             xbmc.log('********************************************************* CALLBACK: STOP Item 1')
             xbmc.log('********************************************************* CALLBACK: PLAY Item 2')
             xbmc.executebuiltin("PlayMedia(special://videoplaylists/Tom and Jerry.xsp)")


player=MyPlayer()

while(1):
    xbmc.sleep(500)

My playlists

Popeye the Sailor:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="episodes">
    <name></name>
    <match>all</match>
    <rule field="tvshow" operator="is">
        <value>Popeye the Sailor</value>
    </rule>
    <limit>1</limit>
    <order direction="ascending">random</order>
</smartplaylist>

Tom and Jerry:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="episodes">
    <name>Tom and Jerry</name>
    <match>all</match>
    <rule field="tvshow" operator="is">
        <value>Tom and Jerry</value>
    </rule>
    <rule field="playcount" operator="is">
        <value>0</value>
    </rule>
    <limit>1</limit>
    <order direction="ascending">random</order>
</smartplaylist>

and here's the log.

You had me worried there for a second when you asked me to post the playlists also. I tried playing the two original playlists again (they worked) so I then tried substituting the above playlists (I know they both work, I use them often combined into another, larger smart playlist). The script does the same thing; plays the first list and fails on the second.

Hope you can figure something out. I've seen other threads where people want to combine two incompatible playlists (like movies and TV shows, something I've tried myself) maybe a fix or a work-around would help others.
Reply
#7
In that session the STOPPED callback isn't fired (you didn't stop the video) so the second playlist isn't queued up.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#8
No, I didn't stop the video, the playlist ended. For testing my playlist is one item long. I started the script (have it mapped to a sub-menu button on the skin I'm using) and the video began playing. I then used the mouse to fast forward the video (I think I did) to close to the end and then let the video finish on it's own. The video was over and the one item playlist was finished. The same thing happens if I just let the video play through instead of skipping to the end. When the video ends, the second playlist never starts.

I've modified the script many times, checking the normal log after each change. Sometimes I make a mistake and neither playlist will play,and I check the log. Sometimes the first playlist will play, and I check the log to see what happened and why the next playlist didn't play (I forgot about the debug log). Sometimes the second playlist never gets the play call because of some error I've made. Other times I get it right and the first playlist plays, the call is initiated for the second playlist, but the second one never plays. In the normal log I always see:
ERROR: XFILE::CDirectory::GetDirectory - Error getting special://videoplaylists/playlist #2.xsp
NOTICE: DVDPlayer: Opening: special://videoplaylists/playlist #2.xsp"
and a little later...
"ERROR: CDVDPlayer::OpenInputStream - error opening [special://videoplaylists/playlist #2.xsp]"
and
"ERROR: XBMC.PlayMedia could not play media: special://videoplaylists/playlist #2.xsp"
It appears to me that XBMC is trying to open the playlist like a video file. I don't know. When I looked at the verbose debugging log I wasn't really sure what I was looking for (will look at it again later when I get the time).

Like I said, this happens everytime I play my one item playlist and let the video finish on it's own. I don't use the next/skip button because there's only one item playing (if I can get this figured out I will work on modifying the script to take the next/skip button into account). Sometimes I seek to close-to-the-end using the mouse, other times I let the video just play until the end (and therefore the end of the playlist). I repeat, I let the video finish on it's own no matter what. The second playlist never plays though, instead the DVDPlayer tries to open the playlist where XBMC should be processing the playlist and sending the items to the now playing playlist (In my ignorant opinion).

Please, I don't mean to be rude in this, just trying to be thorough in what I'm saying. I've spent a fair amount of time on this (3+ weeks of when-I-can time) and don't want to screw things up now.

Is there some way to close the player or reset it when a smart playlist is done? Maybe I'm missing that.
Reply
#9
The Debug Log above does not contain those lines. i.e. no attempt at all is made of the second playlist because it isn't ever triggered by your script, as your script above only triggers it when onPlaybackStopped() is called, which it isn't in that Debug Log session.

I need a Debug Log where you actually reproduce the problem (i.e. second playlist is requested to be played after the first, you get the log line you're mentioning) so I can start figuring out where in the code it might be happening.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#10
I cann't believe that worked. I could have sworn I tried it before. I just pasted the call in at the onPlayBackEnded and it worked.

I am so sorry for your time I have wasted on this. I could have sworn I tried that before. I haven't tried it lately. Maybe I did something else wrong when I tried it before. Oh well....

Thank you so much for your time, and the advice. When I come up with a script that works as I want, I'll post it here for anybody else to use.

Thank you.
Reply
#11
Never know - it could just be luck. Keep an eye on it and see if it does it again Smile
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#12
So far, this works. A little loop is set up with the last playlist, but that's alright...

Code:
import xbmc

xbmc.executebuiltin("PlayMedia(special://videoplaylists/Popeye the Sailor.xsp)")

class MyPlayer(xbmc.Player) :

         def __init__ (self):
             xbmc.Player.__init__(self)

         def onPlayBackStarted(self):
             xbmc.log('********************************************************* CALLBACK: PLAY Item 1')

         def onPlayBackEnded(self):
             xbmc.log('********************************************************* CALLBACK: END Item 1')
             xbmc.executebuiltin("PlayMedia(special://videoplaylists/Tom and Jerry.xsp)")

         def onPlayBackStopped(self):
             xbmc.log('********************************************************* CALLBACK: STOP Item 1')
             xbmc.Player.stop(self)

player=MyPlayer()

while(1):
    xbmc.sleep(500)

Thank you for your support (sounds like the old TV commercial). When i get a chance, I'll modify it to play as many smart playlists in a row as desired.

I feel like a total idiot sometimes. Thank you once again master.
Reply
#13
Masters please help. I've come up with the code below, but it does not work as I would hope...
Code:
import xbmc
import time

COUNTER = 0

xbmc.executebuiltin("PlayMedia(special://videoplaylists/test simp.xsp)")

xbmc.sleep(250)

while xbmc.Player().isPlaying():
  xbmc.log
  time.sleep(1.0)
  COUNTER = 1

if (COUNTER == 1 and xbmc.Player().isPlayingVideo() == False):
  
  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://videoplaylists/Criminal intent - Sitcoms in order.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 2

if (COUNTER == 2 and xbmc.Player().isPlayingVideo() == False):

  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://videoplaylists/_L n O Criminal Intent in Order.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 3

if (COUNTER == 3 and xbmc.Player().isPlayingVideo() == False):

  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://videoplaylists/Criminal intent - Live random channels.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)

else:
  xbmc.Player().stop()
  xbmc.executebuiltin("StopScript(special://masterprofile/criminalintent1.py)")
Instead of playing four smart playlists in a row, it only plays two, then fails when trying to load the third. In the log I see...
NOTICE: DVDPlayer: Opening: special://videoplaylists/_L n O Criminal Intent in Order.xsp...
ERROR: CDVDPlayer::OpenInputStream - error opening [special://videoplaylists/_L n O Criminal Intent in Order.xsp]...
ERROR: XBMC.PlayMedia could not play media: special://videoplaylists/_L n O Criminal Intent in Order.xsp...
when it comes to playing the third playlist.
If I try...
Code:
if (COUNTER == 2 and xbmc.Player().isPlayingVideo() == False):

  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://videoplaylists/_L n O Criminal Intent in Order.xsp)")

  xbmc.sleep(2500)

  while (COUNTER == 2 and xbmc.Player().isPlayingVideo() == False):
    xbmc.executebuiltin("PlayMedia(special://videoplaylists/_L n O Criminal Intent in Order.xsp)")
  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 3
for the third item XBMC freezes up completely as it tries to endlessly load a playlist it can not play.

What have I done wrong? I have spent a lot of time on this, and have put in lots of trial and error time. I have tried getting the third list to play many ways, even using a separate script for each playlist and closing each as it went, hoping to find something that would work. No matter what I've tried it fails. What am I doing wrong?
I've posted a log here. I'm sorry, it's on pastebin. I tried using the official log uploader on the log right before that one and it failed. I couldn't post the whole thing on pastebin, so if you need the rest, I have it. I did try to capture the end of my script in the log.
Please help. This is driving me nuts.
Reply
#14
Try using special://profile/playlists/video/ rather than special://videoplaylists/ perhaps?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#15
Dude, that did it! Thank you so much. Strange how such a little thing could make such a big change. And it's strange that the wrong thing would work two out of three times. I just copied and pasted your suggestion in and it worked. I have to admit, the original line came from somewhere online, and I've just been copying and pasting since. Looking at it now, it does look weird, but I never gave it a second look before, because it worked, all be it only sometimes.

OK, for anybody else who's interested, here's a base code to use for yourself to launch more than one smart playlist from within a script. Just substitute your playlist name in for the playlist 1, playlist 2, etc. And change the /video/ to /music/ or /mixed/ if necessary. To use this for more than four playlists, just copy the
Code:
if (COUNTER == 1 and xbmc.Player().isPlayingVideo() == False):
  
  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://profile/playlists/video/playlist 2.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 2
and add it to the bottom of the script. Increase the COUNTER parts as necessary, following the pattern in the script.

Here's the code:
Code:
import xbmc
import time

COUNTER = 0

xbmc.executebuiltin("PlayMedia(special://profile/playlists/video/playlist 1.xsp)")

xbmc.sleep(250)

while xbmc.Player().isPlaying():
  xbmc.log
  time.sleep(1.0)
  COUNTER = 1

if (COUNTER == 1 and xbmc.Player().isPlayingVideo() == False):
  
  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://profile/playlists/video/playlist 2.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 2

if (COUNTER == 2 and xbmc.Player().isPlayingVideo() == False):

  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://profile/playlists/video/playlist 3.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)
    COUNTER = 3

if (COUNTER == 3 and xbmc.Player().isPlayingVideo() == False):

  xbmc.Player().stop()

  xbmc.executebuiltin("PlayMedia(special://profile/playlists/video/playlist 4.xsp)")

  xbmc.sleep(2500)

  while xbmc.Player().isPlaying():
    time.sleep(1.0)

else:
  xbmc.Player().stop()
  xbmc.executebuiltin("StopScript(special://masterprofile/your script name.py)")
Don't forget to change the name of the script in the last line (StopScript...) to the name of the script you are running.

One further note. You may have to play around with the first sleep time [ xbmc.sleep(250) ] to work with how you launch the script. Sleep(250) worked for me when launching from a skin Submenu button. It DID NOT work I tried to launch the script from either a skin addon button or from within a SuperFavorites menu button. The machine need time to process all the functions before playing the playlist. The time needed varies depending on where you launch the script (or any other for that matter) from. As a submenu button, it launches quick, from an addon button, a little slower, and from within SuperFavorites possibly the slowest. You'll just have to play around with the first time to get it right. If you launch the script and it skips the first item, add time. If it take too long to launch the first item, remove time.

Thank you so much for your help. You've just made my work as Home Programming Director easier (and given me lots of homework too.)

Thank You.

How do I mark this as solved?
Reply

Logout Mark Read Team Forum Stats Members Help
Playing smart playlists0