From dd63d9edb7ee37d88fbde52f7dcd6029263a4dd9 Mon Sep 17 00:00:00 2001
From: Gonzalo Odiard <godiard@gmail.com>
Date: Wed, 20 Mar 2013 09:57:20 -0300
Subject: [PATCH] Don't save preview encoded - SL #4470
We don't need save the preview in the metadata encoded,
doing it makes more difficult the interoperability with other
activities using it, and takes more space in the disk.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
---
glive.py | 2 +-
serialize.py | 9 +++++----
utils.py | 9 ++++++++-
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/glive.py b/glive.py
index 8618284..8fd11e7 100644
a
|
b
|
class Glive: |
366 | 366 | taglist = self._get_tags(constants.TYPE_AUDIO) |
367 | 367 | |
368 | 368 | if self._audio_pixbuf: |
369 | | pixbuf_b64 = utils.getStringFromPixbuf(self._audio_pixbuf) |
| 369 | pixbuf_b64 = utils.getStringEncodedFromPixbuf(self._audio_pixbuf) |
370 | 370 | taglist[gst.TAG_EXTENDED_COMMENT] = "coverart=" + pixbuf_b64 |
371 | 371 | |
372 | 372 | vorbis_enc = audioline.get_by_name('audioVorbisenc') |
diff --git a/serialize.py b/serialize.py
index 687bbaa..74e3a3c 100644
a
|
b
|
import cStringIO |
3 | 3 | import os |
4 | 4 | import gtk |
5 | 5 | import logging |
| 6 | import dbus |
6 | 7 | |
7 | 8 | from sugar.datastore import datastore |
8 | 9 | |
… |
… |
def _addRecdXmlAttrs(el, recd, forMeshTransmit): |
163 | 164 | if (recd.type == constants.TYPE_AUDIO) and (not forMeshTransmit): |
164 | 165 | aiPixbuf = recd.getAudioImagePixbuf() |
165 | 166 | if aiPixbuf: |
166 | | aiPixbufString = str(utils.getStringFromPixbuf(aiPixbuf)) |
| 167 | aiPixbufString = str(utils.getStringEncodedFromPixbuf(aiPixbuf)) |
167 | 168 | el.setAttribute('audioImage', aiPixbufString) |
168 | 169 | |
169 | 170 | if (recd.datastoreId != None) and (not forMeshTransmit): |
… |
… |
def _addRecdXmlAttrs(el, recd, forMeshTransmit): |
189 | 190 | |
190 | 191 | pixbuf = recd.getThumbPixbuf() |
191 | 192 | if pixbuf: |
192 | | thumb64 = str(utils.getStringFromPixbuf(pixbuf)) |
| 193 | thumb64 = str(utils.getStringEncodedFromPixbuf(pixbuf)) |
193 | 194 | el.setAttribute('base64Thumb', thumb64) |
194 | 195 | |
195 | 196 | def saveMediaHash(mediaHashs, activity): |
… |
… |
def _saveMediaToDatastore(el, recd, activity): |
272 | 273 | if datastorePreviewPixbuf.get_width() != datastorePreviewWidth: |
273 | 274 | datastorePreviewPixbuf = datastorePreviewPixbuf.scale_simple(datastorePreviewWidth, datastorePreviewHeight, gtk.gdk.INTERP_NEAREST) |
274 | 275 | |
275 | | datastorePreviewBase64 = utils.getStringFromPixbuf(datastorePreviewPixbuf) |
276 | | mediaObject.metadata['preview'] = datastorePreviewBase64 |
| 276 | datastorePreview = utils.getStringFromPixbuf(datastorePreviewPixbuf) |
| 277 | mediaObject.metadata['preview'] = dbus.ByteArray(datastorePreview) |
277 | 278 | |
278 | 279 | colors = str(recd.colorStroke) + "," + str(recd.colorFill) |
279 | 280 | mediaObject.metadata['icon-color'] = colors |
diff --git a/utils.py b/utils.py
index 28adc9c..701e45f 100644
a
|
b
|
from time import strftime |
8 | 8 | |
9 | 9 | import constants |
10 | 10 | |
11 | | def getStringFromPixbuf(pixbuf): |
| 11 | |
| 12 | def getStringEncodedFromPixbuf(pixbuf): |
12 | 13 | data = [""] |
13 | 14 | pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data) |
14 | 15 | return base64.b64encode(str(data[0])) |
15 | 16 | |
16 | 17 | |
| 18 | def getStringFromPixbuf(pixbuf): |
| 19 | data = [""] |
| 20 | pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data) |
| 21 | return str(data[0]) |
| 22 | |
| 23 | |
17 | 24 | def _saveDataToBufferCb(buf, data): |
18 | 25 | data[0] += buf |
19 | 26 | return True |