def renumber(itemlist, item='', typography=''): info() dict_series = load(itemlist[0]) if len(itemlist) > 0 else {} if item: # from core.support import dbg;dbg() item.channel = item.from_channel if item.from_channel else item.channel title = item.fulltitle.rstrip() already_renumbered = scrapertools.find_single_match( itemlist[0].title, r'(\d+\D\d+)') if already_renumbered: return itemlist elif item.channel in item.channel_prefs and TAG_TVSHOW_RENUMERATE in item.channel_prefs[ item.channel] and title not in dict_series: from core.videolibrarytools import check_renumber_options from specials.videolibrary import update_videolibrary check_renumber_options(item) update_videolibrary(item) elif inspect.stack()[2][3] == 'find_episodes': return itemlist elif title in dict_series and TAG_ID in dict_series[title]: ID = dict_series[title][TAG_ID] Episode = dict_series[title][TAG_EPISODE] Season = dict_series[title][ TAG_SEASON] if TAG_SEASON in dict_series[title] else '' Mode = dict_series[title][TAG_MODE] if TAG_MODE in dict_series[ title] else False Type = dict_series[title][TAG_TYPE] if TAG_TYPE in dict_series[ title] else 'auto' renumeration(itemlist, item, typography, dict_series, ID, Season, Episode, Mode, title, Type) else: if config.get_setting('autorenumber', item.channel): config_item(item, itemlist, typography, True) else: return itemlist else: for item in itemlist: title = item.fulltitle.rstrip() if title in dict_series and TAG_ID in dict_series[title]: ID = dict_series[title][TAG_ID] exist = True else: exist = False if item.contentType != 'movie': if item.context: context2 = item.context item.show = item.fulltitle = title item.context = context(exist) + context2 else: item.show = item.fulltitle = title item.context = context(exist)
def get_seasons(item): logger.info() # logger.debug("item:\n" + item.tostring('\n')) itemlist = [] dict_temp = {} videolibrarytools.check_renumber_options(item) raiz, carpetas_series, ficheros = next(filetools.walk(item.path)) # Menu contextual: Releer tvshow.nfo head_nfo, item_nfo = videolibrarytools.read_nfo(item.nfo) if config.get_setting("no_pile_on_seasons", "videolibrary") == 2: # Ever return get_episodes(item) for f in ficheros: if f.endswith('.json'): season = f.split('x')[0] dict_temp[season] = config.get_localized_string(60027) % season if config.get_setting("no_pile_on_seasons", "videolibrary") == 1 and len( dict_temp) == 1: # Only if there is a season return get_episodes(item) else: # We create one item for each season for season, title in list(dict_temp.items()): new_item = item.clone(action="get_episodes", title=title, contentSeason=season, filtrar_season=True, channel='videolibrary') #Contextual menu: Mark the season as viewed or not visto = item_nfo.library_playcounts.get("season %s" % season, 0) new_item.infoLabels["playcount"] = visto if visto > 0: texto = config.get_localized_string(60028) value = 0 else: texto = config.get_localized_string(60029) value = 1 new_item.context = [{"title": texto, "action": "mark_season_as_watched", "channel": "videolibrary", "playcount": value}] # logger.debug("new_item:\n" + new_item.tostring('\n')) itemlist.append(new_item) if len(itemlist) > 1: itemlist = sorted(itemlist, key=lambda it: int(it.contentSeason)) if config.get_setting("show_all_seasons", "videolibrary"): new_item = item.clone(action="get_episodes", title=config.get_localized_string(60030)) new_item.infoLabels["playcount"] = 0 itemlist.insert(0, new_item) add_download_items(item, itemlist) return itemlist
def __init__(self, itemlist, item=None): self.item = item self.itemlist = itemlist self.auto = False self.dictSeries = load( self.itemlist[0]) if self.itemlist else load(item) if item else {} self.Episodes = {} self.sp = False if self.item: self.auto = config.get_setting('autorenumber', item.channel) self.title = self.item.fulltitle.strip() if match(self.itemlist[0].title, patron=r'[Ss]?(\d+)(?:x|_|\s+)[Ee]?[Pp]?(\d+)').match: item.exit = True return elif self.item.channel in self.item.channel_prefs and TVSHOW_RENUMERATE in self.item.channel_prefs[ item.channel] and self.title not in self.dictSeries: from core.videolibrarytools import check_renumber_options from specials.videolibrary import update_videolibrary check_renumber_options(self.item) update_videolibrary(self.item) if self.title in self.dictSeries and ID in self.dictSeries[ self.title] and self.dictSeries[self.title][ID] != '0': self.id = self.dictSeries[self.title][ID] self.Episodes = b64(self.dictSeries[self.title][EPISODE], 'decode') if EPISODE in self.dictSeries[ self.title] else {} self.Season = self.dictSeries[self.title][SEASON] self.Mode = self.dictSeries[self.title].get(MODE, False) self.Type = self.dictSeries[self.title].get(TYPE, False) if self.item.renumber: self.config() else: self.renumber() elif self.auto or self.item.renumber: self.Episodes = {} self.config() else: for item in self.itemlist: item.context = [{ "title": typo(config.get_localized_string(70585), 'bold'), "action": "start", "channel": "autorenumber", "from_channel": item.channel, "from_action": item.action }]
def __init__(self, itemlist, item=None): self.item = item self.itemlist = itemlist self.selectspecials = False self.manual = False self.auto = False if self.item: self.renumberdict = load(item) self.auto = config.get_setting('autorenumber', item.channel) self.title = self.item.fulltitle.strip() if match(self.itemlist[0].title, patron=r'[Ss]?(\d+)(?:x|_|\s+)[Ee]?[Pp]?(\d+)').match: item.exit = True return elif self.item.channel in self.item.channel_prefs and RENUMBER in self.item.channel_prefs[ item.channel] and self.title not in self.renumberdict: from core.videolibrarytools import check_renumber_options from specials.videolibrary import update_videolibrary check_renumber_options(self.item) update_videolibrary(self.item) self.series = self.renumberdict.get(self.title, {}) self.id = self.series.get(ID, 0) self.episodes = self.series.get(EPISODES, {}) self.seasonsdict = self.series.get(SEASONSDICT, {}) self.season = self.series.get(SEASON, -1) self.episode = self.series.get(EPISODE, -1) self.manual = self.series.get(MANUALMODE, False) self.specials = self.series.get(SPECIALEPISODES, {}) if self.id and self.episodes and self.season >= 0 and self.episode >= 0: if self.item.renumber: self.config() else: self.renumber() elif self.auto or self.item.renumber: self.episodes = {} self.config() else: self.renumberdict = {} for item in self.itemlist: if item.contentType != 'movie': item.context = [{ "title": typo(config.get_localized_string(70585), 'bold'), "action": "start", "channel": "autorenumber", "from_channel": item.channel, "from_action": item.action }]
def findvideos(item): from core import autoplay logger.info() # logger.debug("item:\n" + item.tostring('\n')) videolibrarytools.check_renumber_options(item) itemlist = [] list_canales = {} item_local = None # Disable autoplay # autoplay.set_status(False) if not item.contentTitle or not item.strm_path: logger.debug("Unable to search for videos due to lack of parameters") return [] content_title = str(item.contentSeason) + 'x' + (str(item.contentEpisodeNumber) if item.contentEpisodeNumber > 9 else '0' + str(item.contentEpisodeNumber)) if item.contentType == 'movie': item.strm_path = filetools.join(videolibrarytools.MOVIES_PATH, item.strm_path) path_dir = filetools.dirname(item.strm_path) item.nfo = filetools.join(path_dir, filetools.basename(path_dir) + ".nfo") else: item.strm_path = filetools.join(videolibrarytools.TVSHOWS_PATH, item.strm_path) path_dir = filetools.dirname(item.strm_path) item.nfo = filetools.join(path_dir, 'tvshow.nfo') for fd in filetools.listdir(path_dir): if fd.endswith('.json'): contenido, nom_canal = fd[:-6].split('[') if (contenido.startswith(content_title) or item.contentType == 'movie') and nom_canal not in list(list_canales.keys()): list_canales[nom_canal] = filetools.join(path_dir, fd) num_canales = len(list_canales) if 'downloads' in list_canales: json_path = list_canales['downloads'] item_json = Item().fromjson(filetools.read(json_path)) item_json.contentChannel = "local" # Support for relative paths in downloads if filetools.is_relative(item_json.url): item_json.url = filetools.join(videolibrarytools.VIDEOLIBRARY_PATH, item_json.url) del list_canales['downloads'] # Check that the video has not been deleted if filetools.exists(item_json.url): item_local = item_json.clone(action='play') itemlist.append(item_local) else: num_canales -= 1 filtro_canal = '' if num_canales > 1 and config.get_setting("ask_channel", "videolibrary"): opciones = [config.get_localized_string(70089) % k.capitalize() for k in list(list_canales.keys())] opciones.insert(0, config.get_localized_string(70083)) if item_local: opciones.append(item_local.title) from platformcode import platformtools index = platformtools.dialog_select(config.get_localized_string(30163), opciones) if index < 0: return [] elif item_local and index == len(opciones) - 1: filtro_canal = 'downloads' platformtools.play_video(item_local) elif index > 0: filtro_canal = opciones[index].replace(config.get_localized_string(70078), "").strip() itemlist = [] for nom_canal, json_path in list(list_canales.items()): if filtro_canal and filtro_canal != nom_canal.capitalize(): continue item_canal = Item() # We import the channel of the selected part try: if nom_canal == 'community': channel = __import__('specials.%s' % nom_canal, fromlist=["channels.%s" % nom_canal]) else: channel = __import__('channels.%s' % nom_canal, fromlist=["channels.%s" % nom_canal]) except ImportError: exec("import channels." + nom_canal + " as channel") item_json = Item().fromjson(filetools.read(json_path)) list_servers = [] # from core.support import dbg;dbg() try: # FILTERTOOLS # if the channel has a filter, the name it has saved is passed to it so that it filters correctly. if "list_language" in item_json: # if it comes from the addon video library if "library_filter_show" in item: item_json.show = item.library_filter_show.get(nom_canal, "") # We run find_videos, from the channel or common item_json.contentChannel = 'videolibrary' item_json.play_from = item.play_from item_json.nfo = item.nfo item_json.strm_path = item.strm_path if hasattr(channel, 'findvideos'): from core import servertools if item_json.videolibray_emergency_urls: del item_json.videolibray_emergency_urls list_servers = getattr(channel, 'findvideos')(item_json) elif item_json.action == 'play': from platformcode import platformtools # autoplay.set_status(True) item_json.contentChannel = item_json.channel item_json.channel = "videolibrary" platformtools.play_video(item_json) return '' else: from core import servertools list_servers = servertools.find_video_items(item_json) except Exception as ex: logger.error("The findvideos function for the channel %s failed" % nom_canal) template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) logger.error(traceback.format_exc()) # Change the title to the servers adding the name of the channel in front and the infoLabels and the images of the item if the server does not have for server in list_servers: server.contentChannel = server.channel server.channel = "videolibrary" server.nfo = item.nfo server.strm_path = item.strm_path server.play_from = item.play_from # Kodi 18 Compatibility - Prevents wheel from spinning around in Direct Links if server.action == 'play': server.folder = False # Channel name is added if desired if config.get_setting("quit_channel_name", "videolibrary") == 0: server.title = "%s: %s" % (nom_canal.capitalize(), server.title) if not server.thumbnail: server.thumbnail = item.thumbnail # logger.debug("server:\n%s" % server.tostring('\n')) itemlist.append(server) if autoplay.play_multi_channel(item, itemlist): # hideserver return [] add_download_items(item, itemlist) return itemlist