Help with my first add-on

clairvius

New member
May 9, 2018
4
0
0
Hey guys, I've been working on my first add-on but have hit another wall and was wondering if someone could point me in the right direction. I have my add-on created and working with a few video sources, but i would like to use Request to populate the links in the code from a hosted txt file. That way i don't have to manually enter every link in the code and i could also update the videos via txt instead of having to update the add-on itself. I've seen a few videos but can't seem to get it working correctly, if anyone could help me out or point me in the direction of a good Noob friendly tutorial i'd greatly appreciate it. Below is the code that I am using. Thanks

Code:
import urlparse
import sys,urllib
import xbmc, xbmcgui, xbmcaddon, xbmcplugin
import urlresolver
import os,requests,urllib2,re




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

_addon = xbmcaddon.Addon()
_icon = _addon.getAddonInfo('icon')



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

def resolve_url(url):
    duration=7500   #in milliseconds
    message = "Cannot Play URL"
    stream_url = urlresolver.HostedMediaFile(url=url).resolve()
    # If urlresolver returns false then the video url was not resolved.
    if not stream_url:
        dialog = xbmcgui.Dialog()
        dialog.notification("URL Resolver Error", message, xbmcgui.NOTIFICATION_INFO, duration)
        return False
    else:        
        return stream_url    

def play_video(path):
    """
    Play a video by the provided path.
    :param path: str
    """
    # Create a playable item with a path to play.
    play_item = xbmcgui.ListItem(path=path)
    vid_url = play_item.getfilename()
    stream_url = resolve_url(vid_url)
    if stream_url:
        play_item.setPath(stream_url)
    # Pass the item to the Kodi player.
    xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)

# addon kicks in

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


if mode is None:
    video_play_url = "https://openload.co/f/jZlK1qL9NmA/TNT_Monstervision_Joe_Bob_Briggs_Presents_Slaughter_High.mp4"
    url = build_url({'mode' :'play', 'playlink' : video_play_url})
    li = xbmcgui.ListItem('Slaughter High', iconImage='https://i.imgur.com/QmX16hR.jpg')
    li.setProperty('IsPlayable' , 'true')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    video_play_url = "https://openload.co/f/i6en49nqvV8/TNT_Monstervision_Joe_Bob_Briggs_Presents_Xtro_2.mp4"
    url = build_url({'mode' :'play', 'playlink' : video_play_url})
    li = xbmcgui.ListItem('Xtro 2', iconImage='https://i.imgur.com/YpHnzXf.jpg')
    li.setProperty('IsPlayable' , 'true')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)


    video_play_url = "https://openload.co/f/kXNhVdl2ql0/TNT_Monstersion_Joe_Bob_Briggs_Presents_Breeders.mp4"
    url = build_url({'mode' :'play', 'playlink' : video_play_url})
    li = xbmcgui.ListItem('Breeders', iconImage='https://i.imgur.com/v2uRc6O.jpg')
    li.setProperty('IsPlayable' , 'true')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    video_play_url = "https://openload.co/f/RWEnFlmW9Do/TNT_Monstervision_Joe_Bob_Briggs_Presents_The_Beast_Within.mp4"
    url = build_url({'mode' :'play', 'playlink' : video_play_url})
    li = xbmcgui.ListItem('The Beast Within', iconImage='https://i.imgur.com/9Xkg0tz.jpg')
    li.setProperty('IsPlayable' , 'true')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)

    

    xbmcplugin.endOfDirectory(addon_handle)


elif mode[0] == 'play':
    final_link = args['playlink'][0]
    play_video(final_link)
 
Thread starter Similar threads Forum Replies Date
T Kodi Support 9
S Random Topics 1
C Addon Development 3