Could use some help.
How can I do something like this?
dir=MediaContainer(title=‘whatever’)
dir.Append(TrackItem(url=Callback(myFunction, arg1=‘test’))
def myFunction(arg1):
Log.Debug(arg1)
return ‘http://www.somesite.com/mySong.mp3’
I’m consistently getting back an error following a big stack trace that ultimately ends with:
TypeError: init() takes at least 4 non-keyword arguments (2 given)
The error is happening on the dir.Append(TrackItem… line
I’ve also tried doing something like this:
dir=MediaContainer(title=‘whatever’)
dir.Append(TrackItem(url=‘http://127.0.0.1:32400/music/mypluginprefix/myFunction/test’))
@route(’/music/mypluginprefix/myFunction/{arg1}’)
def myFunction(arg1):
Log.Debug(arg1)
return ‘http://www.somesite.com/mySong.mp3’
No luck this way either, BUT if I enter the URL http://127.0.0.1:32400/music/mypluginprefix/myFunction/test in my browser’s address bar, I DO get back good results. So its not a problem with the response from “myFunction”, but its something wrong with calling the URL from inside of Plex.
I’d be grateful for any help or a hint of what I’m doing wrong. The error messages in the plugin log are not very helpful to track down the problem.
Hi MachThree!
MediaContainers are something from the “older” version (version 1) of the plugin framework, whereas Callback is from a newer (2.1) version. If you’re using the older version with the MediaContainers, instead of a Callback you have to use Function, like so:
dir = MediaContainer(title='whatever')<br />
dir.Append(Function(TrackItem(myFunction, title="Test"), arg1='test'))<br />
<br />
def myFunction(arg1):<br />
Log.Debug(arg1)<br />
return 'http://www.somesite.com/mySong.mp3'
Hi Sander1,
Thanks, that helped a bit. Now my dir.Append call is working and my menu gets built and displayed. But when I select one of the items (i.e. the TrackItem) I just get an error "ERROR ERROR While Opening File" but my logging indicates that "myFunction" never got called.
Also, I did not realize that I was mixing v1 and v2.1 API's - been trying to follow the online docs but also basing my code off of some existing plugins so maybe I pulled in some old stuff. How would you do this entirely with v2.1?
Something like (and you'll have to excuse any errors, I haven't really done much with audio plugins and this is just off the top of my head):
<br />
def AddTrack()<br />
oc = ObjectContainer(title="whatever")<br />
oc.add(TrackObject(url=Callback(MyFunction, arg1='test')))<br />
return oc # don't forget you will always have to return the object container<br />
<br />
def myFunction(arg1):<br />
Log.Debug(arg1)<br />
return 'http://www.somesite.com/mySong.mp3'<br />
<br />
http://dev.plexapp.com/docs/api/objectkit.html#TrackObject
It's totally worth it to learn the v2.1 framework right from the start. Again the above code may be totally wrong but it may be enough to get you going in the right direction with things ...
Hope this helps. If you need further info I suggest digging around on the github plex plugins repo and find a v2.1 audio plugin as a working example. I honestly can't think of one off the top of my head but I'm sure they are there somewhere ...
https://github.com/plexinc-plugins/
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.