def scan_library(self, my_status=None, rescan=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError( 'Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directory is not set.') if not utils.dir_exists(self.config['searchdir']): raise utils.EngineError('The set media directory doesn\'t exist.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: my_status = self.mediainfo['status_start'] self.msg.info(self.name, "Scanning local library...") self.msg.debug(self.name, "Directory: %s" % self.config['searchdir']) tracker_list = self._get_tracker_list(my_status) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos( 'mkv|mp4|avi', self.config['searchdir']): (library, library_cache) = self._add_show_to_library( library, library_cache, rescan, fullpath, filename, tracker_list) self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library
def scan_library(self, my_status=None, rescan=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError('Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directory is not set.') if not utils.dir_exists(self.config['searchdir']): raise utils.EngineError('The set media directory doesn\'t exist.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: if self.config['scan_whole_list']: my_status = self.mediainfo['statuses'] else: my_status = self.mediainfo['status_start'] self.msg.info(self.name, "Scanning local library...") self.msg.debug(self.name, "Directory: %s" % self.config['searchdir']) tracker_list = self._get_tracker_list(my_status) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): (library, library_cache) = self._add_show_to_library(library, library_cache, rescan, fullpath, filename, tracker_list) self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library
def scan_library(self, my_status=None, ignorecache=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError('Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directory is not set.') if not utils.dir_exists(self.config['searchdir']): raise utils.EngineError('The set media directory doesn\'t exist.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: my_status = self.mediainfo['status_start'] self.msg.info(self.name, "Scanning local library...") tracker_list = self._get_tracker_list(my_status) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']): show_id = None if not ignorecache and filename in library_cache.keys(): # 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 = library_cache[filename][0] show_ep = library_cache[filename][1] else: continue 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, show_ep) = (aie.getName(), aie.getEpisode()) if show_title: show = utils.guess_show(show_title, tracker_list) if show: show_id = show['id'] library_cache[filename] = (show['id'], show_ep) else: library_cache[filename] = None else: library_cache[filename] = None # After we got our information, add it to our library if show_id: if show_id not in library.keys(): library[show_id] = {} library[show_id][show_ep] = fullpath self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library
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 scan_library(self, my_status=None, rescan=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError( 'Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directories not set.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: if self.config['scan_whole_list']: my_status = self.mediainfo['statuses'] else: my_status = self.mediainfo.get( 'statuses_library', self.mediainfo['statuses_start']) if rescan: self.msg.info(self.name, "Scanning local library (overriding cache)...") else: self.msg.info(self.name, "Scanning local library...") tracker_list = self._get_tracker_list(my_status) for searchdir in self.searchdirs: self.msg.debug(self.name, "Directory: %s" % searchdir) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos(searchdir): if self.config['library_full_path']: filename = self._get_show_name_from_full_path( searchdir, fullpath).strip() (library, library_cache) = self._add_show_to_library( library, library_cache, rescan, fullpath, filename, tracker_list) self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library
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 scan_library(self, my_status=None, rescan=False): # Check if operation is supported by the API if not self.mediainfo.get('can_play'): raise utils.EngineError('Operation not supported by current site or mediatype.') if not self.config['searchdir']: raise utils.EngineError('Media directories not set.') t = time.time() library = {} library_cache = self.data_handler.library_cache_get() if not my_status: if self.config['scan_whole_list']: my_status = self.mediainfo['statuses'] else: my_status = self.mediainfo.get('statuses_library', self.mediainfo['statuses_start']) if rescan: self.msg.info(self.name, "Scanning local library (overriding cache)...") else: self.msg.info(self.name, "Scanning local library...") tracker_list = self._get_tracker_list(my_status) for searchdir in self.searchdirs: self.msg.debug(self.name, "Directory: %s" % searchdir) # Do a full listing of the media directory for fullpath, filename in utils.regex_find_videos(searchdir): if self.config['library_full_path']: filename = self._get_show_name_from_full_path(searchdir, fullpath).strip() (library, library_cache) = self._add_show_to_library(library, library_cache, rescan, fullpath, filename, tracker_list) self.msg.debug(self.name, "Time: %s" % (time.time() - t)) self.data_handler.library_save(library) self.data_handler.library_cache_save(library_cache) return library