def encodeVideo(filename, outfile, preset): global hbpid logger.debug(" [*] params are %s %s %s" % ( filename, outfile, preset, )) dencoderCommon.gNotify("dencoder on %s is encoding %s using %s" % ( hostname(), filename, preset, )) logger.info(" [*] encoding " + filename + " using " + preset) args = [ hbpath, '-Z', preset, '-i', basePath + sourcePath + filename, '-o', basePath + destPath + outfile, '--main-feature' ] p = subprocess.Popen(args, stdout=open(hblog, 'w'), stderr=open(hberr, 'w')) hbpid = p.pid logger.info(" [*] HandBrakeCLI started with pid %i" % (p.pid), ) hbStatus = p.wait() dencoderCommon.gNotify("dencoder on %s has finished encoding %s using %s" % ( hostname(), filename, preset, )) return hbStatus
def writeMetadata(filename,metadata): # these options are used to tag the file try: show = metadata['show'] title = metadata['title'] description = metadata['description'] season = metadata['season'] episode = metadata['episode'] hd = metadata['hd'] except: return logger.debug(' [*] writing metadata using mp4tags') logger.debug(' [*] received title=%s, description=%s, season=%d, episode=%d' % (title,description,int(season),int(episode),)) dencoderCommon.gNotify("%s is tagging %s" % (filename,hostname(),)) # build the argument list for mp4tags # FIXME: take advantage of the properties of a dictionary # to make building the args list easier args = [mp4tagsPath,'-S',"'" + show + "'",'-o',"'" + title + "'",'-m',"'" + description + "'",'-M',episode, '-n',season, basePath+destPath+filename] logger.debug(' [*] mp4tags args are %r' % args) p = subprocess.Popen(args,stdout=open(mp4tagslog, 'w'),stderr=open(mp4tagserr,'w')) p.wait() return
def main(): # launchd on OS X seems to handle placing things in the background. # The default config for OS X prevents this script from running in the # the background. On Linux systems this value should be set to true. global channel if background == "True": doFork() wasConnected = False while True: growl = [] if wasConnected is True: wasConnected = False dencoderCommon.gNotify("Connection to AMQP server lost on %s" % (RabbitMQServer.getSelectedHost(), )) writePid() dencoderSetup() RabbitMQServer = dencoderAMQP.AMQPConnection() RabbitMQServer.setQueueName("encodejobs") if not RabbitMQServer: logger.info(' [*] connecting to RabbitMQ @%s' % (RabbitMQServer, )) try: logger.info(' [*] connected') except IOError: logger.critical(' [*] failed to connect to RabbitMQ!') logger.critical( ' [*] Please check RabbitMQ host and configuration') # waitAndSee() # check to see if paths exist # ensure that configured paths exist. If they don't, HandBrakeCLI will # immediately fail but as the script is currently written it'll still # ack the message. This ack tells RabbitMQ the encode was successful, # even though it wasn't if not checkPaths(): logger.critical( " [*] source path (%s) doesn't exist, is the file system mounted?" % (basePath + sourcePath, )) if sys.platform == "darwin": shutdownDencoder() else: waitAndSee() continue logger.debug(' [*] entering pika.asyncore_loop') logger.info(' [*] Waiting for encode jobs. Issue kill to %i to end' % (os.getpid(), )) dencoderCommon.gNotify( 'Dencoder on %s is now available for encoding jobs' % (dencoderCommon.hostname(), )) wasConnected = True RabbitMQServer.doLoop()
def shutdownDencoder(): dencoderCommon.gNotify('Dencoder on %s is shutting down' % (dencoderCommon.hostname(),) ) logger.info(' [*] SIGTERM received') logger.info(' [*] shutting down...') logger.info(' [*] terminating any running encodes...') disconnectRabbitMQ(dencoderCommon.channel) stopEncodes() logger.info(' [*] good bye') exit()
def main(): # launchd on OS X seems to handle placing things in the background. # The default config for OS X prevents this script from running in the # the background. On Linux systems this value should be set to true. global channel if background == "True": doFork() wasConnected = False while True: growl = [] if wasConnected is True: wasConnected = False dencoderCommon.gNotify("Connection to AMQP server lost on %s" % (RabbitMQServer.getSelectedHost(),)) writePid() dencoderSetup() RabbitMQServer = dencoderAMQP.AMQPConnection() RabbitMQServer.setQueueName("encodejobs") if not RabbitMQServer: logger.info(' [*] connecting to RabbitMQ @%s' %(RabbitMQServer,)) try: logger.info(' [*] connected') except IOError: logger.critical(' [*] failed to connect to RabbitMQ!') logger.critical(' [*] Please check RabbitMQ host and configuration') # waitAndSee() # check to see if paths exist # ensure that configured paths exist. If they don't, HandBrakeCLI will # immediately fail but as the script is currently written it'll still # ack the message. This ack tells RabbitMQ the encode was successful, # even though it wasn't if not checkPaths(): logger.critical(" [*] source path (%s) doesn't exist, is the file system mounted?" % (basePath + sourcePath,)) if sys.platform == "darwin": shutdownDencoder() else: waitAndSee() continue logger.debug(' [*] entering pika.asyncore_loop') logger.info(' [*] Waiting for encode jobs. Issue kill to %i to end' % (os.getpid(),)) dencoderCommon.gNotify('Dencoder on %s is now available for encoding jobs' % (dencoderCommon.hostname(),)) wasConnected = True RabbitMQServer.doLoop()
def shutdownDencoder(): dencoderCommon.gNotify('Dencoder on %s is shutting down' % (dencoderCommon.hostname(), )) logger.info(' [*] SIGTERM received') logger.info(' [*] shutting down...') logger.info(' [*] terminating any running encodes...') disconnectRabbitMQ(dencoderCommon.channel) stopEncodes() logger.info(' [*] good bye') exit()
def encodeVideo(filename,outfile,preset): global hbpid logger.debug(" [*] params are %s %s %s" % (filename, outfile, preset,)) dencoderCommon.gNotify("dencoder on %s is encoding %s using %s" % (hostname(),filename,preset,)) logger.info(" [*] encoding " + filename + " using " + preset) args = [hbpath,'-Z',preset,'-i',basePath+sourcePath+filename,'-o',basePath+destPath+outfile,'--main-feature'] p = subprocess.Popen(args,stdout=open(hblog, 'w'),stderr=open(hberr,'w')) hbpid = p.pid logger.info(" [*] HandBrakeCLI started with pid %i" % (p.pid),) hbStatus = p.wait() dencoderCommon.gNotify("dencoder on %s has finished encoding %s using %s" % (hostname(),filename,preset,)) return hbStatus
def writeMetadata(filename, metadata): # these options are used to tag the file try: show = metadata['show'] title = metadata['title'] description = metadata['description'] season = metadata['season'] episode = metadata['episode'] hd = metadata['hd'] except: return logger.debug(' [*] writing metadata using mp4tags') logger.debug( ' [*] received title=%s, description=%s, season=%d, episode=%d' % ( title, description, int(season), int(episode), )) dencoderCommon.gNotify("%s is tagging %s" % ( filename, hostname(), )) # build the argument list for mp4tags # FIXME: take advantage of the properties of a dictionary # to make building the args list easier args = [ mp4tagsPath, '-S', "'" + show + "'", '-o', "'" + title + "'", '-m', "'" + description + "'", '-M', episode, '-n', season, basePath + destPath + filename ] logger.debug(' [*] mp4tags args are %r' % args) p = subprocess.Popen(args, stdout=open(mp4tagslog, 'w'), stderr=open(mp4tagserr, 'w')) p.wait() return