def testSaveProject(self): uri = "file://" + os.path.abspath("testproject.xptv") uri2 = "file://" + os.path.abspath("testproject2.xptv") path = gst.uri_get_location(uri) path2 = gst.uri_get_location(uri2) # unlink any existing project files try: os.unlink(path) os.unlink(path2) except OSError: pass # save a project self.failUnless(self.manager.newBlankProject()) self.failUnless(self.manager.saveProject( self.manager.current, uri, True)) self.failUnless(uri_is_reachable(uri)) # wait a bit time.sleep(1.0) # save project under new path self.failUnless(self.manager.saveProject( self.manager.current, uri2, True)) self.failUnless(uri_is_reachable(uri2)) # make sure the old path and the new path have different mtime mtime = os.path.getmtime(path) mtime2 = os.path.getmtime(path2) self.failUnless(mtime < mtime2) # wait a bit more time.sleep(1.0) # save project again under new path (by omitting uri arg) self.failUnless(self.manager.saveProject( self.manager.current, overwrite=True)) # regression test for bug 594396 # make sure we didn't save to the old URI self.failUnlessEqual(mtime, os.path.getmtime(path)) # make sure we did save to the new URI self.failUnless(mtime2 < os.path.getmtime(path2)) # unlink any existing project files try: os.unlink(path) os.unlink(path2) except OSError: pass
def _analyze(self): """ Sets up a pipeline to analyze the given uri """ self.current_uri = self.queue[0] self.info("Analyzing %s", self.current_uri) # check if file exists and is readable if gst.uri_get_protocol(self.current_uri) == "file": filename = gst.uri_get_location(self.current_uri) error = None if not os.access(filename, os.F_OK): error = _("File does not exist") elif not os.access(filename, os.R_OK): error = _("File not readable by current user") if error: self.info("Error: %s", self.error) self.error = error self._finishAnalysis( "File does not exist or is not readable by the current user" ) return False # setup graph and start analyzing self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri) # create the source element source = self._createSource() if source is None: self._finishAnalysis("no source") return False # create decodebin(2) dbin = self._createDecodeBin() self.pipeline.add(source, dbin) source.link(dbin) self.info("analysis pipeline created") # connect to bus messages self._connectToBus() self.info("setting pipeline to PAUSED") # go to PAUSED if self.pipeline.set_state( gst.STATE_PAUSED) == gst.STATE_CHANGE_FAILURE: if not self.error: self.error = _("Pipeline didn't want to go to PAUSED.") self.info("Pipeline didn't want to go to PAUSED") self._finishAnalysis("failure going to PAUSED") return False self._scheduleTimeout() # return False so we don't get called again return False
def uri_is_valid(uri): """Checks if the given uri is a valid uri (of type file://) Will also check if the size is valid (> 0). @param uri: The location to check @type uri: C{URI} """ return (gst.uri_is_valid(uri) and gst.uri_get_protocol(uri) == "file" and len(os.path.basename(gst.uri_get_location(uri))) > 0)
def _analyze(self): """ Sets up a pipeline to analyze the given uri """ self.current_uri = self.queue[0] self.info("Analyzing %s", self.current_uri) # check if file exists and is readable if gst.uri_get_protocol(self.current_uri) == "file": filename = gst.uri_get_location(self.current_uri) error = None if not os.access(filename, os.F_OK): error = _("File does not exist") elif not os.access(filename, os.R_OK): error = _("File not readable by current user") if error: self.info("Error: %s", self.error) self.error = error self._finishAnalysis("File does not exist or is not readable by the current user") return False # setup graph and start analyzing self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri) # create the source element source = self._createSource() if source is None: self._finishAnalysis("no source") return False # create decodebin(2) dbin = self._createDecodeBin() self.pipeline.add(source, dbin) source.link(dbin) self.info("analysis pipeline created") # connect to bus messages self._connectToBus() self.info("setting pipeline to PAUSED") # go to PAUSED if self.pipeline.set_state(gst.STATE_PAUSED) == gst.STATE_CHANGE_FAILURE: if not self.error: self.error = _("Pipeline didn't want to go to PAUSED.") self.info("Pipeline didn't want to go to PAUSED") self._finishAnalysis("failure going to PAUSED") return False self._scheduleTimeout() # return False so we don't get called again return False
def __init__(self, uri, size=100): object.__init__(self) self.hash = utils.misc.hash_file(gst.uri_get_location(uri)) self.cache = {} self.queue = collections.deque() dbfile = os.path.join(settings.get_dir(os.path.join(settings.xdg_cache_home(), "thumbs")), self.hash) self.conn = sqlite3.connect(dbfile) self.cur = self.conn.cursor() self.cur.execute("CREATE TABLE IF NOT EXISTS Thumbs (Time INTEGER NOT NULL PRIMARY KEY,\ Data BLOB NOT NULL, Width INTEGER NOT NULL, Height INTEGER NOT NULL)") self.size = size
def uri_is_reachable(uri): """ Check whether the given uri is reachable and we can read/write to it. @param uri: The location to check @type uri: C{URI} @return: C{True} if the uri is reachable. @rtype: C{bool} """ if not uri_is_valid(uri): raise NotImplementedError( # Translators: "non local" means the project is not stored # on a local filesystem _("%s doesn't yet handle non-local projects") % APPNAME) return os.path.isfile(gst.uri_get_location(uri))
def _on_zoom_clicked_cb(self, button, increment): if self.current_preview_type == 'video': w, h = self.preview_video.get_size_request() if increment > 0: w *= 1.2 h *= 1.2 else: w *= 0.8 h *= 0.8 if (w, h) < self.original_dims: (w, h) = self.original_dims self.preview_video.set_size_request(int(w), int(h)) self.settings.FCpreviewWidth = int(w) self.settings.FCpreviewHeight = int(h) elif self.current_preview_type == 'image': pixbuf = self.preview_image.get_pixbuf() w = pixbuf.get_width() h = pixbuf.get_height() if increment > 0: w *= 1.2 h *= 1.2 else: w *= 0.8 h *= 0.8 if (w, h) < self.original_dims: (w, h) = self.original_dims pixbuf = gtk.gdk.pixbuf_new_from_file( gst.uri_get_location(self.current_selected_uri)) pixbuf = pixbuf.scale_simple(int(w), int(h), gtk.gdk.INTERP_BILINEAR) w = max(w, self.settings.FCpreviewWidth) h = max(h, self.settings.FCpreviewHeight) self.preview_image.set_size_request(int(w), int(h)) self.preview_image.set_from_pixbuf(pixbuf) self.preview_image.show() self.settings.FCpreviewWidth = int(w) self.settings.FCpreviewHeight = int(h)
def _on_zoom_clicked_cb(self, button, increment): if self.current_preview_type == 'video': w, h = self.preview_video.get_size_request() if increment > 0: w *= 1.2 h *= 1.2 else: w *= 0.8 h *= 0.8 if (w, h) < self.original_dims: (w, h) = self.original_dims self.preview_video.set_size_request(int(w), int(h)) self.settings.FCpreviewWidth = int(w) self.settings.FCpreviewHeight = int(h) elif self.current_preview_type == 'image': pixbuf = self.preview_image.get_pixbuf() w = pixbuf.get_width() h = pixbuf.get_height() if increment > 0: w *= 1.2 h *= 1.2 else: w *= 0.8 h *= 0.8 if (w, h) < self.original_dims: (w, h) = self.original_dims pixbuf = gtk.gdk.pixbuf_new_from_file(gst.uri_get_location(self.current_selected_uri)) pixbuf = pixbuf.scale_simple(int(w), int(h), gtk.gdk.INTERP_BILINEAR) w = max(w, self.settings.FCpreviewWidth) h = max(h, self.settings.FCpreviewHeight) self.preview_image.set_size_request(int(w), int(h)) self.preview_image.set_from_pixbuf(pixbuf) self.preview_image.show() self.settings.FCpreviewWidth = int(w) self.settings.FCpreviewHeight = int(h)
def load(self): try: playlist = open(self._playlist_name, 'r') except: print "error reading playlist" return try: self._current_index = pickle.load(playlist) self._last_index = -1 self._media_position = pickle.load(playlist) self._media_duration = pickle.load(playlist) l = pickle.load(playlist) model = self._queue_listview.get_model() for uri, name, pos, userdata in l: model.append([uri, name, "", pos, userdata]) filename = gst.uri_get_location(uri) self.emit('item-queued', filename, name, pos, userdata) if self.__is_exposed: if not self._seek_in_ready(self._media_position): #retry once self._seek_in_ready(self._media_position) except ValueError, e: logging.warning("Playlist has incorrect format, unable to load")
def show_preview(self, uri, info): if info: self.preview_cache[uri] = info else: self.log("Show preview for " + uri) info = self.preview_cache.get(uri, None) if info is None: self.log("No preview for " + uri) return duration = info.get_duration() pretty_duration = beautify_length(duration) videos = info.get_video_streams() if videos: video = videos[0] if video.is_image(): self.current_preview_type = 'image' self.preview_video.hide() pixbuf = gtk.gdk.pixbuf_new_from_file(gst.uri_get_location(uri)) pixbuf_w = pixbuf.get_width() pixbuf_h = pixbuf.get_height() w, h = self.__get_best_size(pixbuf_w, pixbuf_h) pixbuf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_NEAREST) self.preview_image.set_from_pixbuf(pixbuf) self.preview_image.set_size_request(self.settings.FCpreviewWidth, self.settings.FCpreviewHeight) self.preview_image.show() self.bbox.show() self.play_button.hide() self.seeker.hide() self.b_zoom_in.show() self.b_zoom_out.show() else: self.current_preview_type = 'video' self.preview_image.hide() self.player.set_property("video-sink", self.__videosink) self.player.set_property("uri", self.current_selected_uri) self.player.set_state(gst.STATE_PAUSED) self.pos_adj.upper = duration w, h = self.__get_best_size((video.get_par_num() / video.get_par_denom()) * video.get_width(), video.get_height()) self.preview_video.set_size_request(w, h) self.preview_video.show() self.bbox.show() self.play_button.show() self.seeker.show() self.b_zoom_in.show() self.b_zoom_out.show() self.description = _(u"<b>Resolution</b>: %d×%d") % \ ((video.get_par_num() / video.get_par_denom()) * video.get_width(), video.get_height()) +\ "\n" + _("<b>Duration</b>: %s") % pretty_duration + "\n" else: self.current_preview_type = 'audio' self.preview_video.hide() audio = info.get_audio_streams() if not audio: return audio = audio[0] self.pos_adj.upper = duration self.preview_image.set_from_file(DEFAULT_AUDIO_IMAGE) self.preview_image.show() self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT) self.description = beautify_stream(audio) + "\n" + \ _("<b>Duration</b>: %s") % pretty_duration + "\n" self.player.set_state(gst.STATE_NULL) self.player.set_property("uri", self.current_selected_uri) self.player.set_property("video-sink", self.__fakesink) self.player.set_state(gst.STATE_PAUSED) self.play_button.show() self.seeker.show() self.b_zoom_in.hide() self.b_zoom_out.hide() self.bbox.show()
def show_preview(self, uri): self.log("Show preview for " + uri) factory = self.preview_cache.get(uri, None) if factory is None: self.log("No preview for " + uri) return if not factory.duration or factory.duration == gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(factory.duration) video = factory.getOutputStreams(VideoStream) if video: video = video[0] if type(factory) == PictureFileSourceFactory: self.current_preview_type = 'image' self.preview_video.hide() pixbuf = gtk.gdk.pixbuf_new_from_file(gst.uri_get_location(uri)) pixbuf_w = pixbuf.get_width() pixbuf_h = pixbuf.get_height() w, h = self.__get_best_size(pixbuf_w, pixbuf_h) pixbuf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_NEAREST) self.preview_image.set_from_pixbuf(pixbuf) self.preview_image.set_size_request(self.settings.FCpreviewWidth, self.settings.FCpreviewHeight) self.preview_image.show() self.bbox.show() self.play_button.hide() self.seeker.hide() self.b_zoom_in.show() self.b_zoom_out.show() else: self.current_preview_type = 'video' self.preview_image.hide() self.player.set_property("video-sink", self.__videosink) self.player.set_property("uri", self.current_selected_uri) self.player.set_state(gst.STATE_PAUSED) self.clip_duration = factory.duration self.pos_adj.upper = self.clip_duration w, h = self.__get_best_size(video.par * video.width, video.height) self.preview_video.set_size_request(w, h) self.preview_video.show() self.bbox.show() self.play_button.show() self.seeker.show() self.b_zoom_in.show() self.b_zoom_out.show() self.description = _(u"<b>Resolution</b>: %d×%d") % \ (video.par * video.width, video.height) + "\n" + \ _("<b>Duration</b>: %s") % duration + "\n" else: self.current_preview_type = 'audio' self.preview_video.hide() audio = factory.getOutputStreams(AudioStream) audio = audio[0] self.clip_duration = factory.duration self.pos_adj.upper = self.clip_duration self.preview_image.set_from_file(DEFAULT_AUDIO_IMAGE) self.preview_image.show() self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT) self.description = beautify_stream(audio) + "\n" + \ _("<b>Duration</b>: %s") % duration + "\n" self.player.set_state(gst.STATE_NULL) self.player.set_property("uri", self.current_selected_uri) self.player.set_property("video-sink", self.__fakesink) self.player.set_state(gst.STATE_PAUSED) self.play_button.show() self.seeker.show() self.b_zoom_in.hide() self.b_zoom_out.hide() self.bbox.show()
def show_preview(self, uri): self.log("Show preview for " + uri) factory = self.preview_cache.get(uri, None) if factory is None: self.log("No preview for " + uri) return if not factory.duration or factory.duration == gst.CLOCK_TIME_NONE: duration = '' else: duration = beautify_length(factory.duration) video = factory.getOutputStreams(VideoStream) if video: video = video[0] if type(factory) == PictureFileSourceFactory: self.current_preview_type = 'image' self.preview_video.hide() pixbuf = gtk.gdk.pixbuf_new_from_file( gst.uri_get_location(uri)) pixbuf_w = pixbuf.get_width() pixbuf_h = pixbuf.get_height() w, h = self.__get_best_size(pixbuf_w, pixbuf_h) pixbuf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_NEAREST) self.preview_image.set_from_pixbuf(pixbuf) self.preview_image.set_size_request( self.settings.FCpreviewWidth, self.settings.FCpreviewHeight) self.preview_image.show() self.bbox.show() self.play_button.hide() self.seeker.hide() self.b_zoom_in.show() self.b_zoom_out.show() else: self.current_preview_type = 'video' self.preview_image.hide() self.player.set_property("video-sink", self.__videosink) self.player.set_property("uri", self.current_selected_uri) self.player.set_state(gst.STATE_PAUSED) self.clip_duration = factory.duration self.pos_adj.upper = self.clip_duration w, h = self.__get_best_size(video.par * video.width, video.height) self.preview_video.set_size_request(w, h) self.preview_video.show() self.bbox.show() self.play_button.show() self.seeker.show() self.b_zoom_in.show() self.b_zoom_out.show() self.description = _(u"<b>Resolution</b>: %d×%d") % \ (video.par * video.width, video.height) + "\n" + \ _("<b>Duration</b>: %s") % duration + "\n" else: self.current_preview_type = 'audio' self.preview_video.hide() audio = factory.getOutputStreams(AudioStream) audio = audio[0] self.clip_duration = factory.duration self.pos_adj.upper = self.clip_duration self.preview_image.set_from_file(DEFAULT_AUDIO_IMAGE) self.preview_image.show() self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT) self.description = beautify_stream(audio) + "\n" + \ _("<b>Duration</b>: %s") % duration + "\n" self.player.set_state(gst.STATE_NULL) self.player.set_property("uri", self.current_selected_uri) self.player.set_property("video-sink", self.__fakesink) self.player.set_state(gst.STATE_PAUSED) self.play_button.show() self.seeker.show() self.b_zoom_in.hide() self.b_zoom_out.hide() self.bbox.show()
def addFile(self, uri, x=100, y=100): element = gst.element_factory_make("filesrc", os.path.basename(uri)) element.props.location = gst.uri_get_location(uri) self.addElement(element, x, y)