Exemple #1
0
def make_search_list(params):
    try:
        listing = comm.get_search_results(params.get('name'))
        ok = True
        for s in listing:
            url = "{0}?action=series_list&{1}".format(sys.argv[0],
                                                      s.make_kodi_url())
            thumb = s.get_thumb()
            listitem = xbmcgui.ListItem(s.get_list_title())
            listitem.setArt({'icon': thumb, 'thumb': thumb})
            listitem.setInfo('video', {'plot': s.get_description()})
            folder = False
            if s.type == 'Program':
                listitem.setProperty('IsPlayable', 'true')
            else:
                if not s.dummy:
                    folder = True

            # add the item to the media list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=folder)
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error('Unable to fetch search history list')
def list_categories():
    """
    Make initial list
    """
    try:
        listing = []
        categories = config.CATEGORIES
        for category in categories:
            li = xbmcgui.ListItem(category)
            url_string = '{0}?action=listcategories&category={1}'
            url = url_string.format(_url, category)
            is_folder = True
            listing.append((url, li, is_folder))

        genres = comm.list_genres()
        for g in genres:
            li = xbmcgui.ListItem(g.title, iconImage=g.thumb,
                                  thumbnailImage=g.thumb)
            li.setArt({'fanart': g.fanart})
            url_string = '{0}?action=listcategories&category=genre&genre={1}'
            url = url_string.format(_url, urllib.quote_plus(g.title))
            is_folder = True
            listing.append((url, li, is_folder))
        li = xbmcgui.ListItem('Settings')
        listing.append(('{0}?action=settings'.format(_url), li, is_folder))
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list categories')
def make_category_list(url):
    utils.log("Making category list")
    try:
        params = utils.get_url(url)
        category = params.get('category')
        categories = comm.get_category(category)
        utils.log(categories)

        ok = True
        for c in categories.get('rows'):
            
            if c.get('layout', {}).get('itemType') == 'genre':
                genre = 'True'
            else:
                genre = 'False'
            
            url = "%s?%s" % (sys.argv[0], utils.make_url({
                                 'category': category,
                                 'genre': genre,
                                 'feed_url': c.get('feedUrl')}))
            
            thumbnail = c.get('thumbnail', '')
            listitem = xbmcgui.ListItem(label=c['name'],
                                        thumbnailImage=thumbnail)
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build categories list')
Exemple #4
0
def make_rounds(params):
    utils.log('Making rounds list...')
    try:
        season = comm.get_seasons(season=params.get('season'))
        rounds = reversed(season.get('rounds'))
        for r in rounds:
            name = r.get('name')
            round_id = r.get('roundId')
            season_id = r.get('seasonId')
            listitem = xbmcgui.ListItem(label=name)
            url = '{0}?name={1}&round_id={2}&season_id={3}'.format(
                sys.argv[0], name, round_id, season_id)

            # Add the item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True,
                                             totalItems=len(
                                                 season.get('rounds')))

        # send notification we're finished, successfully or unsuccessfully
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
    except Exception:
        utils.handle_error('Unable to make round list')
Exemple #5
0
def make_series_list(params, atoz=True):

    try:
        if atoz:
            series_list = comm.get_atoz_programme_from_feed(params)
        else:
            series_list = comm.get_collection_from_feed(params)
        series_list.sort()
        ok = True
        for s in series_list:
            url = "{0}?action=series_list&{1}".format(sys.argv[0],
                                                      s.make_kodi_url())
            thumb = s.get_thumb()
            listitem = xbmcgui.ListItem(s.get_list_title())
            listitem.setArt({'fanart': s.get_fanart(),
                             'icon': thumb,
                             'thumb': thumb})
            listitem.setInfo('video', {'plot': s.get_description()})
            if s.type == 'Program':
                listitem.setProperty('IsPlayable', 'true')
                folder = False
            else:
                folder = True

            # add the item to the media list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=folder)
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error('Unable to fetch program list. '
                           'Please try again later.')
Exemple #6
0
def play(url):
    try:
        addon = xbmcaddon.Addon()
        p = classes.Program()
        p.parse_xbmc_url(url)
        stream_data = comm.get_stream(p.id)
        stream_url = [x['url'] for x in stream_data if x['quality'] == 'Auto'][0]

        """
        bandwidth = addon.getSetting('BANDWIDTH')

        if bandwidth == '0':
            stream_url = stream_url.replace('&b=0-2000', '&b=400-600')
        elif bandwidth == '1':
            stream_url = stream_url.replace('&b=0-2000', '&b=900-1100')
        elif bandwidth == '2':
            stream_url = stream_url.replace('&b=0-2000', '&b=1400-1600')
        """
        
        listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                    iconImage=p.thumbnail,
                                    thumbnailImage=p.thumbnail,
                                    path=stream_url)
        listitem.setInfo('video', p.get_kodi_list_item())

        """# Add subtitles if available
        if 'subtitles' in stream_info:
            sub_url = stream_info['subtitles']
            profile = addon.getAddonInfo('profile')
            path = xbmc.translatePath(profile).decode('utf-8')
            if not os.path.isdir(path):
                os.makedirs(path)
            subfile = xbmc.translatePath(
                os.path.join(path, 'subtitles.eng.srt'))
            if os.path.isfile(subfile):
                os.remove(subfile)
            try:
                data = urllib2.urlopen(sub_url).read()
                f = open(subfile, 'w')
                f.write(data)
                f.close()
                if hasattr(listitem, 'setSubtitles'):
                    # This function only supported from Kodi v14+
                    listitem.setSubtitles([subfile])
            except Exception:
                utils.log('Subtitles not available for this program')"""
        
        """
        listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
        listitem.setProperty('inputstream.adaptive.manifest_type', 'hls')
        listitem.setProperty('inputstream.adaptive.license_key', stream_url)
        """
        if hasattr(listitem, 'addStreamInfo'):
            listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
            listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error("Unable to play video")
Exemple #7
0
def make_livestreams_list():
    try:
        programs = comm.get_livestreams_from_feed()

        ok = True
        for p in programs:
            listitem = xbmcgui.ListItem(label=p.get_list_title())
            listitem.setInfo('video', p.get_kodi_list_item())
            listitem.setProperty('IsPlayable', 'true')
            thumb = p.get_thumb()
            listitem.setArt({
                'fanart': p.get_fanart(),
                'icon': thumb,
                'thumb': thumb
            })

            if hasattr(listitem, 'addStreamInfo'):
                listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
                listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

            # Build the URL for the program, including the list_info
            url = "{0}?action=livestreams&{1}".format(sys.argv[0],
                                                      p.make_kodi_url())

            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=False,
                                             totalItems=len(programs))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to fetch livestream list')
def make_content_list(params):
    """ create list of playable movies/tv shows"""
    try:
        listing = []
        category = params['category']
        if category == 'episodes':
            content = comm.list_episodes(params['series_id'])
        elif category == 'movies':
            content = comm.list_movies()
        elif category == 'Thanks Thursdays Trailers':
            content = comm.list_trailers('thanks')
        elif category == 'Featured Movie Trailers':
            content = comm.list_trailers('featured')
        for p in content:
            li = xbmcgui.ListItem(label=str(p.title),
                                  iconImage=p.thumb,
                                  thumbnailImage=p.thumb)
            url = '{0}?action=listplayable{1}'.format(_url, p.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setProperty('inputstreamaddon', 'inputstream.adaptive')
            li.addStreamInfo('video', p.get_stream_info())
            li.setInfo('video', p.get_info())
            li.setArt(p.get_art())
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list content')
Exemple #9
0
def list_shows(params):
    try:
        shows = comm.get_shows(params)
        genre = ('All'
                 if params['category'] == 'All shows' else params['category'])
        listing = []
        for s in shows:
            if genre == 'All':
                pass
            else:
                if not genre == s.genre:
                    continue
            li = xbmcgui.ListItem(s.title,
                                  iconImage=s.thumb,
                                  thumbnailImage=s.thumb)
            li.setArt({'fanart': s.get_fanart(), 'banner': s.get_banner()})
            url = '{0}?action=listshows&category={1}{2}'.format(
                _url, params['category'], s.make_kodi_url())
            is_folder = True
            listing.append((url, li, is_folder))
        xbmcplugin.addSortMethod(_handle,
                                 xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list shows')
Exemple #10
0
def list_episodes(params):
    try:
        episodes = comm.get_episodes(params)
        listing = []
        if episodes:
            page = episodes[0].page
            for e in episodes:
                li = xbmcgui.ListItem(e.title,
                                      iconImage=e.thumb,
                                      thumbnailImage=e.thumb)
                li.setArt({'fanart': e.fanart})
                url = '{0}?action=listepisodes{1}'.format(
                    _url, e.make_kodi_url())
                is_folder = False
                li.setProperty('IsPlayable', 'true')
                li.setInfo(
                    'video', {
                        'plot': e.desc,
                        'plotoutline': e.desc,
                        'duration': e.duration,
                        'date': e.get_airdate()
                    })
                listing.append((url, li, is_folder))

            if episodes[0].total_episodes - (page * 30) > 30:
                url = '{0}?action=listshows{1}&page={2}'.format(
                    _url, episodes[0].make_kodi_url(), episodes[0].page + 1)
                is_folder = True
                li = xbmcgui.ListItem('next page')
                listing.append((url, li, is_folder))
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list episodes')
def play_video(params):
    """
    Play a video by the provided path.
    :param path: str
    """
    if 'dummy' in params:
        if params['dummy'] == 'True':
            return
    try:
        import drmhelper
        if drmhelper.check_inputstream():
            dash_stream = ooyalahelper.get_dash_playlist(params['video_id'])
            url = dash_stream['dash_url']
            play_item = xbmcgui.ListItem(path=url)
            play_item.setProperty('inputstream.adaptive.manifest_type', 'mpd')
            play_item.setProperty('inputstream.adaptive.license_type',
                                  'com.widevine.alpha')
            play_item.setProperty(
                'inputstream.adaptive.license_key',
                dash_stream['wv_lic'] + ('|Content-Type=application%2F'
                                         'x-www-form-urlencoded|A{SSM}|'))
            xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
        else:
            xbmcplugin.setResolvedUrl(_handle, True,
                                      xbmcgui.ListItem(path=None))
            return

    except Exception:
        utils.handle_error('Unable to play video')
Exemple #12
0
def make_entries_list(url):
    utils.log('Making entries list')
    try:
        params = utils.get_url(url)
        programs = comm.get_entries(params['feed_url'])

        ok = True
        for p in sorted(programs):
            listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                        iconImage=p.get_thumbnail(),
                                        thumbnailImage=p.get_thumbnail())
            if type(p) is classes.Program:
                listitem.setInfo('video', p.get_kodi_list_item())
                listitem.setProperty('IsPlayable', 'true')

            #if hasattr(listitem, 'addStreamInfo'):
                listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
                listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

                # Build the URL for the program, including the list_info
                url = "%s?play=true&%s" % (sys.argv[0], p.make_xbmc_url())
            else:
                url = "%s?%s" % (sys.argv[0], utils.make_url({
                                 'feed_url': p.feed_url}))
            # Add the program item to the list
            isFolder = type(p) is classes.Series
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url,
                                             listitem=listitem, isFolder=isFolder,
                                             totalItems=len(programs))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to fetch program list')
Exemple #13
0
def make_episodes_list(url):
    """ Make list of episode Listitems for Kodi"""
    try:
        params = dict(urlparse.parse_qsl(url))
        episodes = comm.list_episodes(params)
        listing = []
        for e in episodes:
            li = xbmcgui.ListItem(e.title,
                                  iconImage=e.thumb,
                                  thumbnailImage=e.thumb)
            li.setArt({'fanart': e.fanart})
            url = '{0}?action=listepisodes{1}'.format(_url, e.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            if e.drm is True:
                li.setProperty('inputstreamaddon', 'inputstream.adaptive')
            li.setInfo(
                'video', {
                    'plot': e.desc,
                    'plotoutline': e.desc,
                    'duration': e.duration,
                    'date': e.get_airdate()
                })
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list episodes')
Exemple #14
0
def list_rounds(params):
    """ create list of rounds for the season. If in current year then only
        create to current date"""
    try:
        listing = []
        params['action'] = 'listrounds'
        if params['year'] == '2017':
            no_of_rounds = get_round_no()
        else:
            no_of_rounds = 30
        for i in range(no_of_rounds, 0, -1):
            params['rnd'] = str(i)
            if i <= 26:
                li = xbmcgui.ListItem('Round ' + str(i))
            elif i == 27:
                li = xbmcgui.ListItem('Finals Week 1')
            elif i == 28:
                li = xbmcgui.ListItem('Semi Finals')
            elif i == 29:
                li = xbmcgui.ListItem('Preliminary Finals')
            elif i == 30:
                li = xbmcgui.ListItem('Grand Final')
            url = '{0}?{1}'.format(_url, utils.make_url(params))
            is_folder = True
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list rounds')
def play_video(params):
    """
    Play a video by the provided path.
    :param path: str
    """
    if 'dummy' in params:
        if params['dummy'] == 'True':
            return

    try:
        if params.get('video_id') == 'None':
            if ooyalahelper.get_user_ticket():
                playlist = comm.get_replay_playlist(params)
        else:
            live = params['live'] == 'true'
            video_id = params['video_id']
            pcode = ''
            if 'p_code' in params:
                pcode = params['p_code']
            playlist = ooyalahelper.get_m3u8_playlist(video_id, pcode, live)

        play_item = xbmcgui.ListItem(path=playlist)
        xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)

    except Exception:
        utils.handle_error('Unable to play video')
Exemple #16
0
def play(url):
    try:
        addon = xbmcaddon.Addon()
        p = classes.Program()
        p.parse_xbmc_url(url)

        # Some programs don't have protected streams. 'Public' streams are
        # set in program.url, otherwise we fetch it separately
        if p.get_url():
            stream_info = {}
            stream_url = p.get_url()
        else:
            stream_info = comm.get_stream(p.id)
            stream_url = stream_info['url']

        bandwidth = addon.getSetting('BANDWIDTH')

        if bandwidth == '0':
            stream_url = stream_url.replace('&b=0-2000', '&b=400-600')
        elif bandwidth == '1':
            stream_url = stream_url.replace('&b=0-2000', '&b=900-1100')
        elif bandwidth == '2':
            stream_url = stream_url.replace('&b=0-2000', '&b=1400-1600')

        listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                    iconImage=p.thumbnail,
                                    thumbnailImage=p.thumbnail,
                                    path=stream_url)
        listitem.setInfo('video', p.get_kodi_list_item())

        # Add subtitles if available
        if 'subtitles' in stream_info:
            sub_url = stream_info['subtitles']
            profile = addon.getAddonInfo('profile')
            path = xbmc.translatePath(profile).decode('utf-8')
            if not os.path.isdir(path):
                os.makedirs(path)
            subfile = xbmc.translatePath(
                os.path.join(path, 'subtitles.eng.srt'))
            if os.path.isfile(subfile):
                os.remove(subfile)
            try:
                data = urllib2.urlopen(sub_url).read()
                f = open(subfile, 'w')
                f.write(data)
                f.close()
                if hasattr(listitem, 'setSubtitles'):
                    # This function only supported from Kodi v14+
                    listitem.setSubtitles([subfile])
            except Exception:
                utils.log('Subtitles not available for this program')

        if hasattr(listitem, 'addStreamInfo'):
            listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
            listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error("Unable to play video")
Exemple #17
0
def play(url):
    try:
        params = utils.get_url(url)
        v = classes.Video()
        v.parse_xbmc_url(url)

        if 'ooyalaid' in params:
            login_token = None
            if params.get('subscription_required') == 'True':
                login_token = ooyalahelper.get_user_token()

            stream_url = ooyalahelper.get_m3u8_playlist(
                params['ooyalaid'], v.live, login_token)
        else:
            stream_url = v.get_url()

        listitem = xbmcgui.ListItem(label=v.get_title(),
                                    iconImage=v.get_thumbnail(),
                                    thumbnailImage=v.get_thumbnail(),
                                    path=stream_url)

        listitem.addStreamInfo('video', v.get_kodi_stream_info())
        listitem.setInfo('video', v.get_kodi_list_item())

        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error('Unable to play video')
Exemple #18
0
def make_programs_list(url):
    try:
        params = utils.get_url(url)
        programs = comm.get_series_from_feed(params['series_url'],
                                             params['episode_count'])

        ok = True
        for p in programs:
            listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                        iconImage=p.get_thumbnail(),
                                        thumbnailImage=p.get_thumbnail())
            listitem.setInfo('video', p.get_kodi_list_item())
            listitem.setProperty('IsPlayable', 'true')

            if hasattr(listitem, 'addStreamInfo'):
                listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
                listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

            # Build the URL for the program, including the list_info
            url = "%s?play=true&%s" % (sys.argv[0], p.make_xbmc_url())

            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=False,
                                             totalItems=len(programs))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to fetch program list')
Exemple #19
0
def make_series_list(params):
    utils.log('Showing series list')
    try:
        series_list = comm.get_series_list(params)
        series_list.sort()

        ok = True
        for s in series_list:
            url = '{0}?action=list_series&{1}'.format(sys.argv[0],
                                                      s.make_kodi_url())
            listitem = xbmcgui.ListItem(s.title,
                                        iconImage=s.get_thumb(),
                                        thumbnailImage=s.get_thumb())
            listitem.setInfo('video', {'plot': ''})

            # add the item to the media list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error("Unable to fetch series listing")
Exemple #20
0
def list_matches(params, live=False):
    """
    """
    try:
        listing = []
        matches = comm.list_matches(params, live)

        for m in matches:
            li = xbmcgui.ListItem(label=str(m.title),
                                  iconImage=m.thumb,
                                  thumbnailImage=m.thumb)
            url = '{0}?action=listmatches{1}'.format(_url, m.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setInfo('video', {'plot': m.desc, 'plotoutline': m.desc})
            listing.append((url, li, is_folder))

        if live:
            upcoming = comm.get_upcoming()
            for event in upcoming:
                thumb = os.path.join(addonPath, 'resources', 'soon.jpg')
                li = xbmcgui.ListItem(event.title, iconImage=thumb)
                url = '{0}?action=listmatches{1}'.format(
                    _url, event.make_kodi_url())
                is_folder = False
                listing.append((url, li, is_folder))
            xbmcplugin.addSortMethod(
                _handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to fetch match list')
Exemple #21
0
def list_categories():
    """
    Make initial list
    """
    try:
        listing = []
        categories = config.CATEGORIES
        for category in categories:
            li = xbmcgui.ListItem(category)
            url_string = '{0}?action=listcategories&category={1}'
            url = url_string.format(_url, category)
            is_folder = True
            listing.append((url, li, is_folder))

        genres = comm.list_genres()
        for g in genres:
            li = xbmcgui.ListItem(g.title,
                                  iconImage=g.thumb,
                                  thumbnailImage=g.thumb)
            li.setArt({'fanart': g.fanart})
            url_string = '{0}?action=listcategories&category=genre&genre={1}'
            url = url_string.format(_url, urllib.quote_plus(g.title))
            is_folder = True
            listing.append((url, li, is_folder))
        li = xbmcgui.ListItem('Settings')
        listing.append(('{0}?action=settings'.format(_url), li, is_folder))
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list categories')
def play(params):
    try:
        import drmhelper
        if not drmhelper.check_inputstream(drm=False):
            return
    except ImportError:
        utils.log("Failed to import drmhelper")
        utils.dialog_message('DRM Helper is needed for inputstream.adaptive '
                             'playback. For more information, please visit: '
                             'http://aussieaddons.com/drm')
        return

    try:
        stream = comm.get_stream(params['video_id'])

        utils.log('Attempting to play: {0} {1}'.format(stream['name'],
                                                       stream['url']))
        item = xbmcgui.ListItem(label=stream['name'], path=stream['url'])
        item.setProperty('inputstreamaddon', 'inputstream.adaptive')
        item.setProperty('inputstream.adaptive.manifest_type', 'hls')
        item.setMimeType('application/vnd.apple.mpegurl')
        item.setContentLookup(False)
        xbmcplugin.setResolvedUrl(pluginhandle, True, listitem=item)
    except Exception:
        utils.handle_error('Unable to play video')
Exemple #23
0
def make_matches_list(params):
    """
    Build match listing for Kodi
    """
    try:
        listing = []
        matches = comm.list_matches(params)

        for m in matches:
            li = xbmcgui.ListItem(label=str(m.title))
            url = '{0}?action=listmatches{1}'.format(_url, m.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setInfo('video', {'plot': m.title, 'plotoutline': m.title})
            li.setArt({'icon': m.thumb, 'thumb': m.thumb})
            listing.append((url, li, is_folder))

        if params['category'] == 'livematches':
            upcoming = comm.get_upcoming()
            for event in upcoming:
                thumb = os.path.join(addon_path, 'resources', 'soon.jpg')
                li = xbmcgui.ListItem(event.title)
                li.setArt({'icon': thumb, 'thumb': thumb})
                url = '{0}?action=listmatches{1}'.format(
                    _url, event.make_kodi_url())
                is_folder = False
                listing.append((url, li, is_folder))
            xbmcplugin.addSortMethod(
                _handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to display matches')
Exemple #24
0
 def test_handle_error(self, mock_exc_info, mock_traceback,
                       mock_format_dialog_error, mock_connection_info,
                       mock_not_already_reported, mock_get_latest_version,
                       mock_yesno_dialog, mock_send_report,
                       mock_save_last_report):
     mock_exc_info.return_value = (fakes.FakeException, fakes.EXC_VALUE,
                                   fakes.TB)
     mock_traceback.return_value = ''.join(
         traceback.format_exception(fakes.FakeException, fakes.EXC_VALUE,
                                    fakes.TB))
     mock_format_dialog_error.return_value = [
         'Test Add-on v0.0.1 ERROR', fakes.EXC_FORMATTED_SUMMARY
     ]
     mock_connection_info.return_value = fakes.VALID_CONNECTION_INFO[0]
     mock_not_already_reported.return_value = True
     mock_get_latest_version.return_value = '0.0.1'
     mock_yesno_dialog.return_value = True
     utils.handle_error('Big error', force=True)
     mock_send_report.assert_called_once_with(
         fakes.EXC_VALUE_FORMATTED,
         trace=''.join(
             traceback.format_exception(fakes.FakeException,
                                        fakes.EXC_VALUE, fakes.TB)),
         connection_info=fakes.VALID_CONNECTION_INFO[0])
     mock_save_last_report.assert_called_once_with(
         fakes.EXC_VALUE_FORMATTED)
Exemple #25
0
def make_series_list(url):
    """ Make list of series Listitems for Kodi"""
    try:
        params = dict(urlparse.parse_qsl(url))
        series_list = comm.list_series()
        filtered = []
        if 'genre' in params:
            for s in series_list:
                if s.genre == urllib.unquote_plus(params['genre']):
                    filtered.append(s)
        else:
            filtered = series_list

        listing = []
        for s in filtered:
            li = xbmcgui.ListItem(s.title,
                                  iconImage=s.thumb,
                                  thumbnailImage=s.thumb)
            li.setArt({'fanart': s.fanart})
            url = '{0}?action=listseries{1}'.format(_url, s.make_kodi_url())
            is_folder = True
            listing.append((url, li, is_folder))

        xbmcplugin.addSortMethod(_handle,
                                 xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list series')
Exemple #26
0
def make_series_list(params):
    """ Make list of series Listitems for Kodi"""
    try:
        _url = sys.argv[0]
        _handle = int(sys.argv[1])
        series_list = comm.list_series()
        if 'genre' in params:
            series_slug_list = comm.list_series_by_genre(params['genre'])
            series_list = [
                s for s in series_list if s.series_slug in series_slug_list
            ]
        listing = []
        for s in series_list:
            li = create_listitem(s.title)
            li.setArt({'fanart': s.fanart, 'icon': s.thumb, 'thumb': s.thumb})
            url = '{0}?action=listseries{1}'.format(_url, s.make_kodi_url())
            is_folder = True
            li.setInfo('video', {'plot': s.desc, 'plotoutline': s.desc})
            listing.append((url, li, is_folder))

        xbmcplugin.addSortMethod(_handle,
                                 xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list series')
def play_video(params):
    """
    Play a video by the provided path.
    :param path: str
    """
    if 'dummy' in params:
        if params['dummy'] == 'True':
            return

    v = classes.Video()
    v.parse_params(params)

    try:
        # ticket = stream_auth.get_user_ticket()
        media_auth_token = None
        # if v.live == 'true':
        #    media_auth_token = stream_auth.get_media_auth_token(
        #        ticket, v.video_id)
        playlist = comm.get_stream_url(v, media_auth_token)
        play_item = xbmcgui.ListItem(path=playlist)
        xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)

    except Exception:
        utils.handle_error('Unable to play video')
        raise
Exemple #28
0
def make_live_list(url):
    try:
        channels = comm.get_live()
        if not channels:
            return

        ok = True
        for c in channels:

            listitem = xbmcgui.ListItem(label=c.get_list_title(),
                                        iconImage=c.get_thumb(dummy_req=True),
                                        thumbnailImage=c.get_thumb())
            listitem.setInfo('video', c.get_kodi_list_item())
            listitem.setProperty('IsPlayable', 'true')

            if hasattr(listitem, 'addStreamInfo'):
                listitem.addStreamInfo('audio', c.get_kodi_audio_stream_info())
                listitem.addStreamInfo('video', c.get_kodi_video_stream_info())

            # Build the URL for the program, including the list_info
            url = '{0}?action=list_programs&{1}'.format(sys.argv[0],
                                                        c.make_kodi_url())
            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=False)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error("Unable to fetch live channel listing")
def make_search_list(params):
    try:
        listing = comm.get_search_results(params)
        ok = True
        for s in listing:
            url = "{0}?action=series_list&{1}".format(sys.argv[0],
                                                      s.make_kodi_url())
            thumb = s.get_thumb()
            listitem = comm.create_listitem(s.get_list_title())
            listitem.setArt({'icon': thumb, 'thumb': thumb})
            listitem.setInfo('video', {'plot': s.get_description()})
            folder = False
            if isinstance(s, classes.Program):
                listitem.setProperty('IsPlayable', 'true')
            else:
                folder = True

            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=folder)
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error('Unable to fetch search list')
def make_episodes_list(url):
    """ Make list of episode Listitems for Kodi"""
    try:
        params = dict(urlparse.parse_qsl(url))
        episodes = comm.list_episodes(params)
        listing = []
        for e in episodes:
            li = xbmcgui.ListItem(e.title, iconImage=e.thumb,
                                  thumbnailImage=e.thumb)
            li.setArt({'fanart': e.fanart})
            url = '{0}?action=listepisodes{1}'.format(_url, e.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            if e.drm is True:
                li.setProperty('inputstreamaddon', 'inputstream.adaptive')
            li.setInfo('video', {'plot': e.desc,
                                 'plotoutline': e.desc,
                                 'duration': e.duration,
                                 'date': e.get_airdate()})
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list episodes')
def make_search_history_list():
    try:
        listing = search.get_search_history_listing()
        ok = True
        for item in listing:
            listitem = comm.create_listitem(label=item)
            listitem.setInfo('video', {'plot': ''})
            listitem.addContextMenuItems([
                ('Remove from search history',
                 ('RunPlugin(plugin://plugin.video.sbs/?action=remove'
                  'search&name={0})'.format(item)))
            ])
            url = "{0}?action=searchhistory&name={1}".format(
                sys.argv[0], quote_plus(item))

            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True)
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]),
                                  succeeded=ok,
                                  cacheToDisc=False)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error('Unable to fetch search history list')
def make_series_list(url):
    """ Make list of series Listitems for Kodi"""
    try:
        params = dict(urlparse.parse_qsl(url))
        series_list = comm.list_series()
        filtered = []
        if 'genre' in params:
            for s in series_list:
                if s.genre == urllib.unquote_plus(params['genre']):
                    filtered.append(s)
        else:
            filtered = series_list

        listing = []
        for s in filtered:
            li = xbmcgui.ListItem(s.title, iconImage=s.thumb,
                                  thumbnailImage=s.thumb)
            li.setArt({'fanart': s.fanart})
            url = '{0}?action=listseries{1}'.format(_url, s.make_kodi_url())
            is_folder = True
            listing.append((url, li, is_folder))

        xbmcplugin.addSortMethod(
            _handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list series')
Exemple #33
0
def make_episodes_list(params):
    """ Make list of episode Listitems for Kodi"""
    try:
        _url = sys.argv[0]
        _handle = int(sys.argv[1])
        episodes = comm.list_episodes(params)
        listing = []
        for e in episodes:
            li = create_listitem(e.title)
            li.setArt({'fanart': e.fanart, 'icon': e.thumb, 'thumb': e.thumb})
            url = '{0}?action=listepisodes{1}'.format(_url, e.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setInfo(
                'video', {
                    'plot': e.desc,
                    'plotoutline': e.desc,
                    'duration': e.duration,
                    'date': e.airdate
                })
            listing.append((url, li, is_folder))

        xbmcplugin.addSortMethod(_handle,
                                 xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
        xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_EPISODE)
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list episodes')
Exemple #34
0
def make_list():
    try:
        for t in config.TEAMS:
            # Add our resources/lib to the python path
            try:
                current_dir = os.path.dirname(os.path.abspath(__file__))
            except Exception:
                current_dir = os.getcwd()

            thumbnail = os.path.join(current_dir, "..", "..", "resources",
                                     "img", t['thumb'])
            listitem = xbmcgui.ListItem(label=t['name'],
                                        iconImage=thumbnail,
                                        thumbnailImage=thumbnail)
            url = "%s?team=%s" % (sys.argv[0], t['team_id'])

            # Add the item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True,
                                             totalItems=len(config.TEAMS))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to fetch video list')
Exemple #35
0
def list_categories():
    """
    Make initial list
    """
    try:
        _url = sys.argv[0]
        _handle = int(sys.argv[1])
        listing = []
        categories = config.CATEGORIES
        for category in categories:
            li = create_listitem(category)
            url_string = '{0}?action=listcategories&category={1}'
            url = url_string.format(_url, category)
            is_folder = True
            listing.append((url, li, is_folder))

        genres = comm.list_genres()
        for g in genres:
            li = create_listitem(g.title)
            li.setArt({'fanart': g.fanart, 'icon': g.thumb, 'thumb': g.thumb})
            url_string = '{0}?action=listcategories&category=genre&genre={1}'
            url = url_string.format(_url, quote_plus(g.genre_slug))
            is_folder = True
            listing.append((url, li, is_folder))
        li = create_listitem('Settings')
        listing.append(('{0}?action=settings'.format(_url), li, is_folder))
        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list categories')
Exemple #36
0
def make_list():
    try:
        videos = comm.get_videos()

        if len(videos) == 0:
            utils.dialog_message(['No videos found.',
                                  'Please try again later.'])
        else:
            for video in videos:
                url = "%s?video_id=%s" % (sys.argv[0], video['video_id'])
                listitem = xbmcgui.ListItem(video['name'],
                                            iconImage=video['thumbnail'],
                                            thumbnailImage=video['thumbnail'])
                listitem.setProperty('IsPlayable', 'true')
                listitem.setInfo('video', {'plot': video['name']})

                # add the item to the media list
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=url,
                                            listitem=listitem,
                                            isFolder=False,
                                            totalItems=len(videos))

            xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
    except Exception:
        utils.handle_error('Unable build video list')
def list_matches(params, live=False):
    """
    """
    try:
        listing = []
        if not live:
            matches = comm.list_matches(params, live)
        else:
            matches = comm.get_live_matches()

        for m in matches:
            li = xbmcgui.ListItem(label=str(m.title), iconImage=m.thumb,
                                  thumbnailImage=m.thumb)
            url = '{0}?action=listmatches{1}'.format(_url, m.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setInfo('video', {'plot': m.desc, 'plotoutline': m.desc})
            listing.append((url, li, is_folder))

        if live:
            upcoming = comm.get_upcoming()
            for event in upcoming:
                thumb = os.path.join(addonPath, 'resources', 'soon.jpg')
                li = xbmcgui.ListItem(event.title, iconImage=thumb)
                url = '{0}?action=listmatches{1}'.format(
                    _url, event.make_kodi_url())
                is_folder = False
                listing.append((url, li, is_folder))
            xbmcplugin.addSortMethod(
                _handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to fetch match list')
Exemple #38
0
def make_index_list():
    try:
        index = comm.get_index()
        ok = True
        for i in index:
            if 'url' in i:
                url = "%s?%s" % (sys.argv[0], utils.make_url({
                                 'category': i['name']}))
                listitem = xbmcgui.ListItem(i['name'])
                # Add the program item to the list
                ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                 url=url, listitem=listitem,
                                                 isFolder=True)

        listitem = xbmcgui.ListItem(label='Settings')
        ok = xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url="{0}?action=settings".format(sys.argv[0]),
            listitem=listitem,
            isFolder=False)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build index')
Exemple #39
0
def make_list():
    try:
        matches = comm.get_matches()

        if len(matches) == 0:
            utils.dialog_message(['No matches are currently being played.',
                                  'Please try again later.'])
        else:
            for match in matches:
                url = "%s?video_id=%s" % (sys.argv[0], match['video_id'])
                listitem = xbmcgui.ListItem(match['name'],
                                            iconImage=match['thumbnail'],
                                            thumbnailImage=match['thumbnail'])
                listitem.setProperty('IsPlayable', 'true')
                listitem.setInfo('video', {'plot': match['name']})

                # add the item to the media list
                ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                 url=url,
                                                 listitem=listitem,
                                                 isFolder=False,
                                                 totalItems=len(matches))

            xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
    except Exception:
        utils.handle_error('Unable build match list')
def make_rounds(params):
    utils.log('Making rounds list...')
    try:
        season = comm.get_seasons(season=params.get('season'))
        rounds = reversed(season.get('rounds'))
        for r in rounds:
            name = r.get('name')
            round_id = r.get('roundId')
            season_id = r.get('seasonId')
            listitem = xbmcgui.ListItem(label=name)
            url = '{0}?name={1}&round_id={2}&season_id={3}'.format(
                sys.argv[0], name, round_id, season_id)

            # Add the item to the list
            ok = xbmcplugin.addDirectoryItem(
                handle=int(sys.argv[1]),
                url=url,
                listitem=listitem,
                isFolder=True,
                totalItems=len(season.get('rounds')))

        # send notification we're finished, successfully or unsuccessfully
        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
    except Exception:
        utils.handle_error('Unable to make round list')
Exemple #41
0
def make_index_list():
    print "hasdhsadhsa"
    utils.log('g2')
    try:
        utils.log('hello')
        index = comm.get_index()['contentStructure'].get('menu')
        ok = True
        for i in index:
            url = "%s?%s" % (sys.argv[0], utils.make_url({
                             'category': i}))
            listitem = xbmcgui.ListItem(i)
            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url, listitem=listitem,
                                             isFolder=True)

        listitem = xbmcgui.ListItem(label='Settings')
        ok = xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url="{0}?action=settings".format(sys.argv[0]),
            listitem=listitem,
            isFolder=False)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build index')
def play(url):
    try:
        params = utils.get_url(url)
        v = classes.Video()
        v.parse_xbmc_url(url)
        if params.get('isdummy'):
            xbmcgui.Dialog().ok(
                    'Dummy item',
                    'This item is not playable, it is used only to display '
                    'the upcoming schedule. Please check back once the match '
                    'has started. Playable matches will have "LIVE NOW" in '
                    'green next to the title.')
        if 'ooyalaid' in params:
            login_token = None
            if params.get('subscription_required') == 'True':
                login_token = ooyalahelper.get_user_token()

            stream_data = ooyalahelper.get_m3u8_playlist(params['ooyalaid'],
                                                         v.live, login_token)
        else:
            stream_data = {'stream_url': v.get_url()}

        listitem = xbmcgui.ListItem(label=v.get_title(),
                                    iconImage=v.get_thumbnail(),
                                    thumbnailImage=v.get_thumbnail(),
                                    path=stream_data.get('stream_url'))

        inputstream = drmhelper.check_inputstream(drm=v.live)
        if not inputstream:
            utils.dialog_message(
                'Failed to play stream. Please visit our website at '
                'http://aussieaddons.com/addons/afl/ for more '
                'information.')
            return

        widevine_url = stream_data.get('widevine_url')

        if inputstream and (not v.live or not widevine_url):
            listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
            listitem.setProperty('inputstream.adaptive.manifest_type', 'hls')
            listitem.setProperty('inputstream.adaptive.license_key',
                                 stream_data.get('stream_url'))
        elif v.live:
            listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
            listitem.setProperty('inputstream.adaptive.manifest_type', 'mpd')
            listitem.setProperty('inputstream.adaptive.license_type',
                                 'com.widevine.alpha')
            listitem.setProperty('inputstream.adaptive.license_key',
                                 widevine_url +
                                 '|Content-Type=application%2F'
                                 'x-www-form-urlencoded|A{SSM}|')
        listitem.addStreamInfo('video', v.get_kodi_stream_info())
        listitem.setInfo('video', v.get_kodi_list_item())

        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error('Unable to play video')
def list_categories():
    try:
        listing = []
        for category in config.CATEGORIES:
            li = xbmcgui.ListItem(category)
            urlString = '{0}?action=listcategories&category={1}'
            url = urlString.format(_url, category)
            is_folder = True
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to make categories list')
def make_list():
    try:
        for category in config.CATEGORIES:
            url = "%s?category=%s" % (sys.argv[0], category)
            listitem = xbmcgui.ListItem(category)

            # add the item to the media list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True,
                                             totalItems=len(config.CATEGORIES))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
    except Exception:
        utils.handle_error('Unable build video category list')
def list_videos(params):
    """ make our list of videos"""
    try:
        video_list = comm.get_videos(params)
        listing = []
        for v in video_list:
            li = xbmcgui.ListItem(v.title, thumbnailImage=v.thumb)
            li.setProperty('IsPlayable', 'true')
            li.setInfo('video', {'plot': v.desc, 'plotoutline': v.desc})
            url = '{0}?action=listvideos{1}'.format(_url, v.make_kodi_url())
            is_folder = False
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list comps')
def list_years(params):
    """ create a list of the years that match replays are currently
        available for"""
    try:
        listing = []
        params['action'] = 'listyears'
        for year in config.YEARS:
            params['year'] = year
            li = xbmcgui.ListItem(str(year))
            url = '{0}?{1}'.format(_url, utils.make_url(params))
            is_folder = True
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle,
                                     sorted(listing, reverse=True),
                                     len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list years')
def make_live_list(url):
    """ Make list of channel Listitems for Kodi"""
    try:
        params = dict(urlparse.parse_qsl(url))
        channels = comm.list_live(params)
        listing = []
        for c in channels:
            li = xbmcgui.ListItem(c.title, iconImage=c.thumb,
                                  thumbnailImage=c.thumb)
            li.setArt({'fanart': c.fanart})
            url = '{0}?action=listchannels{1}'.format(_url, c.make_kodi_url())
            is_folder = False
            li.setProperty('IsPlayable', 'true')
            li.setInfo('video', {'plot': c.desc,
                                 'plotoutline': c.episode_name})
            listing.append((url, li, is_folder))

        xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
        xbmcplugin.endOfDirectory(_handle)
    except Exception:
        utils.handle_error('Unable to list channels')
def make_category_list():
    try:
        categories = comm.get_categories()
        categories = sorted(categories, key=lambda k: k['name'].lower())
        categories.append({'path': 'settings', 'name': 'Settings'})

        ok = True
        for g in categories:
            url = "%s?category=%s" % (sys.argv[0], g['path'])
            listitem = xbmcgui.ListItem(g['name'])
            if 'thumbnail' in g:
                listitem.setArt({'thumb': g['thumbnail']})

            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build category list')
def make_seasons_list():
    try:
        seasons = comm.get_seasons()
        sorted_seasons = sorted(
            seasons, key=lambda x: x.get('name'), reverse=True)
        for season in sorted_seasons:
            id = season.get('id')
            current_round = season.get('currentRoundId')
            name = season.get('name')
            url = "{0}?season={1}&current_round={2}&name={3}".format(
                sys.argv[0], id, current_round, name)
            listitem = xbmcgui.ListItem(name)

            # add the item to the media list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True,
                                             totalItems=len(seasons))

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
    except Exception:
        utils.handle_error('Unable build seasons list')
def make_categories_list():
    utils.log('Showing category list')
    try:
        categories_list = comm.get_categories()
        categories_list.sort()
        categories_list.insert(0, classes.Category(title='Live TV'))
        categories_list.append(classes.Category(title='Settings'))

        for c in categories_list:
            url = '{0}?action=list_categories&{1}'.format(sys.argv[0],
                                                          c.make_kodi_url())
            listitem = xbmcgui.ListItem(label=c.title,
                                        iconImage=c.get_thumb(),
                                        thumbnailImage=c.get_thumb())

            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=url,
                                             listitem=listitem,
                                             isFolder=True)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='tvshows')
    except Exception:
        utils.handle_error("Unable to show category listing")
Exemple #51
0
def play(params):
    try:
        p = comm.get_program(params)
        # enable HD streams
        if ADDON.getSetting('hd_enabled') == 'true':
            if p.dash_url:
                if '&rule=sd-only' in p.dash_url:
                    p.dash_url = p.dash_url.replace('&rule=sd-only', '')
            if p.hls_url:
                if '&rule=sd-only' in p.hls_url:
                    p.hls_url = p.hls_url.replace('&rule=sd-only', '')
        listitem = xbmcgui.ListItem(label=p.get_title(),
                                    path=p.get_url())
        listitem.setInfo('video', p.get_kodi_list_item())

        if hasattr(listitem, 'addStreamInfo'):
            listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
            listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

        if (p.dash_preferred and p.dash_url) or not p.hls_url:
            import drmhelper
            drm = p.drm_key is not None

            if drmhelper.check_inputstream(drm=drm):
                listitem.setProperty('inputstreamaddon',
                                     'inputstream.adaptive')
                listitem.setProperty('inputstream.adaptive.manifest_type',
                                     'mpd')
                if drm:
                    listitem.setProperty('inputstream.adaptive.license_type',
                                         'com.widevine.alpha')
                    listitem.setProperty(
                        'inputstream.adaptive.license_key',
                        p.drm_key+'|Content-Type=application%2F'
                                  'x-www-form-urlencoded|A{SSM}|')
            else:
                if drm:
                    xbmcplugin.setResolvedUrl(int(sys.argv[1]),
                                              True,
                                              xbmcgui.ListItem(path=None))
                    return
                else:
                    pass  # let's try to play hls if available

        # Pull subtitles if available
        if p.subtitle:
            utils.log('Enabling subtitles: {0}'.format(p.subtitle))
            profile = ADDON.getAddonInfo('profile')
            subfilename = xbmc.translatePath(os.path.join(profile,
                                                          'subtitle.srt'))
            profiledir = xbmc.translatePath(os.path.join(profile))
            if not os.path.isdir(profiledir):
                os.makedirs(profiledir)

            webvtt_data = session.Session().get(
                p.subtitle).text
            if webvtt_data:
                with open(subfilename, 'w') as f:
                    webvtt_subtitle = WebVTTReader().read(webvtt_data)
                    srt_subtitle = SRTWriter().write(webvtt_subtitle)
                    srt_unicode = srt_subtitle.encode('utf-8')
                    f.write(srt_unicode)

            if hasattr(listitem, 'setSubtitles'):
                # This function only supported from Kodi v14+
                listitem.setSubtitles([subfilename])

        # Play video
        utils.log('Attempting to play: {0} : {1}'.format(p.get_title(),
                                                         p.get_url()))
        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error('Unable to play video')
Exemple #52
0
def make_section_list(url):
    utils.log("Making section list")
    try:
        params = utils.get_url(url)
        section = comm.get_section(params['category'], params['section'])

        ok = True
        if 'children' in section and len(section['children']) > 0:
            for s in section['children']:
                entries_url = s.get('url')
                if entries_url:
                    url = "%s?%s" % (
                        sys.argv[0],
                        utils.make_url({'entries_url': entries_url}))

                    thumbnail = s.get('thumbnail')
                    listitem = xbmcgui.ListItem(s.get('name'),
                                                iconImage=thumbnail,
                                                thumbnailImage=thumbnail)

                    listitem.setInfo('video',
                                     {'title': s.get('name'),
                                      'genre': s.get('genre'),
                                      'plot': s.get('description'),
                                      'plotoutline': s.get('description')})

                    # Add the program item to the list
                    ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                     url=url,
                                                     listitem=listitem,
                                                     isFolder=True)

        elif 'url' in section:
            # no children, so fetch children by URL
            programs = comm.get_entries(section['url'])
            for p in sorted(programs):
                thumbnail = p.get_thumbnail()
                listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                            iconImage=thumbnail,
                                            thumbnailImage=thumbnail)
                listitem.setInfo('video', p.get_kodi_list_item())

                if hasattr(listitem, 'addStreamInfo'):
                    listitem.addStreamInfo('audio',
                                           p.get_kodi_audio_stream_info())
                    listitem.addStreamInfo('video',
                                           p.get_kodi_video_stream_info())

                # Build the URL for the program, including the list_info
                url = "%s?play=true&%s" % (sys.argv[0], p.make_xbmc_url())

                # Add the program item to the list
                ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                 url=url,
                                                 listitem=listitem,
                                                 isFolder=False,
                                                 totalItems=len(programs))
        else:
            utils.log("No children or url found for %s" % section)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=ok)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build section list')
def play(url):
    try:
        # Remove cookies.dat for Kodi < 17.0 - causes issues with playback
        addon = xbmcaddon.Addon()
        cookies_dat = xbmc.translatePath('special://home/cache/cookies.dat')
        if os.path.isfile(cookies_dat):
            os.remove(cookies_dat)
        p = classes.Program()
        p.parse_xbmc_url(url)
        stream = comm.get_stream_url(p.get_house_number(), p.get_url())
        use_ia = addon.getSetting('use_ia') == 'true'
        if use_ia:
            if addon.getSetting('ignore_drm') == 'false':
                try:
                    import drmhelper
                    if not drmhelper.check_inputstream(drm=False):
                        return
                except ImportError:
                    utils.log("Failed to import drmhelper")
                    utils.dialog_message(
                        'DRM Helper is needed for inputstream.adaptive '
                        'playback. Disable "Use inputstream.adaptive for '
                        'playback" in settings or install drmhelper. For '
                        'more information, please visit: '
                        'http://aussieaddons.com/drm')
                    return
            hdrs = stream[stream.find('|') + 1:]

        listitem = xbmcgui.ListItem(label=p.get_list_title(),
                                    iconImage=p.thumbnail,
                                    thumbnailImage=p.thumbnail,
                                    path=stream)
        if use_ia:
            listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
            listitem.setProperty('inputstream.adaptive.manifest_type', 'hls')
            listitem.setProperty('inputstream.adaptive.stream_headers', hdrs)
            listitem.setProperty('inputstream.adaptive.license_key', stream)
        listitem.setInfo('video', p.get_kodi_list_item())

        # Add subtitles if available
        if p.subtitle_url:
            profile = xbmcaddon.Addon().getAddonInfo('profile')
            path = xbmc.translatePath(profile).decode('utf-8')
            if not os.path.isdir(path):
                os.makedirs(path)
            subfile = xbmc.translatePath(
                os.path.join(path, 'subtitles.eng.srt'))
            if os.path.isfile(subfile):
                os.remove(subfile)

            try:
                webvtt_data = urllib2.urlopen(
                    p.subtitle_url).read().decode('utf-8')
                if webvtt_data:
                    with open(subfile, 'w') as f:
                        webvtt_subtitle = WebVTTReader().read(webvtt_data)
                        srt_subtitle = SRTWriter().write(webvtt_subtitle)
                        srt_unicode = srt_subtitle.encode('utf-8')
                        f.write(srt_unicode)
                if hasattr(listitem, 'setSubtitles'):
                    listitem.setSubtitles([subfile])
            except Exception as e:
                utils.log(
                    'Subtitles not available for this program {0}'.format(e))

        if hasattr(listitem, 'addStreamInfo'):
            listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info())
            listitem.addStreamInfo('video', p.get_kodi_video_stream_info())

        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem)

    except Exception:
        utils.handle_error('Unable to play video')