def processFile(inputfile, tagdata, stop_event, relativePath=None): # Gather tagdata if tagdata is False: return # This means the user has elected to skip the file elif tagdata is None: tagmp4 = None # No tag data specified but convert the file anyway elif tagdata[0] is 1: imdbid = tagdata[1] tagmp4 = tmdb_mp4(imdbid, language=settings.taglanguage, logger=log) try: print("Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))) except: print("Processing movie") elif tagdata[0] is 2: tmdbid = tagdata[1] tagmp4 = tmdb_mp4(tmdbid, True, language=settings.taglanguage, logger=log) try: print("Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))) except: print("Processing movie") elif tagdata[0] is 3: tvdbid = int(tagdata[1]) season = int(tagdata[2]) episode = int(tagdata[3]) tagmp4 = Tvdb_mp4(tvdbid, season, episode, language=settings.taglanguage, logger=log) try: print("Processing %s Season %02d Episode %02d - %s" % (tagmp4.show.encode(sys.stdout.encoding, errors='ignore'), int(tagmp4.season), int(tagmp4.episode), tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))) except: print("Processing TV episode") # Process if MkvtoMp4(settings, logger=log).validSource(inputfile): converter = MkvtoMp4(settings, logger=log) output = converter.process(inputfile, stop_event, True) if output: if tagmp4 is not None: try: tagmp4.setHD(output['x'], output['y']) tagmp4.writeTags(output['output'], settings.artwork, settings.thumbnail) except Exception as e: print("There was an error tagging the file") print(e) if settings.relocate_moov: converter.QTFS(output['output']) output_files = converter.replicate(output['output'], relativePath=relativePath) if settings.postprocess: post_processor = PostProcessor(output_files) if tagdata: if tagdata[0] is 1: post_processor.setMovie(tagdata[1]) elif tagdata[0] is 2: post_processor.setMovie(tagdata[1]) elif tagdata[0] is 3: post_processor.setTV(tagdata[1], tagdata[2], tagdata[3]) post_processor.run_scripts() print("Conversion Successful. File: %s" % (output))
def processFile(inputfile, tagdata, converter, info=None, relativePath=None): # Process info = info if info else converter.isValidSource(inputfile) if not info: return # Gather tagdata if tagdata is False: return # This means the user has elected to skip the file elif tagdata is None: tagmp4 = None # No tag data specified but convert the file anyway elif tagdata[0] == 1: imdbid = tagdata[1] tagmp4 = tmdb_mp4(imdbid, language=settings.taglanguage, logger=log) safePrint("Processing %s" % (tagmp4.title)) elif tagdata[0] == 2: tmdbid = tagdata[1] tagmp4 = tmdb_mp4(tmdbid, True, language=settings.taglanguage, logger=log) safePrint("Processing %s" % (tagmp4.title)) elif tagdata[0] == 3: tvdbid = int(tagdata[1]) season = int(tagdata[2]) episode = int(tagdata[3]) tagmp4 = Tvdb_mp4(tvdbid, season, episode, language=settings.taglanguage, logger=log, tmdbid=True) safePrint("Processing %s Season %02d Episode %02d - %s" % (tagmp4.show, int(tagmp4.season), int(tagmp4.episode), tagmp4.title)) elif tagdata[0] == 4: tagNfoFile = tagdata[1] tree = tagdata[2] tagmp4 = home_mp4(tagNfoFile, tree, logger=log) safePrint("Processing %s" % (tagmp4.title)) output = converter.process(inputfile, True) if output: if tagmp4 is not None and output['output_extension'] in valid_tagging_extensions: try: tagmp4.setHD(output['x'], output['y']) tagmp4.writeTags(output['output'], settings.artwork, settings.thumbnail) except Exception as e: log.exception("There was an error tagging the file") print("There was an error tagging the file") print(e) if settings.relocate_moov and output['output_extension'] in valid_tagging_extensions: converter.QTFS(output['output']) output_files = converter.replicate(output['output'], relativePath=relativePath) if settings.postprocess: post_processor = PostProcessor(output_files) if tagdata: if tagdata[0] == 1: post_processor.setMovie(tagdata[1]) elif tagdata[0] == 2: post_processor.setMovie(tagdata[1]) elif tagdata[0] == 3: post_processor.setTV(tagdata[1], tagdata[2], tagdata[3]) post_processor.run_scripts() else: log.error("File is not in the correct format")
def processFile(inputfile, tagdata, relativePath=None): # Gather tagdata if tagdata is False: return # This means the user has elected to skip the file elif tagdata is None: tagmp4 = None # No tag data specified but convert the file anyway elif tagdata[0] is 1: imdbid = tagdata[1] tagmp4 = tmdb_mp4(imdbid, language=settings.taglanguage) try: print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore')) except: print "Processing movie" elif tagdata[0] is 2: tmdbid = tagdata[1] tagmp4 = tmdb_mp4(tmdbid, True, language=settings.taglanguage) try: print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore')) except: print "Processing movie" elif tagdata[0] is 3: tvdbid = int(tagdata[1]) season = int(tagdata[2]) episode = int(tagdata[3]) tagmp4 = Tvdb_mp4(tvdbid, season, episode, language=settings.taglanguage) try: print "Processing %s Season %02d Episode %02d - %s" % ( tagmp4.show.encode(sys.stdout.encoding, errors='ignore'), int(tagmp4.season), int(tagmp4.episode), tagmp4.title.encode(sys.stdout.encoding, errors='ignore')) except: print "Processing TV episode" # Process try: inputfile = inputfile.encode(locale.getpreferredencoding()) except: raise Exception, "File contains an unknown character that cannot be handled by under Python in your operating system, please rename the file" if MkvtoMp4(settings).validSource(inputfile): converter = MkvtoMp4(settings) output = converter.process(inputfile, True) if tagmp4 is not None: try: tagmp4.setHD(output['x'], output['y']) tagmp4.writeTags(output['output'], settings.artwork) except: print "There was an error tagging the file" if settings.relocate_moov: converter.QTFS(output['output']) converter.replicate(output['output'], relativePath=relativePath)
def getTagData(filename, args=None): if args is None: args = vars(parser.parse_args()) tagdata = None tagmp4 = None provid = None if settings.tagfile: log.info(">>> Fetching metadata ...") lang = processor.getPrimaryLanguage(filename) searcher.language = lang[0] settings.taglanguage = lang[0] log.debug( "Auto-selected tagging language %s based on first audio stream" % lang[1]) # Gather tagdata if args is not None: log.debug("Tagging: Args") if (args['tvdbid'] and not (args['imdbid'] or args['tmdbid'])): provid = int(args['tvdbid']) if args['tvdbid'] else None season = int(args['season']) if args['season'] else None episode = int(args['episode']) if args['episode'] else None if (provid and season and episode): log.debug("TvDB show data found in arguments") tagdata = { 'type': 3, 'provid': provid, 'season': season, 'episode': episode } elif ((args['imdbid'] or args['tmdbid']) and not args['tvdbid']): if (args['imdbid']): log.debug("IMDB movie data found in arguments") provid = args['imdbid'] tagdata = {'type': 1, 'provid': provid} elif (args['tmdbid']): log.debug("TMDB movie data found in arguments") provid = int(args['tmdbid']) tagdata = {'type': 2, 'provid': provid} #if args is None or tagdata is None: tagdata = getinfo(filename, silent=args['auto'], tagdata=tagdata) # False if user skipped tagging if tagdata is not False: if tagdata is not None: # Evaluate appropriate MP4 handler try: if tagdata['type'] is 1: imdbid = tagdata['provid'] tagmp4 = tmdb_mp4(imdbid, settings=settings, language=lang[0], guessData=tagdata['guess']) elif tagdata['type'] is 2: tmdbid = tagdata['provid'] tagmp4 = tmdb_mp4(tmdbid, True, settings=settings, language=lang[0], guessData=tagdata['guess']) elif tagdata['type'] is 3: tvdbid = int(tagdata['provid']) season = int(tagdata['season']) episode = int(tagdata['episode']) tagmp4 = Tvdb_mp4(tvdbid, season, episode, settings=settings, language=lang[0], guessData=tagdata['guess']) except Exception as e: log.exception(e) tagmp4 = None if tagmp4 is None: if settings.meks_tagmandatory: log.error( "Unknown metadata received and tagging is mandatory, abort" ) tagdata = False else: log.warning( "Unknown metadata received, file will not be tagged") else: log.debug("Tagging is disabled") return [tagdata, tagmp4]
log.debug("Season: %s episode: %s." % (season, episode)) if MkvtoMp4(settings).validSource(inputfile): log.info("Processing %s." % inputfile) output = converter.process(inputfile, original=original) if output: # Tag with metadata if settings.tagfile: log.info("Tagging %s with ID %s season %s episode %s." % (inputfile, tvdb_id, season, episode)) try: tagmp4 = Tvdb_mp4(tvdb_id, season, episode, original, language=settings.taglanguage) tagmp4.setHD(output['x'], output['y']) tagmp4.writeTags(output['output'], settings.artwork, settings.thumbnail) except: log.error("Unable to tag file") # QTFS if settings.relocate_moov: converter.QTFS(output['output']) # Copy to additional locations output_files = converter.replicate(output['output'])
settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini") if len(sys.argv) > 4: inputfile = sys.argv[1] original = sys.argv[2] tvdb_id = int(sys.argv[3]) season = int(sys.argv[4]) episode = int(sys.argv[5]) converter = MkvtoMp4(settings) if MkvtoMp4(settings).validSource(inputfile): output = converter.process(inputfile, original=original) # Tag with metadata if settings.tagfile: tagmp4 = Tvdb_mp4(tvdb_id, season, episode, original) tagmp4.setHD(output['x'], output['y']) tagmp4.writeTags(output['output'], settings.artwork) #QTFS if settings.relocate_moov: converter.QTFS(output['output']) # Copy to additional locations converter.replicate(output['output']) try: refresh = json.load(urllib.urlopen(settings.getRefreshURL(tvdb_id))) for item in refresh: print refresh[item] except IOError:
iOS=settings.iOS, awl=settings.awl, swl=settings.swl, adl=settings.adl, sdl=settings.sdl, audio_codec=settings.acodec) if extension not in valid_output_extensions: path = convert.output try: refresh = json.load(urllib.urlopen( settings.getRefreshURL(tvdb_id))) for item in refresh: print refresh[item] except IOError: print "Couldn't refresh Sickbeard, check your settings" tagmp4 = Tvdb_mp4(tvdb_id, season, episode) tagmp4.setHD(convert.width, convert.height) tagmp4.writeTags(path) if settings.output_dir is not None: output = os.path.join(settings.output_dir, os.path.split(path)[1]) if extension in valid_output_extensions and settings.delete is False: # If the file is already in a valid format, this will duplicate the file in the output directory since no original would be left behind try: shutil.copy(path, output) except (OSError, IOError) as e: print "Unable to copy %s to %s: %s" % (path, output, e.strerror) else: # Otherwise just move the file like normal, leaving behind the original MKV try: shutil.move(path, output) except (OSError, IOError) as e: print "Unable to move %s to %s: %s" % (path, output,