adding to queue
#1
can a plugin add videos to the queue? I don't mean pressing the context button and then manually adding it, I mean the pluggin picking out a video and then adding it to the queue?

Looking at the docs, it looks like scripts can but not plugins. I haven't tried writing a script yet though.

Would anyone like to share with how to go about queuing a video with either a script or plugin?
Reply
#2
I guess you could use the HTTP API for that, never tried it myself, but from looking at the Wiki it should be possible.

Looking at the HTTP API wiki page I ran into this command:

AddToPlayList(media;[playlist];[mask];[recursive])

Here is an example code, not sure it might work though, also don't know if you NEED the webserver up and running, but that will be somewhere in the wiki aswell.
Code:
import xbmc

# variable that contains the media files
file = xbmc.translatePath("F:\\Music\\")
# store the response, if any, in a variable
response = xbmc.executehttpapi("AddToPlayList(" + file + ";1)")
# xbmc.executehttpapi("AddToPlayList(F:\\Music\\;1)")
Reply
#3
I got it Smile It was a complete RTFM moment (a guy from #xbmc on irc helped me realize that)

you gotta set a listitem like so

listitem = xbmcgui.ListItem('How you want the title to appear')
listitem.setInfo('video', {'Detail 1': 'Something to go with a detail', 'Genre': 'Action'})

then simply:

playlist = xbmc.PlayList(1) #this sets it to the 'now playing' playlist
playlist.add(url,listitem)




Having said that...

I am now having three problems/misunderstandings

ONE::

xbmc.Player.onPlayBackStarted()(functionA())
^ seems to call functionA whether or nor anything is playing. will test/play around more.

TWO::

there seem to be differences between how items are named between library mode and 'normal' mode.

here is the code I'm using (taken from one of Voinage's plugins -- thanks voinage!):

Code:
def addLink(name,url):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png")
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok

addLink('radio',VariableContainingUrl)

in files mode that works fine, radio is displayed as the link name. in library mode however, it shows me get_videoHuh where did that come from? I don't have anything named get_video

THREE::

Is there a way to get a last.fm username from the xbmc profile?
Reply
#4
Guess that works too, didn't took a look at the Python Docs before posting.

About your questions,

1. What exactly are you trying to do, what does functionA() do, seems kinda extra when looking at the documentation.

2. I'm not really a plugin coder, maybe if you could post the current plugin script on pastebins, I could take a look at the big picture, or someone else that can make more sense out of it then me.
Can you maybe make a screenshot of the 'get_video' your talking about.

3. As far as i know there is no built in command for fetching the LastFM username, you could try to parse the guisettings.xml.
Reply
#5
1. look at xbmc lyrics for an example on how to subclass the Player() and use the onPlayback* events.

2. try adding a sort method. links to pydocs in my signature. you want xbmcplugin module.

3. use the httpapi and getguisetting or something like that. link to manual in my signature.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#6
OK, I've been trying but I can't seem to get anywhere Sad

I'm using something like:

Code:
class MyPlayer( xbmc.Player ) :
    def __init__ ( self ):
        xbmc.Player.__init__( self )
        
    def onPlayBackStarted(self):
        queueVid()

I'm using addDirectoryItem(...) to list the options, but I don't know how to make that use MyPlayer instead of whatever default it uses.

I know I could use
Quote:p = MyPlayer()
p.play(url)
but that still only 1/2 works. The files do get queued like that, but the original url doesn't show up in the playlist for some reason, so once it finishes playing it doesn't continue into the files that I just queued... then when I manually play one of the queued files, it's back to using the default player instead of MyPlayer so onPlayBackStarted() never gets called.
Plus, I don't know how to add a clickable item in the plugin that would run p.play(url) (though I haven't really looked hard because it wouldn't work anyways)

Eventually what it will do is use your last.fm username, grab a video [video a] from youtube from your top artists (using tv.timbormans.com) and then play it. When video a plays that should trigger onPlayBackStarted and grab another video [video b], and stick it in the queue so it will play next. Then when video b starts it should grab a video c and queue it...and so on
Reply
#7
you need to find a way to keep your script running, without stealing too many cpu cycles.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#8
Nuka1195 Wrote:you need to find a way to keep your script running, without stealing too many cpu cycles.

Not really sure what you mean by that... it isn't using any cpu cycles when it isn't running

I tried looking at xbmclyrics like you suggested but it was hard to make sense out of it. I don't really know how to code, and everything is so spread out in that script...
Reply
#9
Nevermind I understand what you mean... not really sure how I missed that one Wink

Anyways, I was trying

while(1):
xbmc.sleep(500)

from thor918's playerclass ( think that's his nick -- its definately something like that) assuming it was working but I just tried, hopefully that won't take up too many rams?

x=1
while (x<=3):
x=x+0

... on testing, these seems to cause a problem, and shuts down xbmc for windows when I go back to the plugin's window... presumably because it is already still running. Any thoughts on this?
Reply
#10
oh I think I understand you know... to keep it running I used

import time
while(1):
time.sleep(50)

which i got from some other script... but apparently doesn't work.

x=1
while (x<=1)
x=1+0

that does work(woot!!!), but causes xbmc for windows to crash everytime I try to return to the Plugin's Window (presumably because it is already running, and xbmc doesn't know how to re-run it)

I'm out of town on business at the moment, so I can't test it on the xbox

Any ideas on how to keep it from crashing?
... I have a few ideas that *may* work, but I don't think they will.

Will test. If I don't come back and say 'I figured it out, you do it like this:' then I didn't, and still want help Sad
Reply
#11
just got home and tried out my script on my xbox...

seems like the crash only happens on xbmc for windows
don't have anything to test linux or osxbmc, will file bugreport
Reply
#12
you definately need a sleep in there. could be the reason for the crash

while 1:
xbmc.sleep( 1000 ) # sleeps for one second
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#13
Nuka1195 Wrote:you definately need a sleep in there. could be the reason for the crash

while 1:
xbmc.sleep( 1000 ) # sleeps for one second

it didn't crash on the XBOX version, only the windows one, and only when I call another plugin or script.

It DOES slowly eat ram on the xbox though

On testing your code, all I have to say is WTF??!??!

It works so perfectly and smoothly, much better than my mathy infinite while loop, no (obvious) strange bugs, it ends the plugin when it is supposed to, doesn't kill xbmc.

I'll have to test to see about its ram usage, but I'd be willing to bet it's less than what I had before.

I MUST know--why is a sleeping loop so much better than what I had?
(for reference i was using x=1 while(x==1)x=1)
Also-- I had originally tried while(1):xbmc.sleep(500) and that wasn't working, i also tried using pythons timer class, and that wasn't working so what's going on here?
I don't get it!!

Oh, and THANK YOU NUKA!!!
Reply

Logout Mark Read Team Forum Stats Members Help
adding to queue0