def create(self, filename): """ create mmpython information about the given file """ info = mmpython.Factory().create(filename) if info: thumbnail = None if info.has_key('thumbnail'): thumbnail = info.thumbnail info = self.simplify(info) name = util.getname(filename) if name == name.upper() and info.has_key('type') and \ info['type'] in ('DVD', 'VCD'): name = util.getname(filename.lower()) info['title:filename'] = name if info.has_key('video'): for video in info['video']: for variable in ('width', 'height', 'length', 'aspect'): if video.has_key(variable) and not \ (info.has_key(variable) and info[variable]): info[variable] = video[variable] if thumbnail and config.IMAGE_USE_EXIF_THUMBNAIL and config.CACHE_IMAGES: util.cache_image(filename, thumbnail) elif config.CACHE_IMAGES and info.has_key('mime') and info['mime'] and \ info['mime'].startswith('image'): util.cache_image(filename) return info return {}
def cover_create(self, arg=None, menuw=None): """ create cover file for the item """ import directory box = PopupBox(text= _('getting data...')) box.show() #filename = os.path.splitext(self.item.filename)[0] if self.item.type == 'audiocd': filename = '%s/disc/metadata/%s.jpg' % (config.OVERLAY_DIR, self.item.info['id']) elif self.item.type == 'dir': filename = os.path.join(self.item.dir, 'cover.jpg') else: filename = '%s/cover.jpg' % (os.path.dirname(self.item.filename)) fp = urllib2.urlopen(str(arg)) m = vfs.open(filename,'wb') m.write(fp.read()) m.close() fp.close() # try to crop the image to avoid ugly borders try: image = imlib2.open(filename) width, height = image.size image.crop((2, 2), (width-4, height-4)).save(filename) util.cache_image(filename) except Exception, why: logger.warning(why)
def cover_create(self, arg=None, menuw=None): """ create cover file for the item """ import directory box = PopupBox(text=_('getting data...')) box.show() #filename = os.path.splitext(self.item.filename)[0] if self.item.type == 'audiocd': filename = '%s/disc/metadata/%s.jpg' % (config.OVERLAY_DIR, self.item.info['id']) elif self.item.type == 'dir': filename = os.path.join(self.item.dir, 'cover.jpg') else: filename = '%s/cover.jpg' % (os.path.dirname(self.item.filename)) fp = urllib2.urlopen(str(arg)) m = vfs.open(filename, 'wb') m.write(fp.read()) m.close() fp.close() # try to crop the image to avoid ugly borders try: image = imlib2.open(filename) width, height = image.size image.crop((2, 2), (width - 4, height - 4)).save(filename) util.cache_image(filename) except Exception, why: logger.warning(why)
def cache_thumbnails(): """ cache all image files by creating thumbnails """ import cStringIO print checking('checking thumbnails'), sys.__stdout__.flush() files = [] for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS: try: d = d[1] except: pass if not os.path.isdir(d): continue files += util.match_files_recursively(d, config.IMAGE_SUFFIX) + \ util.match_files_recursively(vfs.getoverlay(d), config.IMAGE_SUFFIX) files = util.misc.unique(files) for filename in copy.copy(files): thumb = vfs.getoverlay(filename + '.raw') try: sinfo = os.stat(filename) if os.stat(thumb)[ST_MTIME] > sinfo[ST_MTIME]: files.remove(filename) except OSError: pass for bad_dir in ('.svn', '.xvpics', '.thumbnails', '.pics'): if filename.find(os.path.join(os.path.sep, bad_dir + '')) > 0: try: files.remove(filename) except: pass print '%s file%s' % (len(files), len(files) != 1 and 's' or '') for filename in files: fname = filename if len(fname) > 65: fname = fname[:20] + ' [...] ' + fname[-40:] print ' %4d/%-4d %s' % (files.index(filename) + 1, len(files), Unicode(fname)) util.cache_image(filename) if files: print
def cache_thumbnails(): """ cache all image files by creating thumbnails """ import cStringIO print checking('checking thumbnails'), sys.__stdout__.flush() files = [] for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS: try: d = d[1] except: pass if not os.path.isdir(d): continue files += util.match_files_recursively(d, config.IMAGE_SUFFIX) + \ util.match_files_recursively(vfs.getoverlay(d), config.IMAGE_SUFFIX) files = util.misc.unique(files) for filename in copy.copy(files): thumb = vfs.getoverlay(filename + '.raw') try: sinfo = os.stat(filename) if os.stat(thumb)[ST_MTIME] > sinfo[ST_MTIME]: files.remove(filename) except OSError: pass for bad_dir in ('.svn', '.xvpics', '.thumbnails', '.pics'): if filename.find(os.path.join(os.path.sep, bad_dir + '')) > 0: try: files.remove(filename) except: pass print '%s file%s' % (len(files), len(files) != 1 and 's' or '') for filename in files: fname = filename if len(fname) > 65: fname = fname[:20] + ' [...] ' + fname[-40:] print ' %4d/%-4d %s' % (files.index(filename)+1, len(files), Unicode(fname)) util.cache_image(filename) if files: print
def create(self, filename): """ create mmpython information about the given file """ data = os.path.split(filename) if len(data) == 2: if data[1] == '.directory': filename = data[0] info = mmpython.parse(filename) if info: thumbnail = None if info.has_key('thumbnail'): thumbnail = info.thumbnail info = self.simplify(info) name = util.getname(filename) if name == name.upper() and info.has_key('type') and \ info['type'] in ('DVD', 'VCD'): name = util.getname(filename.lower()) info['title:filename'] = name if info.has_key('video'): for video in info['video']: for variable in ('width', 'height', 'length', 'aspect', 'fps'): if video.has_key(variable) and not \ (info.has_key(variable) and info[variable]): info[variable] = video[variable] if thumbnail and config.IMAGE_USE_EXIF_THUMBNAIL and config.CACHE_IMAGES: util.cache_image(filename, thumbnail) elif config.CACHE_IMAGES and info.has_key('mime') and info['mime'] and \ info['mime'].startswith('image'): util.cache_image(filename) if info.has_key('media') and info['media'] == 'MEDIA_DIRECTORY': pass info = self.normalize(info) return info return {}
def loadbitmap(self, url, cache=False): """ Load a bitmap and return the pygame image object. """ if cache: if cache == True: cache = self.bitmapcache s = cache[url] if s: return s if not pygame.display.get_init(): return None try: if url.mode == 'BGRA': url.mode = 'RGBA' image = pygame.image.fromstring( str(url.get_raw_data(format=url.mode)), url.size, url.mode) except AttributeError: pass if url[:8] == 'thumb://': filename = os.path.abspath(url[8:]) thumbnail = True else: filename = os.path.abspath(url) thumbnail = False if not os.path.isfile(filename): filename = os.path.join(config.IMAGE_DIR, url[8:]) if not os.path.isfile(filename): print 'osd.py: Bitmap file "%s" doesn\'t exist!' % filename return None try: if isstring(filename) and filename.endswith('.raw'): # load cache data = util.read_thumbnail(filename) #self.printdata(data) # convert to pygame image image = pygame.image.fromstring(data[0], data[1], data[2]) elif thumbnail: # load cache or create it data = util.cache_image(filename) #self.printdata(data) # convert to pygame image try: image = pygame.image.fromstring( data[0], data[1], data[2]) except: data = util.create_thumbnail(filename) #self.printdata(data) image = pygame.image.fromstring( data[0], data[1], data[2]) else: try: image = pygame.image.load(filename) except pygame.error, e: print 'SDL image load problem: %s - trying Imaging' % e i = Image.open(filename) image = pygame.image.fromstring( i.tostring(), i.size, i.mode) except: print 'Problem while loading image %s' % String(url) if config.DEBUG: traceback.print_exc() return None except Exception, e: print 'image.fromstring:', e return None
def loadbitmap(self, url, cache=False): """ Load a bitmap and return the pygame image object. """ if cache: if cache == True: cache = self.bitmapcache s = cache[url] if s: return s if not pygame.display.get_init(): return None try: if url.mode == 'BGRA': url.mode = 'RGBA' image = pygame.image.fromstring(str(url.get_raw_data(format=url.mode)), url.size, url.mode) except AttributeError: pass if url[:8] == 'thumb://': filename = os.path.abspath(url[8:]) thumbnail = True else: filename = os.path.abspath(url) thumbnail = False if not os.path.isfile(filename): filename = os.path.join(config.IMAGE_DIR, url[8:]) if not os.path.isfile(filename): _debug_('Bitmap file "%s" doesn\'t exist!' % filename, DWARNING) #raise 'Bitmap file' return None try: if isstring(filename) and filename.endswith('.raw'): # load cache data = util.read_thumbnail(filename) #self.printdata(data) # convert to pygame image image = pygame.image.fromstring(data[0], data[1], data[2]) elif thumbnail: # load cache or create it data = util.cache_image(filename) #self.printdata(data) # convert to pygame image try: image = pygame.image.fromstring(data[0], data[1], data[2]) except: data = util.create_thumbnail(filename) #self.printdata(data) image = pygame.image.fromstring(data[0], data[1], data[2]) else: try: image = pygame.image.load(filename) except pygame.error, e: _debug_('SDL image load problem: %s - trying imlib2' % e, DINFO) try: i = Image.open(filename) image = pygame.image.fromstring(i.tostring(), i.size, i.mode) except IOError, why: _debug_('imlib2 image load problem: %s' % (why), DERROR)