def main(): # Ensure a valid config file ReadSettings() if not os.path.isfile(autoProcess): logging.error("autoProcess.ini does not exist") sys.exit(1) safeConfigParser = configparser.ConfigParser() safeConfigParser.read(autoProcess) # Set FFMPEG/FFProbe Paths safeConfigParser.set("Converter", "ffmpeg", "/usr/local/bin/ffmpeg") safeConfigParser.set("Converter", "ffprobe", "/usr/local/bin/ffprobe") section = os.environ.get("SMA_RS") if section and os.path.isfile(xml): tree = ET.parse(xml) root = tree.getroot() port = root.find("Port").text try: sslport = root.find("SslPort").text except: sslport = port webroot = root.find("UrlBase").text webroot = webroot if webroot else "" ssl = root.find("EnableSsl").text ssl = ssl.lower() in ["true", "yes", "t", "1", "y"] if ssl else False apikey = root.find("ApiKey").text # Set values from config.xml safeConfigParser.set(section, "apikey", apikey) safeConfigParser.set(section, "ssl", str(ssl)) safeConfigParser.set(section, "port", sslport if ssl else port) safeConfigParser.set(section, "webroot", webroot) # Set IP from environment variable ip = os.environ.get("HOST") if ip: safeConfigParser.set(section, "host", ip) else: safeConfigParser.set(section, "host", "127.0.0.1") fp = open(autoProcess, "w") safeConfigParser.write(fp) fp.close()
log.info("qBittorrent post processing started.") if len(sys.argv) != 7: log.error( "Not enough command line parameters present, are you launching this from qBittorrent?" ) log.error( "#Args: %L %T %R %F %N %I Category, Tracker, RootPath, ContentPath , TorrentName, InfoHash" ) log.error("Length was %s" % str(len(sys.argv))) log.error(str(sys.argv[1:])) sys.exit(1) try: settings = ReadSettings() label = sys.argv[1].lower().strip() root_path = str(sys.argv[3]) content_path = str(sys.argv[4]) name = sys.argv[5] torrent_hash = sys.argv[6] categories = [ settings.qBittorrent['sb'], settings.qBittorrent['sonarr'], settings.qBittorrent['radarr'], settings.qBittorrent['sr'], settings.qBittorrent['bypass'] ] path_mapping = settings.qBittorrent['path-mapping'] log.debug("Root Path: %s." % root_path) log.debug("Content Path: %s." % content_path) log.debug("Label: %s." % label)
# 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) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 def progressOutput(timecode, debug): print("%d%%" % timecode) try: settings = ReadSettings() categories = [settings.SAB['sb'], settings.SAB['sonarr'], settings.SAB['radarr'], settings.SAB['sr'], settings.SAB['bypass']] category = str(sys.argv[5]).lower().strip() path = str(sys.argv[1]) nzb = str(sys.argv[2]) path_mapping = settings.SAB['path-mapping'] log.debug("Path: %s." % path) log.debug("Category: %s." % category) log.debug("Categories: %s." % categories) log.debug("NZB: %s." % nzb) if len([x for x in categories if x.startswith(category)]) < 1: log.error("No valid category detected.") sys.exit(1)
try: os.rename(k, subs[k]) log.info("Restoring %s to %s." % (k, subs[k])) except: os.remove(k) log.exception("Unable to restore %s, deleting." % (k)) log = getLogger("RadarrPostProcess") log.info("Radarr extra script post processing started.") if os.environ.get('radarr_eventtype') == "Test": sys.exit(0) settings = ReadSettings() log.debug(os.environ) try: inputfile = os.environ.get('radarr_moviefile_path') original = os.environ.get('radarr_moviefile_scenename') imdbid = os.environ.get('radarr_movie_imdbid') tmdbid = os.environ.get('radarr_movie_tmdbid') movieid = int(os.environ.get('radarr_movie_id')) moviefileid = int(os.environ.get('radarr_moviefile_id')) scenename = os.environ.get('radarr_moviefile_scenename') releasegroup = os.environ.get('radarr_moviefile_releasegroup') moviefile_sourcefolder = os.environ.get('radarr_moviefile_sourcefolder') except: log.exception("Error reading environment variables")
def main(): global settings parser = argparse.ArgumentParser( description= "Manual conversion and tagging script for sickbeard_mp4_automator") parser.add_argument( '-i', '--input', help='The source that will be converted. May be a file or a directory') parser.add_argument( '-c', '--config', help='Specify an alternate configuration file location') parser.add_argument( '-a', '--auto', action="store_true", help= "Enable auto mode, the script will not prompt you for any further input, good for batch files. It will guess the metadata using guessit" ) parser.add_argument('-s', '--season', help="Specifiy the season number") parser.add_argument('-e', '--episode', help="Specify the episode number") parser.add_argument('-tvdb', '--tvdbid', help="Specify the TVDB ID for media") parser.add_argument('-imdb', '--imdbid', help="Specify the IMDB ID for media") parser.add_argument('-tmdb', '--tmdbid', help="Specify the TMDB ID for media") parser.add_argument( '-nm', '--nomove', action='store_true', help= "Overrides and disables the custom moving of file options that come from output_dir and move-to" ) parser.add_argument( '-nc', '--nocopy', action='store_true', help= "Overrides and disables the custom copying of file options that come from output_dir and move-to" ) parser.add_argument( '-nd', '--nodelete', action='store_true', help="Overrides and disables deleting of original files") parser.add_argument( '-nt', '--notag', action="store_true", help="Overrides and disables tagging when using the automated option") parser.add_argument( '-np', '--nopost', action="store_true", help= "Overrides and disables the execution of additional post processing scripts" ) parser.add_argument( '-pr', '--preserverelative', action='store_true', help= "Preserves relative directories when processing multiple files using the copy-to or move-to functionality" ) parser.add_argument( '-pse', '--processsameextensions', action='store_true', help= "Overrides process-same-extensions setting in autoProcess.ini enabling the reprocessing of files" ) parser.add_argument( '-fc', '--forceconvert', action='store_true', help= "Overrides force-convert setting in autoProcess.ini and also enables process-same-extenions if true forcing the conversion of files" ) parser.add_argument( '-m', '--moveto', help= "Override move-to value setting in autoProcess.ini changing the final destination of the file" ) parser.add_argument( '-oo', '--optionsonly', action="store_true", help= "Display generated conversion options only, do not perform conversion") parser.add_argument( '-cl', '--codeclist', action="store_true", help="Print a list of supported codecs and their paired FFMPEG encoders" ) parser.add_argument('-o', '--original', help="Specify the original source/release filename") args = vars(parser.parse_args()) # Setup the silent mode silent = args['auto'] print("Python %s-bit %s." % (struct.calcsize("P") * 8, sys.version)) print("Guessit version: %s." % guessit.__version__) if args['codeclist']: showCodecs() return # Settings overrides if args['config'] and os.path.exists(args['config']): settings = ReadSettings(args['config'], logger=log) elif args['config'] and os.path.exists( os.path.join(os.path.dirname(sys.argv[0]), args['config'])): settings = ReadSettings(os.path.join(os.path.dirname(sys.argv[0]), args['config']), logger=log) else: settings = ReadSettings(logger=log) if (args['nomove']): settings.output_dir = None settings.moveto = None print("No-move enabled") elif (args['moveto']): settings.moveto = args['moveto'] print("Overriden move-to to " + args['moveto']) if (args['nocopy']): settings.copyto = None print("No-copy enabled") if (args['nodelete']): settings.delete = False print("No-delete enabled") if (args['processsameextensions']): settings.process_same_extensions = True print("Reprocessing of same extensions enabled") if (args['forceconvert']): settings.process_same_extensions = True settings.force_convert = True print( "Force conversion of files enabled. As a result conversion of mp4 files is also enabled" ) if (args['notag']): settings.tagfile = False print("No-tagging enabled") if (args['nopost']): settings.postprocess = False print("No post processing enabled") if (args['optionsonly']): logging.getLogger("resources.mediaprocessor").setLevel( logging.CRITICAL) print("Options only mode enabled") # Establish the path we will be working with if (args['input']): path = (str(args['input'])) try: path = glob.glob(path)[0] except: pass else: path = getValue("Enter path to file") if os.path.isdir(path): walkDir(path, silent=silent, tmdbid=args.get('tmdbid'), tvdbid=args.get('tvdbid'), imdbid=args.get('imdbid'), preserveRelative=args['preserverelative'], tag=settings.tagfile, optionsOnly=args['optionsonly']) elif (os.path.isfile(path)): mp = MediaProcessor(settings, logger=log) info = mp.isValidSource(path) if info: if (args['optionsonly']): displayOptions(path) return try: processFile(path, mp, info=info, silent=silent, tag=settings.tagfile, tmdbid=args.get('tmdbid'), tvdbid=args.get('tvdbid'), imdbid=args.get('imdbid'), season=args.get('season'), episode=args.get('episode'), original=args.get('original')) except SkipFileException: log.debug("Skipping file %s" % path) else: print("File %s is not in a valid format" % (path)) else: print("File %s does not exist" % (path))
sys.exit(POSTPROCESS_NONE) # Make sure one of the appropriate categories is set if len([x for x in categories if x.startswith(category)]) < 1: log.error("Post-Process: No valid category detected. Category was %s." % (category)) status = 1 sys.exit(POSTPROCESS_NONE) # Make sure there are no duplicate categories if len(categories) != len(set(categories)): log.error("Duplicate category detected. Category names must be unique.") status = 1 sys.exit(POSTPROCESS_NONE) # All checks done, now launching the script. settings = ReadSettings(MP4folder) if shouldConvert: if output_dir: settings.output_dir = output_dir mp = MediaProcessor(settings, logger=log) ignore = [] for r, d, f in os.walk(path): for files in f: inputfile = os.path.join(r, files) #DEBUG#print inputfile info = mp.isValidSource(inputfile) if info and inputfile not in ignore: log.info("Processing file %s." % inputfile) try: output = mp.process(inputfile, info=info, reportProgress=True, progressOutput=progressOutput)
import sys import json import urllib import struct from resources.log import getLogger from resources.readsettings import ReadSettings from resources.metadata import MediaType from resources.mediaprocessor import MediaProcessor from urllib import request log = getLogger("SickbeardPostProcess") log.info("Sickbeard extra script post processing started.") try: settings = ReadSettings() 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]) log.debug("Input file: %s." % inputfile) log.debug("Original name: %s." % original) log.debug("TVDB ID: %s." % tvdb_id) log.debug("Season: %s episode: %s." % (season, episode)) mp = MediaProcessor(settings)
import os import sys import re from autoprocess import autoProcessTV, autoProcessMovie, autoProcessTVSR, sonarr, radarr from resources.readsettings import ReadSettings from resources.mediaprocessor import MediaProcessor from resources.log import getLogger from deluge_client import DelugeRPCClient import shutil log = getLogger("DelugePostProcess") log.info("Deluge post processing started.") try: settings = ReadSettings() categories = [settings.deluge['sb'], settings.deluge['cp'], settings.deluge['sonarr'], settings.deluge['radarr'], settings.deluge['sr'], settings.deluge['bypass']] remove = settings.deluge['remove'] if len(sys.argv) < 4: log.error("Not enough command line parameters present, are you launching this from deluge?") sys.exit(1) path = str(sys.argv[3]) torrent_name = str(sys.argv[2]) torrent_id = str(sys.argv[1]) delete_dir = None path_mapping = settings.deluge['path-mapping'] log.debug("Path: %s." % path) log.debug("Torrent: %s." % torrent_name)
return False if len(sys.argv) < 6: log.error( "Not enough command line parameters present, are you launching this from uTorrent?" ) log.error( "#Args: %L %T %D %K %F %I %N Label, Tracker, Directory, single|multi, NameofFile(if single), InfoHash, Name" ) log.error("Length was %s" % str(len(sys.argv))) log.error(str(sys.argv[1:])) sys.exit(1) try: settings = ReadSettings() path = str(sys.argv[3]) label = sys.argv[1].lower().strip() kind = sys.argv[4].lower().strip() filename = sys.argv[5].strip() categories = [ settings.uTorrent['cp'], settings.uTorrent['sb'], settings.uTorrent['sonarr'], settings.uTorrent['radarr'], settings.uTorrent['sr'], settings.uTorrent['bypass'] ] torrent_hash = sys.argv[6] try: name = sys.argv[7] except: name = sys.argv[6]
import os import sys from autoprocess import autoProcessTV, autoProcessMovie, autoProcessTVSR, sonarr, radarr from resources.readsettings import ReadSettings from resources.mediaprocessor import MediaProcessor from resources.log import getLogger from deluge_client import DelugeRPCClient import shutil log = getLogger("DelugePostProcess") log.info("Deluge post processing started.") try: settings = ReadSettings() categories = [ settings.deluge['sb'], settings.deluge['cp'], settings.deluge['sonarr'], settings.deluge['radarr'], settings.deluge['sr'], settings.deluge['bypass'] ] remove = settings.deluge['remove'] if len(sys.argv) < 4: log.error( "Not enough command line parameters present, are you launching this from deluge?" ) sys.exit(1) path = str(sys.argv[3]) torrent_name = str(sys.argv[2])
return False if len(sys.argv) < 6: log.error( "Not enough command line parameters present, are you launching this from uTorrent?" ) log.error( "#Args: %L %T %D %K %F %I %N Label, Tracker, Directory, single|multi, NameofFile(if single), InfoHash, Name" ) log.error("Length was %s" % str(len(sys.argv))) log.error(str(sys.argv[1:])) sys.exit(1) try: settings = ReadSettings() path = str(sys.argv[3]) label = sys.argv[1].lower().strip() kind = sys.argv[4].lower().strip() filename = sys.argv[5].strip() categories = [ settings.uTorrent['cp'], settings.uTorrent['sb'], settings.uTorrent['sonarr'], settings.uTorrent['radarr'], settings.uTorrent['sr'], settings.uTorrent['bypass'] ] torrent_hash = sys.argv[6] try: name = sys.argv[7] except: name = sys.argv[6] path_mapping = settings.uTorrent['path-mapping']