Help With my first Add-on

clairvius

New member
May 9, 2018
4
0
0
I'm making my first video add-on. I have the addon made and working in Kodi by adding each video link inside the code one by one. But i would like to use request to get the urls from a hosted txt file and enter them in my code automatically. That way i don't have to code each and every film, and i can also add or remove items via the txt file and won't have to update the plugin often. Any help is greatly appreciated as im new to coding. Thank you

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