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_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_index_list():
    try:
        addon = xbmcaddon.Addon()
        index = comm.get_config()['contentStructure'].get('menu')
        ok = True
        for i in index:
            url = "%s?%s" % (sys.argv[0], utils.make_url({'category': i}))
            listitem = comm.create_listitem(i)
            # Add the program item to the list
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=str(url),
                                             listitem=listitem,
                                             isFolder=True)

        listitem = comm.create_listitem(label='Favourites')
        ok = xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url="{0}?action=favouritescategories".format(sys.argv[0]),
            listitem=listitem,
            isFolder=True)

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

        if not addon.getSetting('user_token'):
            listitem = comm.create_listitem(label='Login')
            ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url="{0}?action=login".format(
                                                 sys.argv[0]),
                                             listitem=listitem,
                                             isFolder=False)

        xbmcplugin.endOfDirectory(handle=int(sys.argv[1]),
                                  succeeded=ok,
                                  cacheToDisc=False)
        xbmcplugin.setContent(handle=int(sys.argv[1]), content='episodes')
    except Exception:
        utils.handle_error('Unable to build index')
def make_favourites_categories_list():
    utils.log("Making favourites category list")
    try:
        favourites_categories = comm.get_favourites_categories()
        ok = True
        for c in favourites_categories:
            url = '{0}?{1}'.format(sys.argv[0], c.make_kodi_url())

            listitem = comm.create_listitem(label=c.get_list_title())
            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 favourites categories list')
def make_category_list(params):
    utils.log("Making category list")
    try:
        categories = comm.get_category(params)
        ok = True
        for c in categories:
            url = '{0}?{1}'.format(sys.argv[0], c.make_kodi_url())
            thumb = c.get_thumb()
            listitem = comm.create_listitem(label=c.get_list_title())
            listitem.setArt({'thumb': thumb, 'icon': 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='episodes')
    except Exception:
        utils.handle_error('Unable to build categories list')
Exemple #6
0
def play(url):
    try:
        addon = xbmcaddon.Addon()
        p = classes.Program()
        p.parse_kodi_url(url)
        stream_info = comm.get_stream(p.id)
        if not stream_info:
            return
        stream_url = stream_info.get('stream_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 = comm.create_listitem(label=p.get_list_title(),
                                        path=str(stream_url))
        listitem.setArt({'icon': p.thumb, 'thumb': p.thumb})
        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)
            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:
                sess = session.Session()
                data = sess.get(sub_url).text
                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())

        listitem.setProperty('isPlayable', 'true')
        if utils.get_kodi_major_version() >= 18:
            listitem.setIsFolder(False)

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

        try:
            import upnext
        except Exception as e:
            utils.log('UpNext addon not installed: %s' % e)
            return

        np = comm.get_next_program(p)
        if not isinstance(np, classes.Program):
            return

        next_info = OrderedDict(current_episode=OrderedDict(
            episodeid=p.id,
            tvshowid=p.get_tvshowid(),
            title=p.get_title(),
            art={
                'thumb': p.get_thumb(),
                'tvshow.fanart': p.get_fanart(),
            },
            season=p.get_season_no(),
            episode=p.get_episode_no(),
            showtitle=p.get_series_title(),
            plot=p.get_description(),
            playcount=0,
            rating=None,
            firstaired=p.get_date(),
            runtime=p.get_duration(),
        ),
                                next_episode=OrderedDict(
                                    episodeid=np.id,
                                    tvshowid=np.get_tvshowid(),
                                    title=np.get_title(),
                                    art={
                                        'thumb': np.get_thumb(),
                                        'tvshow.fanart': np.get_fanart(),
                                    },
                                    season=np.get_season_no(),
                                    episode=np.get_episode_no(),
                                    showtitle=np.get_series_title(),
                                    plot=np.get_description(),
                                    playcount=0,
                                    rating=None,
                                    firstaired=np.get_date(),
                                    runtime=np.get_duration(),
                                ),
                                play_url='{0}?{1}'.format(
                                    sys.argv[0], np.make_kodi_url()),
                                notification_offset=p.get_credits_time())

        upnext.send_signal(xbmcaddon.Addon().getAddonInfo('id'), next_info)

    except Exception:
        utils.handle_error("Unable to play video")
def make_entries_list(params):
    utils.log('Making entries list')
    try:
        programs = comm.get_entries(params)
        ok = True
        items = []
        for p in programs:
            listitem = comm.create_listitem(label=p.get_list_title())

            if isinstance(p, classes.Program):
                listitem.setInfo('video', p.get_kodi_list_item())
                listitem.setProperty('IsPlayable', 'true')
                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
            elif isinstance(p, classes.Series):
                if p.page_begin and p.page_size:
                    listitem.setProperty('SpecialSort', 'bottom')
                else:
                    listitem.setInfo('video', p.get_kodi_list_item())
            thumb = p.get_thumb()
            listitem.setArt({
                'thumb': thumb,
                'icon': thumb,
                'fanart': p.get_fanart()
            })
            url = '{0}?{1}'.format(sys.argv[0], p.make_kodi_url())
            # Add the program item to the list
            isFolder = isinstance(p, classes.Series)
            if p.entry_type in ['TVSeries', 'Movie', 'OneOff']:
                if params.get('favourite'):
                    listitem.addContextMenuItems([
                        ('Remove from SBS favourites',
                         ('RunPlugin(plugin://plugin.video.sbs/?action=remove'
                          'favourites&program_id={0}&entry_type={1})'.format(
                              p.id, p.entry_type)))
                    ])
                else:
                    listitem.addContextMenuItems([
                        ('Add to SBS favourites',
                         ('RunPlugin(plugin://plugin.video.sbs/?action=add'
                          'favourites&program_id={0}&entry_type={1})'.format(
                              p.id, p.entry_type)))
                    ])

            items.append((url, listitem, isFolder))

        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE)
        xbmcplugin.addSortMethod(int(sys.argv[1]),
                                 xbmcplugin.SORT_METHOD_EPISODE)
        xbmcplugin.addSortMethod(int(sys.argv[1]),
                                 xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)

        ok = xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]),
                                          items=items,
                                          totalItems=len(items))

        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 entries list')