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)
        print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))
    elif tagdata[0] is 2:
        tmdbid = tagdata[1]
        tagmp4 = tmdb_mp4(tmdbid, True)
        print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))
    elif tagdata[0] is 3:
        tvdbid = int(tagdata[1])
        season = int(tagdata[2])
        episode = int(tagdata[3])
        tagmp4 = Tvdb_mp4(tvdbid, season, episode)
        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'))
    
    # 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:
            tagmp4.setHD(output['x'], output['y'])
            tagmp4.writeTags(output['output'], settings.artwork)
        if settings.relocate_moov:
            converter.QTFS(output['output'])
        converter.replicate(output['output'], relativePath=relativePath)
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))
Example #3
0
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 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)
Example #6
0
    def callscript(self, message=None, group=None):

        log.info('MP4 Automator Post Processing script initialized version 2')

        sys.path.append(path)
        try:
            from readSettings import ReadSettings
            from mkvtomp4 import MkvtoMp4
            from tmdb_mp4 import tmdb_mp4
            from autoprocess import plex
        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
                    converter.replicate(output['output'])

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

        plex.refreshPlex(settings, 'movie')

        return success
Example #7
0
    def callscript(self, message = None, group = None):

        log.info('MP4 Automator Post Processing script initialized version 2')

        sys.path.append(path)
        try:
            from readSettings import ReadSettings
            from mkvtomp4 import MkvtoMp4
            from tmdb_mp4 import tmdb_mp4
            from autoprocess import plex
        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
                    converter.replicate(output['output'])

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

        plex.refreshPlex(settings, 'movie')

        return success
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]
original = sys.argv[3]

log.debug("IMDBID: %s" % imdbid)
log.debug("Input file path: %s" % inputfile)
log.debug("Original file name: %s" % original)

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()
Example #10
0
                  print "Rename Failed because %s" % e
                  log.write("Rename Failed. Tag data: %s. Reason: %s\n" % (tagmp4, e))
         if "SETH" in inputfile.upper() and "MEYERS" in inputfile.upper():
             newfilepath = "D:\Library\TV Shows\Late Night with Seth Meyers\Season 1\%s" % (inputfile.split("Converted"))[1][1:].replace(":","_")
             try:
                 os.rename(inputfile, newfilepath)
                 #os.copy(inputfile, newfilepath)
                 print "Renamed file and moved to %s\n" % newfilepath
                 log.write("Renamed file and moved to %s\n" % newfilepath)
             except Exception, e:
                  print "Rename Failed because %s" % e
                  log.write("Rename Failed. Tag data: %s. Reason: %s\n" % (tagmp4, e))
     return
 elif tagdata[0] is 1:
     imdbid = tagdata[1]
     tagmp4 = tmdb_mp4(imdbid)
     print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))
     log.write("Processing %s\n" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore')))
     newpath = "%s%s/" % ("D:/Library/Movies/", tagmp4.title.encode(sys.stdout.encoding, errors='ignore').replace(":",""))
     newname = "%s (%d)%s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'), int(tagmp4.date[:4]), inputfile[-4:])   
 elif tagdata[0] is 2:
     tmdbid = tagdata[1]
     tagmp4 = tmdb_mp4(tmdbid, True)
     print "Processing %s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'))
     log.write("Processing %s\n" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore')))
     newpath = "%s%s/" % ("D:/Library/Movies/", tagmp4.title.encode(sys.stdout.encoding, errors='ignore').replace(":",""))
     newname = "%s (%d)%s" % (tagmp4.title.encode(sys.stdout.encoding, errors='ignore'), int(tagmp4.date[:4]), inputfile[-4:])
 elif tagdata[0] is 3:
     tvdbid = int(tagdata[1])
     season = int(tagdata[2])
     episode = int(tagdata[3])
Example #11
0
from mkvtomp4 import MkvtoMp4

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")

if len(sys.argv) > 2:
    inputfiles = sys.argv[3:]
    imdb_id = sys.argv[1]
    original = sys.argv[2]
    converter = MkvtoMp4(settings)

    for inputfile in inputfiles:
        if MkvtoMp4(settings).validSource(inputfile):
            output = converter.process(inputfile, original=original)

            # Tag with metadata
            if settings.tagfile:
                tagmp4 = tmdb_mp4(imdb_id, original=original)
                tagmp4.setHD(output['x'], output['y'])
                tagmp4.writeTags(output['output'])

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

            # Copy to additional locations
            converter.replicate(output['output'])

else:
    print "Not enough command line arguments present " + str(len(sys.argv))
    sys.exit()
                    moviefile = inputfile
                    maxsize = size

    if moviefile:
        output = converter.process(moviefile)
        # Tag with metadata
        if settings.tagfile:
            if imdb_id == "":
                try:
                    print "Going to guess the following files info: %s" % (sys.argv[2])
                    imdb_id = FILEtoIMDB(os.path.basename(sys.argv[2]))
                except:
                    print "Unable to accurately identify movie file %s" % (moviefile)
            print "IMDB ID is: %s" % (imdb_id)
            try:
                imdbmp4 = tmdb_mp4(imdb_id)
                imdbmp4.setHD(output['x'], output['y'])
                imdbmp4.writeTags(output['output'])
                converter.QTFS(output['output'])
            except AttributeError:
                print "Unable to tag file, Couch Potato probably screwed up passing the IMDB ID"
        # Copy to additional locations
        converter.replicate(output['output'])


# SABnzbd
if len(sys.argv) == 8:
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# 3 Clean version of the job name (no path info and ".nzb" removed)

settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")

if len(sys.argv) > 2:
    inputfiles = sys.argv[3:]
    imdb_id = sys.argv[1]
    original = sys.argv[2]
    converter = MkvtoMp4(settings)

    for inputfile in inputfiles:
        if MkvtoMp4(settings).validSource(inputfile):
            output = converter.process(inputfile, original=original)
            
            # Tag with metadata
            if settings.tagfile:
                tagmp4 = tmdb_mp4(imdb_id, original=original)
                tagmp4.setHD(output['x'], output['y'])
                tagmp4.writeTags(output['output'])

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

            # Copy to additional locations
            converter.replicate(output['output'])

else:
    print "Not enough command line arguments present " + str(len(sys.argv))
    sys.exit()