def __init__(self):
        GObject.GObject.__init__(self)
        ScannerTagReader.__init__(self)

        self._inotify = None
        if Lp.settings.get_value('auto-update'):
            self._inotify = Inotify()
        self._is_empty = True
        self._in_thread = False
        self._is_locked = False
        self._progress = None
Exemple #2
0
    def __init__(self):
        """
            Init collection scanner
        """
        GObject.GObject.__init__(self)
        ScannerTagReader.__init__(self)

        self._thread = None
        self._inotify = None
        if Lp().settings.get_value('auto-update'):
            self._inotify = Inotify()
        self._progress = None
    def __init__(self):
        """
            Init collection scanner
        """
        GObject.GObject.__init__(self)
        ScannerTagReader.__init__(self)

        self._thread = None
        self._inotify = None
        if Lp().settings.get_value('auto-update'):
            self._inotify = Inotify()
        self._progress = None
Exemple #4
0
    def __init__(self):
        """
            Init collection scanner
        """
        GObject.GObject.__init__(self)
        ScannerTagReader.__init__(self)

        self._albums_popularity = {}
        self._albums_mtime = {}
        self._tracks_popularity = {}
        self._tracks_ltime = {}
        self._thread = None
        self._inotify = None
        if Lp.settings.get_value("auto-update"):
            self._inotify = Inotify()
        self._is_empty = True
        self._progress = None
Exemple #5
0
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.set_position(Gtk.PositionType.BOTTOM)
        self.connect('unmap', self._on_self_unmap)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
        self._signal_id = Lp().player.connect('current-changed',
                                              self._on_current_changed)
        size_setting = Lp().settings.get_value('window-size')
        if isinstance(size_setting[1], int):
            self.set_size_request(400, size_setting[1] * 0.7)
        else:
            self.set_size_request(400, 600)
Exemple #6
0
    def __init__(self):
        """
            Init collection scanner
        """
        GObject.GObject.__init__(self)
        ScannerTagReader.__init__(self)

        self._albums_popularity = {}
        self._albums_mtime = {}
        self._tracks_popularity = {}
        self._tracks_ltime = {}

        self._inotify = None
        if Lp.settings.get_value('auto-update'):
            self._inotify = Inotify()
        self._is_empty = True
        self._in_thread = False
        self._is_locked = False
        self._progress = None
Exemple #7
0
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
Exemple #8
0
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.set_position(Gtk.PositionType.BOTTOM)
        self.connect('unmap', self._on_self_unmap)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
        self._signal_id = Lp().player.connect('current-changed',
                                              self._on_current_changed)
        size_setting = Lp().settings.get_value('window-size')
        if isinstance(size_setting[1], int):
            self.set_size_request(400, size_setting[1]*0.7)
        else:
            self.set_size_request(400, 600)
Exemple #9
0
    def _on_bus_message_tag(self, bus, message):
        """
            Read tags from stream
            @param bus as Gst.Bus
            @param message as Gst.Message
        """
        if self.current_track.id >= 0 or\
           self.current_track.duration > 0.0:
            return
        debug("Player::_on_bus_message_tag(): %s" % self.current_track.uri)
        reader = ScannerTagReader()
        tags = message.parse_tag()

        title = reader.get_title(tags, '')
        if title != '':
            self.current_track.name = title
        if self.current_track.name == '':
            self.current_track.name = self.current_track.uri

        artist = reader.get_artists(tags)
        if artist != '':
            self.current_track.artist_names = artist

        # If title set, force artist
        if self.current_track.title != '' and self.current_track.artist == '':
            self.current_track.artist_names = self.current_track.album_artist

        if self.current_track.id == Type.EXTERNALS:
            (b, duration) = self._playbin.query_duration(Gst.Format.TIME)
            if b:
                self.current_track.duration = duration / 1000000000
            # We do not use tagreader as we need to check if value is None
            self.current_track.album_name = tags.get_string_index('album',
                                                                  0)[1]
            if self.current_track.album_name is None:
                self.current_track.album_name = ''
            self.current_track.artist_names = reader.get_artists(tags)
            self.current_track.set_album_artist(reader.get_album_artist(tags))
            if self.current_track.album_artist == '':
                self.current_track.set_album_artist(self.current_track.artist)
            self.current_track.genre_name = reader.get_genres(tags)
        self.emit('current-changed')
Exemple #10
0
    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
Exemple #11
0
    def _on_bus_message_tag(self, bus, message):
        if self.current_track.id >= 0:
            return
        reader = ScannerTagReader()
        tags = message.parse_tag()

        self.current_track.title = reader.get_title(tags,
                                                    self.current_track.uri)
        if self.current_track.id == Type.EXTERNALS:
            (b, duration) = self._playbin.query_duration(Gst.Format.TIME)
            if b:
                self.current_track.duration = duration/1000000000
            self.current_track.album = reader.get_album_name(tags)
            self.current_track.artist = reader.get_artists(tags)
            self.current_track.aartist = reader.get_album_artist(tags)
            if self.current_track.aartist is None:
                self.current_track.aartist = self.current_track.artist
            self.current_track.genre = reader.get_genres(tags)
        self.emit('current-changed')
Exemple #12
0
    def _on_bus_message_tag(self, bus, message):
        """
            Read tags from stream
            @param bus as Gst.Bus
            @param message as Gst.Message
        """
        if self.current_track.id >= 0 or\
           self.current_track.duration > 0.0:
            return
        debug("Player::_on_bus_message_tag(): %s" % self.current_track.uri)
        reader = ScannerTagReader()
        tags = message.parse_tag()

        title = reader.get_title(tags, '')
        if title != '':
            self.current_track.name = title
        if self.current_track.name == '':
            self.current_track.name = self.current_track.uri

        artist = reader.get_artists(tags)
        if artist != '':
            self.current_track.artist_names = artist

        # If title set, force artist
        if self.current_track.title != '' and self.current_track.artist == '':
            self.current_track.artist_names = self.current_track.album_artist

        if self.current_track.id == Type.EXTERNALS:
            (b, duration) = self._playbin.query_duration(Gst.Format.TIME)
            if b:
                self.current_track.duration = duration/1000000000
            # We do not use tagreader as we need to check if value is None
            self.current_track.album_name = tags.get_string_index('album',
                                                                  0)[1]
            if self.current_track.album_name is None:
                self.current_track.album_name = ''
            self.current_track.artist_names = reader.get_artists(tags)
            self.current_track.set_album_artist(reader.get_album_artist(tags))
            if self.current_track.album_artist == '':
                self.current_track.set_album_artist(self.current_track.artist)
            self.current_track.genre_name = reader.get_genres(tags)
        self.emit('current-changed')
Exemple #13
0
class ExternalsPopover(Gtk.Popover):
    """
        Popover for external tracks
    """

    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)

    def populate(self):
        """
            Populate popover
        """
        self._model.clear()
        start_new_thread(self._populate, (Lp.player.get_externals(),))

    def do_show(self):
        """
            Adjuste size and connect signals
        """
        self._signal_id = Lp.player.connect('current-changed',
                                            self._on_current_changed)
        size_setting = Lp.settings.get_value('window-size')
        if isinstance(size_setting[1], int):
            self.set_size_request(400, size_setting[1]*0.7)
        else:
            self.set_size_request(400, 600)
        Gtk.Popover.do_show(self)

    def do_hide(self):
        """
            Disconnect signals
        """
        if self._signal_id is not None:
            Lp.player.disconnect(self._signal_id)
        Gtk.Popover.do_hide(self)

#######################
# PRIVATE             #
#######################
    def _populate(self, tracks):
        """
            Populate popover
            @param tracks as [Track]
            @thread safe
        """
        for track in tracks:
            if track.duration == 0.0:
                try:
                    path = GLib.filename_from_uri(track.uri)[0]
                    infos = self._tagreader.get_infos(path)
                    if infos is not None:
                        tags = infos.get_tags()
                        track.duration = infos.get_duration()/1000000000
                        track.title = self._tagreader.get_title(tags, path)
                        track.artist = self._tagreader.get_artists(tags)
                except:
                    track.title = track.uri
            GLib.idle_add(self._add_track, track)

    def _add_track(self, track):
        """
            Add track to model
            @param track as Track
            @param filepath as string
        """
        if track.uri == Lp.player.current_track.uri:
            self._model.append((track.uri, 'media-playback-start-symbolic',
                                track.artist, track.title,
                                seconds_to_string(track.duration)))
        else:
            self._model.append((track.uri, '', track.artist, track.title,
                                seconds_to_string(track.duration)))

    def _on_current_changed(self, player):
        """
            Update play symbol
            @param player as Player
        """
        for item in self._model:
            if item[0] == player.current_track.uri:
                item[1] = 'media-playback-start-symbolic'
            else:
                item[1] = ''

    def _on_row_activated(self, view, path, column):
        """
            Play selected track
            @param view as Gtk.TreeView
            @param path as Gtk.TreePath
            @param column as Gtk.TreeViewColumn
        """    
        if path is not None:
            iterator = self._model.get_iter(path)
            if iterator is not None:
                uri = self._model.get_value(iterator, 0)
                Lp.player.play_this_external(uri)
Exemple #14
0
class ExternalsPopover(Gtk.Popover):
    """
        Popover for external tracks
    """

    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.set_position(Gtk.PositionType.BOTTOM)
        self.connect('unmap', self._on_self_unmap)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ExternalsPopover.ui')
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object('view')
        self._model = builder.get_object('model')
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property('weight', 800)
        renderer1.set_property('weight-set', True)
        renderer1.set_property('ellipsize-set', True)
        renderer1.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property('ellipsize-set', True)
        renderer2.set_property('ellipsize', Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn('')
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, 'icon-name', 1)
        column.add_attribute(renderer1, 'text', 2)
        column.add_attribute(renderer2, 'text', 3)
        column.add_attribute(renderer3, 'text', 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
        self._signal_id = Lp().player.connect('current-changed',
                                              self._on_current_changed)
        height = Lp().window.get_size()[1]
        self.set_size_request(400, height*0.7)

    def populate(self):
        """
            Populate popover
        """
        self._model.clear()
        self._populate(Lp().player.get_externals())

#######################
# PRIVATE             #
#######################
    def _populate(self, tracks):
        """
            Populate popover
            @param tracks as [Track]
            @thread safe
        """
        for track in tracks:
            if track.duration == 0.0:
                try:
                    infos = self._tagreader.get_infos(track.path)
                    if infos is not None:
                        tags = infos.get_tags()
                        track.duration = infos.get_duration()/1000000000
                        track.name = self._tagreader.get_title(tags,
                                                               track.path)
                        track.artist_names = self._tagreader.get_artists(tags)
                except Exception as e:
                    print("ExternalsPopover::_populate(): %s" % e)
                    track.name = track.uri
            GLib.idle_add(self._add_track, track)

    def _add_track(self, track):
        """
            Add track to model
            @param track as Track
            @param filepath as string
        """
        if track.uri == Lp().player.current_track.uri:
            self._model.append((track.uri, 'media-playback-start-symbolic',
                                track.artist, track.title,
                                seconds_to_string(track.duration)))
        else:
            self._model.append((track.uri, '', track.artist, track.title,
                                seconds_to_string(track.duration)))

    def _on_self_unmap(self, widget):
        """
            Disconnect signals and destroy
            @param widget as Gtk.Widget
        """
        if self._signal_id is not None:
            Lp().player.disconnect(self._signal_id)
        GLib.idle_add(self.destroy)

    def _on_current_changed(self, player):
        """
            Update play symbol
            @param player as Player
        """
        for item in self._model:
            if item[0] == player.current_track.uri:
                item[1] = 'media-playback-start-symbolic'
            else:
                item[1] = ''

    def _on_row_activated(self, view, path, column):
        """
            Play selected track
            @param view as Gtk.TreeView
            @param path as Gtk.TreePath
            @param column as Gtk.TreeViewColumn
        """
        if path is not None:
            iterator = self._model.get_iter(path)
            if iterator is not None:
                uri = self._model.get_value(iterator, 0)
                Lp().player.play_this_external(uri)
Exemple #15
0
class ExternalsPopover(Gtk.Popover):
    """
        Popover for external tracks
    """

    def __init__(self):
        """
            Init popover
        """
        Gtk.Popover.__init__(self)
        self.set_position(Gtk.PositionType.BOTTOM)
        self.connect("unmap", self._on_self_unmap)
        builder = Gtk.Builder()
        builder.add_from_resource("/org/gnome/Lollypop/ExternalsPopover.ui")
        builder.connect_signals(self)

        self._signal_id = None
        self._view = builder.get_object("view")
        self._model = builder.get_object("model")
        self._tagreader = ScannerTagReader()

        renderer0 = Gtk.CellRendererPixbuf()
        renderer1 = Gtk.CellRendererText()
        renderer1.set_property("weight", 800)
        renderer1.set_property("weight-set", True)
        renderer1.set_property("ellipsize-set", True)
        renderer1.set_property("ellipsize", Pango.EllipsizeMode.END)
        renderer2 = Gtk.CellRendererText()
        renderer2.set_property("ellipsize-set", True)
        renderer2.set_property("ellipsize", Pango.EllipsizeMode.END)
        renderer3 = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn("")
        column.pack_start(renderer0, True)
        column.pack_start(renderer1, True)
        column.pack_start(renderer2, True)
        column.pack_end(renderer3, False)
        column.add_attribute(renderer0, "icon-name", 1)
        column.add_attribute(renderer1, "text", 2)
        column.add_attribute(renderer2, "text", 3)
        column.add_attribute(renderer3, "text", 4)
        column.set_expand(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        self._view.append_column(column)
        self.add(self._view)
        self._signal_id = Lp().player.connect("current-changed", self._on_current_changed)
        size_setting = Lp().settings.get_value("window-size")
        if isinstance(size_setting[1], int):
            self.set_size_request(400, size_setting[1] * 0.7)
        else:
            self.set_size_request(400, 600)

    def populate(self):
        """
            Populate popover
        """
        self._model.clear()
        self._populate(Lp().player.get_externals())

    #######################
    # PRIVATE             #
    #######################
    def _populate(self, tracks):
        """
            Populate popover
            @param tracks as [Track]
            @thread safe
        """
        for track in tracks:
            if track.duration == 0.0:
                try:
                    infos = self._tagreader.get_infos(track.path)
                    if infos is not None:
                        tags = infos.get_tags()
                        track.duration = infos.get_duration() / 1000000000
                        track.name = self._tagreader.get_title(tags, track.path)
                        track.artist_names = self._tagreader.get_artists(tags)
                except Exception as e:
                    print("ExternalsPopover::_populate(): %s" % e)
                    track.name = track.uri
            GLib.idle_add(self._add_track, track)

    def _add_track(self, track):
        """
            Add track to model
            @param track as Track
            @param filepath as string
        """
        if track.uri == Lp().player.current_track.uri:
            self._model.append(
                (
                    track.uri,
                    "media-playback-start-symbolic",
                    track.artist,
                    track.title,
                    seconds_to_string(track.duration),
                )
            )
        else:
            self._model.append((track.uri, "", track.artist, track.title, seconds_to_string(track.duration)))

    def _on_self_unmap(self, widget):
        """
            Disconnect signals and destroy
            @param widget as Gtk.Widget
        """
        if self._signal_id is not None:
            Lp().player.disconnect(self._signal_id)
        GLib.idle_add(self.destroy)

    def _on_current_changed(self, player):
        """
            Update play symbol
            @param player as Player
        """
        for item in self._model:
            if item[0] == player.current_track.uri:
                item[1] = "media-playback-start-symbolic"
            else:
                item[1] = ""

    def _on_row_activated(self, view, path, column):
        """
            Play selected track
            @param view as Gtk.TreeView
            @param path as Gtk.TreePath
            @param column as Gtk.TreeViewColumn
        """
        if path is not None:
            iterator = self._model.get_iter(path)
            if iterator is not None:
                uri = self._model.get_value(iterator, 0)
                Lp().player.play_this_external(uri)