diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index fa02080c..af5b1004 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -58,6 +58,7 @@ def scanTvMedia(media): for item in media.seasons[season].episodes[episode].items: for part in item.parts: scannedVideo = scanVideo(part, "episode") + scannedVideo.id = media.seasons[season].episodes[episode].id videos[scannedVideo] = part return videos @@ -66,6 +67,7 @@ def scanMovieMedia(media): for item in media.items: for part in item.parts: scannedVideo = scanVideo(part, "movie") + scannedVideo.id = media.id videos[scannedVideo] = part return videos @@ -166,44 +168,46 @@ def updateLocalMedia(media, media_type="movies"): else: pass -class SubZeroSubtitlesAgentMovies(Agent.Movies): - name = 'Sub-Zero Subtitles (Movies)' + +class SubZeroAgent(object): + agent_type = None languages = [Locale.Language.English] primary_provider = False - contributes_to = ['com.plexapp.agents.imdb', 'com.plexapp.agents.xbmcnfo', 'com.plexapp.agents.themoviedb'] + + def __init__(self, *args, **kwargs): + super(SubZeroAgent, self).__init__(*args, **kwargs) + self.name = "Sub-Zero Subtitles (%s, %s)" % ("Movies" if self.agent_type == "movies" else "TV", config.getVersion()) + self.agent_type = "movies" if isinstance(self, Agent.Movies) else "series" def search(self, results, media, lang): - Log.Debug("MOVIE SEARCH CALLED") + Log.Debug("Sub-Zero %s, %s search" % (config.version, self.agent_type)) results.Append(MetadataSearchResult(id='null', score=100)) def update(self, metadata, media, lang): - Log.Debug("MOVIE UPDATE CALLED") + Log.Debug("Sub-Zero %s, %s update called" % (config.version, self.agent_type)) initSubliminalPatches() + videos, subtitles = getattr(self, "update_%s" % self.agent_type)(metadata, media, lang) + + if subtitles: + saveSubtitles(videos, subtitles) + + updateLocalMedia(media, media_type=self.agent_type) + + def update_movies(self, metadata, media, lang): videos = scanMovieMedia(media) subtitles = downloadBestSubtitles(videos, min_score=int(Prefs["subtitles.search.minimumMovieScore"])) - if subtitles: - saveSubtitles(videos, subtitles) - - updateLocalMedia(media, media_type="movies") + return videos, subtitles -class SubZeroSubtitlesAgentTvShows(Agent.TV_Shows): - - name = 'Sub-Zero Subtitles (TV)' - languages = [Locale.Language.English] - primary_provider = False + def update_series(self, metadata, media, lang): + videos = scanTvMedia(media) + subtitles = downloadBestSubtitles(videos, min_score=int(Prefs["subtitles.search.minimumTVScore"])) + return videos, subtitles + + +class SubZeroSubtitlesAgentMovies(SubZeroAgent, Agent.Movies): + contributes_to = ['com.plexapp.agents.imdb', 'com.plexapp.agents.xbmcnfo', 'com.plexapp.agents.themoviedb'] + + +class SubZeroSubtitlesAgentTvShows(SubZeroAgent, Agent.TV_Shows): contributes_to = ['com.plexapp.agents.thetvdb', 'com.plexapp.agents.thetvdbdvdorder', 'com.plexapp.agents.xbmcnfotv'] - def search(self, results, media, lang): - Log.Debug("TV SEARCH CALLED") - results.Append(MetadataSearchResult(id='null', score=100)) - - def update(self, metadata, media, lang): - Log.Debug("TvUpdate. Lang %s" % lang) - initSubliminalPatches() - videos = scanTvMedia(media) - subtitles = downloadBestSubtitles(videos, min_score=int(Prefs["subtitles.search.minimumTVScore"])) - if subtitles: - saveSubtitles(videos, subtitles) - - updateLocalMedia(media, media_type="series") - diff --git a/Contents/Code/subzero/config.py b/Contents/Code/subzero/config.py index cf5213ac..774e62a1 100644 --- a/Contents/Code/subzero/config.py +++ b/Contents/Code/subzero/config.py @@ -1,24 +1,40 @@ # coding=utf-8 +import os +import re +import inspect from babelfish import Language +from subzero.lib.io import FileIO SUBTITLE_EXTS = ['utf','utf8','utf-8','srt','smi','rt','ssa','aqt','jss','ass','idx','sub','txt', 'psb'] VIDEO_EXTS = ['3g2', '3gp', 'asf', 'asx', 'avc', 'avi', 'avs', 'bivx', 'bup', 'divx', 'dv', 'dvr-ms', 'evo', 'fli', 'flv', 'm2t', 'm2ts', 'm2v', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mts', 'nsv', 'nuv', 'ogm', 'ogv', 'tp', 'pva', 'qt', 'rm', 'rmvb', 'sdp', 'svq3', 'strm', 'ts', 'ty', 'vdr', 'viv', 'vob', 'vp3', 'wmv', 'wpl', 'wtv', 'xsp', 'xvid', 'webm'] +VERSION_RE = re.compile(ur'CFBundleVersion.+?([0-9\.]+)', re.DOTALL) + class Config(object): + version = None langList = None subtitleDestinationFolder = None providers = None providerSettings = None def initialize(self): + self.version = self.getVersion() self.langList = self.getLangList() self.subtitleDestinationFolder = self.getSubtitleDestinationFolder() self.providers = self.getProviders() self.providerSettings = self.getProviderSettings() + def getVersion(self): + curDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + info_file_path = os.path.abspath(os.path.join(curDir, "..", "..", "Info.plist")) + data = FileIO.read(info_file_path) + result = VERSION_RE.search(data) + if result: + return result.group(1) + # Prepare a list of languages we want subs for def getLangList(self): l = {Language.fromietf(Prefs["langPref1"])} diff --git a/Contents/Libraries/Shared/subzero/__init__.py b/Contents/Libraries/Shared/subzero/__init__.py new file mode 100644 index 00000000..e69de29b