From f5a848a3a8736a74da68f174fce6c67e3e702132 Mon Sep 17 00:00:00 2001 From: Apkawa Date: Sun, 12 Jul 2009 14:01:13 +0400 Subject: [PATCH] kawaiiing screenlist.py --- ASCHE_0/code/SH/volume | 29 ------------- Apkawa/pyscreenlist/screenlist.py | 85 ++++++++++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 47 deletions(-) delete mode 100644 ASCHE_0/code/SH/volume diff --git a/ASCHE_0/code/SH/volume b/ASCHE_0/code/SH/volume deleted file mode 100644 index fd31fc5..0000000 --- a/ASCHE_0/code/SH/volume +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -if [ "$1" = "" ]; then - - exit - -elif [ "$1" = "mute" ]; then - - if [ "`amixer get PCM | grep off -o | uniq`" = "off" ]; then - amixer set PCM unmute &>/dev/null - else - amixer set PCM mute &>/dev/null - fi - -elif [ "`echo $1 | grep + -o`" = "+" ]; then - - vol=`echo $1 | grep -P "\d{1,}" -o` - amixer set PCM $vol"%+" unmute &>/dev/null - -elif [ "`echo $1 | grep - -o`" = "-" ]; then - - vol=`echo $1 | grep -P "\d{1,}" -o` - amixer set PCM $vol"%-" unmute &>/dev/null - -else - - amixer set PCM $1"%" unmute &>/dev/null - -fi diff --git a/Apkawa/pyscreenlist/screenlist.py b/Apkawa/pyscreenlist/screenlist.py index 499b883..bdb042b 100755 --- a/Apkawa/pyscreenlist/screenlist.py +++ b/Apkawa/pyscreenlist/screenlist.py @@ -45,7 +45,8 @@ import optparse def test(__s): s = __s() s.open_video('01.mkv') - s.make_screens('tmp') + #s.make_screens('tmp') + s.SETTING.title.logo = True s.make_screenlist(s.GRID,grid=(6,6),) s.save_result('tmp/s.png') @@ -56,6 +57,16 @@ def human_format(num, suffix='b'): return "%3.1f%s%s" % (num, x, suffix) num /=1024 +def calc_resize( orig_wxh, w=None, h=None ): + def ince(__float): + return int( ceil( __float )) + o_w, o_h = orig_wxh + if w: + h= ince( ( o_h * w ) / float(o_w) ) + if h: + w = ince( ( o_w * h ) / float(o_h) ) + return (w, h) + #@test class Screenlist: FRAMES = 0 @@ -78,9 +89,10 @@ class Screenlist: 'title': type('Title_Setting',(),{ 'fgcolor':'#000', 'fontsize':18, - 'logo': True, + 'logo': False, 'logopath': 'logo.png', - }) + }), + '__doc__': 'Setting Screenlist class', }) imgs = [] @@ -110,6 +122,7 @@ class Screenlist: self.exec_mplayer_thumb = self.exec_mplayer+ '-zoom -xy %(t_width)i ' def open_video(self, video_path): + 'Open video and return bool' self.videopath = video_path __info = os.popen( self.exec_mplayer_info% video_path).read() #print __info @@ -171,6 +184,7 @@ class Screenlist: raise Exception('%s not dir'%outdir) s_time = int( self.video_length / frames ) + files = [] for f in xrange(frames): __filepath = os.path.join( os.path.abspath(outdir), @@ -179,16 +193,22 @@ class Screenlist: s_time*f if f else s_time/3 ) if self.get_screen( __filepath, time_pos, t_width ): - pass + files.append(__filepath) + return files def make_screenlist(self, - time_type=FRAMES, + time_type=FRAMES,# frames=24, grid=(6,6), columns=6, s_time=120, t_width=200, ): + ''' + time_type - set method get frames of video. + self.FRAMES, self.SECONDS, self.GRID + t_width - width frame thumbinail + ''' padding = self.SETTING.canvas.padding fgcolor = self.SETTING.canvas.fgcolor @@ -218,25 +238,39 @@ class Screenlist: if self.get_screen( __tempfile, time_pos, t_width): self.temp_files.append( __tempfile ) self.imgs.append( - self.make_frame( Image.open( __tempfile ), time_pos ) ) + self._make_frame( Image.open( __tempfile ), time_pos ) ) else: self.frames -=1 continue #print self.frames def title( img, text_tuple,font=None, title_height=150, ): + logo = self.SETTING.title.logo + logo_left = 0 + if logo: + logo_img = Image.open( self.SETTING.title.logopath) + logo_img = logo_img.resize( calc_resize( logo_img.size, h=title_height-padding*2) ) + l_w,l_h = logo_img.size + left = marl + right = left+l_h + top = mart + bottom = top+l_h + bbox = (left, top, right, bottom) + img.paste( logo_img, bbox) + + logo_left = marl+l_w+padding fgcolor= self.SETTING.title.fgcolor if not font: - font, fontsize = self.font() + font, fontsize = self._font() draw = ImageDraw.Draw( img) for r in xrange(len( text_tuple)): t = text_tuple[r] draw.text( - xy=(marl,mart+r*(padding+fontsize)), + xy=(marl+logo_left ,mart+r*(padding+fontsize)), text=t, font=font, fill=fgcolor ) @@ -282,20 +316,21 @@ class Screenlist: except IndexError: break - self.clean() + self._clean() def str_time(self, seconds): + 'Return str_time in %H:%M:%S format' return time.strftime("%H:%M:%S", time.gmtime( int( float(seconds) ) )) - def make_frame(self, img, str_time,): + def _make_frame(self, img, str_time,): __frame = self.SETTING.frame padding = __frame.padding bgcolor = __frame.bgcolor fgcolor = __frame.fgcolor border_color = __frame.border_color - font, fontsize = self.font( self.SETTING.frame.fontsize) + font, fontsize = self._font( self.SETTING.frame.fontsize) title_frame_height= fontsize + padding img = ImageOps.expand(img,(padding,padding,padding,title_frame_height),fill=bgcolor) @@ -309,7 +344,7 @@ class Screenlist: fill= fgcolor) return img - def font(self, fontsize=18, fontpath='fonts/arial.ttf'): + def _font(self, fontsize=18, fontpath='fonts/arial.ttf'): try: font = ImageFont.truetype( fontpath,fontsize) except IOError: @@ -319,7 +354,7 @@ class Screenlist: def save_result(self,dest='tmp/screenlist.png'): self.image_new.save(dest, 'PNG') - def clean(self): + def _clean(self): for tf in self.temp_files: try: os.remove(tf) @@ -334,13 +369,14 @@ class CliAppScreenlist: frames=None seconds=None grid=None + screenshots = False def __init__(self): pass def parseopt(self): def time_parse(option, opt_str, value, __parser, *args, **kwargs): if not self.time_type: - self.time_type = kwargs['time_type'] + self.time_type = kwargs.get('time_type') else: parser.error('select only of -f,-s,-g') if self.time_type == Screenlist.FRAMES: @@ -353,7 +389,10 @@ class CliAppScreenlist: self.grid = [int(i) for i in self.grid[0]] else: parser.error('not valid values in %s. \d+,\d+'%option) - #print option, opt_str, value, args, kwargs + if opt_str == '--sh': + if value: + print dir(value) + print option, opt_str, value, args, kwargs return 1 parser = optparse.OptionParser() @@ -365,6 +404,7 @@ class CliAppScreenlist: callback=time_parse, callback_kwargs={'time_type':Screenlist.GRID}) parser.add_option('-o','--outdir', action='store', type='string',dest='outdir',) + parser.add_option('--sh','--screenshots', action='store_true',dest='screenshots') if os.sys.argv[1:]: (options, self.videofiles ) = parser.parse_args() #print options, self.videofiles @@ -374,12 +414,15 @@ class CliAppScreenlist: self.outdir = os.path.abspath( options.outdir ) if not os.path.isdir(self.outdir): parser.error('-o select dir name') + if options.screenshots: + self.screenshots = True else: parser.print_help() os.sys.exit(1) def main(self): screenlist = Screenlist() + #screenlist.SETTING.title.logo = True for vf in self.videofiles: if os.path.isfile( vf): if not screenlist.open_video(vf): @@ -396,16 +439,22 @@ class CliAppScreenlist: screenlist.make_screenlist( screenlist.GRID ) video_dir, video_name = os.path.split(vf) if not self.outdir: - result_path = os.path.join( video_dir, video_name+'.png') + save_dir = video_dir else: - result_path = os.path.join( self.outdir, video_name+'.png') + save_dir= self.outdir + save_dir=os.path.abspath( save_dir) + result_path = os.path.join( save_dir, video_name+'.png') + + if self.screenshots: + files = screenlist.make_screens( save_dir, prefix='screenshots_'+video_name+'_') + print '\n'.join(files) if os.path.exists( result_path): i=1 while True: if os.path.exists( result_path): result_path = os.path.join( - self.outdir, video_name+'-%i.png'%i) + save_dir, video_name+'-%i.png'%i) i += 1 else: break -- 2.11.4.GIT