Пример #1
0
def search(search_func, term=None):
    """ Search wrapper """
    external = False
    if plugin.id == xbmc.getInfoLabel('Container.PluginName'):
        # Skip if search item isn't currently selected
        label = xbmc.getInfoLabel('ListItem.label')
        if label and not equals(label, _("Search")):
            return
    else:
        external = True

    if term is None:
        # Get search keyword
        search_entered = plugin.keyboard(heading=_("search for"))
        if not search_entered:
            return

    else:
        search_entered = term
    # Perform search
    url = plugin.url_for(search_func, term=search_entered, page='1')
    if external:
        xbmc.executebuiltin('ActivateWindow(10025,"plugin://%s/",return)' %
                            plugin.id)
        xbmc.executebuiltin('Container.Update("%s")' % url)
    else:
        plugin.redirect(url)
Пример #2
0
def search(search_func, term = None):
    """ Search wrapper """
    external = False
    if plugin.id == xbmc.getInfoLabel('Container.PluginName'):
        # Skip if search item isn't currently selected    
        label = xbmc.getInfoLabel('ListItem.label')
        if label and not equals(label, _("Search")):
            return
    else:
        external = True

    if term is None:
        # Get search keyword
        search_entered = plugin.keyboard(heading=_("search for"))
        if not search_entered:
            return

    else:
        search_entered = term
    # Perform search
    url = plugin.url_for(search_func, term=search_entered, page='1')
    if external:
        xbmc.executebuiltin('ActivateWindow(10025,"plugin://%s/",return)' % plugin.id)
        xbmc.executebuiltin('Container.Update("%s")' % url)
    else:
        plugin.redirect(url)
Пример #3
0
def add_tvshow_to_library(library_folder, show, play_plugin=None):
    clean_needed = False
    id = show['id']
    showname = to_utf8(show['seriesname'])
    if showname == "None" or showname == None:
        show_folder = os.path.join(library_folder, str(id) + '/')
        if os.path.isdir(show_folder): return shutil.rmtree(show_folder)
    playlist_folder = plugin.get_setting(SETTING_TV_PLAYLIST_FOLDER, unicode)
    if not xbmcvfs.exists(playlist_folder):
        try:
            xbmcvfs.mkdir(playlist_folder)
        except:
            dialogs.notify(msg=_(
                'Creation of [COLOR limegreen]M[/COLOR]etalli[COLOR limegreen]Q[/COLOR] 4[COLOR limegreen]Q[/COLOR]ed Playlist Folder'
            ),
                           title=_('Failed'),
                           delay=5000,
                           image=get_icon_path("lists"))
    playlist_file = os.path.join(playlist_folder, id + ".xsp")
    if not xbmcvfs.exists(playlist_file):
        playlist_file = xbmcvfs.File(playlist_file, 'w')
        content = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><smartplaylist type="tvshows"><name>%s</name><match>all</match><rule field="path" operator="contains"><value>%s%s</value></rule><rule field="playcount" operator="is"><value>0</value></rule><order direction="ascending">numepisodes</order></smartplaylist>' % (
            showname, plugin.get_setting(
                SETTING_TV_LIBRARY_FOLDER, str).replace(
                    'special://profile', ''), str(id))
        playlist_file.write(str(content))
        playlist_file.close()
    ## Create show folder
    enc_show = showname.translate(None, '\/:*?"<>|').strip('.')
    show_folder = os.path.join(library_folder, str(id) + '/')
    if not xbmcvfs.exists(show_folder):
        try:
            xbmcvfs.mkdir(show_folder)
        except:
            pass
        # Create play with file
        if play_plugin is not None:
            player_filepath = os.path.join(show_folder, 'player.info')
            player_file = xbmcvfs.File(player_filepath, 'w')
            content = "{0}".format(play_plugin)
            player_file.write(content)
            player_file.close()
        # Create nfo file
        nfo_filepath = os.path.join(show_folder, 'tvshow.nfo')
        if not xbmcvfs.exists(nfo_filepath):
            nfo_file = xbmcvfs.File(nfo_filepath, 'w')
            content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id)
            nfo_file.write(content)
            nfo_file.close()
    ## Get existing items in library
    # get all ids of the show
    ids = [id, show.get('imdb_id', None)]  # TODO: add tmdb!
    ids = [x for x in ids if x]
    # get show episodes in library
    try:
        # get tvshow from library
        libshows = RPC.VideoLibrary.GetTVShows(
            properties=["imdbnumber", "title", "year"])['tvshows']
        libshows = [
            i for i in libshows if str(i['imdbnumber']) in ids or (
                str(i['year']) == str(show.get('year', 0))
                and equals(show['seriesname'], i['title']))
        ]
        libshow = libshows[0]
        # get existing (non strm) episodes in library
        libepisodes = RPC.VideoLibrary.GetEpisodes(
            filter={
                "and": [{
                    "field": "tvshow",
                    "operator": "is",
                    "value": to_utf8(libshow['title'])
                }]
            },
            properties=["season", "episode", "file"])['episodes']
        libepisodes = [(int(i['season']), int(i['episode']))
                       for i in libepisodes if not i['file'].endswith(".strm")]
    except:
        libepisodes = []
    ## Create content strm files
    for (season_num, season) in show.items():
        if season_num == 0:  # or not season.has_aired():
            continue
        for (episode_num, episode) in season.items():
            if episode_num == 0:
                continue
            delete = False
            if plugin.get_setting(SETTING_AIRED_UNKNOWN, bool) == True:
                aired_unknown = True
            else:
                aired_unknown = False
            if not episode.has_aired(flexible=aired_unknown):
                delete = True
                #break
            if delete or (season_num, episode_num) in libepisodes:
                if library_tv_remove_strm(show, show_folder, id, season_num,
                                          episode_num):
                    clean_needed = True
            else:
                library_tv_strm(show, show_folder, id, season_num, episode_num)
    files, dirs = xbmcvfs.listdir(show_folder)
    if not dirs:
        shutil.rmtree(show_folder)
        clean_needed = True


#    if xbmc.getCondVisibility("system.hasaddon(script.qlickplay)"): xbmc.executebuiltin("RunScript(script.qlickplay,info=afteradd)")
#    elif xbmc.getCondVisibility("system.hasaddon(script.extendedinfo)"): xbmc.executebuiltin("RunScript(script.extendedinfo,info=afteradd)")
    return clean_needed
Пример #4
0
def add_tvshow_to_library(library_folder, show, play_plugin = None):
    clean_needed = False
    
    id = show['id']
    showname = to_utf8(show['seriesname'])

    ## Create show folder
    enc_show = showname.translate(None, '\/:*?"<>|').strip('.')
    show_folder = os.path.join(library_folder, str(id)+'/')
    if not xbmcvfs.exists(show_folder):
        try: 
            xbmcvfs.mkdir(show_folder)
        except:
            pass

        # Create play with file
        if play_plugin is not None:
            player_filepath = os.path.join(show_folder, 'player.info')
            player_file = xbmcvfs.File(player_filepath, 'w')
            content = "{0}".format(play_plugin)
            player_file.write(content)
            player_file.close()
            
        # Create nfo file
        nfo_filepath = os.path.join(show_folder, 'tvshow.nfo')
        if not xbmcvfs.exists(nfo_filepath):
            nfo_file = xbmcvfs.File(nfo_filepath, 'w')
            content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id)
            nfo_file.write(content)
            nfo_file.close()

    ## Get existing items in library
    
    # get all ids of the show
    ids = [id, show.get('imdb_id', None)]   # TODO: add tmdb!
    ids = [x for x in ids if x]

    # get show episodes in library
    try:
#        if not plugin.get_setting(SETTING_CHECK_LIBRARY_DUPS, converter=bool):
#            raise Exception()

        # get tvshow from library
        libshows = RPC.VideoLibrary.GetTVShows(properties=["imdbnumber", "title", "year"])['tvshows']
        libshows = [i for i in libshows if str(i['imdbnumber']) in ids or (str(i['year']) == str(show.get('year', 0)) and equals(show['seriesname'], i['title']))]
        libshow = libshows[0]
        
        # get existing (non strm) episodes in library
        libepisodes = RPC.VideoLibrary.GetEpisodes(filter={"and": [ {"field": "tvshow", "operator": "is", "value": to_utf8(libshow['title'])}]}, properties=["season", "episode", "file"])['episodes']
        libepisodes = [(int(i['season']), int(i['episode'])) for i in libepisodes if not i['file'].endswith(".strm")]
    except:
        libepisodes = []
    
    ## Create content strm files
    for (season_num,season) in show.items():
        if season_num == 0: # or not season.has_aired():
            continue
            
        for (episode_num, episode) in season.items():
            if episode_num == 0:
                continue
            
            delete = False
            if not episode.has_aired(flexible=True):
                delete = True
                #break
            
            if delete or (season_num, episode_num) in libepisodes:
                if library_tv_remove_strm(show, show_folder, id, season_num, episode_num):
                    clean_needed = True
            else:
                library_tv_strm(show, show_folder, id, season_num, episode_num)

    files, dirs = xbmcvfs.listdir(show_folder)
    if not dirs:
        shutil.rmtree(show_folder)
        clean_needed = True
                
    return clean_needed
Пример #5
0
def add_tvshow_to_library(library_folder, show, play_plugin = None):
    clean_needed = False
    id = show['id']
    showname = to_utf8(show['seriesname'])
    if showname == "None" or showname == None:
        show_folder = os.path.join(library_folder, str(id)+'/')
        if os.path.isdir(show_folder): return shutil.rmtree(show_folder)
    playlist_folder = plugin.get_setting(SETTING_TV_PLAYLIST_FOLDER, unicode)
    if not xbmcvfs.exists(playlist_folder):
        try: xbmcvfs.mkdir(playlist_folder)
        except: dialogs.notify(msg=_('Creation of [COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR] Playlist Folder'), title=_('Failed'), delay=5000, image=get_icon_path("lists"))
    playlist_file = os.path.join(playlist_folder, id+".xsp")
    if not xbmcvfs.exists(playlist_file):
        playlist_file = xbmcvfs.File(playlist_file, 'w')
        content = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><smartplaylist type="tvshows"><name>%s</name><match>all</match><rule field="path" operator="contains"><value>%s%s</value></rule><rule field="playcount" operator="is"><value>0</value></rule><order direction="ascending">numepisodes</order></smartplaylist>' % (showname, plugin.get_setting(SETTING_TV_LIBRARY_FOLDER, str).replace('special://profile',''), str(id))
        playlist_file.write(str(content))
        playlist_file.close()
    ## Create show folder
    enc_show = showname.translate(None, '\/:*?"<>|').strip('.')
    show_folder = os.path.join(library_folder, str(id)+'/')
    if not xbmcvfs.exists(show_folder):
        try:
            xbmcvfs.mkdir(show_folder)
        except:
            pass
        # Create play with file
        if play_plugin is not None:
            player_filepath = os.path.join(show_folder, 'player.info')
            player_file = xbmcvfs.File(player_filepath, 'w')
            content = "{0}".format(play_plugin)
            player_file.write(content)
            player_file.close()
        # Create nfo file
        nfo_filepath = os.path.join(show_folder, 'tvshow.nfo')
        if not xbmcvfs.exists(nfo_filepath):
            nfo_file = xbmcvfs.File(nfo_filepath, 'w')
            content = "http://thetvdb.com/index.php?tab=series&id=%s" % str(id)
            nfo_file.write(content)
            nfo_file.close()
    ## Get existing items in library
    # get all ids of the show
    ids = [id, show.get('imdb_id', None)]   # TODO: add tmdb!
    ids = [x for x in ids if x]
    # get show episodes in library
    try:
        # get tvshow from library
        libshows = RPC.VideoLibrary.GetTVShows(properties=["imdbnumber", "title", "year"])['tvshows']
        libshows = [i for i in libshows if str(i['imdbnumber']) in ids or (str(i['year']) == str(show.get('year', 0)) and equals(show['seriesname'], i['title']))]
        libshow = libshows[0]
        # get existing (non strm) episodes in library
        libepisodes = RPC.VideoLibrary.GetEpisodes(filter={"and": [ {"field": "tvshow", "operator": "is", "value": to_utf8(libshow['title'])}]}, properties=["season", "episode", "file"])['episodes']
        libepisodes = [(int(i['season']), int(i['episode'])) for i in libepisodes if not i['file'].endswith(".strm")]
    except: libepisodes = []
    ## Create content strm files
    for (season_num,season) in show.items():
        if season_num == 0 and not plugin.get_setting(SETTING_INCLUDE_SPECIALS, bool): continue
        if not season.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): continue
        for (episode_num, episode) in season.items():
            if not season_num == 0 and not episode.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): continue
            delete = False
            if not episode.has_aired(flexible=plugin.get_setting(SETTING_AIRED_UNKNOWN, bool)): delete = True
            if delete or (season_num, episode_num) in libepisodes:
                if library_tv_remove_strm(show, show_folder, id, season_num, episode_num): clean_needed = True
            else: library_tv_strm(show, show_folder, id, season_num, episode_num)
    files, dirs = xbmcvfs.listdir(show_folder)
    if not dirs:
        shutil.rmtree(show_folder)
        clean_needed = True
#    if xbmc.getCondVisibility("system.hasaddon(script.qlickplay)"): xbmc.executebuiltin("RunScript(script.qlickplay,info=afteradd)")
#    elif xbmc.getCondVisibility("system.hasaddon(script.extendedinfo)"): xbmc.executebuiltin("RunScript(script.extendedinfo,info=afteradd)")
    return clean_needed