How to create a response to an item selection in a list
#1
Hi.

I'm trying to create a plugin to that will enable viewing of mako.co.il website. I have managed to scrap all the programs into a list and display it on the screen using (modified) t0mm0 method in his Jerry Seinfeld plugin. How can I create a response for a sellection? Here is the part of the code which I use to create Items:

Code:
def add_dir_item(url, desc, img=''):
    listitem = xbmcgui.ListItem(desc, iconImage=img,
                                thumbnailImage=img)
    listitem.setProperty('IsPlayable', 'false')
    xbmcplugin.addDirectoryItem(plugin_handle, url, listitem, isFolder=True)


for n in range (0,len(myp.descriptions)):
    add_video_item(myp.hyperlinks[n], myp.descriptions[n])

xbmcplugin.endOfDirectory(plugin_handle)

Code:
myp
is a class I use to scrap the webpage.
Reply
#2
yotama9 Wrote:Hi.

I'm trying to create a plugin to that will enable viewing of mako.co.il website. I have managed to scrap all the programs into a list and display it on the screen using (modified) t0mm0 method in his Jerry Seinfeld plugin. How can I create a response for a sellection? Here is the part of the code which I use to create Items:

Code:
def add_dir_item(url, desc, img=''):
    listitem = xbmcgui.ListItem(desc, iconImage=img,
                                thumbnailImage=img)
    listitem.setProperty('IsPlayable', 'false')
    xbmcplugin.addDirectoryItem(plugin_handle, url, listitem, isFolder=True)


for n in range (0,len(myp.descriptions)):
    add_video_item(myp.hyperlinks[n], myp.descriptions[n])

xbmcplugin.endOfDirectory(plugin_handle)

Code:
myp
is a class I use to scrap the webpage.

you need to think of it more like how a web server works. everytime something in your plugin is selected it is passed a bunch of arguments.

sys.argv[0] is the path to your plugin (eg. 'plugin://my.cool.plugin/')
sys.argv[1] is a handle that needs to be passed back to some xbmc functions
sys.argv[2] is the query part (eg. '?mode=hello&test=12345')

when you add a directory, you will get the above results if you had set the url you pass to xbmcplugin.addDirectoryItem() to 'plugin://my.cool.plugin/?mode=hello&test=12345'

play around with existing addons, add print statements to them to see what is going on (a 'print sys.argv' at the beginning of the main addon file (usually default.py) will show you the arguments passed to the addon from xbmc).

t0mm0
Reply
#3
OK.

I have toyed around with stuff and I am now proud to say that I know even less about the plugin righting paradigm of xbmc.

I am using cnet plugin as something to begin with and I want to create an alphabetical index of the shows.

So... I have printed the sys.argv[2] and I know that I am storing there, among other stuff the name of the selected dir. How can extract it and use it for some scrapping?
Reply
#4
yotama9 Wrote:OK.

I have toyed around with stuff and I am now proud to say that I know even less about the plugin righting paradigm of xbmc.

I am using cnet plugin as something to begin with and I want to create an alphabetical index of the shows.

So... I have printed the sys.argv[2] and I know that I am storing there, among other stuff the name of the selected dir. How can extract it and use it for some scrapping?

you can use cgi.parse_qs() to parse the query string
Reply
#5
I tried, I really, did, and still am, but I could have figure, no matter what, how to work with that function. I searched for an example of how to use it but didn't find any? Why can't I simply regexp it? Also, how does the sys.argv[2] determined?

Also, How can I print anything to terminal (or a file) when running the plugin in xbmc?
Reply
#6
i'm running out of ways to explain stuff - maybe someone else could jump in from a different angle?

yotama9 Wrote:I tried, I really, did, and still am, but I could have figure, no matter what, how to work with that function. I searched for an example of how to use it but didn't find any?
i linked to the python docs, i've also previously linked to my github which is full of examples.
yotama9 Wrote:Why can't I simply regexp it?
you can if you want, but it seems pointless when there is a built in python function to do it for you and if you wanted to use regex why ask how to do it?
yotama9 Wrote:Also, how does the sys.argv[2] determined?

pretty much every plugin except the most basic does this so try reading code (and i have already previously explained it as well as i can (see the second post in this thread).

specifically there is lots of well documented common xbmc stuff in my new script.module.t0mm0.common module here (docs can be read here).
yotama9 Wrote:Also, How can I print anything to terminal (or a file) when running the plugin in xbmc?

as i've said before, you can just use 'print' for testing and stuff will appear in the logfile at log level xbmc.LOGNOTICE. if you want to specify log levels there is xbmc.log() (examples available in the module i linked above).

hope that helps

t0mm0
Reply
#7
Thanks.

I'm not criticizing you in any way. I have read the documentation of parse_qs() which sent me to urllib however. I couldn't have find any explanation of the data format that is generated.

I don't *want* to use regexp, I am simply more familiar with it than with url parsing (which I am not completely sure what it means).

Thank you for the print tip, I'll use it.


Maybe the problem is with me. All my programming (well, almost all) experience is for scientific purposes which is inherently different from what I'm trying to achieve here. I'm doing this ``project'' only because I'm trying to create a media streamer for my parrents
Reply

Logout Mark Read Team Forum Stats Members Help
How to create a response to an item selection in a list0