def movieInfo(guessData, tmdbid=None, imdbid=None, language=None, original=None): if not tmdbid and not imdbid: tmdb.API_KEY = tmdb_api_key search = tmdb.Search() title = guessData['title'] if 'year' in guessData: response = search.movie(query=title, year=guessData["year"]) if len(search.results) < 1: response = search.movie(query=title, year=guessData["year"]) else: response = search.movie(query=title) if len(search.results) < 1: return None result = search.results[0] release = result['release_date'] tmdbid = result['id'] log.debug("Guessed filename resulted in TMDB ID %s" % tmdbid) metadata = Metadata(MediaType.Movie, tmdbid=tmdbid, imdbid=imdbid, language=language, logger=log, original=original) log.info("Matched movie title as: %s %s (TMDB ID: %s)" % (metadata.title, metadata.date, metadata.tmdbid)) return metadata
def getInfo(fileName=None, silent=False, tag=True, tvdbid=None, tmdbid=None, imdbid=None, season=None, episode=None, language=None, original=None): if not tag: return None tagdata = None # Try to guess the file is guessing is enabled if fileName is not None: tagdata = guessInfo(fileName, tvdbid=tvdbid, tmdbid=tmdbid, imdbid=imdbid, season=season, episode=episode, language=language, original=original) if not silent: if tagdata: print("Proceed using guessed identification from filename?") if getYesNo(): return tagdata else: print("Unable to determine identity based on filename, must enter manually") m_type = mediatype() if m_type is MediaTypes.TV_TMDB: tmdbid = getValue("Enter TMDB ID (TV)", True) season = getValue("Enter Season Number", True) episode = getValue("Enter Episode Number", True) return Metadata(MediaType.TV, tmdbid=tmdbid, season=season, episode=episode, language=language, logger=log, original=original) if m_type is MediaTypes.TV_TVDB: tvdbid = getValue("Enter TVDB ID (TV)", True) season = getValue("Enter Season Number", True) episode = getValue("Enter Episode Number", True) return Metadata(MediaType.TV, tvdbid=tvdbid, season=season, episode=episode, language=language, logger=log, original=original) if m_type is MediaTypes.TV_IMDB: imdbid = getValue("Enter IMDB ID (TV)", True) season = getValue("Enter Season Number", True) episode = getValue("Enter Episode Number", True) return Metadata(MediaType.TV, imdbid=imdbid, season=season, episode=episode, language=language, logger=log, original=original) elif m_type is MediaTypes.MOVIE_IMDB: imdbid = getValue("Enter IMDB ID (Movie)") return Metadata(MediaType.Movie, imdbid=imdbid, language=language, logger=log, original=original) elif m_type is MediaTypes.MOVIE_TMDB: tmdbid = getValue("Enter TMDB ID (Movie)", True) return Metadata(MediaType.Movie, tmdbid=tmdbid, language=language, logger=log, original=original) elif m_type is MediaTypes.CONVERT: return None elif m_type is MediaTypes.SKIP: raise SkipFileException else: if tagdata and tag: return tagdata else: return None
def processFile(inputfile, mp, info=None, relativePath=None, silent=False, tag=True, tmdbid=None, tvdbid=None, imdbid=None, season=None, episode=None, original=None, processedList=None, processedArchive=None): if checkAlreadyProcessed(inputfile, processedList): log.debug("%s is already processed and will be skipped based on archive %s." % (inputfile, processedArchive)) return # Process info = info or mp.isValidSource(inputfile) if not info: log.debug("Invalid file %s." % inputfile) return language = mp.settings.taglanguage or None tagdata = getInfo(inputfile, mp.settings, silent=silent, tag=tag, tmdbid=tmdbid, tvdbid=tvdbid, imdbid=imdbid, season=season, episode=episode, language=language, original=original) if not tagdata: log.info("Processing file %s" % inputfile) elif tagdata.mediatype == MediaType.Movie: log.info("Processing %s" % (tagdata.title)) elif tagdata.mediatype == MediaType.TV: log.info("Processing %s Season %02d Episode %02d - %s" % (tagdata.showname, int(tagdata.season), int(tagdata.episode), tagdata.title)) output = mp.process(inputfile, True, info=info, original=original, tagdata=tagdata) if output: if not language: language = mp.getDefaultAudioLanguage(output["options"]) or None if language and tagdata: tagdata = Metadata(tagdata.mediatype, tmdbid=tagdata.tmdbid, imdbid=tagdata.imdbid, tvdbid=tagdata.tvdbid, season=tagdata.season, episode=tagdata.episode, original=original, language=language, logger=log) log.debug("Tag language setting is %s, using language %s for tagging." % (mp.settings.taglanguage or None, language)) tagfailed = False if tagdata: try: tagdata.writeTags(output['output'], mp.converter, mp.settings.artwork, mp.settings.thumbnail, width=output['x'], height=output['y'], streaming=output['rsi']) except KeyboardInterrupt: raise except: log.exception("There was an error tagging the file") tagfailed = True if mp.settings.relocate_moov and not tagfailed: mp.QTFS(output['output']) output_files = mp.replicate(output['output'], relativePath=relativePath) print(json.dumps(output, indent=4)) for sub in output['external_subs']: output_files.extend(mp.replicate(sub, relativePath=relativePath)) for file in output_files: mp.setPermissions(file) if mp.settings.postprocess: postprocessor = PostProcessor(output_files, wait=mp.settings.waitpostprocess) if tagdata: if tagdata.mediatype == MediaType.Movie: postprocessor.setMovie(tagdata.tmdbid) elif tagdata.mediatype == MediaType.TV: postprocessor.setTV(tagdata.tmdbid, tagdata.season, tagdata.episode) postprocessor.run_scripts() addtoProcessedArchive(output_files + [output['input']] if not output['input_deleted'] else output_files, processedList, processedArchive) else: log.error("There was an error processing file %s, no output data received" % inputfile)
def tvInfo(guessData, tmdbid=None, tvdbid=None, imdbid=None, season=None, episode=None, language=None, original=None): season = season or guessData["season"] episode = episode or guessData["episode"] if not tmdbid and not tvdbid and not imdbid: tmdb.API_KEY = tmdb_api_key search = tmdb.Search() series = guessData["title"] if 'year' in guessData: response = search.tv(query=series, first_air_date_year=guessData["year"]) if len(search.results) < 1: response = search.tv(query=series) else: response = search.tv(query=series) if len(search.results) < 1: return None result = search.results[0] tmdbid = result['id'] metadata = Metadata(MediaType.TV, tmdbid=tmdbid, imdbid=imdbid, tvdbid=tvdbid, season=season, episode=episode, language=language, logger=log, original=original) log.info( "Matched TV episode as %s (TMDB ID: %d) S%02dE%02d" % (metadata.showname, int(metadata.tmdbid), int(season), int(episode))) return metadata
def processFile(inputfile, mp, info=None, relativePath=None, silent=False, tag=True, tmdbid=None, tvdbid=None, imdbid=None, season=None, episode=None, original=None): # Process info = info or mp.isValidSource(inputfile) if not info: log.debug("Invalid file %s." % inputfile) return language = settings.taglanguage or None tagdata = getInfo(inputfile, silent, tag=tag, tmdbid=tmdbid, tvdbid=tvdbid, imdbid=imdbid, season=season, episode=episode, language=language, original=original) if not tagdata: log.info("Processing file %s" % inputfile) elif tagdata.mediatype == MediaType.Movie: log.info("Processing %s" % (tagdata.title)) elif tagdata.mediatype == MediaType.TV: log.info("Processing %s Season %02d Episode %02d - %s" % (tagdata.showname, int(tagdata.season), int( tagdata.episode), tagdata.title)) output = mp.process(inputfile, True, info=info, original=original, tagdata=tagdata) if output: if not language: language = mp.getDefaultAudioLanguage(output["options"]) or None if language and tagdata: tagdata = Metadata(tagdata.mediatype, tmdbid=tagdata.tmdbid, imdbid=tagdata.imdbid, tvdbid=tagdata.tvdbid, season=tagdata.season, episode=tagdata.episode, original=original, language=language, logger=log) log.debug( "Tag language setting is %s, using language %s for tagging." % (settings.taglanguage or None, language)) tagfailed = False if tagdata: try: tagdata.writeTags(output['output'], mp.converter, settings.artwork, settings.thumbnail, width=output['x'], height=output['y']) except: log.exception("There was an error tagging the file") tagfailed = True if settings.relocate_moov and not tagfailed: mp.QTFS(output['output']) output_files = mp.replicate(output['output'], relativePath=relativePath) for file in output_files: mp.setPermissions(file) if settings.postprocess: postprocessor = PostProcessor(output_files, wait=settings.waitpostprocess) if tagdata: if tagdata.mediatype == MediaType.Movie: postprocessor.setMovie(tagdata.tmdbid) elif tagdata.mediatype == MediaType.TV: postprocessor.setTV(tagdata.tmdbid, tagdata.season, tagdata.episode) postprocessor.run_scripts() else: log.error( "There was an error processing file %s, no output data received" % inputfile)