def update(self, metadata, media, lang): if not config.enable_agent: Log.Debug("Skipping Sub-Zero agent(s)") return Log.Debug("Sub-Zero %s, %s update called" % (config.version, self.agent_type)) intent = get_intent() if not media: Log.Error( "Called with empty media, something is really wrong with your setup!" ) return item_ids = [] try: config.init_subliminal_patches() videos = media_to_videos(media, kind=self.agent_type) # find local media update_local_media(metadata, media, media_type=self.agent_type) # media ignored? use_any_parts = False for video in videos: if is_ignored(video["id"]): Log.Debug(u"Ignoring %s" % video) continue use_any_parts = True if not use_any_parts: Log.Debug(u"Nothing to do.") return try: use_score = int(Prefs[self.score_prefs_key].strip()) except ValueError: Log.Error( "Please only put numbers into the scores setting. Exiting") return set_refresh_menu_state(media, media_type=self.agent_type) # scanned_video_part_map = {subliminal.Video: plex_part, ...} providers = config.get_providers(media_type=self.agent_type) scanned_video_part_map = scan_videos(videos, providers=providers) # auto extract embedded if config.embedded_auto_extract: agent_extract_embedded(videos) # clear missing subtitles menu data if not scheduler.is_task_running("MissingSubtitles"): scheduler.clear_task_data("MissingSubtitles") downloaded_subtitles = None # debounce for self.debounce seconds now = datetime.datetime.now() if "last_call" in Dict: last_call = Dict["last_call"] if last_call + datetime.timedelta(seconds=self.debounce) > now: wait = self.debounce - (now - last_call).seconds if wait >= 1: Log.Debug("Waiting %s seconds until continuing", wait) Thread.Sleep(wait) # downloaded_subtitles = {subliminal.Video: [subtitle, subtitle, ...]} try: downloaded_subtitles = download_best_subtitles( scanned_video_part_map, min_score=use_score, throttle_time=self.debounce, providers=providers) except: Log.Exception( "Something went wrong when downloading subtitles") if downloaded_subtitles is not None: Dict["last_call"] = datetime.datetime.now() item_ids = get_media_item_ids(media, kind=self.agent_type) downloaded_any = False if downloaded_subtitles: downloaded_any = any(downloaded_subtitles.values()) if downloaded_any: save_successful = False try: save_successful = save_subtitles(scanned_video_part_map, downloaded_subtitles, mods=config.default_mods) except: Log.Exception("Something went wrong when saving subtitles") track_usage("Subtitle", "refreshed", "download", 1) # store SZ meta info even if download wasn't successful if not save_successful: self.store_blank_subtitle_metadata(scanned_video_part_map) else: for video, video_subtitles in downloaded_subtitles.items(): # store item(s) in history for subtitle in video_subtitles: item_title = get_title_for_video_metadata( video.plexapi_metadata, add_section_title=False) history = get_history() history.add(item_title, video.id, section_title=video. plexapi_metadata["section"], subtitle=subtitle) history.destroy() else: # store SZ meta info even if we've downloaded none self.store_blank_subtitle_metadata(scanned_video_part_map) update_local_media(metadata, media, media_type=self.agent_type) finally: # update the menu state set_refresh_menu_state(None) # notify any running tasks about our finished update for item_id in item_ids: #scheduler.signal("updated_metadata", item_id) # resolve existing intent for that id intent.resolve("force", item_id) Dict.Save() # fsync cache if config.new_style_cache: config.sync_cache()
finally: # update the menu state set_refresh_menu_state(None) # notify any running tasks about our finished update for item_id in item_ids: #scheduler.signal("updated_metadata", item_id) # resolve existing intent for that id intent.resolve("force", item_id) Dict.Save() # fsync cache if config.new_style_cache: config.sync_cache() class SubZeroSubtitlesAgentMovies(SubZeroAgent, Agent.Movies): contributes_to = [ 'com.plexapp.agents.imdb', 'com.plexapp.agents.xbmcnfo', 'com.plexapp.agents.themoviedb', 'com.plexapp.agents.hama' ] score_prefs_key = "subtitles.search.minimumMovieScore2" agent_type_verbose = "Movies" class SubZeroSubtitlesAgentTvShows(SubZeroAgent, Agent.TV_Shows): contributes_to = [ 'com.plexapp.agents.thetvdb', 'com.plexapp.agents.themoviedb', 'com.plexapp.agents.thetvdbdvdorder', 'com.plexapp.agents.xbmcnfotv',
finally: # update the menu state set_refresh_menu_state(None) # notify any running tasks about our finished update for item_id in item_ids: #scheduler.signal("updated_metadata", item_id) # resolve existing intent for that id intent.resolve("force", item_id) Dict.Save() # fsync cache if config.new_style_cache: config.sync_cache() class SubZeroSubtitlesAgentMovies(SubZeroAgent, Agent.Movies): contributes_to = ['com.plexapp.agents.imdb', 'com.plexapp.agents.xbmcnfo', 'com.plexapp.agents.themoviedb', 'com.plexapp.agents.hama'] score_prefs_key = "subtitles.search.minimumMovieScore2" agent_type_verbose = "Movies" class SubZeroSubtitlesAgentTvShows(SubZeroAgent, Agent.TV_Shows): contributes_to = ['com.plexapp.agents.thetvdb', 'com.plexapp.agents.themoviedb', 'com.plexapp.agents.thetvdbdvdorder', 'com.plexapp.agents.xbmcnfotv', 'com.plexapp.agents.hama'] score_prefs_key = "subtitles.search.minimumTVScore2" agent_type_verbose = "TV"