def _add_show_to_library(self, library, library_cache, rescan, fullpath, filename, tracker_list): show_id = None if not rescan and filename in library_cache: # If the filename was already seen before # use the cached information, if there's no information (None) # then it means it doesn't correspond to any show in the list # and can be safely skipped. if library_cache[filename]: (show_id, show_ep) = library_cache[filename] if type(show_ep) is tuple: (show_ep_start, show_ep_end) = show_ep else: show_ep_start = show_ep_end = show_ep self.msg.debug(self.name, "File in cache: {}".format(fullpath)) else: self.msg.debug(self.name, "File in cache but skipped: {}".format(fullpath)) return library, library_cache else: # If the filename has not been seen, extract # the information from the filename and do a fuzzy search # on the user's list. Cache the information. # If it fails, cache it as None. aie = AnimeInfoExtractor(filename) show_title = aie.getName() (show_ep_start, show_ep_end) = aie.getEpisodeNumbers(True) if show_title: show = utils.guess_show(show_title, tracker_list) if show: self.msg.debug(self.name, "Adding to library: {}".format(fullpath)) if show_ep_start == show_ep_end: # TODO : Support redirections for episode ranges (show, show_ep) = utils.redirect_show((show, show_ep_start), self.redirections, tracker_list) show_ep_end = show_ep_start = show_ep self.msg.debug(self.name, "Redirected to {} {}".format(show['title'], show_ep)) library_cache[filename] = (show['id'], show_ep) else: library_cache[filename] = (show['id'], (show_ep_start, show_ep_end)) show_id = show['id'] else: self.msg.debug(self.name, "Not a show, skipping: {}".format(fullpath)) library_cache[filename] = None else: self.msg.debug(self.name, "Not recognized, skipping: {}".format(fullpath)) library_cache[filename] = None # After we got our information, add it to our library if show_id: if show_id not in library: library[show_id] = {} for show_ep in range(show_ep_start, show_ep_end+1): library[show_id][show_ep] = fullpath return library, library_cache
def _get_playing_show(self, filename): if not self.active: # Don't do anything if the Tracker is disabled return (utils.TRACKER_NOVIDEO, None) if filename: self.msg.debug(self.name, "Guessing filename: {}".format(filename)) # Trim out watch dir if os.path.isabs(filename): for watch_prefix in self.watch_dirs: if filename.startswith(watch_prefix): filename = filename[len(watch_prefix):] if filename.startswith(os.path.sep): filename = filename[len(os.path.sep):] break if filename == self.last_filename: # It's the exact same filename, there's no need to do the processing again self.msg.debug(self.name, "Same filename as before. Skipping.") return (self.last_state, self.last_show_tuple) self.last_filename = filename # Do a regex to the filename to get # the show title and episode number aie = AnimeInfoExtractor(filename) (show_title, show_ep) = (aie.getName(), aie.getEpisode()) if not show_title: # Format not recognized return (utils.TRACKER_UNRECOGNIZED, None) playing_show = utils.guess_show(show_title, self.list) self.msg.debug( self.name, "Show guess: {}: {}".format(show_title, playing_show)) if playing_show: (playing_show, show_ep) = utils.redirect_show( (playing_show, show_ep), self.redirections, self.list) return (utils.TRACKER_PLAYING, (playing_show, show_ep)) else: # Show not in list if self.config['tracker_not_found_prompt']: # Dummy show to search for show = {'id': 0, 'title': show_title} return (utils.TRACKER_NOT_FOUND, (show, show_ep)) else: return (utils.TRACKER_NOT_FOUND, None) else: self.last_filename = None return (utils.TRACKER_NOVIDEO, None) # Not playing
def _get_playing_show(self, filename): if not self.active: # Don't do anything if the Tracker is disabled return (utils.TRACKER_NOVIDEO, None) if filename: self.msg.debug(self.name, "Guessing filename: {}".format(filename)) # Trim out watch dir if os.path.isabs(filename): for watch_prefix in self.watch_dirs: if filename.startswith(watch_prefix): filename = filename[len(watch_prefix):] if filename.startswith(os.path.sep): filename = filename[len(os.path.sep):] break if filename == self.last_filename: # It's the exact same filename, there's no need to do the processing again return (self.last_state, self.last_show_tuple) self.last_filename = filename # Do a regex to the filename to get # the show title and episode number aie = AnimeInfoExtractor(filename) (show_title, show_ep) = (aie.getName(), aie.getEpisode()) if not show_title: return (utils.TRACKER_UNRECOGNIZED, None) # Format not recognized playing_show = utils.guess_show(show_title, self.list) if playing_show: (playing_show, show_ep) = utils.redirect_show((playing_show, show_ep), self.redirections, self.list) return (utils.TRACKER_PLAYING, (playing_show, show_ep)) else: # Show not in list if self.config['tracker_not_found_prompt']: # Dummy show to search for show = {'id': 0, 'title': show_title} return (utils.TRACKER_NOT_FOUND, (show, show_ep)) else: return (utils.TRACKER_NOT_FOUND, None) else: self.last_filename = None return (utils.TRACKER_NOVIDEO, None) # Not playing
def get_show_info(self, showid=None, title=None, filename=None): """ Returns the show dictionary for the specified **showid**. """ showdict = self.data_handler.get() if showid: # Get show by ID try: return showdict[showid] except KeyError: raise utils.EngineError("Show not found.") elif title: showdict = self.data_handler.get() # Get show by title, slower for show in showdict.values(): if show['title'] == title: return show raise utils.EngineError("Show not found.") elif filename: # Guess show by filename self.msg.debug(self.name, "Guessing by filename.") aie = AnimeInfoExtractor(filename) (show_title, ep) = aie.getName(), aie.getEpisode() self.msg.debug(self.name, "Guessed {}".format(show_title)) if show_title: tracker_list = self._get_tracker_list() show = utils.guess_show(show_title, tracker_list) if show: return utils.redirect_show((show, ep), self.redirections, tracker_list) else: raise utils.EngineError("Show not found.") else: raise utils.EngineError("File name not recognized.")
def _add_show_to_library(self, library, library_cache, rescan, fullpath, filename, tracker_list): show_id = None if not rescan and filename in library_cache: # If the filename was already seen before # use the cached information, if there's no information (None) # then it means it doesn't correspond to any show in the list # and can be safely skipped. if library_cache[filename]: (show_id, show_ep) = library_cache[filename] if type(show_ep) is tuple: (show_ep_start, show_ep_end) = show_ep else: show_ep_start = show_ep_end = show_ep self.msg.debug(self.name, "File in cache: {}".format(fullpath)) else: self.msg.debug( self.name, "File in cache but skipped: {}".format(fullpath)) return library, library_cache else: # If the filename has not been seen, extract # the information from the filename and do a fuzzy search # on the user's list. Cache the information. # If it fails, cache it as None. aie = AnimeInfoExtractor(filename) show_title = aie.getName() (show_ep_start, show_ep_end) = aie.getEpisodeNumbers(True) if show_title: show = utils.guess_show(show_title, tracker_list) if show: self.msg.debug( self.name, "Adding to library: {}".format(fullpath)) if show_ep_start == show_ep_end: # TODO : Support redirections for episode ranges (show, show_ep) = utils.redirect_show( (show, show_ep_start), self.redirections, tracker_list) show_ep_end = show_ep_start = show_ep self.msg.debug(self.name, "Redirected to {} {}".format( show['title'], show_ep)) library_cache[filename] = (show['id'], show_ep) else: library_cache[filename] = ( show['id'], (show_ep_start, show_ep_end)) show_id = show['id'] else: self.msg.debug( self.name, "Not a show, skipping: {}".format(fullpath)) library_cache[filename] = None else: self.msg.debug( self.name, "Not recognized, skipping: {}".format(fullpath)) library_cache[filename] = None # After we got our information, add it to our library if show_id: if show_id not in library: library[show_id] = {} for show_ep in range(show_ep_start, show_ep_end+1): library[show_id][show_ep] = fullpath return library, library_cache