;ς B|Dc@sAdZdkZdkZdkZdkZdfd„ƒYZdS(sTemplate for a thumbnail generation program. This provides a Python class which you extend to generate a thumbnail image for a type of file. An example is included which generates thumbnails for text files. A more useful implemetation is VideoThumbnail. Ns ThumbnaillercBsktZdZeed„Zedd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z RS( s¨Base class for programs which generate thumbnails. You should override the method get_image() to create the image. You can also override post_process_image().cCs(||_||_||_||_dS(sInitialise the thumbnailler. name - name of the program fname - a string to use in generated temp file names use_wdir - if true then use a temp directory to store files debug - if false then suppress most error messages N(snamesselfsfnamesuse_wdirsdebug(sselfsnamesfnamesuse_wdirsdebug((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys__init__s    i`c CsG| otd|} ti| ƒiƒ}d}x"|D]}|dt |ƒ7}q4Wt i i t i ddd|dƒ}n+t i i|ƒ ot i i|ƒ}n|io|iƒnyY|i||ƒ}|iƒ} |iƒ}|i||ƒ}|i|||| |ƒWn|iƒnX|io|iƒndS( s΅Generate the thumbnail from the file inname - source file outname - path to store thumbnail image rsize - maximum size of thumbnail (in either axis) sfile://ss%02xsHOMEs .thumbnailssnormals.pngN(soutnamesinnamesurismd5snewsdigeststmpsleafscsordsosspathsjoinsenvironsisabssabspathsselfsuse_wdirsmake_working_dirs get_imagesrsizesimgs get_widthsows get_heightsohs process_images store_imagesreport_exceptionsremove_working_dir( sselfsinnamesoutnamesrsizestmpsleafsimgsohscsurisow((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pysrun!s0     cCstdƒ‚dS(s;Method you must define for your thumbnailler to do anythingsThumbnail not implementedN(s_(sselfsinnamesrsize((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys get_imageAscCsͺ|iƒ}|iƒ}||jot|ƒt|ƒ}nt|ƒt|ƒ}t||ƒ}t||ƒ}|i ||t i iiƒ}|i|||ƒSdS(sTake the raw image and scale it to the correct size. Returns the result of scaling img and passing it to post_process_image()N(simgs get_widthsows get_heightsohsfloatsrsizesssintswshs scale_simplesroxsgsgdksINTERP_BILINEARsselfspost_process_image(sselfsimgsrsizesohshsowsssw((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys process_imageEs   cCs|SdS(sΩPerform some post-processing on the image. img - gdk-pixbuf of the image w - width h - height Return: modified image The default implementation just returns the image unchanged.N(simg(sselfsimgswsh((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pyspost_process_imageVsc Cs¨ti|ƒ}|i||idhdt |ƒ<dt |ƒ<dt |i ƒ<dt |i ƒ<dtid|ƒ<d|i<ƒti||i|ƒd S( spStore the thumbnail image it the correct location, adding the extra data required by the thumbnail spec.spngstEXt::Thumb::Image::WidthstEXt::Thumb::Image::HeightstEXt::Thumb::SizestEXt::Thumb::MTimestEXt::Thumb::URIsfile://stEXt::SoftwareN(sossstatsinnamesssimgssavesoutnamesselfsfnamesstrsowsohsst_sizesst_mtimesroxsescapesnamesrename(sselfsimgsinnamesoutnamesowsohss((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys store_image_s kcCsƒtiidd|itiƒfƒ|_yti|iƒWn|iƒt |_dSnXti ƒ|_ ti |iƒdS(s2Create the temporary directory and change into it.s/tmps%s.%dN( sosspathsjoinsselfsfnamesgetpidswork_dirsmakedirssreport_exceptionsNonesgetcwdsold_dirschdir(sself((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pysmake_working_dirms   cCs©|i odSnti|iƒxWti|iƒD]C}tii|i|ƒ}yti |ƒWq6|i ƒq6Xq6Wyti |iƒWn|i ƒnXdS(sORemove our temporary directory, after changing back to the previous oneN( sselfswork_dirsosschdirsold_dirslistdirsfspathsjoinsremovesreport_exceptionsrmdir(sselfspathsf((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pysremove_working_dir|s cCs&|idjodSntiƒdS(s&Report an exception (if debug enabled)iN(sselfsdebugsroxsreport_exception(sself((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pysreport_exception‘s(s__name__s __module__s__doc__sFalses__init__sNonesruns get_images process_imagespost_process_images store_imagesmake_working_dirsremove_working_dirsreport_exception(((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys Thumbnaillers       (s__doc__sosssyssmd5sroxs Thumbnailler(ssyssroxs Thumbnaillersossmd5((sM/mnt/gmirror/ports/multimedia/rox-videothumbnail/work/VideoThumbnail/thumb.pys? s