Пример #1
0
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()
                    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'])

            # run any post process scripts
            if settings.postprocess:
                post_processor = PostProcessor(output_files, log)
                post_processor.setTV(tvdb_id, season, episode)
                post_processor.run_scripts()

            try:
                refresh = json.load(urllib.urlopen(settings.getRefreshURL(tvdb_id)))
                for item in refresh:
                    log.debug(refresh[item])
            except (IOError, ValueError):
                log.exception("Couldn't refresh Sickbeard, check your autoProcess.ini settings.")

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

else:
    log.error("Not enough command line arguments present %s." % len(sys.argv))
    sys.exit()
                # Then set that episode to monitored
                log.info(
                    "Sending PUT request with following payload:")  # debug
                log.info(str(sonarrepinfo))  # debug

                url = protocol + host + ":" + port + webroot + "/api/episode/" + str(
                    sonarrepinfo['id'])
                r = requests.put(url, json=sonarrepinfo, headers=headers)
                success = r.json()

                log.info("PUT request returned:")  # debug
                log.info(str(success))  # debug
                log.info(
                    "Sonarr monitoring information updated for episode %s." %
                    success['title'])
            else:
                log.error(
                    "Your Sonarr API Key can not be blank. Update autoProcess.ini."
                )
        except:
            log.exception("Sonarr monitor status update failed.")

        # Run any post process scripts
        if settings.postprocess:
            post_processor = PostProcessor(output_files, log)
            post_processor.setTV(tvdb_id, season, episode)
            post_processor.run_scripts()

        plex.refreshPlex(settings, 'show', log)
Пример #4
0
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:
                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()