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, 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, 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:
                    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] 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()
    def process(self,
                inputfile,
                tagmp4=None,
                relativePath=None,
                original=None,
                fileno=[1, 1]):
        output_files = []

        if self.converter.validSource(inputfile) == True:
            self.tagInfo(tagmp4)

            output = self.converter.process(inputfile=inputfile,
                                            reportProgress=True,
                                            original=original)
            if output:
                # TAG
                if tagmp4 is not None:
                    try:
                        tagmp4.setHD(output['x'], output['y'])
                        tagmp4.writeTags(output['output'],
                                         self.settings.artwork,
                                         self.settings.thumbnail)
                    except:
                        self.log.exception(
                            "There was an error tagging the file")

                # OPTIMIZE
                #if self.settings.relocate_moov:
                #    self.converter.QTFS(output['output'])

                # REPLICATE
                output['tag'] = tagmp4
                output_files = self.converter.replicate(
                    output, relativePath=relativePath)

                # FINALIZE
                if self.settings.postprocess:  #and fileno[0] == fileno[1]:
                    post_processor = PostProcessor(output_files)
                    if tagmp4 is not None:
                        if tagmp4.provider == "imdb" or tagmp4.provider == "tmdb":
                            post_processor.setMovie(tagmp4.providerid)
                        elif tagmp4.provider == "tvdb":
                            post_processor.setTV(tagmp4.providerid,
                                                 tagmp4.season, tagmp4.episode)
                    post_processor.run_scripts()

        return output_files
Beispiel #5
0
def processFile(inputfile, tagdata, converter, info=None, relativePath=None):
    # Process
    info = info or converter.isValidSource(inputfile)
    if not info:
        log.debug("Invalid file %s." % inputfile)
        return

    if 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 = converter.process(inputfile, True)
    if output:
        if tagdata:
            try:
                tagdata.setHD(output['x'], output['y'])
                tagdata.writeTags(output['output'], settings.artwork,
                                  settings.thumbnail)
            except:
                log.exception("There was an error tagging the file")
        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.mediatype == MediaType.Movie:
                    post_processor.setMovie(tagdata.tmdbid)
                elif tagdata.mediatype == MediaType.TV:
                    post_processor.setTV(tagdata.tmdbid, tagdata.season,
                                         tagdata.episode)
            post_processor.run_scripts()
    else:
        log.error(
            "There was an error processing file %s, no output data received" %
            inputfile)
Beispiel #6
0
    def callscript(self, message = None, group = None):

        log.info('MP4 Automator - Post processing script initialized')

        sys.path.append(path)
        try:
            from readSettings import ReadSettings
            from mkvtomp4 import MkvtoMp4
            from tmdb_mp4 import tmdb_mp4
            from autoprocess import plex
            from post_processor import PostProcessor
        except ImportError:
            log.error('Path to script folder appears to be invalid.')
            return False

        settings = ReadSettings(path, "autoProcess.ini")
        converter = MkvtoMp4(settings)

        try:
            imdbid = group['library']['identifier']
        except:
            imdbid = group['identifier']

        moviefile = group['renamed_files']
        original = group['files']['movie'][0]

        success = False

        for inputfile in moviefile:
            try:
                log.info('Processing file: %s', inputfile)
                if MkvtoMp4(settings).validSource(inputfile):
                    log.info('File is valid')
                    output = converter.process(inputfile, original=original)

                    # Tag with metadata
                    if settings.tagfile:
                        log.info('Tagging file with IMDB ID %s', imdbid)
                        tagmp4 = tmdb_mp4(imdbid, original=original, language=settings.taglanguage)
                        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
                    output_files = converter.replicate(output['output'])

                    # Run any post process scripts
                    if settings.postprocess:
                        post_processor = PostProcessor(output_files, log)
                        post_processor.setMovie(imdbid)
                        post_processor.run_scripts()

                    success = True
                else:
                    log.info('File is invalid')
            except:
                log.error('File processing failed: %s', (traceback.format_exc()))

        plex.refreshPlex(settings, 'movie', log)

        return success
    if MkvtoMp4(settings).validSource(inputfile):
        log.info('File is valid')
        output = converter.process(inputfile, original=original)

        # Tag with metadata
        if settings.tagfile:
            log.info('Tagging file with IMDB ID %s', imdbid)
            tagmp4 = tmdb_mp4(imdbid, original=original, language=settings.taglanguage)
            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
        output_files = converter.replicate(output['output'])

        # Run any post process scripts
        if settings.postprocess:
            post_processor = PostProcessor(output_files, log)
            post_processor.setMovie(imdbid)
            post_processor.run_scripts()

    else:
        log.info('File %s is invalid, ignoring' % inputfile)
except:
    log.exception('File processing failed: %s' % inputfile)

plex.refreshPlex(settings, 'movie', log)