コード例 #1
0
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)
コード例 #2
0
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)