def onChange(filename): filename = fixZfsMount(filename) for root, sync in syncs.items(): if filename.startswith(root): # this one reads .n3 files into sesame log.info("rdf data sync on %r", filename) sync.someChange(filename, doubleCheckMtime=True) break if filename.startswith('/my/pic') and '/.hide/' not in filename: # this one wants to hear about image files for path/exif data if filename.startswith('/my/pic/upload'): fixSftpPerms() log.info("scanFs and scanExif on %r", filename) picUri = scanFs.fileChanged(filename) log.info('picUri is %r', picUri) if picUri is not None: # this will fail on videos (though i wish i could get the Pre metadata out of them) scanExif.addPic(picUri, rerunScans=True) mr = MediaResource(graph, picUri) if mr.isVideo(): mr.videoProgress() # todo: freshen thumbs here too? that should be on a lower # priority queue than getting the exif/file data v2.imageset.client.changed(picUri)
def imageDoc(self, uri): # check image first- maybe it was deleted try: t = photoCreated(self.graph, uri, useImageSet=False) unixTime = time.mktime(t.timetuple()) # untested except ValueError: t = None unixTime = 0 m = MediaResource(self.graph, uri, allVideos=self.allVideos) viewableBy = [] doc = { 'uri': uri, 't': t, # may be none 'unixTime': unixTime, # always a number, maybe 0 'isVideo': m.isVideo(), 'tags': set(unicode(lit) for lit in getTagLabels(self.graph, 'todo', uri)), } doc['_docTime'] = time.time() - t1 return [doc]
def imageResource(self, uri, ctx, t1, t2): r = MediaResource(graph, uri) size = getRequestedSize(ctx) useMp4 = ctx.arg('type') == 'mp4' jpg, mtime = r.getImageAndMtime(size, useMp4=useMp4) if r.isVideo(): if size is Video2: if useMp4: ct = 'video/mp4' else: ct = 'video/webm' else: ct = 'application/binary' else: ct = 'image/jpeg' if uri.endswith('webm'): ct = 'video/webm' return StaticCached(jpg, ct, mtime, t1, t2)
def featured(self): current = self.desc.currentPhoto() if current is None: return '' currentLocal = localSite(current) _, nextUri = self.prevNext() feat = MediaResource(self.graph, current) if feat.isVideo(): progress = feat.videoProgress() if progress is Done: w, h = feat.getSize(Video2) return dict(video=dict(sources=[ dict(src=currentLocal + "?size=video2", type='video/webm'), dict(src=currentLocal + "?size=video2&type=mp4", type='video/mp4') ], width=600, height=600 / w * h)) else: return dict(videoNotReady=dict(progress=progress, failed=isinstance( progress, FailedStatus))) else: try: size = feat.getSize(sizes["large"]) except (ValueError, IOError) as e: log.warn('current=%r', current) import traceback traceback.print_exc() size = (0, 0) marg = (602 - 2 - size[0]) // 2 return dict(image=dict( nextClick=self.desc.otherImageUrl(nextUri), src=currentLocal + "?size=large", w=size[0], h=size[1], marg=marg, alt=self.graph.label(current), ))
def onChange(filename): for root, sync in syncs.items(): if filename.startswith(root): # this one reads .n3 files into sesame log.info("rdf data sync on %r", filename) sync.someChange(filename, doubleCheckMtime=True) break if filename.startswith('/my/pic') and '/.hide/' not in filename: # this one wants to hear about image files for path/exif data if filename.startswith('/my/pic/upload'): fixSftpPerms() log.info("scanFs and scanExif on %r", filename) picUri = scanFs.fileChanged(filename) log.info('picUri is %r', picUri) if picUri is not None: # this will fail on videos (though i wish i could get the Pre metadata out of them) scanExif.addPic(picUri, rerunScans=True) mr = MediaResource(graph, picUri) if mr.isVideo(): mr.videoProgress()
def featured(self): current = self.desc.currentPhoto() if current is None: return '' currentLocal = localSite(current) _, nextUri = self.prevNext() feat = MediaResource(self.graph, current) if feat.isVideo(): progress = feat.videoProgress() if progress is Done: w, h = feat.getSize(Video2) return dict( video=dict( sources=[ dict(src=currentLocal+"?size=video2", type='video/webm'), dict(src=currentLocal+"?size=video2&type=mp4", type='video/mp4') ], width=600, height=600 / w * h)) else: return dict(videoNotReady=dict( progress=progress, failed=isinstance(progress, FailedStatus))) else: try: size = feat.getSize(sizes["large"]) except (ValueError, IOError) as e: log.warn('current=%r', current) import traceback;traceback.print_exc() size = (0,0) marg = (602 - 2 - size[0]) // 2 return dict(image=dict( nextClick=self.desc.otherImageUrl(nextUri), src=currentLocal+"?size=large", w=size[0], h=size[1], marg=marg, alt=self.graph.label(current), ))
def gatherDocs(self, uri): t1 = time.time() # check image first- maybe it was deleted try: t = photoCreated(self.graph, uri) unixTime = time.mktime(t.timetuple()) # untested except ValueError: t = None unixTime = 0 m = MediaResource(self.graph, uri) viewableBy = [] doc = { 'uri': uri, 't': t, # may be none 'unixTime': unixTime, # always a number, maybe 0 'isVideo': m.isVideo(), 'tags': set(str(lit) for lit in getTagLabels(self.graph, 'todo', uri)), } doc['_docTime'] = time.time() - t1 return [doc]