First add on -- any help appreciated
#1
I am trying to use the tutorial to create an add on that has live and archived sporting events using rtmp links that I have mined.

My problem is that the tutorial explains a method of making multiple folders, but following that method puts the same file in both folder.

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, 'movies')

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('Live Action', iconImage='http://www.garnishmusicproduction.com/wp-content/uploads/2010/09/Live-Stream.jpg')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    url = build_url({'mode': 'folder', 'foldername': 'Folder Two'})
    li = xbmcgui.ListItem('Archived Action', iconImage='http://www.iconeasy.com/icon/png/File%20Type/Pull%20Tab%20Archives/archive.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 = 'rtmp://23.108.15.5:1935/flash1/salisburyvideo'
    li = xbmcgui.ListItem('Salisbury v. Merchent Marine Mens Soccer', iconImage='http://alumni.salisbury.edu/resource/resmgr/images/sammy_logo.jpg')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)

The above example puts the live rtmp stream in both the "live" and "archived" folders. I'm trying to understand how to place some files in the "live action" folder and others in the "archived action" folder. For instance, the link above would go in the "live action" folder and rtmp://o1.stretchinternet.com:1935/ondemand/mp4:cnu/cnu-214573-v.mp4 and rtmp://o1.stretchinternet.com:1935/ondemand/mp4Confusedtevenson/stevenson-216769-v.mp4 would go in the "archived action" folder.

I realize that this is probably very basic, but please indulge me if you would be so kind.
Reply
#2
This is un-tested but give it a shot. The problem you were having was messing with the modes in the URL string. You had both links set to "folder" when they need to be unique names.

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, 'movies')

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

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

if mode is None:
    url = build_url({'mode': 'folder_one', 'foldername': 'live action'})
    li = xbmcgui.ListItem('Live Action', iconImage='http://www.garnishmusicproduction.com/wp-content/uploads/2010/09/Live-Stream.jpg')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    url = build_url({'mode': 'folder_two', 'foldername': 'archived action'})
    li = xbmcgui.ListItem('Archived Action', iconImage='http://www.iconeasy.com/icon/png/File%20Type/Pull%20Tab%20Archives/archive.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'folder_one':
    url = build_url({'mode': 'play_live_game_1', 'foldername': 'archived action'})
    li = xbmcgui.ListItem('Some Live Game', iconImage='http://www.iconeasy.com/icon/png/File%20Type/Pull%20Tab%20Archives/archive.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'play_live_game_1':
    xbmc.Player().play('rtmp://o1.stretchinternet.com:1935/ondemand/mp4:cnu/cnu-214573-v.mp4')

elif mode[0] == 'folder_two':
    url = build_url({'mode': 'play_archived_game_1', 'foldername': 'archived action'})
    li = xbmcgui.ListItem('some archived game', iconImage='http://alumni.salisbury.edu/resource/resmgr/images/sammy_logo.jpg')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'play_archived_game_1':
    xbmc.Player().play('rtmp://o1.stretchinternet.com:1935/ondemand/mp4:stevenson/stevenson-216769-v.mp4')
Reply
#3
Thank you so much erfg12! Although I couldn't get your exact code to work, I was able to change the "modes" to "folder_one" and "folder_two" that did the trick.

So baby steps.

Since you have been so helpful, are you aware of a a way to populate a folder with links from a remotely hosted .xml file or .m3u? What I would like to do is manage the live links in an xml or m3u that is hosted outside of the add on itself. I get the live links a few hours before the event and instead of changing the add on every time it would be great if I could just edit a file.

Thanks!!!!
Reply
#4
Janus 247 I would like to talk to you about helping each other create our first addon. I am good friends with Alki David the owner of Filmon and also good friends with the top manufacturer in China of the best Android TV Box. I really need to get a Addon done because they are going to preload it for me. Would love to work together and help each other if your interested.
Reply
#5
Xteremetech: Thanks, but I'm not interested. I'm just trying this to do it to see if I can in my spare time. I have no coding experience and am tryingto teach myself python for the first time. My target release date is Spring, if at all, and I even if I can do it, it's not going to be much. Just some special interest archived videos maintained on m3u playlists and maybe a few live video links.
Reply
#6
Janus: I wrote that tutorial, so hopefully I can explain how I'd do things. From the tutorial, you start out with a fragment like this:

Code:
elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = '...'
    li = xbmcgui.ListItem('...')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)

The important bit for you is the second line: it fetches the folder name from the arguments. You can use that to show different things based on which folder you're in:

Code:
elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    if foldername == 'Live':
        url = '...'
        li = xbmcgui.ListItem('...')
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    else:
        ...
    xbmcplugin.endOfDirectory(addon_handle)

Obviously, as your code gets more complex, you might want to do something more elaborate than just using if/else statements. For instance, you could use "foldername" to load an XML file or make an HTTP request to populate each folder.
Reply
#7
Thank you. That is helpful.
Reply

Logout Mark Read Team Forum Stats Members Help
First add on -- any help appreciated0