def playNextClip(self, fmp=None, *args): # first, process the last one, if need be if fmp: if hasattr(fmp, 'keep'): if fmp.keep: logger.debug('Keeping clip') fmp.clip.active = 1 else: logger.debug('Deleting clip') fmp.clip.active = 0 db.getSession().commit() if hasattr(fmp, 'skip') and fmp.skip: logger.debug('Skipping file') db.getSession().delete(fmp.clip) self.clip_picker.replaceTracker() self.skipped_files.append( self.clip_picker.current_tracker.filepath) if hasattr(fmp, 'add') and fmp.add: self.clip_picker.addTrackers(fmp.add) try: same_movie = fmp and fmp.same_movie except: same_movie = False if same_movie: clip = fmp.clip else: clip = self.clip_picker.getNextClip() if clip is None: raise urwid.ExitMainLoop() self.setupController(clip)
def playNextClip(self, fmp=None, *args): # first, process the last one, if need be if fmp: if hasattr(fmp, 'keep'): if fmp.keep: logger.debug('Keeping clip') fmp.clip.active = 1 else: logger.debug('Deleting clip') fmp.clip.active = 0 db.getSession().commit() if hasattr(fmp, 'skip') and fmp.skip: logger.debug('Skipping file') db.getSession().delete(fmp.clip) self.clip_picker.replaceTracker() self.skipped_files.append(self.clip_picker.current_tracker.filepath) if hasattr(fmp, 'add') and fmp.add: self.clip_picker.addTrackers(fmp.add) try: same_movie = fmp and fmp.same_movie except: same_movie = False if same_movie: clip = fmp.clip else: clip = self.clip_picker.getNextClip() if clip is None: raise urwid.ExitMainLoop() self.setupController(clip)
def addFlagNow(self): location = self.player.getTime() file_id = self.filepath.file_id flag = tables.Flag(file_id=file_id, location=location) db.getSession().add(flag) logger.debug('Adding flag at %s', location) self.widget.setStatus('Flag added at {}'.format(location))
def saveScrub(self, end): # should probably just make this available and have the caller save it if self.save_scrub and self._scrub_start is not None: db.getSession().execute(tables.Scrub.insert().values( file_id=self.filepath.file_id, start=self._scrub_start, end=end)) self._scrub_start = None
def getGirl(name): _loadAllTags() girl_object = _cache.get(name) if not girl_object: girl_object = tables.Girl(name=name) _cache[name] = girl_object db.getSession().add(girl_object) return girl_object
def getTag(tag): _loadAllTags() tag_object = _cache.get(tag) if not tag_object: tag_object = tables.Tag(tag=tag) _cache[tag] = tag_object db.getSession().add(tag_object) return tag_object
def getGirl(name): _loadAllTags() girl_object = _cache.get(name) if not girl_object: girl_object = tables.Girl(name=name) _cache[name] = girl_object db.getSession().add(girl_object) return girl_object
def getTag(tag): _loadAllTags() tag_object = _cache.get(tag) if not tag_object: tag_object = tables.Tag(tag=tag) _cache[tag] = tag_object db.getSession().add(tag_object) return tag_object
def getProject(args): name = args.project try: PROJECT = db.getSession().query(tables.Project).filter(tables.Project.name==name).one() except orm.exc.NoResultFound: PROJECT = t.Project(name=name) db.getSession().add(PROJECT) return PROJECT
def editMovie(filepath): # first, save a usage instance db.saveUsage(filepath.pornfile, CONTROLLER.player.playtime) db.getSession().commit() main = menu.FileMenuPadding(filepath, NORMALRATINGS) main.addFinishedHandler(nextMovie, fmp=main) main.setLoop(loop.event_loop) loop.widget = urwid.Overlay( main, urwid.SolidFill(), align='left', width=('relative', 90), valign='bottom', height=('relative', 100), min_width=20, min_height=7)
def addRowsByScrubs(self, rows): pornfile = self.filepath.pornfile query = sql.select( [t.Scrub.c.start, t.Scrub.c.end] ).select_from( t.Scrub ).where( t.Scrub.c.file_id == pornfile.id_) scrubs = sorted([Scrub(s, e) for s,e in db.getSession().execute(query).fetchall()]) last_end = 0 for scrub in scrubs: start = scrub.start end = scrub.end # deal with overlap if end < last_end: continue if start < last_end: start = last_end last_end = end while True: clip_length = end - start # ignore the short stuff if end - start < 1: break target_length = self._length() if clip_length > target_length: self.addRow(rows, start, start + target_length, 1) # skip ahead some bit to make it interesting start = start + target_length + random.randint(10, 20) else: self.addRow(rows, start, end, 1) break
def addRowsByScrubs(self, rows): pornfile = self.filepath.pornfile query = sql.select([t.Scrub.c.start, t.Scrub.c.end]).select_from( t.Scrub).where(t.Scrub.c.file_id == pornfile.id_) scrubs = sorted([ Scrub(s, e) for s, e in db.getSession().execute(query).fetchall() ]) last_end = 0 for scrub in scrubs: start = scrub.start end = scrub.end # deal with overlap if end < last_end: continue if start < last_end: start = last_end last_end = end while True: clip_length = end - start # ignore the short stuff if end - start < 1: break target_length = self._length() if clip_length > target_length: self.addRow(rows, start, start + target_length, 1) # skip ahead some bit to make it interesting start = start + target_length + random.randint(10, 20) else: self.addRow(rows, start, end, 1) break
def editMovie(filepath): # first, save a usage instance db.saveUsage(filepath.pornfile, CONTROLLER.player.playtime) db.getSession().commit() main = menu.FileMenuPadding(filepath, NORMALRATINGS) main.addFinishedHandler(nextMovie, fmp=main) main.setLoop(loop.event_loop) loop.widget = urwid.Overlay(main, urwid.SolidFill(), align='left', width=('relative', 90), valign='bottom', height=('relative', 100), min_width=20, min_height=7)
def queryFiles(filenames=None): filenames = filenames or ['/'] filepaths = [] FilePath = tables.FilePath for file_ in filenames: some_filepaths = db.getSession().query(FilePath).filter( (FilePath.hostname == util.hostname) & (FilePath.path.like(u'{}%'.format(file_))) ).all() filepaths.extend(some_filepaths) return filepaths
def addRowsByFlag(self, rows): pornfile = self.filepath.pornfile flags = db.getSession().query(t.Flag).filter( t.Flag.file_id==pornfile.id_).all() # with a flag, we want to do +/- 5 around it, split randomlyish for flag in flags: start = flag.location - 5 while start < flag.location + 5: end = start + self._length() self.addRow(rows, start, end, 0) start = end
def addRowsByFlag(self, rows): pornfile = self.filepath.pornfile flags = db.getSession().query( t.Flag).filter(t.Flag.file_id == pornfile.id_).all() # with a flag, we want to do +/- 5 around it, split randomlyish for flag in flags: start = flag.location - 5 while start < flag.location + 5: end = start + self._length() self.addRow(rows, start, end, 0) start = end
def nextMovie(fmp=None, *args): global CONTROLLER try: try: if fmp.same_movie: filepath = fmp.filepath else: filepath = next(iinventory) except: filepath = next(iinventory) CONTROLLER = controller.FlagController(filepath, fill) CONTROLLER.addFinishedHandler(editMovie, filepath=filepath) CONTROLLER.setLoop(loop.event_loop) loop.widget = fill CONTROLLER.start() except StopIteration: logging.debug('Exiting!') raise urwid.ExitMainLoop() finally: db.getSession().commit()
def nextMovie(fmp=None, *args): global CONTROLLER try: try: if fmp.same_movie: filepath = fmp.filepath else: filepath = next(iinventory) except: filepath = next(iinventory) CONTROLLER = controller.FlagController(filepath, fill) CONTROLLER.addFinishedHandler(editMovie, filepath=filepath) CONTROLLER.setLoop(loop.event_loop) loop.widget = fill CONTROLLER.start() except StopIteration: logging.debug('Exiting!') raise urwid.ExitMainLoop() finally: db.getSession().commit()
def loadFiles(files=None, add_movie=None): if isinstance(files, basestring): files = [files] if not files: return db.getSession().query(tables.FilePath).join(tables.MovieFile).filter( tables.FilePath.hostname==util.hostname).all() else: filepath_list = [] for file_ in files: file_ = file_.decode('utf-8') abspath = os.path.abspath(file_) checkAndAddFile(abspath, filepath_list, add_movie) return filepath_list
def addMovie(filename): # 2 << 17 = 256kb = 1/4 mb # so hashing requires reading a meg of the data file_hash = util.hash_file(filename, 2<<17) session = db.getSession() try: mf = session.query(tables.MovieFile).filter(tables.MovieFile.hash_==file_hash).one() except sql.NoResultFound: logger.info('Adding a new file: %s', filename) mf = tables.MovieFile(hash_=file_hash, active=1, size=os.path.getsize(filename)) session.add(mf) except sql.MultipleResultsFound: logging.error('Multiple results found for %s', file_hash) raise fp = tables.FilePath(path=filename, hostname=util.hostname) mf.paths.append(fp) return fp
def getMovie(filename, add_movie=None): if not os.path.exists(filename): logger.debug('%s does not exist', filename) return None ext = os.path.splitext(filename)[1] if not isMovie(filename): return None session = db.getSession() # need to search to see if this path exists try: fp = session.query(tables.FilePath).filter( tables.FilePath.path==filename, tables.FilePath.hostname==util.hostname).one() return fp except sql.NoResultFound: if not add_movie: logger.debug('No filepath found for %s:%s', util.hostname, filename) return None logger.debug('Adding new filepath for %s:%s', util.hostname, filename) fp = add_movie(filename) return fp
return None def exportObject(instance, instance_type): d = {key: getattr(instance, key) for key in instance.__mapper__.c.keys()} d['obj_type'] = instance_type return d parser = argparse.ArgumentParser() parser.add_argument('clip_dir') parser.add_argument('-o', default='export.json') args = parser.parse_args() try: script.standardSetup(copy_db=False) session = db.getSession() clips = {c.id_: c for c in session.query(tables.Clip)} parsed_ids = [parseClipFilename(clipfile) for clipfile in os.listdir(args.clip_dir)] extracted_ids = set(c for c in parsed_ids if c) extracted_clips = {key: clips[key] for key in extracted_ids} extracted_files = {c.moviefile.id_: c.moviefile for c in extracted_clips.itervalues()} extracted_girls = {g.id_: g for g in itertools.chain.from_iterable( f.girls for f in extracted_files.itervalues())} extracted_tags = {t.id_: t for t in itertools.chain.from_iterable( f.tags for f in extracted_files.itervalues())} extracted_tags.update({t.id_: t for t in itertools.chain.from_iterable( c.tags for c in extracted_clips.itervalues())}) to_export = []
def _loadAllTags(): if not _cache: girls = db.getSession().query(tables.Girl) for girl in girls: _cache[girl.name] = girl
parser.add_argument('--extra', default='') parser.add_argument('--clip-tag', default='cumshot') ARGS = parser.parse_args() try: script.standardSetup() logging.info('****** Starting new script ********') cmd_line_files = [f.decode('utf-8') for f in ARGS.files] if ARGS.update_library: filepaths = movie.loadFiles(cmd_line_files, add_movie=movie.addMovie) else: filepaths = movie.queryFiles(cmd_line_files) logging.debug('filepaths: %s', len(filepaths)) db.getSession().commit() logging.debug('%s files loaded', len(filepaths)) PROJECT = project.getProject(ARGS) all_filters = [filters.ExcludeTags(['pmv', 'c**k.hero', 'compilation', 'solo', 'lesbian'])] if ARGS.clip_tag.lower != 'none': all_filters.append(ExcludeClipTag(PROJECT, ARGS.clip_tag)) all_filters.extend(filters.applyArgs(ARGS, db.getSession())) inventory = movie.MovieInventory(filepaths, ARGS.shuffle, all_filters) iinventory = inventoryFilter(inventory) normalratings = rating.NormalRatings(db.getSession())
def saveScrub(self, end): # should probably just make this available and have the caller save it if self.save_scrub and self._scrub_start is not None: db.getSession().execute(tables.Scrub.insert().values( file_id=self.filepath.file_id, start=self._scrub_start, end=end)) self._scrub_start = None
def _makeClip(self, **kwargs): clip = t.Clip(**kwargs) db.getSession().add(clip) db.getSession().flush() return clip
def _loadAllTags(): if not _cache: girls = db.getSession().query(tables.Girl) for girl in girls: _cache[girl.name] = girl
ARGS = parser.parse_args() try: if ARGS.resolution: w, h = ARGS.resolution.split('x') resolution = extract.Resolution(float(w), float(h)) else: resolution = None script.standardSetup(copy_db=False, file_handler=False) logging.info('****** Starting new script ********') cmd_line_files = [f.decode('utf-8') for f in ARGS.files] filepaths = movie.queryFiles(cmd_line_files) logging.debug('filepaths: %s', len(filepaths)) db.getSession().commit() logging.debug('%s files loaded', len(filepaths)) all_filters = filters.applyArgs(ARGS, db.getSession()) all_clips = [] for filepath in movie.MovieInventory(filepaths, False, all_filters): for clip in filepath.pornfile._clips: if clip.active and clip.project_id == ARGS.project_id: all_clips.append(clip) for clip in all_clips: output = os.path.join(ARGS.output_dir, '{:06d}.mp4'.format(clip.id_)) if os.path.exists(output): continue try:
ARGS = parser.parse_args() try: if ARGS.resolution: w,h = ARGS.resolution.split('x') resolution = extract.Resolution(float(w), float(h)) else: resolution = None script.standardSetup(copy_db=False, file_handler=False) logging.info('****** Starting new script ********') cmd_line_files = [f.decode('utf-8') for f in ARGS.files] filepaths = movie.queryFiles(cmd_line_files) logging.debug('filepaths: %s', len(filepaths)) db.getSession().commit() logging.debug('%s files loaded', len(filepaths)) all_filters = filters.applyArgs(ARGS, db.getSession()) all_clips = [] for filepath in movie.MovieInventory(filepaths, False, all_filters): for clip in filepath.pornfile._clips: if clip.active and clip.project_id == ARGS.project_id: all_clips.append(clip) for clip in all_clips: output = os.path.join(ARGS.output_dir, '{:06d}.mp4'.format(clip.id_)) if os.path.exists(output): continue try:
db.getSession().commit() parser = argparse.ArgumentParser(description='Play your p**n collection', parents=[filters.getParser()]) parser.add_argument('files', nargs='*', help='files to play; play entire collection if omitted') parser.add_argument('--shuffle', default=True, type=flexibleBoolean) args = parser.parse_args() script.standardSetup() try: filepaths = movie.loadFiles(args.files, add_movie=movie.addMovie) db.getSession().commit() all_filters = [filters.Exists()] all_filters.extend(filters.applyArgs(args, db.getSession())) inventory = movie.MovieInventory(filepaths, args.shuffle, all_filters) iinventory = iter(inventory) NORMALRATINGS = rating.NormalRatings(db.getSession()) CONTROLLER = None fill = reviewer.UrwidReviewWidget(valign='bottom') loop = urwid.MainLoop(fill, unhandled_input=handleKey, handle_mouse=False) loop.set_alarm_in(1, nextMovie) loop.run()
import argparse from porntool import db from porntool import movie from porntool import script from porntool import tag parser = argparse.ArgumentParser(description='Play your p**n collection') parser.add_argument('files', nargs='+', help='files to play') parser.add_argument('--tags', nargs='+', help='tags to add to each file') args = parser.parse_args() if not args.tags: raise Exception("Must specify at least one tag") script.standardSetup(file_handler=False, copy_db=False) try: tags = [tag.getTag(t) for t in args.tags] filepaths = movie.loadFiles(args.files, add_movie=movie.addMovie) for fp in filepaths: for tag_ in tags: if tag_ not in fp.pornfile.tags: fp.pornfile.tags.append(tag_) finally: db.getSession().commit() script.standardCleanup()
def exportObject(instance, instance_type): d = {key: getattr(instance, key) for key in instance.__mapper__.c.keys()} d['obj_type'] = instance_type return d parser = argparse.ArgumentParser() parser.add_argument('clip_dir') parser.add_argument('-o', default='export.json') args = parser.parse_args() try: script.standardSetup(copy_db=False) session = db.getSession() clips = {c.id_: c for c in session.query(tables.Clip)} parsed_ids = [ parseClipFilename(clipfile) for clipfile in os.listdir(args.clip_dir) ] extracted_ids = set(c for c in parsed_ids if c) extracted_clips = {key: clips[key] for key in extracted_ids} extracted_files = { c.moviefile.id_: c.moviefile for c in extracted_clips.itervalues() } extracted_girls = { g.id_: g for g in itertools.chain.from_iterable(
parser.add_argument('--update-library', action='store_true', default=False) parser.add_argument('--extra', default='') parser.add_argument('--clip-tag', default='cumshot') ARGS = parser.parse_args() try: script.standardSetup() logging.info('****** Starting new script ********') cmd_line_files = [f.decode('utf-8') for f in ARGS.files] if ARGS.update_library: filepaths = movie.loadFiles(cmd_line_files, add_movie=movie.addMovie) else: filepaths = movie.queryFiles(cmd_line_files) logging.debug('filepaths: %s', len(filepaths)) db.getSession().commit() logging.debug('%s files loaded', len(filepaths)) PROJECT = project.getProject(ARGS) all_filters = [ filters.ExcludeTags( ['pmv', 'c**k.hero', 'compilation', 'solo', 'lesbian']) ] if ARGS.clip_tag.lower != 'none': all_filters.append(ExcludeClipTag(PROJECT, ARGS.clip_tag)) all_filters.extend(filters.applyArgs(ARGS, db.getSession())) inventory = movie.MovieInventory(filepaths, ARGS.shuffle, all_filters) iinventory = inventoryFilter(inventory)
def _loadAllTags(): if not _cache: tags = db.getSession().query(tables.Tag) for tag in tags: _cache[tag.tag] = tag
def _onSave(self, left, right, tags): logger.debug('Would have saved: %s, %s, %s', left, right, tags) tag_objects = [tag.getTag(t) for t in tags] clip = tables.Clip( file_id = self.filepath.file_id, start=left, duration=right-left, tags=tag_objects) db.getSession().add(clip)
logging.debug('Exiting!') raise urwid.ExitMainLoop() finally: db.getSession().commit() parser = argparse.ArgumentParser( description='Play your p**n collection', parents=[filters.getParser()]) parser.add_argument('files', nargs='*', help='files to play; play entire collection if omitted') parser.add_argument('--shuffle', default=True, type=flexibleBoolean) args = parser.parse_args() script.standardSetup() try: filepaths = movie.loadFiles(args.files, add_movie=movie.addMovie) db.getSession().commit() all_filters = [filters.Exists()] all_filters.extend(filters.applyArgs(args, db.getSession())) inventory = movie.MovieInventory(filepaths, args.shuffle, all_filters) iinventory = iter(inventory) NORMALRATINGS = rating.NormalRatings(db.getSession()) CONTROLLER = None fill = reviewer.UrwidReviewWidget(valign='bottom') loop = urwid.MainLoop(fill, unhandled_input=handleKey, handle_mouse=False) loop.set_alarm_in(1, nextMovie) loop.run()
def _makeClip(self, **kwargs): clip = t.Clip(**kwargs) db.getSession().add(clip) db.getSession().flush() return clip
def _loadAllTags(): if not _cache: tags = db.getSession().query(tables.Tag) for tag in tags: _cache[tag.tag] = tag
parser.add_argument('--output', help='directory for output', default='.') parser.add_argument('--time', default=5, type=int, help="minutes of clips to extract") parser.add_argument('--shuffle', default=True, type=util.flexibleBoolean) parser.add_argument('--extra', default='', help='extra args to pass to player') parser.add_argument('--resolution') parser.add_argument('--images', nargs='*', help='images to insert between clips') parser.add_argument('--only-blanks', action='store_true') ARGS = parser.parse_args() try: script.standardSetup(copy_db=False, file_handler=False) logging.info('****** Starting new script ********') filepaths = library.getFilePaths(ARGS) all_filters = [filters.Exists(), filters.IsMovie(), filters.ByMinCount(db.getSession(), 1), filters.ExcludeTags(['pmv', 'c**k.hero', 'compilation'])] all_filters.extend(filters.applyArgs(ARGS, db.getSession())) PROJECT = project.getProject(ARGS) inventory = movie.MovieInventory(filepaths, ARGS.shuffle, all_filters) inventory = ensureProperties(inventory) normalratings = rating.NormalRatings(db.getSession()) segment_tracker = select.getSegmentTrackerType(ARGS) #clip_type = select.getClipPickerType(ARGS, [clippicker.TargetLength(ARGS.time)]) clip_picker = clippicker.TargetLength( inventory, PROJECT, normalratings, ARGS.time, segment_tracker)
import argparse from porntool import db from porntool import movie from porntool import script parser = argparse.ArgumentParser() parser.add_argument('directory') args = parser.parse_args() try: script.standardSetup(copy_db=False, file_handler=False) movie.loadFiles(args.directory, movie.addMovie) db.getSession().commit() finally: script.standardCleanup()