def __init__(self, filepath, cmd=None, extra='', geom=None): filename = filepath.path self.filepath = filepath if not cmd: cmd = self.DEFAULT_CMD if geom is None: geom = configure.get('GEOMETRY') self.cmd = cmd.format(player=configure.get('MPLAYER'), options=configure.get('MPLAYER_OPTIONS'), extra=extra, geom=geom).split() + [filename] self.p = None self.playtime = 0 self._log = open('mplayer.log', 'w') self._paused = True self._finished = False self._starttime = None self._current_position = None self._parsers = [ IsFinishedParser(self.onFinished), TimePosParser(self._setPos) ] self._scrub_start = 0 self.save_scrub = True widget.OnFinished.__init__(self) widget.LoopAware.__init__(self)
def __init__(self, cmd=None, extra='', geom=None): if not cmd: cmd = self.DEFAULT_CMD if geom is None: geom = configure.get('GEOMETRY') self.cmd = cmd.format( player=configure.get('MPLAYER'), options=configure.get('MPLAYER_OPTIONS'), extra=extra, geom=geom).split() self.p = None self.playtime = 0 self._log = open('mplayer.log', 'w') self._parsers = [IsEndOfFile(self.onFinished), TimePosParser(self._setPos)] self.save_scrub = True widget.OnFinished.__init__(self) widget.LoopAware.__init__(self)
def standardSetup(echo=False, file_handler=True, copy_db=True): """Utility function to setup up the configuration, logging and database Args: echo: enable sqlalchemy db echoing file_handler: log to a file if True, log to screen if False copy_db: write changes to a copy of the database, which upon cleanup replaces the existing one """ global SQL_FILE, TMP_FILE, COPIED, LOCK_FILE configure.load() util.configureLogging(file_handler=file_handler) # I store my database in dropbox and the incremental updates # while running the program can get expensive LOCK_FILE = LockFile() LOCK_FILE.lock() SQL_FILE = configure.get('SQL_FILE') COPIED = copy_db if copy_db: TMP_FILE = tempfile.NamedTemporaryFile() logger.debug('Temp database is %s', TMP_FILE.name) with open(SQL_FILE) as f: shutil.copyfileobj(f, TMP_FILE) TMP_FILE.flush() _setSession(echo, TMP_FILE.name) else: _setSession(echo, SQL_FILE)
def _setSession(echo=False, filename=None): filename = filename or configure.get('SQL_FILE') engine = sql.create_engine(db.urlFromFile(filename), echo=echo) tables.Base.metadata.create_all(engine) Session = orm.sessionmaker(bind=engine) session = Session() db.setSession(session)
def start(self, *args): cmd = "{} --really-quiet".format(configure.get('MPLAYER')).strip().split() cmd += args cmd.append(self.filename) logger.debug('Running: %s', cmd) p = subprocess.Popen(cmd) p.wait()
def start(self, *args): cmd = "{} --really-quiet".format( configure.get('MPLAYER')).strip().split() cmd += args cmd.append(self.filename) logger.debug('Running: %s', cmd) p = subprocess.Popen(cmd) p.wait()
def extractClip( clip, output, target_resolution=None, clip_resolution=None, cleanup=True): input_ = clip.moviefile.getActivePath().path # seeking before input uses keyframes preseek = max(clip.start - 10, 0) # and then normal decoding after that postseek = clip.start - preseek # decided that mpegts wasn't the way to go # '-bsf:v', 'h264_mp4toannexb', '-f', 'mpegts', cmd = ['ffmpeg', '-y', '-ss', str(preseek), '-i', input_, '-ss', str(postseek), '-t', str(clip.duration)] if clip_resolution and target_resolution: cmd += ['-vf', padAndScaleFilter(clip_resolution, target_resolution)] cmd = cmd + configure.get('VIDEO') + configure.get('AUDIO') cmd += [output] logger.info('Extraction command: %s', cmd) def delete(): logger.error("Failed to process {}".format(output)) try: os.remove(output) except OSError: pass try: log_output = '{}.log'.format(clip.id_) with codecs.open(log_output, 'w', 'utf-8') as f: f.write(u'ffmpeg-{}\n'.format(' '.join(cmd))) if clip_resolution: f.write('Input Resolution: height: {}, width: {}\n'.format( clip_resolution.height, clip_resolution.width)) f.flush() returncode = subprocess.call(cmd, stderr=f) except: delete() raise if returncode != 0: delete() return False if cleanup: os.remove(log_output) return True
def identify(filename): logger.debug('Calling `identify` on %s', filename) p = subprocess.Popen( [configure.get('MPLAYER'), "--vo=null", "--ao=null", "--identify", "--frames=0", filename], stdout=subprocess.PIPE, stderr=util.DEVNULL) (out, err) = p.communicate() out = out.decode('utf-8') return out
def __init__(self, cmd=None, extra='', geom=None): if not cmd: cmd = self.DEFAULT_CMD if geom is None: geom = configure.get('GEOMETRY') self.cmd = cmd.format(player=configure.get('MPLAYER'), options=configure.get('MPLAYER_OPTIONS'), extra=extra, geom=geom).split() self.p = None self.playtime = 0 self._log = open('mplayer.log', 'w') self._parsers = [ IsEndOfFile(self.onFinished), TimePosParser(self._setPos) ] self.save_scrub = True widget.OnFinished.__init__(self) widget.LoopAware.__init__(self)
def __init__(self, filepath, cmd=None, extra='', geom=None): filename = filepath.path self.filepath = filepath if not cmd: cmd = self.DEFAULT_CMD if geom is None: geom = configure.get('GEOMETRY') self.cmd = cmd.format( player=configure.get('MPLAYER'), options=configure.get('MPLAYER_OPTIONS'), extra=extra, geom=geom).split() + [filename] self.p = None self.playtime = 0 self._log = open('mplayer.log', 'w') self._paused = True self._finished = False self._starttime = None self._current_position = None self._parsers = [IsFinishedParser(self.onFinished), TimePosParser(self._setPos)] self._scrub_start = 0 self.save_scrub = True widget.OnFinished.__init__(self) widget.LoopAware.__init__(self)
import os.path import sqlalchemy from porntool import configure from porntool import db from porntool import tables configure.load() SQL_FILE = configure.get('SQL_FILE') if not SQL_FILE: raise Exception('The location of the database (SQL_FILE) is not specified.') if os.path.exists(SQL_FILE): raise Exception("The file %s already exists. Can't create database", SQL_FILE) engine = sqlalchemy.create_engine(db.urlFromFile(SQL_FILE), echo=False) tables.Base.metadata.create_all(engine) print "Succesfully created a new database: {}".format(SQL_FILE)
import argparse import os import subprocess from porntool import configure configure.load() parser = argparse.ArgumentParser() parser.add_argument('playlist') parser.add_argument('output') args = parser.parse_args() concat = 'concat_file' with open(concat, 'w') as inpt: if args.playlist: with open(args.playlist) as f: for l in f: inpt.write("file '{}'\n".format(l.strip())) video = configure.get('VIDEO') audio = configure.get('AUDIO') subprocess.call( ['ffmpeg', '-f', 'concat', '-i', concat, '-c', 'copy', args.output]) os.remove(concat)
def __init__(self): self.lockfile = configure.get('SQL_FILE') + '.lock' self.delete = True
import argparse import os import subprocess from porntool import configure configure.load() parser = argparse.ArgumentParser() parser.add_argument('playlist') parser.add_argument('output') args = parser.parse_args() concat = 'concat_file' with open(concat, 'w') as inpt: if args.playlist: with open(args.playlist) as f: for l in f: inpt.write("file '{}'\n".format(l.strip())) video = configure.get('VIDEO') audio = configure.get('AUDIO') subprocess.call(['ffmpeg', '-f', 'concat', '-i', concat, '-c', 'copy', args.output]) os.remove(concat)
import os.path import sqlalchemy from porntool import configure from porntool import db from porntool import tables configure.load() SQL_FILE = configure.get('SQL_FILE') if not SQL_FILE: raise Exception( 'The location of the database (SQL_FILE) is not specified.') if os.path.exists(SQL_FILE): raise Exception("The file %s already exists. Can't create database", SQL_FILE) engine = sqlalchemy.create_engine(db.urlFromFile(SQL_FILE), echo=False) tables.Base.metadata.create_all(engine) print "Succesfully created a new database: {}".format(SQL_FILE)