Beispiel #1
0
    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()
Beispiel #2
0
    def test_beautify_length(self):
        """Tests beautification of time duration."""
        self.assertEqual(beautify_length(second), "1 second")
        self.assertEqual(beautify_length(second * 2), "2 seconds")

        self.assertEqual(beautify_length(minute), "1 minute")
        self.assertEqual(beautify_length(minute * 2), "2 minutes")

        self.assertEqual(beautify_length(hour), "1 hour")
        self.assertEqual(beautify_length(hour * 2), "2 hours")

        self.assertEqual(beautify_length(minute + second), "1 minute, 1 second")
        self.assertEqual(beautify_length(hour + minute + second), "1 hour, 1 minute")
        self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
Beispiel #3
0
 def __set_tooltip_text(self, position, seeking=False):
     """Updates the tooltip."""
     if seeking:
         timeline_duration = self.timeline.ges_timeline.props.duration
         if position > timeline_duration:
             position = timeline_duration
     human_time = beautify_length(position)
     cur_frame = int(position / self.ns_per_frame) + 1
     self.set_tooltip_text(human_time + "\n" + _("Frame #%d") % cur_frame)
Beispiel #4
0
 def __set_tooltip_text(self, position, seeking=False):
     """Updates the tooltip."""
     if seeking:
         timeline_duration = self.timeline.ges_timeline.props.duration
         if position > timeline_duration:
             position = timeline_duration
     human_time = beautify_length(position)
     cur_frame = int(position / self.ns_per_frame) + 1
     self.set_tooltip_text(human_time + "\n" + _("Frame #%d") % cur_frame)
Beispiel #5
0
    def do_motion_notify_event(self, event):
        position = self.pixelToNs(event.x + self.pixbuf_offset)
        if self.pressed:
            self.debug("motion at event.x %d", event.x)
            self._seeker.seek(position)

        human_time = beautify_length(position)
        cur_frame = int(position / self.ns_per_frame) + 1
        self.set_tooltip_text(human_time + "\n" + _("Frame #%d" % cur_frame))
        return False
Beispiel #6
0
    def test_beautify_length(self):
        """Tests beautification of time duration."""
        self.assertEqual(beautify_length(second), "1 second")
        self.assertEqual(beautify_length(second * 2), "2 seconds")

        self.assertEqual(beautify_length(minute), "1 minute")
        self.assertEqual(beautify_length(minute * 2), "2 minutes")

        self.assertEqual(beautify_length(hour), "1 hour")
        self.assertEqual(beautify_length(hour * 2), "2 hours")

        self.assertEqual(beautify_length(minute + second),
                         "1 minute, 1 second")
        self.assertEqual(beautify_length(hour + minute + second),
                         "1 hour, 1 minute")
        self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
Beispiel #7
0
 def _sliderTooltipCb(self, unused_slider, unused_x, unused_y, unused_keyboard_mode, tooltip):
     # We assume the width of the ruler is exactly the width of the timeline.
     width_px = self.timeline.ruler.get_allocated_width()
     timeline_width_ns = Zoomable.pixelToNs(width_px)
     if timeline_width_ns >= Gst.SECOND:
         # Translators: %s represents a duration, for example "10 minutes"
         tip = _("%s displayed") % beautify_length(timeline_width_ns)
     else:
         # Translators: This is a tooltip
         tip = _("%d nanoseconds displayed, because we can") % timeline_width_ns
     tooltip.set_text(tip)
     return True
Beispiel #8
0
    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()
Beispiel #9
0
 def _sliderTooltipCb(self, unused_slider, unused_x, unused_y, unused_keyboard_mode, tooltip):
     # We assume the width of the ruler is exactly the width of the
     # timeline.
     width_px = self.timeline.ruler.get_allocated_width()
     timeline_width_ns = Zoomable.pixelToNs(width_px)
     if timeline_width_ns >= Gst.SECOND:
         # Translators: %s represents a duration, for example "10 minutes"
         tip = _("%s displayed") % beautify_length(timeline_width_ns)
     else:
         # Translators: This is a tooltip
         tip = _(
             "%d nanoseconds displayed, because we can") % timeline_width_ns
     tooltip.set_text(tip)
     return True
Beispiel #10
0
    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()
Beispiel #11
0
    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()
Beispiel #12
0
    def do_motion_notify_event(self, event):
        if not self._pipeline:
            return False

        position = self.pixelToNs(event.x + self.pixbuf_offset)

        seek_mask = Gdk.ModifierType.BUTTON3_MASK
        if self.app.settings.leftClickAlsoSeeks:
            seek_mask |= Gdk.ModifierType.BUTTON1_MASK
        if event.state & seek_mask:
            self.debug("motion at event.x %d", event.x)
            self._pipeline.simple_seek(position)

        human_time = beautify_length(position)
        cur_frame = int(position / self.ns_per_frame) + 1
        self.set_tooltip_text(human_time + "\n" + _("Frame #%d" % cur_frame))
        return False
Beispiel #13
0
    def do_motion_notify_event(self, event):
        if not self._pipeline:
            return False

        position = self.pixelToNs(event.x + self.pixbuf_offset)

        seek_mask = Gdk.ModifierType.BUTTON3_MASK
        if self.app.settings.leftClickAlsoSeeks:
            seek_mask |= Gdk.ModifierType.BUTTON1_MASK
        if event.state & seek_mask:
            self.debug("motion at event.x %d", event.x)
            self._pipeline.simple_seek(position)

        human_time = beautify_length(position)
        cur_frame = int(position / self.ns_per_frame) + 1
        self.set_tooltip_text(human_time + "\n" + _("Frame #%d" % cur_frame))
        return False
Beispiel #14
0
 def testBeautifyHoursAndMinutes(self):
     self.assertEqual(beautify_length(hour + minute + second),
                      "1 hour, 1 minute")
Beispiel #15
0
 def testBeautifySeconds(self):
     self.assertEqual(beautify_length(second), "1 second")
     self.assertEqual(beautify_length(second * 2), "2 seconds")
Beispiel #16
0
 def testBeautifyHours(self):
     self.assertEqual(beautify_length(hour), "1 hour")
     self.assertEqual(beautify_length(hour * 2), "2 hours")
Beispiel #17
0
 def testBeautifyHoursAndMinutes(self):
     self.failUnlessEqual(beautify_length(hour + minute + second),
             "1 hour, 1 minute")
Beispiel #18
0
    def _show_preview(self, uri, info):
        self.log("Show preview for %s", uri)
        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()
                path = Gst.uri_get_location(uri)
                try:
                    pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
                except GLib.Error as error:
                    self.debug("Failed loading image because: %s", error)
                    self._show_error(error.message)
                    return False
                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,
                                             GdkPixbuf.InterpType.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.uri = self.current_selected_uri
                self.player.set_simple_state(Gst.State.PAUSED)
                self.pos_adj.props.upper = duration
                video_width = video.get_natural_width()
                video_height = video.get_natural_height()
                w, h = self.__get_best_size(video_width, video_height)
                self.preview_video.set_size_request(w, h)
                self.preview_video.props.ratio = video_width / video_height
                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 = "\n".join([
                    _("<b>Resolution</b>: %d×%d") %
                    (video_width, video_height),
                    _("<b>Duration</b>: %s") % pretty_duration
                ])
        else:
            self.current_preview_type = 'audio'
            self.preview_video.hide()
            audio = info.get_audio_streams()
            if not audio:
                self.debug("Audio has no streams")
                return False

            audio = audio[0]
            self.pos_adj.props.upper = duration
            self.preview_image.set_from_icon_name("audio-x-generic",
                                                  Gtk.IconSize.DIALOG)
            self.preview_image.show()
            self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT)
            self.description = "\n".join([
                beautify_stream(audio),
                _("<b>Duration</b>: %s") % pretty_duration
            ])
            self.player.set_simple_state(Gst.State.NULL)
            self.player.uri = self.current_selected_uri
            self.player.set_simple_state(Gst.State.PAUSED)
            self.play_button.show()
            self.seeker.show()
            self.b_zoom_in.hide()
            self.b_zoom_out.hide()
            self.bbox.show()
        return True
Beispiel #19
0
 def testBeautifySeconds(self):
     self.failUnlessEqual(beautify_length(second), "1 second")
     self.failUnlessEqual(beautify_length(second * 2), "2 seconds")
Beispiel #20
0
 def testBeautifyHours(self):
     self.failUnlessEqual(beautify_length(hour), "1 hour")
     self.failUnlessEqual(beautify_length(hour * 2), "2 hours")
Beispiel #21
0
 def testBeautifyHoursAndMinutes(self):
     self.assertEqual(beautify_length(hour + minute + second),
                      "1 hour, 1 minute")
Beispiel #22
0
 def test_beautify_hours_and_minutes(self):
     self.assertEqual(beautify_length(hour + minute + second),
                      "1 hour, 1 minute")
Beispiel #23
0
 def testBeautifyHoursAndMinutes(self):
     self.failUnlessEqual(beautify_length(hour + minute + second),
             "1 hour, 1 minute")
Beispiel #24
0
 def testBeautifyMinutesAndSeconds(self):
     self.assertEqual(beautify_length(minute + second),
                      "1 minute, 1 second")
Beispiel #25
0
 def testBeautifyMinutesAndSeconds(self):
     self.failUnlessEqual(beautify_length(minute + second),
             "1 minute, 1 second")
Beispiel #26
0
 def testBeautifyHours(self):
     self.failUnlessEqual(beautify_length(hour), "1 hour")
     self.failUnlessEqual(beautify_length(hour * 2), "2 hours")
Beispiel #27
0
 def testBeautifyMinutes(self):
     self.failUnlessEqual(beautify_length(minute), "1 minute")
     self.failUnlessEqual(beautify_length(minute * 2), "2 minutes")
Beispiel #28
0
 def testBeautifySeconds(self):
     self.failUnlessEqual(beautify_length(second), "1 second")
     self.failUnlessEqual(beautify_length(second * 2), "2 seconds")
Beispiel #29
0
 def test_beautify_minutes_and_seconds(self):
     self.assertEqual(beautify_length(minute + second),
                      "1 minute, 1 second")
Beispiel #30
0
 def test_beautify_nothing(self):
     self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
Beispiel #31
0
    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()
Beispiel #32
0
 def testBeautifyMinutes(self):
     self.failUnlessEqual(beautify_length(minute), "1 minute")
     self.failUnlessEqual(beautify_length(minute * 2), "2 minutes")
Beispiel #33
0
    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 = GdkPixbuf.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, GdkPixbuf.InterpType.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.setClipUri(self.current_selected_uri)
                self.player.setState(Gst.State.PAUSED)
                self.pos_adj.props.upper = duration
                video_width = (
                    video.get_par_num() / video.get_par_denom()) * video.get_width()
                video_height = video.get_height()
                w, h = self.__get_best_size(video_width, video_height)
                self.preview_video.set_size_request(w, h)
                self.preview_video.setDisplayAspectRatio(
                    float(video_width) / video_height)
                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 = "\n".join([
                    _("<b>Resolution</b>: %d×%d") % (
                        video_width, video_height),
                    _("<b>Duration</b>: %s") % pretty_duration])
        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.props.upper = duration
            self.preview_image.set_from_icon_name(
                "audio-x-generic", Gtk.IconSize.DIALOG)
            self.preview_image.show()
            self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT)
            self.description = "\n".join([
                beautify_stream(audio),
                _("<b>Duration</b>: %s") % pretty_duration])
            self.player.setState(Gst.State.NULL)
            self.player.setClipUri(self.current_selected_uri)
            self.player.setState(Gst.State.PAUSED)
            self.play_button.show()
            self.seeker.show()
            self.b_zoom_in.hide()
            self.b_zoom_out.hide()
            self.bbox.show()
Beispiel #34
0
 def testBeautifyMinutesAndSeconds(self):
     self.failUnlessEqual(beautify_length(minute + second),
             "1 minute, 1 second")
Beispiel #35
0
 def test_beautify_seconds(self):
     self.assertEqual(beautify_length(second), "1 second")
     self.assertEqual(beautify_length(second * 2), "2 seconds")
Beispiel #36
0
    def _show_preview(self, uri, info):
        self.log("Show preview for %s", uri)
        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()
                path = Gst.uri_get_location(uri)
                try:
                    pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
                except GLib.Error as error:
                    self.debug("Failed loading image because: %s", error)
                    self._show_error(error.message)
                    return False
                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, GdkPixbuf.InterpType.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.setClipUri(self.current_selected_uri)
                self.player.setState(Gst.State.PAUSED)
                self.pos_adj.props.upper = duration
                video_width = (
                    video.get_par_num() / video.get_par_denom()) * video.get_width()
                video_height = video.get_height()
                w, h = self.__get_best_size(video_width, video_height)
                self.preview_video.set_size_request(w, h)
                aspect_ratio = video_width / video_height
                self.preview_video.setDisplayAspectRatio(aspect_ratio)
                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 = "\n".join([
                    _("<b>Resolution</b>: %d×%d") % (
                        video_width, video_height),
                    _("<b>Duration</b>: %s") % pretty_duration])
        else:
            self.current_preview_type = 'audio'
            self.preview_video.hide()
            audio = info.get_audio_streams()
            if not audio:
                self.debug("Audio has no streams")
                return False

            audio = audio[0]
            self.pos_adj.props.upper = duration
            self.preview_image.set_from_icon_name(
                "audio-x-generic", Gtk.IconSize.DIALOG)
            self.preview_image.show()
            self.preview_image.set_size_request(PREVIEW_WIDTH, PREVIEW_HEIGHT)
            self.description = "\n".join([
                beautify_stream(audio),
                _("<b>Duration</b>: %s") % pretty_duration])
            self.player.setState(Gst.State.NULL)
            self.player.setClipUri(self.current_selected_uri)
            self.player.setState(Gst.State.PAUSED)
            self.play_button.show()
            self.seeker.show()
            self.b_zoom_in.hide()
            self.b_zoom_out.hide()
            self.bbox.show()
        return True
Beispiel #37
0
 def test_beautify_minutes(self):
     self.assertEqual(beautify_length(minute), "1 minute")
     self.assertEqual(beautify_length(minute * 2), "2 minutes")
Beispiel #38
0
    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()
Beispiel #39
0
 def test_beautify_hours(self):
     self.assertEqual(beautify_length(hour), "1 hour")
     self.assertEqual(beautify_length(hour * 2), "2 hours")
Beispiel #40
0
 def testBeautifyMinutes(self):
     self.assertEqual(beautify_length(minute), "1 minute")
     self.assertEqual(beautify_length(minute * 2), "2 minutes")
Beispiel #41
0
 def test_beautify_nothing(self):
     self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
Beispiel #42
0
 def testBeautifyMinutesAndSeconds(self):
     self.assertEqual(beautify_length(minute + second),
                      "1 minute, 1 second")
Beispiel #43
0
 def test_beautify_hours_and_minutes(self):
     self.assertEqual(beautify_length(hour + minute + second),
                      "1 hour, 1 minute")
Beispiel #44
0
 def test_beautify_minutes_and_seconds(self):
     self.assertEqual(beautify_length(minute + second),
                      "1 minute, 1 second")
Beispiel #45
0
    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 = GdkPixbuf.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,
                                             GdkPixbuf.InterpType.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.props.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 = _("<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.props.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()