Learning Python, Beautiful Soup, Addon Dev.
#1
About a month ago i bit the bullet and started to look into how to code an audio/video addon.
Following the Wiki ive been able to create the Hello World and version 0.1 of my plugin.
Currently it just lists hardcoded listitems that are mp3's on my wordpress site, no active scraping of the site happens.

Ive started using beautiful soup, which ive managed to use to list URLs on the page but so far havent been able to marry these two bits together.

Before i post up what i have so far, and beg for help (i want to learn and not just tease bits of code out of people to effectively have them make it for me) im trying to find references to all commands available to me. Googling has returned the basics but i cant see to find a definitive list of what options are open to me.

In general will i find a list like this, or should i just be using knowledge picked up as i go to effectively guess the code i need to use?
Reply
#2
I have recently been through a similar process in developing an addon. It was hard, no doubt about it, documentation is often fragmented, outdated and may only give a basic overview. My suggestion is to find addon(s) that are similar to what you want to achieve, download them and pick them apart. I am not for a moment suggesting to copy them, simply learn how they achieved different aspects of the addon which will of course add to your knowledge-base. Lastly, don't be afraid to ask for help on this forum. For me, rather than asking "how do I"... I tried to do what I wanted, fell into a hole and posted for help on the forum (after at least attempting to find the answer myself). I have found there are a lot of very knowledgable people here that are only too happy to help.

Good luck Smile
The Internet isn't free. It just has an economy that makes no sense to capitalism.
Reply
#3
Thanks, im on the right track then.
This is what i have so far, basic but it works.

Code:
import sys
import xbmcgui
import xbmcplugin

addon_handle = int(sys.argv[1])

xbmcplugin.setContent(addon_handle, 'audio')

url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/04_-_Double_T_with_MC_Surgeon_b2b_Status.mp3'
li = xbmcgui.ListItem('Double T with MC Surgeon & Status - RaverQueen 2012', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Lady_B_B2B_Double_T_June_17th_2011_Mastered.mp3'
li = xbmcgui.ListItem('Double T B2B Lady Brock - HTID Mix 2011', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Double_T_-_October_Hardcore_2010.mp3'
li = xbmcgui.ListItem('Double T - UK Hardcore 2010', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)


xbmcplugin.endOfDirectory(addon_handle)

Looking at the wiki example here section 3.2
I can see its the same video referenced in both folders, but how would i add multiple files, in seperate folders.
This is the part that adds the files, but what part dictates which folder it goes into? I cant see an ID or unique reference to the folders created.
also, if i add the last segment of code twice, but with a new file in, this also doesnt seem to work.

this is where i am currently, and its stopped working. i get a unexpected indent error in the logs, but i cant see where i might have added one.
Code:
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin

base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'audio')

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

mode = args.get('mode', None)

if mode is None:
    url = build_url({'mode': 'folder', 'foldername': 'Folder One'})
    li = xbmcgui.ListItem('Klass A Radio', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    url = build_url({'mode': 'folder', 'foldername': 'Folder Two'})
    li = xbmcgui.ListItem('Double T & Lady Brock Archive', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Double_T_-_October_Hardcore_2010.mp3'
    li = xbmcgui.ListItem('Double T - Hardcore 2010', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)
    
    elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Lady_B_B2B_Double_T_June_17th_2011_Mastered.mp3'
    li = xbmcgui.ListItem('Klass A - Nu Skool', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)

if someone would be so kind as to point me in the right direction, would be great
Reply
#4
The code window may screw up the formatting, or you messed something up with the pasting, but the last 6 lines look all wrong.

1. you have an indented elif without an initial if
2. the indented elif repeats the elif above it
3. the code under that indented elif is not indented

I dont know which is the error.
Reply
#5
Thanks! Ive got it working again, it was the indent on the second elif.
Although working, it still puts the file in both folders. Sad

More trial and error!
Reply
#6
Okay so after a week or so of reading other plugins, reading through documentation i am still confused.
I think the problem is that i am keeping my plugin extremely basic, just putting list items into folders.
Most other examples go above and beyond quite quickly.

Would someone mind putting me out of my misery? how would i put one item in one folder and the other in the other.
I cant see how i would create unique references in the example code other than the folder one and folder two names defined at the top, but when i try to mock up some code to send the list item to a particular folder, the script fails.

Still researching....

Code:
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin
from BeautifulSoup import BeautifulSoup
from xbmcswift2 import Plugin

base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'audio')

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

mode = args.get('mode', None)

if mode is None:
    url = build_url({'mode': 'folder', 'foldername': 'Folder One'})
    li = xbmcgui.ListItem('Klass A Radio', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    url = build_url({'mode': 'folder', 'foldername': 'Folder Two'})
    li = xbmcgui.ListItem('Double T & Lady Brock Archive', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Double_T_-_October_Hardcore_2010.mp3'
    li = xbmcgui.ListItem('Double T - Hardcore 2010', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)
    
elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Lady_B_B2B_Double_T_June_17th_2011_Mastered.mp3'
    li = xbmcgui.ListItem('Klass A - Nu Skool', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)
Reply
#7
2 DoubleT
In plugins you don't create folders per se. You create a list of ListItem objects with addDirectoryItem (which is basically a fancy version of Python's list.append()) and then tell XBMC that you list is complete by calling endOfDirectory for XBMC to display your list.
If you need to create a sub-list that opens when you click an item in a top-level list, you call your plugin recursively via 'plugin://' URL and pass necessary parameters in URL-encoded syntax via the "tail" of your 'plugin://' URL. This "tail" is then passed to your plugin as sys.argv[2], IIRC.
Reply
#8
Thanks for your help, i think i understand.
Off to try some changes!
Reply
#9
So i understand the concept but i cant write the code to achieve what i want to do.
How do i define the different pages?
I get that i need to add in plugin:\\page1 type of thing, but im not getting where and how

I presume i need to define them here...
Code:
def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

mode = args.get('mode', None)

But for the life of me I cant find the correct combination.
Reply
#10
Code:
elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Double_T_-_October_Hardcore_2010.mp3'
    li = xbmcgui.ListItem('Double T - Hardcore 2010', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    url = 'http://www.whitenoisehq.co.uk/v3/wp-content/files/Lady_B_B2B_Double_T_June_17th_2011_Mastered.mp3'
    li = xbmcgui.ListItem('Klass A - Nu Skool', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)
    
elif mode==1:
        print ""+url
        INDEX(url)
        
elif mode==2:

Think i am making more progress, i can now get the script to run without error but of couse the below mode 1 & 2 elif are nonsense and currently do nothing.

Am i right in thinking i need to use the mode 1 & 2 elif for drawing up list of items, and then use the plugin:\\ and mode = args.get('mode', None) to then call the page i want from the add-on's "front page"
Reply
#11
@ DoubleT , did u found a solution for it , if yes kindly plz post it here.

Plz chk ur PM
Reply
#12
Sadly not. I ended up borking my development setup with wrong versions of everything and eventually gave up.
I will more than likely return to looking at all of this again in a few months but for now my focus has shifted away from coding add-ons.

I could never quite get the jist of managing multiple pages within the plugin, but was able to put everything into one page / list of items.
Just a lack of knowledge on my behalf really, didnt have the time to jump head first into Python.

Just read your PM - just adding multiple list items i did work out.

see my code below for kiss fm uk plugin

Code:
import sys
import xbmcgui
import xbmcplugin

addon_handle = int(sys.argv[1])

xbmcplugin.setContent(addon_handle, 'audio')

url = 'http://tx.whatson.com/icecast.php?i=kisstorylow.mp3'
li = xbmcgui.ListItem('Kisstory', iconImage='http://whitenoisehq.co.uk/kisstory.png', thumbnailImage='http://whitenoisehq.co.uk/kisstory.png')
li.setProperty('fanart_image', 'http://whitenoisehq.co.uk/kissbg.jpg')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

url = 'http://tx.whatson.com/icecast.php?i=kissnationallow.mp3'
li = xbmcgui.ListItem('Kiss FM UK - National', iconImage='http://whitenoisehq.co.uk/kisslogo.png', thumbnailImage='http://whitenoisehq.co.uk/kisslogo.png')
li.setProperty('fanart_image', 'http://whitenoisehq.co.uk/kissbg.jpg')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

xbmcplugin.endOfDirectory(addon_handle)

Hope it helps someone
Reply
#13
Hi DoubleT, for listing purposes I have googled, and youtubed some tutorials, they are great and really would be great if You know how to extract things from webpage, then you should add it as a directory.

Getting names, and Variables i meant exact url to the object (Audio,Video, Text or whatever You like).

Try this:
http://www.pythonforbeginners.com/python...tifulsoup/

And that:
https://www.youtube.com/results?q=beautifulsoup+python
(First three, have several parts go from beginning to the end pt1/3 2/3 3/3 etc.
Hope It will show You the right way, also try to change simple plugin.
For example this plugin its quite straight forward but it fetching data from xml file: just need to change it to resolve url from your website.

plugin.video.dmd.streams

Good luck.
hope it helps.


After those tutorials i was able to manage, and find correct url and add as a directory, I assume You should try to make looping variable until variable is empty. That's my thoughts.
Reply

Logout Mark Read Team Forum Stats Members Help
Learning Python, Beautiful Soup, Addon Dev.0