Example #1
0
    def getMediaFilepath(self):
        if (self.datastoreId == None):
            if (not self.buddy):
                #just taken by you, so it is in the tempSessionDir
                mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                return os.path.abspath(mediaFilepath)
            else:
                if (self.downloadedFromBuddy):
                    #the user has requested the high-res version, and it has downloaded
                    mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                    return os.path.abspath(mediaFilepath)
                else:
                    if self.mediaFilename == None:
                        #creating a new filepath, probably just got here from the mesh
                        ext = constants.MEDIA_INFO[self.type]['ext']
                        recdPath = os.path.join(Instance.instancePath, "recdFile_"+self.mediaMd5+"."+ext)
                        recdPath = utils.getUniqueFilepath(recdPath, 0)
                        self.mediaFilename = os.path.basename(recdPath)
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)
                    else:
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)

        else: #pulling from the datastore, regardless of who took it, cause we got it
            #first, get the datastoreObject and hold the reference in this Recorded instance
            if (self.datastoreOb == None):
                self.datastoreOb = serialize.getMediaFromDatastore( self )
            if (self.datastoreOb == None):
                print("RecordActivity error -- unable to get datastore object in getMediaFilepath")
                return None

            return self.datastoreOb.file_path
Example #2
0
    def getMediaFilepath(self):
        if (self.datastoreId == None):
            if (not self.buddy):
                #just taken by you, so it is in the tempSessionDir
                mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                return os.path.abspath(mediaFilepath)
            else:
                if (self.downloadedFromBuddy):
                    #the user has requested the high-res version, and it has downloaded
                    mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                    return os.path.abspath(mediaFilepath)
                else:
                    if self.mediaFilename == None:
                        #creating a new filepath, probably just got here from the mesh
                        ext = Constants.mediaTypes[self.type][Constants.keyExt]
                        recdPath = os.path.join(Instance.instancePath, "recdFile_"+self.mediaMd5+"."+ext)
                        recdPath = utils.getUniqueFilepath(recdPath, 0)
                        self.mediaFilename = os.path.basename(recdPath)
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)
                    else:
                        mediaFilepath = os.path.join(Instance.instancePath, self.mediaFilename)
                        return os.path.abspath(mediaFilepath)

        else: #pulling from the datastore, regardless of who took it, cause we got it
            #first, get the datastoreObject and hold the reference in this Recorded instance
            if (self.datastoreOb == None):
                self.datastoreOb = serialize.getMediaFromDatastore( self )
            if (self.datastoreOb == None):
                print("RecordActivity error -- unable to get datastore object in getMediaFilepath")
                return None

            return self.datastoreOb.file_path
Example #3
0
    def createNewRecorded(self, type):
        recd = Recorded()

        recd.recorderName = self.get_nickname()
        recd.recorderHash = Instance.keyHashPrintable

        # to create a file, use the hardware_id+time *and* check if
        # available or not
        nowtime = int(time.time())
        recd.time = nowtime
        recd.type = type

        mediaThumbFilename = str(recd.recorderHash) + "_" + str(recd.time)
        mediaFilename = mediaThumbFilename
        mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
        mediaFilepath = os.path.join(Instance.instancePath,
                                     mediaFilename)
        mediaFilepath = utils.getUniqueFilepath(mediaFilepath, 0)
        recd.mediaFilename = os.path.basename(mediaFilepath)

        stringType = constants.MEDIA_INFO[type]['istr']

        # Translators: photo by photographer, e.g. "Photo by Mary"
        recd.title = _('%(type)s by %(name)s') % \
            {'type': stringType, 'name': recd.recorderName}

        color = sugar3.profile.get_color()
        recd.colorStroke = color.get_stroke_color()
        recd.colorFill = color.get_fill_color()

        logger.debug('createNewRecorded: ' + str(recd))
        return recd
Example #4
0
    def createNewRecorded(self, type):
        recd = Recorded()

        recd.recorderName = self.get_nickname()
        recd.recorderHash = Instance.keyHashPrintable

        # to create a file, use the hardware_id+time *and* check if
        # available or not
        nowtime = int(time.time())
        recd.time = nowtime
        recd.type = type

        mediaThumbFilename = str(recd.recorderHash) + "_" + str(recd.time)
        mediaFilename = mediaThumbFilename
        mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
        mediaFilepath = os.path.join(Instance.instancePath, mediaFilename)
        mediaFilepath = utils.getUniqueFilepath(mediaFilepath, 0)
        recd.mediaFilename = os.path.basename(mediaFilepath)

        stringType = constants.MEDIA_INFO[type]['istr']

        # Translators: photo by photographer, e.g. "Photo by Mary"
        recd.title = _('%(type)s by %(name)s') % \
            {'type': stringType, 'name': recd.recorderName}

        color = sugar3.profile.get_color()
        recd.colorStroke = color.get_stroke_color()
        recd.colorFill = color.get_fill_color()

        logger.debug('createNewRecorded: ' + str(recd))
        return recd
Example #5
0
    def _copy_to_clipboard(self, recd):
        if recd == None:
            return
        if not recd.isClipboardCopyable():
            return

        media_path = recd.getMediaFilepath()
        tmp_path = utils.getUniqueFilepath(media_path, 0)
        shutil.copyfile(media_path, tmp_path)
        gtk.Clipboard().set_with_data([('text/uri-list', 0, 0)], self._clipboard_get, self._clipboard_clear, tmp_path)
Example #6
0
    def _copy_to_clipboard(self, recd):
        if recd == None:
            return
        if not recd.isClipboardCopyable():
            return

        media_path = recd.getMediaFilepath()
        tmp_path = utils.getUniqueFilepath(media_path, 0)
        shutil.copyfile(media_path, tmp_path)
        gtk.Clipboard().set_with_data([("text/uri-list", 0, 0)], self._clipboard_get, self._clipboard_clear, tmp_path)
Example #7
0
    def createCountdownPng(self, num):
        todisk = True

        rendered = False
        if (todisk):
            path = os.path.join(Instance.dataPath, str(num)+".png")
            if (os.path.exists(path)):
                rendered = True


        if (not rendered):
            w = self.__class__.dim_CONTROLBAR_HT
            h = w
            if (todisk):
                cimg = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
                ctx = cairo.Context(cimg)
            else:
                pixmap = gtk.gdk.Pixmap(None, w, h, 24)
                ctx = pixmap.cairo_create()
            ctx.rectangle(0, 0, w, h)
            ctx.set_source_rgb(0, 0, 0)
            ctx.fill()
            x = 0
            y = 4
            ctx.translate(x,y)
            ctx.set_source_surface (self.__class__.recCircleCairo, 0, 0)
            ctx.paint()
            ctx.translate(-x,-y)

            ctx.set_source_rgb(255, 255, 255)
            pctx = pangocairo.CairoContext(ctx)
            play = pctx.create_layout()
            font = pango.FontDescription("sans 30")
            play.set_font_description(font)
            play.set_text( ""+str(num) )
            dim = play.get_pixel_extents()
            ctx.translate( -dim[0][0], -dim[0][1] )
            xoff = (w-dim[0][2])/2
            yoff = (h-dim[0][3])/2
            ctx.translate( xoff, yoff )
            ctx.translate( -3, 0 )
            pctx.show_layout(play)

        img = gtk.Image()
        if (todisk):
            path = os.path.join(Instance.dataPath, str(num)+".png")
            if (not rendered):
                path = utils.getUniqueFilepath(path, 0)
                cimg.write_to_png(path)
            numPixbuf = gtk.gdk.pixbuf_new_from_file(path)
            img.set_from_pixbuf( numPixbuf )
        else:
            img.set_from_pixmap(pixmap, None)

        self.__class__.countdownImgs[int(num)] = img
Example #8
0
    def _recd_request_cb(self, remote_object, remote_person, md5sum):
        # if we are here, it is because someone has been told we have
        # what they want.  we need to send them that thing, whatever
        # that thing is
        recd = self.model.get_recd_by_md5(md5sum)
        if not recd:
            logger.debug('_recdRequestCb: we dont have the recd '
                         'they asked for')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        if recd.deleted:
            logger.debug('_recdRequestCb: we have the recd, '
                         'but it has been deleted, so we won\'t share')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        if recd.buddy and not recd.downloadedFromBuddy:
            logger.debug('_recdRequestCb: we have an incomplete recd, '
                         'so we won\'t share')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        recd.meshUploading = True
        path = recd.getMediaFilepath()

        if recd.type == constants.TYPE_AUDIO:
            audioImgFilepath = recd.getAudioImageFilepath()

            dest_path = os.path.join(Instance.instancePath, "audioBundle")
            dest_path = utils.getUniqueFilepath(dest_path, 0)
            cmd = "cat " + path + " " + audioImgFilepath + " > " + dest_path
            logger.debug(cmd)
            os.system(cmd)
            path = dest_path
        # TODO: add videoBundle from recd.getVideoImageFilepath() but
        # requires transmitting audioBundle size

        self._tube.broadcastRecd(recd.mediaMd5, path, remote_person)
        recd.meshUploading = False
        # if you were deleted while uploading, now throw away those bits now
        if recd.deleted:
            recd.doDeleteRecorded(recd)
Example #9
0
    def save_audio(self, path, still):
        recd = self.createNewRecorded(constants.TYPE_AUDIO)
        os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename))

        if still:
            image_path = os.path.join(Instance.instancePath, "audioPicture.png")
            image_path = utils.getUniqueFilepath(image_path, 0)
            still.save(image_path, "png")
            recd.audioImageFilename = os.path.basename(image_path)

            still = utils.generate_thumbnail(still)
            still.save(recd.make_thumb_path(), "png")

        self.createNewRecordedMd5Sums( recd )

        gobject.idle_add(self.add_recd, recd, priority=gobject.PRIORITY_HIGH)
        gobject.idle_add(self.set_state, constants.STATE_READY)
Example #10
0
    def save_video(self, path, still):
        recd = self.createNewRecorded(constants.TYPE_VIDEO)
        os.rename(path, os.path.join(Instance.instancePath,
                                     recd.mediaFilename))

        image_path = os.path.join(Instance.instancePath, "videoPicture.png")
        image_path = utils.getUniqueFilepath(image_path, 0)
        still.savev(image_path, "png", [], [])
        recd.videoImageFilename = os.path.basename(image_path)

        still = utils.generate_thumbnail(still)
        still.savev(recd.make_thumb_path(), "png", [], [])

        self.createNewRecordedMd5Sums(recd)

        GLib.idle_add(self.add_recd, recd, priority=GLib.PRIORITY_HIGH)
        GLib.idle_add(self.set_state, constants.STATE_READY)
Example #11
0
    def save_video(self, path, still):
        recd = self.createNewRecorded(constants.TYPE_VIDEO)
        os.rename(path, os.path.join(Instance.instancePath,
                                     recd.mediaFilename))

        image_path = os.path.join(Instance.instancePath, "videoPicture.png")
        image_path = utils.getUniqueFilepath(image_path, 0)
        still.savev(image_path, "png", [], [])
        recd.videoImageFilename = os.path.basename(image_path)

        still = utils.generate_thumbnail(still)
        still.savev(recd.make_thumb_path(), "png", [], [])

        self.createNewRecordedMd5Sums(recd)

        GLib.idle_add(self.add_recd, recd, priority=GLib.PRIORITY_HIGH)
        GLib.idle_add(self.set_state, constants.STATE_READY)
Example #12
0
    def _recd_request_cb(self, remote_object, remote_person, md5sum):
        # if we are here, it is because someone has been told we have
        # what they want.  we need to send them that thing, whatever
        # that thing is
        recd = self.model.get_recd_by_md5(md5sum)
        if not recd:
            logger.debug('_recdRequestCb: we dont have the recd '
                         'they asked for')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        if recd.deleted:
            logger.debug('_recdRequestCb: we have the recd, '
                         'but it has been deleted, so we won\'t share')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        if recd.buddy and not recd.downloadedFromBuddy:
            logger.debug('_recdRequestCb: we have an incomplete recd, '
                         'so we won\'t share')
            self._tube.unavailableRecd(md5sum, Instance.keyHashPrintable,
                                       remote_person)
            return

        recd.meshUploading = True
        path = recd.getMediaFilepath()

        if recd.type == constants.TYPE_AUDIO:
            audioImgFilepath = recd.getAudioImageFilepath()

            dest_path = os.path.join(Instance.instancePath, "audioBundle")
            dest_path = utils.getUniqueFilepath(dest_path, 0)
            cmd = "cat " + path + " " + audioImgFilepath + " > " + dest_path
            logger.debug(cmd)
            os.system(cmd)
            path = dest_path
        # TODO: add videoBundle from recd.getVideoImageFilepath() but
        # requires transmitting audioBundle size

        self._tube.broadcastRecd(recd.mediaMd5, path, remote_person)
        recd.meshUploading = False
        # if you were deleted while uploading, now throw away those bits now
        if recd.deleted:
            recd.doDeleteRecorded(recd)
Example #13
0
    def _recd_bits_arrived_cb(self, remote_object, md5sum, part, num_parts, bytes, sender):
        recd = self.model.get_recd_by_md5(md5sum)
        if not recd:
            logger.debug('_recdBitsArrivedCb: thx 4 yr bits, but we dont even have that photo')
            return
        if recd.deleted:
            logger.debug('_recdBitsArrivedCb: thx 4 yr bits, but we deleted that photo')
            return
        if recd.downloadedFromBuddy:
            logger.debug('_recdBitsArrivedCb: weve already downloadedFromBuddy')
            return
        if not recd.buddy:
            logger.debug('_recdBitsArrivedCb: uh, we took this photo, so dont need your bits')
            return
        if recd.meshDownloadingFrom != sender:
            logger.debug('_recdBitsArrivedCb: wrong bits ' + str(sender) + ", exp:" + str(recd.meshDownloadingFrom))
            return

        #update that we've heard back about this, reset the timeout
        gobject.source_remove(recd.meshReqCallbackId)
        recd.meshReqCallbackId = gobject.timeout_add(self._collab_timeout, self._check_recd_request, recd)

        #update the progress bar
        recd.meshDownlodingPercent = (part+0.0)/(num_parts+0.0)
        recd.meshDownloadingProgress = True
        self.activity.update_download_progress(recd)
        open(recd.getMediaFilepath(), 'a+').write(bytes)

        if part > num_parts:
            logger.error('More parts than required have arrived')
            return
        if part != num_parts:
            return

        logger.debug('Finished receiving %s' % recd.title)
        gobject.source_remove(recd.meshReqCallbackId)
        recd.meshReqCallbackId = 0
        recd.meshDownloading = False
        recd.meshDownlodingPercent = 1.0
        recd.downloadedFromBuddy = True
        if recd.type == constants.TYPE_AUDIO:
            path = recd.getMediaFilepath()
            bundle_path = os.path.join(Instance.instancePath, "audioBundle")
            bundle_path = utils.getUniqueFilepath(bundle_path, 0)

            cmd = "split -a 1 -b " + str(recd.mediaBytes) + " " + path + " " + bundle_path
            logger.debug(cmd)
            os.system(cmd)

            bundle_name = os.path.basename(bundle_path)
            media_filename = bundle_name + "a"
            media_path = os.path.join(Instance.instancePath, media_filename)
            media_path_ext = os.path.join(Instance.instancePath, media_filename+".ogg")
            os.rename(media_path, media_path_ext)
            audio_image_name = bundle_name + "b"
            audio_image_path = os.path.join(Instance.instancePath, audio_image_name)
            audio_image_path_ext = os.path.join(Instance.instancePath, audio_image_name+".png")
            os.rename(audio_image_path, audio_image_path_ext)

            recd.mediaFilename = os.path.basename(media_path_ext)
            recd.audioImageFilename = os.path.basename(audio_image_path_ext)

        self.activity.remote_recd_available(recd)
Example #14
0
    def addMedia(self, lat, lon, datastoreOb):
        rec = Recorded()

        #default photo
        rec.type = Constants.TYPE_PHOTO
        if ((datastoreOb.metadata['mime_type'] == "video/ogg")
                or (datastoreOb.metadata['mime_type'] == "audio/ogg")):
            rec.type = Constants.TYPE_VIDEO

        rec.source = Recorded.SOURCE_DATASTORE
        rec.datastoreOb = datastoreOb
        rec.datastoreId = datastoreOb.object_id

        rec.tags = ""
        if (datastoreOb.metadata.has_key("tags")):
            rec.tags = datastoreOb.metadata['tags']

        rec.latitude = lat
        rec.longitude = lon

        colors = datastoreOb.metadata['icon-color']
        colorStroke, colorFill = colors.split(",")
        rec.colorStroke = Color()
        rec.colorStroke.init_hex(colorStroke)
        rec.colorFill = Color()
        rec.colorFill.init_hex(colorFill)

        thumbPixbuf = None
        if (datastoreOb.metadata.has_key("preview")):
            try:
                thumb = datastoreOb.metadata['preview']
                if thumb[1:4] == 'PNG':
                    pbl = gtk.gdk.PixbufLoader()
                    pbl.write(thumb)
                    pbl.close()
                    thumbPixbuf = pbl.get_pixbuf()
                else:
                    thumbPixbuf = utils.getPixbufFromString(thumb)
            except:
                pass

        if (thumbPixbuf == None):
            #try to create the thumbnail yourself...
            if (rec.type == Constants.TYPE_PHOTO):
                try:
                    #load in the image, make a thumbnail
                    thumbPixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                        rec.getFilepath(), 320, 240)
                except:
                    pass

        if (thumbPixbuf == None):
            #i give up.  load in a blank image from the activity itself.
            thumbPath = os.path.join(self.ca.htmlPath, "1.jpg")
            thumbPixbuf = gtk.gdk.pixbuf_new_from_file(thumbPath)

        thumbFilepath = os.path.join(Instance.instancePath, "thumb.png")
        thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
        thumbPixbuf.save(thumbFilepath, "png", {})
        rec.thumbFilename = os.path.basename(thumbFilepath)

        self.recs.append(rec)

        return rec
Example #15
0
def fillRecdFromNode(recd, el):
    if el.getAttributeNode('type'):
        recd.type = int(el.getAttribute('type'))

    if el.getAttributeNode('title'):
        recd.title = el.getAttribute('title')

    if el.getAttributeNode('time'):
        recd.time = int(el.getAttribute('time'))

    if el.getAttributeNode('photographer'):
        recd.recorderName = el.getAttribute('photographer')

    if el.getAttributeNode('tags'):
        recd.tags = el.getAttribute('tags')
    else:
        recd.tags = ""

    if el.getAttributeNode('recorderHash'):
        recd.recorderHash = el.getAttribute('recorderHash')

    if el.getAttributeNode('colorStroke'):
        recd.colorStroke = el.getAttribute('colorStroke')

    if el.getAttributeNode('colorFill'):
        recd.colorFill = el.getAttribute('colorFill')

    if el.getAttributeNode('buddy'):
        recd.buddy = (el.getAttribute('buddy') == "True")

    if el.getAttributeNode('mediaMd5'):
        recd.mediaMd5 = el.getAttribute('mediaMd5')

    if el.getAttributeNode('thumbMd5'):
        recd.thumbMd5 = el.getAttribute('thumbMd5')

    if el.getAttributeNode('mediaBytes'):
        recd.mediaBytes = el.getAttribute('mediaBytes')

    if el.getAttributeNode('thumbBytes'):
        recd.thumbBytes = el.getAttribute('thumbBytes')

    bt = el.getAttributeNode('base64Thumb')
    if bt:
        try:
            thumbPath = os.path.join(Instance.instancePath,
                                     "datastoreThumb.jpg")
            thumbPath = utils.getUniqueFilepath(thumbPath, 0)
            thumbImg = utils.getPixbufFromString(bt.nodeValue)
            thumbImg.save(thumbPath, "jpeg", {"quality": "85"})
            recd.thumbFilename = os.path.basename(thumbPath)
            logger.debug("saved thumbFilename")
        except:
            logger.error("unable to getRecdBase64Thumb")

    ai = el.getAttributeNode('audioImage')
    if (not ai == None):
        try:
            audioImagePath = os.path.join(Instance.instancePath,
                                          "audioImage.png")
            audioImagePath = utils.getUniqueFilepath(audioImagePath, 0)
            audioImage = utils.getPixbufFromString(ai.nodeValue)
            audioImage.save(audioImagePath, "png", {})
            recd.audioImageFilename = os.path.basename(audioImagePath)
            logger.debug("loaded audio image and set audioImageFilename")
        except:
            logger.error("unable to load audio image")

    datastoreNode = el.getAttributeNode('datastoreId')
    if datastoreNode:
        recd.datastoreId = datastoreNode.nodeValue

    return recd
Example #16
0
def fillRecdFromNode( recd, el ):
    if (el.getAttributeNode(Constants.recdType) != None):
        typeInt = int(el.getAttribute(Constants.recdType))
        recd.type = typeInt

    if (el.getAttributeNode(Constants.recdTitle) != None):
        recd.title = el.getAttribute(Constants.recdTitle)

    if (el.getAttributeNode(Constants.recdTime) != None):
        timeInt = int(el.getAttribute(Constants.recdTime))
        recd.time = timeInt

    if (el.getAttributeNode(Constants.recdRecorderName) != None):
        recd.recorderName = el.getAttribute(Constants.recdRecorderName)

    if (el.getAttributeNode(Constants.recdTags) != None):
        recd.tags = el.getAttribute(Constants.recdTags)
    else:
        recd.tags = ""

    if (el.getAttributeNode(Constants.recdRecorderHash) != None):
        recd.recorderHash = el.getAttribute(Constants.recdRecorderHash)

    if (el.getAttributeNode(Constants.recdColorStroke) != None):
        try:
            colorStrokeHex = el.getAttribute(Constants.recdColorStroke)
            colorStroke = Color()
            colorStroke.init_hex(colorStrokeHex)
            recd.colorStroke = colorStroke
        except:
            record.Record.log.error("unable to load recd colorStroke")

    if (el.getAttributeNode(Constants.recdColorFill) != None):
        try:
            colorFillHex = el.getAttribute(Constants.recdColorFill)
            colorFill = Color()
            colorFill.init_hex( colorFillHex )
            recd.colorFill = colorFill
        except:
            record.Record.log.error("unable to load recd colorFill")

    if (el.getAttributeNode(Constants.recdBuddy) != None):
        recd.buddy = (el.getAttribute(Constants.recdBuddy) == "True")

    if (el.getAttributeNode(Constants.recdMediaMd5) != None):
        recd.mediaMd5 = el.getAttribute(Constants.recdMediaMd5)

    if (el.getAttributeNode(Constants.recdThumbMd5) != None):
        recd.thumbMd5 = el.getAttribute(Constants.recdThumbMd5)

    if (el.getAttributeNode(Constants.recdMediaBytes) != None):
        recd.mediaBytes = el.getAttribute(Constants.recdMediaBytes)

    if (el.getAttributeNode(Constants.recdThumbBytes) != None):
        recd.thumbBytes = el.getAttribute(Constants.recdThumbBytes)

    bt = el.getAttributeNode(Constants.recdBase64Thumb)
    if (bt != None):
        try:
            thumbPath = os.path.join(Instance.instancePath, "datastoreThumb.jpg")
            thumbPath = utils.getUniqueFilepath( thumbPath, 0 )
            thumbImg = utils.getPixbufFromString( bt.nodeValue )
            thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )
            recd.thumbFilename = os.path.basename(thumbPath)
            record.Record.log.debug("saved thumbFilename")
        except:
            record.Record.log.error("unable to getRecdBase64Thumb")

    ai = el.getAttributeNode(Constants.recdAudioImage)
    if (not ai == None):
        try:
            audioImagePath = os.path.join(Instance.instancePath, "audioImage.png")
            audioImagePath = utils.getUniqueFilepath( audioImagePath, 0 )
            audioImage = utils.getPixbufFromString( ai.nodeValue )
            audioImage.save(audioImagePath, "png", {} )
            recd.audioImageFilename = os.path.basename(audioImagePath)
            record.Record.log.debug("loaded audio image and set audioImageFilename")
        except:
            record.Record.log.error("unable to load audio image")

    datastoreNode = el.getAttributeNode(Constants.recdDatastoreId)
    if (datastoreNode != None):
        recd.datastoreId = datastoreNode.nodeValue

    return recd
Example #17
0
def fillRecdFromNode(recd, el):
    if el.getAttributeNode('type'):
        recd.type = int(el.getAttribute('type'))

    if el.getAttributeNode('title'):
        recd.title = el.getAttribute('title')

    if el.getAttributeNode('time'):
        recd.time = int(el.getAttribute('time'))

    if el.getAttributeNode('photographer'):
        recd.recorderName = el.getAttribute('photographer')

    if el.getAttributeNode('tags'):
        recd.tags = el.getAttribute('tags')
    else:
        recd.tags = ""

    if el.getAttributeNode('recorderHash'):
        recd.recorderHash = el.getAttribute('recorderHash')

    if el.getAttributeNode('colorStroke'):
        recd.colorStroke = el.getAttribute('colorStroke')

    if el.getAttributeNode('colorFill'):
        recd.colorFill = el.getAttribute('colorFill')

    if el.getAttributeNode('buddy'):
        recd.buddy = (el.getAttribute('buddy') == "True")

    if el.getAttributeNode('mediaMd5'):
        recd.mediaMd5 = el.getAttribute('mediaMd5')

    if el.getAttributeNode('thumbMd5'):
        recd.thumbMd5 = el.getAttribute('thumbMd5')

    if el.getAttributeNode('mediaBytes'):
        recd.mediaBytes = el.getAttribute('mediaBytes')

    if el.getAttributeNode('thumbBytes'):
        recd.thumbBytes = el.getAttribute('thumbBytes')

    bt = el.getAttributeNode('base64Thumb')
    if bt:
        thumbPath = os.path.join(Instance.instancePath, "datastoreThumb.jpg")
        thumbPath = utils.getUniqueFilepath(thumbPath, 0)
        thumbImg = utils.getPixbufFromString(bt.nodeValue)
        thumbImg.savev(thumbPath, 'png', [], [])
        recd.thumbFilename = os.path.basename(thumbPath)

    ai = el.getAttributeNode('audioImage')
    if (ai is not None):
        audioImagePath = os.path.join(Instance.instancePath, "audioImage.png")
        audioImagePath = utils.getUniqueFilepath(audioImagePath, 0)
        audioImage = utils.getPixbufFromString(ai.nodeValue)
        audioImage.savev(audioImagePath, "png", [], [])
        recd.audioImageFilename = os.path.basename(audioImagePath)

    vi = el.getAttributeNode('videoImage')
    if (vi is not None):
        videoImagePath = os.path.join(Instance.instancePath, "videoImage.png")
        videoImagePath = utils.getUniqueFilepath(videoImagePath, 0)
        videoImage = utils.getPixbufFromString(vi.nodeValue)
        videoImage.savev(videoImagePath, "png", [], [])
        recd.videoImageFilename = os.path.basename(videoImagePath)

    datastoreNode = el.getAttributeNode('datastoreId')
    if datastoreNode:
        recd.datastoreId = datastoreNode.nodeValue

    return recd
Example #18
0
def fillRecdFromNode(recd, el):
    if el.getAttributeNode('type'):
        recd.type = int(el.getAttribute('type'))

    if el.getAttributeNode('title'):
        recd.title = el.getAttribute('title')

    if el.getAttributeNode('time'):
        recd.time = int(el.getAttribute('time'))

    if el.getAttributeNode('photographer'):
        recd.recorderName = el.getAttribute('photographer')

    if el.getAttributeNode('tags'):
        recd.tags = el.getAttribute('tags')
    else:
        recd.tags = ""

    if el.getAttributeNode('recorderHash'):
        recd.recorderHash = el.getAttribute('recorderHash')

    if el.getAttributeNode('colorStroke'):
        recd.colorStroke = el.getAttribute('colorStroke')

    if el.getAttributeNode('colorFill'):
        recd.colorFill = el.getAttribute('colorFill')

    if el.getAttributeNode('buddy'):
        recd.buddy = (el.getAttribute('buddy') == "True")

    if el.getAttributeNode('mediaMd5'):
        recd.mediaMd5 = el.getAttribute('mediaMd5')

    if el.getAttributeNode('thumbMd5'):
        recd.thumbMd5 = el.getAttribute('thumbMd5')

    if el.getAttributeNode('mediaBytes'):
        recd.mediaBytes = el.getAttribute('mediaBytes')

    if el.getAttributeNode('thumbBytes'):
        recd.thumbBytes = el.getAttribute('thumbBytes')

    bt = el.getAttributeNode('base64Thumb')
    if bt:
        try:
            thumbPath = os.path.join(Instance.instancePath, "datastoreThumb.jpg")
            thumbPath = utils.getUniqueFilepath(thumbPath, 0)
            thumbImg = utils.getPixbufFromString(bt.nodeValue)
            thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )
            recd.thumbFilename = os.path.basename(thumbPath)
            logger.debug("saved thumbFilename")
        except:
            logger.error("unable to getRecdBase64Thumb")

    ai = el.getAttributeNode('audioImage')
    if (not ai == None):
        try:
            audioImagePath = os.path.join(Instance.instancePath, "audioImage.png")
            audioImagePath = utils.getUniqueFilepath( audioImagePath, 0 )
            audioImage = utils.getPixbufFromString( ai.nodeValue )
            audioImage.save(audioImagePath, "png", {} )
            recd.audioImageFilename = os.path.basename(audioImagePath)
            logger.debug("loaded audio image and set audioImageFilename")
        except:
            logger.error("unable to load audio image")

    datastoreNode = el.getAttributeNode('datastoreId')
    if datastoreNode:
        recd.datastoreId = datastoreNode.nodeValue

    return recd
Example #19
0
 def make_thumb_path(self):
     thumbFilename = self.mediaFilename + "_thumb.jpg"
     thumbFilepath = os.path.join(Instance.instancePath, thumbFilename)
     thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
     self.thumbFilename = os.path.basename(thumbFilepath)
     return self.getThumbFilepath()
Example #20
0
	def addMedia(self, lat, lon, datastoreOb):
		rec = Recorded()

		#default photo
		rec.type = Constants.TYPE_PHOTO
		if((datastoreOb.metadata['mime_type'] == "video/ogg") or (datastoreOb.metadata['mime_type'] == "audio/ogg")):
			rec.type = Constants.TYPE_VIDEO

		rec.source = Recorded.SOURCE_DATASTORE
		rec.datastoreOb = datastoreOb
		rec.datastoreId = datastoreOb.object_id

		rec.tags = ""
		if (datastoreOb.metadata.has_key("tags")):
			rec.tags = datastoreOb.metadata['tags']

		rec.latitude = lat
		rec.longitude = lon
		

		colors = datastoreOb.metadata['icon-color']
		colorStroke, colorFill = colors.split(",")
		rec.colorStroke = Color()
		rec.colorStroke.init_hex(colorStroke)
		rec.colorFill = Color()
		rec.colorFill.init_hex(colorFill)

		thumbPixbuf = None
		if (datastoreOb.metadata.has_key("preview")):
			try:
				thumb = datastoreOb.metadata['preview']
				if thumb[1:4] == 'PNG':
					pbl = GdkPixbuf.PixbufLoader()
					pbl.write(thumb)
					pbl.close()
					thumbPixbuf = pbl.get_pixbuf()
				else:
					thumbPixbuf = utils.getPixbufFromString(thumb)
			except:
				pass

		if (thumbPixbuf == None):
			#try to create the thumbnail yourself...
			if (rec.type == Constants.TYPE_PHOTO):
				try:
					#load in the image, make a thumbnail
					thumbPixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(rec.getFilepath(), 320, 240)
				except:
					pass

		if (thumbPixbuf == None):
			#i give up.  load in a blank image from the activity itself.
			thumbPath = os.path.join(self.ca.htmlPath, "1.jpg")
			thumbPixbuf = GdkPixbuf.Pixbuf.new_from_file(thumbPath)


		thumbFilepath = os.path.join(Instance.instancePath, "thumb.png")
		thumbFilepath = utils.getUniqueFilepath(thumbFilepath, 0)
		thumbPixbuf.save( thumbFilepath, "png", {} )
		rec.thumbFilename = os.path.basename(thumbFilepath)

		self.recs.append(rec)

		return rec
Example #21
0
    def _recd_bits_arrived_cb(self, remote_object, md5sum, part, num_parts,
                              bytes, sender):
        recd = self.model.get_recd_by_md5(md5sum)
        if not recd:
            logger.debug('_recdBitsArrivedCb: thx 4 yr bits, '
                         'but we dont even have that photo')
            return
        if recd.deleted:
            logger.debug('_recdBitsArrivedCb: thx 4 yr bits, '
                         'but we deleted that photo')
            return
        if recd.downloadedFromBuddy:
            logger.debug('_recdBitsArrivedCb: we\'ve already '
                         'downloadedFromBuddy')
            return
        if not recd.buddy:
            logger.debug('_recdBitsArrivedCb: uh, we took this photo, '
                         'so dont need your bits')
            return
        if recd.meshDownloadingFrom != sender:
            logger.debug('_recdBitsArrivedCb: wrong bits ' + str(sender) +
                         ', exp:' + str(recd.meshDownloadingFrom))
            return

        # update that we've heard back about this, reset the timeout
        if recd.meshReqCallbackId:
            GLib.source_remove(recd.meshReqCallbackId)
        recd.meshReqCallbackId = GLib.timeout_add(self._collab_timeout,
                                                  self._check_recd_request,
                                                  recd)

        # update the progress bar
        recd.meshDownlodingPercent = (part + 0.0) / (num_parts + 0.0)
        recd.meshDownloadingProgress = True
        self.activity.update_download_progress(recd)
        open(recd.getMediaFilepath(), 'a+').write(bytes)

        if part > num_parts:
            logger.error('More parts than required have arrived')
            return
        if part != num_parts:
            return

        logger.debug('Finished receiving %s' % recd.title)
        GLib.source_remove(recd.meshReqCallbackId)
        recd.meshReqCallbackId = 0
        recd.meshDownloading = False
        recd.meshDownlodingPercent = 1.0
        recd.downloadedFromBuddy = True
        if recd.type == constants.TYPE_AUDIO:
            path = recd.getMediaFilepath()
            bundle_path = os.path.join(Instance.instancePath, "audioBundle")
            bundle_path = utils.getUniqueFilepath(bundle_path, 0)
            # TODO: get videoBundle for recd.videoImageFilename
            # requires transmitting audioBundle size

            cmd = "split -a 1 -b " + str(recd.mediaBytes) + " " + path + \
                  " " + bundle_path
            logger.debug(cmd)
            os.system(cmd)

            bundle_name = os.path.basename(bundle_path)
            media_filename = bundle_name + "a"
            media_path = os.path.join(Instance.instancePath, media_filename)
            media_path_ext = os.path.join(Instance.instancePath,
                                          media_filename + ".ogg")
            os.rename(media_path, media_path_ext)
            audio_image_name = bundle_name + "b"
            audio_image_path = os.path.join(Instance.instancePath,
                                            audio_image_name)
            audio_image_path_ext = os.path.join(Instance.instancePath,
                                                audio_image_name + ".png")
            os.rename(audio_image_path, audio_image_path_ext)

            recd.mediaFilename = os.path.basename(media_path_ext)
            recd.audioImageFilename = os.path.basename(audio_image_path_ext)

        self.activity.remote_recd_available(recd)