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)) show_id = show['id'] if show_ep_start == show_ep_end: library_cache[filename] = (show['id'], show_ep_start) else: library_cache[filename] = (show['id'], (show_ep_start, show_ep_end)) 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 _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 _search_video(self, titles, episode): # DEPRECATED !!! self.msg.debug(self.name, "DEPRECATED: _search_video") best_candidate = (None, 0, None) matcher = difflib.SequenceMatcher() # Check over video files and propose our best candidate for (fullpath, filename) in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): # Analyze what's the title and episode of the file aie = AnimeInfoExtractor(filename) candidate_title = aie.getName() candidate_episode_start, candidate_episode_end = aie.getEpisodeNumbers( ) # Skip this file if we couldn't analyze it if not candidate_title: continue if candidate_episode_start is None: continue # Skip this file if it isn't the episode we want if candidate_episode_end is None: if episode != candidate_episode_start: continue else: if not (candidate_episode_start <= episode <= candidate_episode_end): continue matcher.set_seq1(candidate_title.lower()) # We remember to compare all titles (aliases and whatnot) for requested_title in titles: matcher.set_seq2(requested_title.lower()) ratio = matcher.ratio() # Propose as our new candidate if its ratio is # better than threshold and it's better than # what we've seen yet if ratio > 0.7 and ratio > best_candidate[1]: best_candidate = (fullpath, ratio, aie.getEpisode()) return best_candidate[0], best_candidate[2]
def _search_video(self, titles, episode): # DEPRECATED !!! self.msg.debug(self.name, "DEPRECATED: _search_video") best_candidate = (None, 0, None) matcher = difflib.SequenceMatcher() # Check over video files and propose our best candidate for (fullpath, filename) in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): # Analyze what's the title and episode of the file aie = AnimeInfoExtractor(filename) candidate_title = aie.getName() candidate_episode_start, candidate_episode_end = aie.getEpisodeNumbers() # Skip this file if we couldn't analyze it if not candidate_title: continue if candidate_episode_start is None: continue # Skip this file if it isn't the episode we want if candidate_episode_end is None: if episode != candidate_episode_start: continue else: if not (candidate_episode_start <= episode <= candidate_episode_end): continue matcher.set_seq1(candidate_title.lower()) # We remember to compare all titles (aliases and whatnot) for requested_title in titles: matcher.set_seq2(requested_title.lower()) ratio = matcher.ratio() # Propose as our new candidate if its ratio is # better than threshold and it's better than # what we've seen yet if ratio > 0.7 and ratio > best_candidate[1]: best_candidate = (fullpath, ratio, aie.getEpisode()) return best_candidate[0], best_candidate[2]