def _addAsset(self, asset): # 128 is the normal size for thumbnails, but for *icons* it looks insane LARGE_SIZE = 96 info = asset.get_info() # The code below tries to read existing thumbnails from the freedesktop # thumbnails directory (~/.thumbnails). The filenames are simply # the file URI hashed with md5, so we can retrieve them easily. video_streams = [i for i in info.get_stream_list() if isinstance(i, DiscovererVideoInfo)] if len(video_streams) > 0: # From the freedesktop spec: "if the environment variable # $XDG_CACHE_HOME is set and not blank then the directory # $XDG_CACHE_HOME/thumbnails will be used, otherwise # $HOME/.cache/thumbnails will be used." # Older version of the spec also mentioned $HOME/.thumbnails quoted_uri = quote_uri(info.get_uri()) thumbnail_hash = md5(quoted_uri).hexdigest() try: thumb_dir = os.environ['XDG_CACHE_HOME'] thumb_64, thumb_128 = self._getThumbnailInDir(thumb_dir, thumbnail_hash) except KeyError: thumb_64, thumb_128 = (None, None) if thumb_64 is None: thumb_dir = os.path.expanduser("~/.cache/thumbnails/") thumb_64, thumb_128 = self._getThumbnailInDir(thumb_dir, thumbnail_hash) if thumb_64 is None: thumb_dir = os.path.expanduser("~/.thumbnails/") thumb_64, thumb_128 = self._getThumbnailInDir(thumb_dir, thumbnail_hash) if thumb_64 is None: if asset.is_image(): thumb_64 = self._getIcon("image-x-generic") thumb_128 = self._getIcon("image-x-generic", None, LARGE_SIZE) else: thumb_64 = self._getIcon("video-x-generic") thumb_128 = self._getIcon("video-x-generic", None, LARGE_SIZE) # TODO ideally gst discoverer should create missing thumbnails. self.log("Missing a thumbnail for %s, queuing", path_from_uri(quoted_uri)) self._missing_thumbs.append(quoted_uri) else: thumb_64 = self._getIcon("audio-x-generic") thumb_128 = self._getIcon("audio-x-generic", None, LARGE_SIZE) if info.get_duration() == Gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(info.get_duration()) name = info_name(info) self.pending_rows.append((thumb_64, thumb_128, beautify_info(info), asset, info.get_uri(), duration, name)) if len(self.pending_rows) > 50: self.flush_pending_rows()
def _addDiscovererInfo(self, info): # The code below tries to read existing thumbnails from the freedesktop # thumbnails directory (~/.thumbnails). The filenames are simply # the file URI hashed with md5, so we can retrieve them easily. if [i for i in info.get_stream_list() if\ isinstance(i, DiscovererVideoInfo)]: thumbnail_hash = md5(info.get_uri()).hexdigest() thumb_dir = os.path.expanduser("~/.thumbnails/") thumb_path_normal = thumb_dir + "normal/" + thumbnail_hash + ".png" # Pitivi used to consider 64 pixels as normal and 96 as large # However, the fdo spec specifies 128 as normal and 256 as large. # We will thus simply use the "normal" size and scale it down. try: thumbnail = GdkPixbuf.Pixbuf.new_from_file(thumb_path_normal) thumbnail_large = thumbnail thumbnail_height = int(thumbnail.get_height() / 2) thumbnail = thumbnail.scale_simple(64, thumbnail_height, \ GdkPixbuf.InterpType.BILINEAR) except: # TODO gst discoverer should create missing thumbnails. thumbnail = self.videofilepixbuf thumbnail_large = thumbnail else: thumbnail = self.audiofilepixbuf thumbnail_large = self.audiofilepixbuf if info.get_duration() == Gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(info.get_duration()) short_text = None uni = unicode(info_name(info), 'utf-8') if len(uni) > 34: short_uni = uni[0:29] short_uni += unicode('...') short_text = short_uni.encode('utf-8') else: short_text = info_name(info) self.pending_rows.append((thumbnail, thumbnail_large, beautify_info(info), info, info.get_uri(), duration, info_name(info), short_text)) if len(self.pending_rows) > 50: self.flush_pending_rows()
def _addAsset(self, asset): info = asset.get_info() # The code below tries to read existing thumbnails from the freedesktop # thumbnails directory (~/.thumbnails). The filenames are simply # the file URI hashed with md5, so we can retrieve them easily. video_streams = [i for i in info.get_stream_list() if isinstance(i, DiscovererVideoInfo)] if len(video_streams) > 0: # From the freedesktop spec: "if the environment variable # $XDG_CACHE_HOME is set and not blank then the directory # $XDG_CACHE_HOME/thumbnails will be used, otherwise # $HOME/.cache/thumbnails will be used." # Older version of the spec also mentioned $HOME/.thumbnails thumbnail_hash = md5(quote_uri(info.get_uri())).hexdigest() try: thumb_dir = os.environ['XDG_CACHE_HOME'] thumbnail, thumbnail_large = self._getThumbnailInDir(thumb_dir, thumbnail_hash) except KeyError: thumbnail, thumbnail_large = (None, None) if thumbnail is None: thumb_dir = os.path.expanduser("~/.cache/thumbnails/") thumbnail, thumbnail_large = self._getThumbnailInDir(thumb_dir, thumbnail_hash) if thumbnail is None: thumb_dir = os.path.expanduser("~/.thumbnails/") thumbnail, thumbnail_large = self._getThumbnailInDir(thumb_dir, thumbnail_hash) if thumbnail is None: thumbnail = self.videofilepixbuf # TODO gst discoverer should create missing thumbnails. thumbnail_large = thumbnail else: thumbnail = self.audiofilepixbuf thumbnail_large = self.audiofilepixbuf if info.get_duration() == Gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(info.get_duration()) name = info_name(info) self.pending_rows.append((thumbnail, thumbnail_large, beautify_info(info), asset, info.get_uri(), duration, name)) if len(self.pending_rows) > 50: self.flush_pending_rows()
def _addAsset(self, asset): # 128 is the normal size for thumbnails, but for *icons* it looks # insane LARGE_SIZE = 96 info = asset.get_info() # The code below tries to read existing thumbnails from the freedesktop # thumbnails directory (~/.thumbnails). The filenames are simply # the file URI hashed with md5, so we can retrieve them easily. video_streams = [ i for i in info.get_stream_list() if isinstance(i, DiscovererVideoInfo) ] if len(video_streams) > 0: # From the freedesktop spec: "if the environment variable # $XDG_CACHE_HOME is set and not blank then the directory # $XDG_CACHE_HOME/thumbnails will be used, otherwise # $HOME/.cache/thumbnails will be used." # Older version of the spec also mentioned $HOME/.thumbnails quoted_uri = quote_uri(info.get_uri()) thumbnail_hash = md5(quoted_uri.encode()).hexdigest() try: thumb_dir = os.environ['XDG_CACHE_HOME'] thumb_64, thumb_128 = self._getThumbnailInDir( thumb_dir, thumbnail_hash) except KeyError: thumb_64, thumb_128 = (None, None) if thumb_64 is None: thumb_dir = os.path.expanduser("~/.cache/thumbnails/") thumb_64, thumb_128 = self._getThumbnailInDir( thumb_dir, thumbnail_hash) if thumb_64 is None: thumb_dir = os.path.expanduser("~/.thumbnails/") thumb_64, thumb_128 = self._getThumbnailInDir( thumb_dir, thumbnail_hash) if thumb_64 is None: if asset.is_image(): thumb_64 = self._getIcon("image-x-generic") thumb_128 = self._getIcon("image-x-generic", None, LARGE_SIZE) else: thumb_64 = self._getIcon("video-x-generic") thumb_128 = self._getIcon("video-x-generic", None, LARGE_SIZE) # TODO ideally gst discoverer should create missing thumbnails. self.log("Missing a thumbnail for %s, queuing", path_from_uri(quoted_uri)) self._missing_thumbs.append(quoted_uri) else: thumb_64 = self._getIcon("audio-x-generic") thumb_128 = self._getIcon("audio-x-generic", None, LARGE_SIZE) if info.get_duration() == Gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(info.get_duration()) name = info_name(info) self.pending_rows.append((thumb_64, thumb_128, beautify_info(info), asset, info.get_uri(), duration, name)) if len(self.pending_rows) > 50: self.flush_pending_rows()