Example #1
0
 def _append_track(self, tracks):
     if tracks:
         track_id = tracks.pop(0)
         filepath = Objects.tracks.get_path(track_id)
         album_id = Objects.tracks.get_album_id(track_id)
         artist_id = Objects.tracks.get_aartist_id(track_id)
         if artist_id == Navigation.COMPILATIONS:
             artist_ids = Objects.tracks.get_artist_ids(track_id)
             artist_name = ""
             for artist_id in artist_ids:
                 artist_name += translate_artist_name(
                                 Objects.artists.get_name(artist_id)) + ", "
             artist_name = artist_name[:-2]
         else:
             artist_name = Objects.artists.get_name(artist_id)
         track_name = Objects.tracks.get_name(track_id)
         art = Objects.art.get(album_id, ArtSize.SMALL)
         self._model.append([art,
                            "<b>%s</b>\n%s" % (
                                escape(translate_artist_name(artist_name)),
                                escape(track_name)),
                             self._del_pixbuf, filepath])
         self._tracks_orig.append(filepath)
         GLib.idle_add(self._append_track, tracks)
     else:
         self._view.grab_focus()
         self._in_thread = False
Example #2
0
 def _append_track(self, tracks):
     if tracks:
         track_id = tracks.pop(0)
         filepath = Objects.tracks.get_path(track_id)
         album_id = Objects.tracks.get_album_id(track_id)
         artist_id = Objects.tracks.get_aartist_id(track_id)
         if artist_id == Navigation.COMPILATIONS:
             artist_ids = Objects.tracks.get_artist_ids(track_id)
             artist_name = ""
             for artist_id in artist_ids:
                 artist_name += translate_artist_name(
                     Objects.artists.get_name(artist_id)) + ", "
             artist_name = artist_name[:-2]
         else:
             artist_name = Objects.artists.get_name(artist_id)
         track_name = Objects.tracks.get_name(track_id)
         art = Objects.art.get(album_id, ArtSize.SMALL)
         self._model.append([
             art,
             "<b>%s</b>\n%s" % (escape(
                 translate_artist_name(artist_name)), escape(track_name)),
             self._del_pixbuf, filepath
         ])
         self._tracks_orig.append(filepath)
         GLib.idle_add(self._append_track, tracks)
     else:
         self._view.grab_focus()
         self._in_thread = False
Example #3
0
    def _listallinfo(self, cmd_args):
        """
            List all tracks
            @syntax listallinfo
            @param args as str
            @return msg as str
        """
        i = 0
        msg = ""
        for (path, artist, album, album_artist,
             title, date, genre, time,
             track_id, pos) in self.server.mpddb.listallinfos():
            msg += "file: %s\nArtist: %s\nAlbum: %s\nAlbumArtist: %s\
\nTitle: %s\nDate: %s\nGenre: %s\nTime: %s\nId: %s\nPos: %s\nTrack: %s\n" % (
                                        path,
                                        translate_artist_name(artist),
                                        album,
                                        translate_artist_name(album_artist),
                                        title,
                                        date,
                                        genre,
                                        time,
                                        track_id,
                                        pos,
                                        pos)
            if i > 1000:
                self.request.send(msg.encode("utf-8"))
                msg = ""
                i = 0
            else:
                i += 1
        return msg
Example #4
0
 def _append_track(self, tracks):
     if tracks:
         track_id = tracks.pop(0)
         filepath = Lp.tracks.get_path(track_id)
         album_id = Lp.tracks.get_album_id(track_id)
         artist_id = Lp.tracks.get_aartist_id(track_id)
         if artist_id == Type.COMPILATIONS:
             artist_ids = Lp.tracks.get_artist_ids(track_id)
             artist_name = ""
             for artist_id in artist_ids:
                 artist_name += translate_artist_name(Lp.artists.
                                                      get_name(artist_id))\
                     + ", "
             artist_name = artist_name[:-2]
         else:
             artist_name = Lp.artists.get_name(artist_id)
         track_name = Lp.tracks.get_name(track_id)
         art = Lp.art.get_album(album_id, ArtSize.SMALL)
         self._model.append([art,
                            "<b>%s</b>\n%s" % (
                                escape(translate_artist_name(artist_name)),
                                escape(track_name)),
                             'user-trash-symbolic', filepath])
         self._tracks_orig.append(filepath)
         GLib.idle_add(self._append_track, tracks)
     else:
         self._view.grab_focus()
         self._in_thread = False
Example #5
0
	def _get_metadata(self):
		track_id = Objects["player"].get_current_track_id()
		if track_id == -1:
			return dbus.Dictionary({}, signature='sv')

		infos = Objects["tracks"].get_infos(track_id)
		album_id =  infos[4]
		album = Objects["albums"].get_name(album_id)
		artist = Objects["tracks"].get_artist_name(track_id)
		artist = translate_artist_name(artist)
		performer = Objects["tracks"].get_performer_name(track_id)
		performer = translate_artist_name(performer)
		genre_id = Objects["albums"].get_genre(album_id)
		genre = Objects["genres"].get_name(genre_id)
	
		metadata = {}	
		metadata['xesam:trackNumber'] = infos[3]
		metadata['xesam:title'] = infos[0]
		metadata['xesam:album'] = album
		metadata['xesam:artist'] = artist
		metadata['xesam:albumArtist'] = performer
		metadata['mpris:length'] = dbus.Int64(infos[2] * 1000000)
		metadata['xesam:genre'] = genre
		metadata['mpris:artUrl'] = "file://"+Objects["art"].get_path(album_id, ART_SIZE_BIG)
		
		return dbus.Dictionary(metadata, signature='sv')
Example #6
0
    def _load_track(self, track_id, sql=None):
        # Stop if needed
        if self.context.next == NextContext.STOP_TRACK:
            GLib.idle_add(self.stop)
            return False

        # Stop if album changed
        new_album_id = Objects.tracks.get_album_id(track_id, sql)
        if self.context.next == NextContext.STOP_ALBUM and\
           self.current.album_id != new_album_id:
            GLib.idle_add(self.stop)
            return False

        # Stop if aartist changed
        new_aartist_id = Objects.tracks.get_aartist_id(track_id, sql)
        if self.context.next == NextContext.STOP_ARTIST and\
           self.current.aartist_id != new_aartist_id:
            GLib.idle_add(self.stop)
            return False

        self.current.id = track_id
        self.current.title = Objects.tracks.get_name(self.current.id, sql)
        self.current.album_id = new_album_id
        self.current.album = Objects.albums.get_name(self.current.album_id,
                                                     sql)
        self.current.aartist_id = new_aartist_id
        self.current.aartist = translate_artist_name(
            Objects.artists.get_name(self.current.aartist_id, sql))
        artist_name = ""
        for artist_id in Objects.tracks.get_artist_ids(self.current.id, sql):
            artist_name += translate_artist_name(
                Objects.artists.get_name(artist_id, sql)) + ", "
        self.current.artist = artist_name[:-2]

        self.current.genre = Objects.albums.get_genre_name(
            self.current.album_id, sql)
        self.current.duration = Objects.tracks.get_length(self.current.id, sql)
        self.current.number = Objects.tracks.get_number(self.current.id, sql)
        self.current.path = Objects.tracks.get_path(self.current.id, sql)
        if path.exists(self.current.path):
            try:
                self._playbin.set_property(
                    'uri', GLib.filename_to_uri(self.current.path))
            except:  # Gstreamer error, stop
                self._on_errors()
                return False
        else:
            print("File doesn't exist: ", self.current.path)
            self._on_errors()
            return False
        return True
Example #7
0
 def get(self, genre_id, sql=None):
     """
         Get all available artists
         @param None
         or
         @param Filter genre id as int
         @return Array of (artist id as int, artist name as string)
     """
     if not sql:
         sql = Lp.sql
     result = []
     if genre_id == Type.ALL or genre_id is None:
         # Only artist that really have an album
         result = sql.execute("SELECT DISTINCT artists.rowid, artists.name\
                               FROM artists, albums\
                               WHERE albums.artist_id = artists.rowid\
                               ORDER BY artists.name COLLATE NOCASE")
     else:
         result = sql.execute("SELECT DISTINCT artists.rowid, artists.name\
                               FROM artists, albums, album_genres\
                               WHERE artists.rowid == albums.artist_id\
                               AND album_genres.genre_id=?\
                               AND album_genres.album_id=albums.rowid\
                               ORDER BY artists.name\
                               COLLATE NOCASE", (genre_id,))
     return [(row[0], translate_artist_name(row[1])) for row in result]
Example #8
0
    def update(self, values):
        self._updating = True
        if self._signal_id:
            self._view.disconnect(self._signal_id)
            self._signal_id = None
        for item in self._model:
            found = False
            for value in values:
                if item[1] == value[1]:
                    found = True
                    break
            # Remove not found items but not devices
            if not found and item[0] > Navigation.DEVICES:
                self._model.remove(item.iter)

        for value in values:
            found = False
            for item in self._model:
                if item[1] == value[1]:
                    found = True
                    break
            if not found:
                if self._is_artists:
                    string = translate_artist_name(value[1])
                else:
                    string = value[1]
                self._model.append(
                    [value[0], string,
                     self._get_pixbuf(value[0])])
        self._signal_id = self._view.connect('cursor-changed',
                                             self._new_item_selected)
        self._updating = False
Example #9
0
    def __init__(self, artist_id, genre_id):
        View.__init__(self)
        self._artist_id = artist_id
        self._genre_id = genre_id
        self._signal_id = None

        self._artist_name = Lp.artists.get_name(artist_id)
        if Lp.lastfm is not None:
            self._popover = InfosPopover(self._artist_name)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/ArtistView.ui')
        builder.connect_signals(self)
        self.attach(builder.get_object('ArtistView'), 0, 0, 1, 1)
        builder.get_object('artist').set_label(translate_artist_name(
            self._artist_name))

        self._pop_allowed = True

        self._albumbox = Gtk.Grid()
        self._albumbox.set_row_spacing(20)
        self._albumbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self._albumbox.show()

        self._scrolledWindow.set_property('expand', True)
        self._viewport.set_property("valign", Gtk.Align.START)
        self._viewport.add(self._albumbox)
        self.add(self._scrolledWindow)
Example #10
0
    def _add_tracks(self, tracks, widget, i):
        if not tracks or self._stop:
            self._stop = False
            return
        track = tracks.pop(0)
        track_id = track[0]
        title = escape(track[1])
        length = track[2]
        artist_ids = track[3]

        # If we are listening to a compilation, prepend artist name
        if self._artist_id == Navigation.COMPILATIONS or\
           len(artist_ids) > 1 or\
           self._artist_id not in artist_ids:
            artist_name = ""
            for artist_id in artist_ids:
                artist_name += translate_artist_name(
                                Objects.artists.get_name(artist_id)) + ", "
            title = "<b>%s</b>\n%s" % (escape(artist_name[:-2]),
                                       title)

        # Get track position in queue
        pos = None
        if Objects.player.is_in_queue(track_id):
            pos = Objects.player.get_track_position(track_id)

        widget.add_track(track_id,
                         i,
                         title,
                         length,
                         pos)
        GLib.idle_add(self._add_tracks, tracks, widget, i+1)
Example #11
0
    def _really_do_filtering(self):
        sql = Lp.db.get_cursor()
        results = []
        albums = []

        searched = self._text_entry.get_text()

        tracks_non_aartist = []

        # Get all albums for all artists and non aartist tracks
        for artist_id in Lp.artists.search(searched, sql):
            for album_id in Lp.albums.get_ids(artist_id, None, sql):
                if (album_id, artist_id) not in albums:
                    albums.append((album_id, artist_id))
            for track_id, track_name in Lp.tracks.get_as_non_aartist(artist_id,
                                                                     sql):
                tracks_non_aartist.append((track_id, track_name))

        albums += Lp.albums.search(searched, sql)

        for album_id, artist_id in albums:
            search_obj = SearchObject()
            search_obj.artist = Lp.artists.get_name(artist_id, sql)
            search_obj.title = Lp.albums.get_name(album_id, sql)
            search_obj.count = Lp.albums.get_count(album_id, None, sql)
            search_obj.id = album_id
            search_obj.album_id = album_id
            results.append(search_obj)

        for track_id, track_name in Lp.tracks.search(searched, sql) +\
                tracks_non_aartist:
            search_obj = SearchObject()
            search_obj.title = track_name
            search_obj.id = track_id
            search_obj.album_id = Lp.tracks.get_album_id(track_id, sql)
            search_obj.is_track = True

            album_artist_id = Lp.albums.get_artist_id(search_obj.album_id,
                                                      sql)
            artist_name = ""
            if album_artist_id != Type.COMPILATIONS:
                artist_name = Lp.albums.get_artist_name(
                    search_obj.album_id, sql) + ", "
            for artist_id in Lp.tracks.get_artist_ids(track_id, sql):
                if artist_id != album_artist_id:
                    artist_name += translate_artist_name(
                        Lp.artists.get_name(artist_id, sql)) + ", "

            search_obj.artist = artist_name[:-2]

            results.append(search_obj)

        if not self._stop_thread:
            self._clear(results)
            GLib.idle_add(self._add_rows, results)
        else:
            self._in_thread = False
            self._stop_thread = False

        sql.close()
Example #12
0
	def update_toolbar(self, obj, track_id):
		if track_id == None:
			self._cover.hide()
			self._time_label.hide()
			self._total_time_label.hide()
			self._prev_btn.set_sensitive(False)
			self._progress.set_sensitive(False)
			self._play_btn.set_sensitive(False)
			self._next_btn.set_sensitive(False)
			self._title_label.set_text("")
			self._artist_label.set_text("")
		else:
			album_id = self._db.get_album_id_by_track_id(track_id)
			art = self._art.get_small(album_id)
			if art:
				self._cover.set_from_pixbuf(art)
				self._cover.show()
			else:
				self._cover.hide()
			
			title = self._db.get_track_name(track_id)
			artist = self._db.get_artist_name_by_album_id(album_id)
			artist = translate_artist_name(artist)
			self._title_label.set_text(title)
			self._artist_label.set_text(artist)
			self._progress.set_value(0.0)
			duration = self._db.get_track_length(track_id)
			self._progress.set_range(0.0, duration * 60)
			self._total_time_label.set_text(self._player.seconds_to_string(duration))
			self._total_time_label.show()
			self._time_label.set_text("0:00")
			self._time_label.show()
Example #13
0
    def _really_do_filtering(self):
        sql = Objects.db.get_cursor()
        results = []
        albums = []

        searched = self._text_entry.get_text()

        tracks_non_aartist = []

        # Get all albums for all artists and non aartist tracks
        for artist_id in Objects.artists.search(searched, sql):
            for album_id in Objects.albums.get_ids(artist_id, None, sql):
                if (album_id, artist_id) not in albums:
                    albums.append((album_id, artist_id))
            for track_id, track_name in Objects.tracks.get_as_non_aartist(
                    artist_id, sql):
                tracks_non_aartist.append((track_id, track_name))

        albums += Objects.albums.search(searched, sql)

        for album_id, artist_id in albums:
            search_obj = SearchObject()
            search_obj.artist = Objects.artists.get_name(artist_id, sql)
            search_obj.title = Objects.albums.get_name(album_id, sql)
            search_obj.count = Objects.albums.get_count(album_id, None, sql)
            search_obj.id = album_id
            search_obj.album_id = album_id
            results.append(search_obj)

        for track_id, track_name in Objects.tracks.search(searched, sql) +\
                tracks_non_aartist:
            search_obj = SearchObject()
            search_obj.title = track_name
            search_obj.id = track_id
            search_obj.album_id = Objects.tracks.get_album_id(track_id, sql)
            search_obj.is_track = True

            album_artist_id = Objects.albums.get_artist_id(
                search_obj.album_id, sql)
            artist_name = ""
            if album_artist_id != Navigation.COMPILATIONS:
                artist_name = Objects.albums.get_artist_name(
                    search_obj.album_id, sql) + ", "
            for artist_id in Objects.tracks.get_artist_ids(track_id, sql):
                if artist_id != album_artist_id:
                    artist_name += translate_artist_name(
                        Objects.artists.get_name(artist_id, sql)) + ", "

            search_obj.artist = artist_name[:-2]

            results.append(search_obj)

        if not self._stop_thread:
            self._clear(results)
            GLib.idle_add(self._add_rows, results)
        else:
            self._in_thread = False
            self._stop_thread = False

        sql.close()
Example #14
0
	def update_toolbar(self, obj, track_id):
		if track_id == None:
			self._cover.hide()
			self._timelabel.hide()
			self._total_time_label.hide()
			self._prev_btn.set_sensitive(False)
			self._progress.set_sensitive(False)
			self._play_btn.set_sensitive(False)
			self._next_btn.set_sensitive(False)
			self._title_label.set_text("")
			self._artist_label.set_text("")
		else:
			album_id = Objects["tracks"].get_album_id(track_id)
			art = Objects["art"].get(album_id,  ART_SIZE_SMALL)
			if art:
				self._cover.set_from_pixbuf(art)
				self._cover.show()
			else:
				self._cover.hide()
			
			title = Objects["tracks"].get_name(track_id)
			artist = Objects["tracks"].get_artist_name(track_id)
			artist = translate_artist_name(artist)
			self._title_label.set_text(title)
			self._artist_label.set_text(artist)
			self._progress.set_value(0.0)
			duration = Objects["tracks"].get_length(track_id)
			self._progress.set_range(0.0, duration * 60)
			self._total_time_label.set_text(seconds_to_string(duration))
			self._total_time_label.show()
			self._timelabel.set_text("0:00")
			self._timelabel.show()
Example #15
0
    def update(self, values):
        self._updating = True
        if self._signal_id:
            self._view.disconnect(self._signal_id)
            self._signal_id = None
        for item in self._model:
            found = False
            for value in values:
                if item[1] == value[1]:
                    found = True
                    break
            # Remove not found items but not devices
            if not found and item[0] > Navigation.DEVICES:
                self._model.remove(item.iter)

        for value in values:
            found = False
            for item in self._model:
                if item[1] == value[1]:
                    found = True
                    break
            if not found:
                if self._is_artists:
                    string = translate_artist_name(value[1])
                else:
                    string = value[1]
                self._model.append([value[0],
                                   string,
                                   self._get_pixbuf(value[0])])
        self._signal_id = self._view.connect('cursor-changed',
                                             self._new_item_selected)
        self._updating = False
Example #16
0
 def get(self, genre_id, sql=None):
     """
         Get all available artists
         @param None
         or
         @param Filter genre id as int
         @return Array of (artist id as int, artist name as string)
     """
     if not sql:
         sql = Lp.sql
     result = []
     if genre_id == Type.ALL or genre_id is None:
         # Only artist that really have an album
         result = sql.execute("SELECT DISTINCT artists.rowid, artists.name\
                               FROM artists, albums\
                               WHERE albums.artist_id = artists.rowid\
                               ORDER BY artists.name COLLATE NOCASE")
     else:
         result = sql.execute(
             "SELECT DISTINCT artists.rowid, artists.name\
                               FROM artists, albums, album_genres\
                               WHERE artists.rowid == albums.artist_id\
                               AND album_genres.genre_id=?\
                               AND album_genres.album_id=albums.rowid\
                               ORDER BY artists.name\
                               COLLATE NOCASE", (genre_id, ))
     return [(row[0], translate_artist_name(row[1])) for row in result]
Example #17
0
    def __init__(self, artist_id, show_artist_details):
        View.__init__(self)
        self._artist_id = artist_id
        self._signal_id = None

        if show_artist_details:
            self._ui = Gtk.Builder()
            self._ui.add_from_resource('/org/gnome/Lollypop/ArtistView.ui')
            self.add(self._ui.get_object('ArtistView'))
            artist_name = Objects.artists.get_name(artist_id)
            artist_name = translate_artist_name(artist_name)
            self._ui.get_object('artist').set_label(artist_name)

        self._show_menu = show_artist_details

        self._albumbox = Gtk.Grid()
        self._albumbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self._scrolledWindow = Gtk.ScrolledWindow()
        self._scrolledWindow.set_vexpand(True)
        self._scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.AUTOMATIC)
        self._scrolledWindow.add(self._albumbox)

        self.add(self._scrolledWindow)
        self.show_all()
Example #18
0
    def do_show(self):
        size_setting = Objects.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)

        for track_id in Objects.player.get_queue():
            album_id = Objects.tracks.get_album_id(track_id)
            artist_id = Objects.albums.get_artist_id(album_id)
            artist_name = Objects.artists.get_name(artist_id)
            track_name = Objects.tracks.get_name(track_id)
            pixbuf = Objects.art.get(album_id, ArtSize.MEDIUM)
            self._model.append([pixbuf,
                                "<b>%s</b>\n%s" %
                                (escape(translate_artist_name(artist_name)),
                                 escape(track_name)),
                                self._del_pixbuf,
                                track_id])
            del pixbuf

        self._signal_id1 = Objects.player.connect("current-changed",
                                                  self._on_current_changed)
        self._signal_id2 =  self._model.connect("row-deleted",
                                                self._updated_rows)
        Gtk.Popover.do_show(self)
Example #19
0
	def __init__(self, artist_id, genre_id, context):
		View.__init__(self)
		self.set_property("orientation", Gtk.Orientation.VERTICAL)
		
		if not context:
			self._ui = Gtk.Builder()
			self._ui.add_from_resource('/org/gnome/Lollypop/ArtistView.ui')
			self.add(self._ui.get_object('ArtistView'))
			artist_name = Objects.artists.get_name(artist_id)
			artist_name = translate_artist_name(artist_name)
			self._ui.get_object('artist').set_label(artist_name)

		self._artist_id = artist_id
		self._genre_id = genre_id
		self._context = context

		self._size_group = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL)

		self._albumbox = Gtk.Grid()
		self._albumbox.set_property("orientation", Gtk.Orientation.VERTICAL)
		self._scrolledWindow = Gtk.ScrolledWindow()
		self._scrolledWindow.set_vexpand(True)
		self._scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
										Gtk.PolicyType.AUTOMATIC)
		self._scrolledWindow.add(self._albumbox)

		self.add(self._scrolledWindow)
		self.show_all()
Example #20
0
    def do_show(self):
        size_setting = Objects.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)

        for track_id in Objects.player.get_queue():
            album_id = Objects.tracks.get_album_id(track_id)
            artist_id = Objects.albums.get_artist_id(album_id)
            artist_name = Objects.artists.get_name(artist_id)
            track_name = Objects.tracks.get_name(track_id)
            art = Objects.art.get(album_id, ArtSize.MEDIUM)
            self._model.append([
                art,
                "<b>%s</b>\n%s" % (escape(
                    translate_artist_name(artist_name)), escape(track_name)),
                self._del_pixbuf, track_id
            ])

        self._signal_id1 = Objects.player.connect("current-changed",
                                                  self._on_current_changed)
        self._signal_id2 = self._model.connect("row-deleted",
                                               self._updated_rows)
        Gtk.Popover.do_show(self)
Example #21
0
    def do_show(self):
        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)

        for track_id in Lp.player.get_queue():
            album_id = Lp.tracks.get_album_id(track_id)
            artist_id = Lp.albums.get_artist_id(album_id)
            artist_name = Lp.artists.get_name(artist_id)
            track_name = Lp.tracks.get_name(track_id)
            pixbuf = Lp.art.get_album(album_id, ArtSize.MEDIUM)
            title = "<b>%s</b>\n%s" %\
                (escape(translate_artist_name(artist_name)),
                 escape(track_name))
            self._model.append([pixbuf,
                                title,
                                'user-trash-symbolic',
                                track_id])
            del pixbuf

        self._signal_id1 = Lp.player.connect('current-changed',
                                             self._on_current_changed)
        self._signal_id2 = self._model.connect('row-deleted',
                                               self._updated_rows)
        Gtk.Popover.do_show(self)
Example #22
0
    def _add_tracks(self, tracks, widget, pos, previous_album_id=None):
        if not tracks or self._stop:
            return

        track_id = tracks.pop(0)
        if track_id == -1:
            return

        (title, filepath, length, album_id) =\
            Lp.tracks.get_infos(track_id)
        if title is None:
            return
        else:
            title = escape(title)

        artist_id = Lp.albums.get_artist_id(album_id)
        artist_ids = Lp.tracks.get_artist_ids(track_id)
        # If we are listening to a compilation, prepend artist name
        if artist_id == Type.COMPILATIONS or\
           len(artist_ids) > 1 or\
           artist_id not in artist_ids:
            artist_name = ""
            for artist_id in artist_ids:
                artist_name += translate_artist_name(
                    Lp.artists.get_name(artist_id)) + ", "
            title = "<b>%s</b>\n%s" % (escape(artist_name[:-2]),
                                       title)

        if album_id != previous_album_id:
            widget.add_album(track_id, album_id, pos, title, length, None)
        else:
            widget.add_track(track_id, pos, title, length, None)
        GLib.idle_add(self._add_tracks, tracks, widget, pos+1, album_id)
Example #23
0
    def _add_tracks(self, tracks, widget, i):
        if not tracks or self._stop:
            self._stop = False
            return
        track = tracks.pop(0)
        track_id = track[0]
        title = escape(track[1])
        length = track[2]
        artist_ids = track[3]

        # If we are listening to a compilation, prepend artist name
        if self._artist_id == Navigation.COMPILATIONS or\
           len(artist_ids) > 1 or\
           self._artist_id not in artist_ids:
            artist_name = ""
            for artist_id in artist_ids:
                artist_name += translate_artist_name(
                                Objects.artists.get_name(artist_id)) + ", "
            title = "<b>%s</b>\n%s" % (escape(artist_name[:-2]),
                                       title)

        # Get track position in queue
        pos = None
        if Objects.player.is_in_queue(track_id):
            pos = Objects.player.get_track_position(track_id)

        widget.add_track(track_id,
                         i,
                         title,
                         length,
                         pos)
        GLib.idle_add(self._add_tracks, tracks, widget, i+1)
Example #24
0
 def __init__(self, track_id=None, sql=None):
     self.uri = None
     if track_id is None:
         self.id = None
         self.title = ''
         self.album_id = None
         self.album = ''
         self.artist_ids = []
         self.artist = ''
         self.aartist_id = None
         self.aartist = ''
         self.genre_id = None
         self.genre = ''
         self.number = 0
         self.duration = 0.0
         self.year = ''
     else:
         self.id = track_id
         self.title = Lp.tracks.get_name(self.id,
                                         sql)
         self.album_id = Lp.tracks.get_album_id(track_id,
                                                sql)
         self.album = Lp.albums.get_name(self.album_id,
                                         sql)
         self.aartist_id = Lp.tracks.get_aartist_id(track_id,
                                                    sql)
         self.aartist = translate_artist_name(
             Lp.artists.get_name(self.aartist_id, sql))
         self.artist_ids = Lp.tracks.get_artist_ids(self.id, sql)
         artist_name = ""
         for artist_id in self.artist_ids:
             artist_name += translate_artist_name(
                 Lp.artists.get_name(artist_id, sql)) + ", "
         self.artist = artist_name[:-2]
         self.genre = Lp.tracks.get_genre_name(self.id,
                                               sql)
         self.duration = Lp.tracks.get_length(self.id, sql)
         self.year = Lp.albums.get_year(self.album_id, sql)
         self.number = Lp.tracks.get_number(self.id, sql)
         filepath = Lp.tracks.get_path(self.id, sql)
         if path.exists(filepath):
             self.uri = GLib.filename_to_uri(filepath)
Example #25
0
	def _load_track(self, track_id, sql = None):
		self.current.id = track_id
		self.current.title = Objects.tracks.get_name(self.current.id, sql)
		self.current.album_id = Objects.tracks.get_album_id(self.current.id, sql)
		self.current.album = Objects.albums.get_name(self.current.album_id, sql)
		self.current.performer_id = Objects.tracks.get_performer_id(self.current.id, sql)
		self.current.performer = translate_artist_name(Objects.artists.get_name(self.current.performer_id, sql))
		self.current.artist_id = Objects.tracks.get_artist_id(self.current.id, sql)
		self.current.artist = translate_artist_name(Objects.artists.get_name(self.current.artist_id, sql))
		self.current.genre_id = Objects.albums.get_genre_id(self.current.album_id, sql)
		self.current.genre = Objects.genres.get_name(self.current.genre_id, sql)
		self.current.duration = Objects.tracks.get_length(self.current.id, sql)
		tracks = Objects.albums.get_tracks(self.current.album_id, sql)
		self.current.number = tracks.index(self.current.id)
		self.current.path = Objects.tracks.get_path(self.current.id, sql)
		if path.exists(self.current.path):
			self._playbin.set_property('uri', GLib.filename_to_uri(self.current.path))
		else:
			print("File doesn't exist: ", self.current.path)
			self.next(True, sql)
Example #26
0
 def get_artist_names(self, track_id, sql=None):
     """
         Get artist names
         @param track id as int
         @return Genre name as str "artist1, artist2, ..."
     """
     if not sql:
         sql = Lp.sql
     result = sql.execute("SELECT name FROM artists, track_artists\
                           WHERE track_artists.track_id=?\
                           AND track_artists.artist_id=artists.rowid",
                          (track_id,))
     artists = [translate_artist_name(row[0]) for row in result]
     return ", ".join(artists)
Example #27
0
 def add(self, value):
     self._updating = True
     found = False
     for item in self._model:
         if value[0] == item[0]:
             found = True
             break
     if not found:
         if self._is_artists:
             string = translate_artist_name(value[1])
         else:
             string = value[1]
         self._model.append([value[0], string, self._get_pixbuf(value[0])])
     self._updating = False
Example #28
0
    def _copy_to_device(self, playlists, sql):
        for playlist in playlists:
            # Create playlist
            try:
                m3u = open("%s/%s.m3u" % (self._path, playlist), "w")
                m3u.write("#EXTM3U\n")
            except:
                m3u = None

            # Start copying
            tracks_id = Objects.playlists.get_tracks_id(playlist, sql)
            for track_id in tracks_id:
                if not self._syncing:
                    self._fraction = 1.0
                    self._in_thread = False
                    return
                album_id = Objects.tracks.get_album_id(track_id, sql)
                album_name = Objects.albums.get_name(album_id, sql)
                artist_name = translate_artist_name(
                                 Objects.albums.get_artist_name(album_id, sql))
                track_path = Objects.tracks.get_path(track_id, sql)
                on_device_album_path = "%s/tracks/%s_%s" %\
                                       (self._path,
                                        artist_name.lower(),
                                        album_name.lower())

                self._mkdir(on_device_album_path)

                # Copy album art
                art = Objects.art.get_art_path(album_id, sql)
                if art:
                    dst_art = "%s/cover.jpg" % on_device_album_path
                    if not os.path.exists(dst_art):
                        self._copyfile(art, dst_art)

                track_name = os.path.basename(track_path)
                dst_path = "%s/%s" % (on_device_album_path, track_name)
                if m3u:
                    m3u.write("tracks/%s_%s/%s\n" %
                              (artist_name.lower(),
                               album_name.lower(),
                               track_name))
                if not os.path.exists(dst_path):
                    self._copyfile(track_path, dst_path)
                else:
                    self._done += 1
                self._done += 1
                self._fraction = self._done/self._total
            if m3u:
                m3u.close()
Example #29
0
    def _copy_to_device(self, playlists, sql):
        for playlist in playlists:
            # Create playlist
            try:
                m3u = open("%s/%s.m3u" % (self._path, playlist), "w")
                m3u.write("#EXTM3U\n")
            except:
                m3u = None

            # Start copying
            tracks_id = Objects.playlists.get_tracks_id(playlist, sql)
            for track_id in tracks_id:
                if not self._syncing:
                    self._fraction = 1.0
                    self._in_thread = False
                    return
                album_id = Objects.tracks.get_album_id(track_id, sql)
                album_name = Objects.albums.get_name(album_id, sql)
                artist_name = translate_artist_name(
                    Objects.albums.get_artist_name(album_id, sql))
                track_path = Objects.tracks.get_path(track_id, sql)
                on_device_album_path = "%s/tracks/%s_%s" %\
                                       (self._path,
                                        artist_name.lower(),
                                        album_name.lower())

                self._mkdir(on_device_album_path)

                # Copy album art
                art = Objects.art.get_art_path(album_id, sql)
                if art:
                    dst_art = "%s/cover.jpg" % on_device_album_path
                    if not os.path.exists(dst_art):
                        self._copyfile(art, dst_art)

                track_name = os.path.basename(track_path)
                dst_path = "%s/%s" % (on_device_album_path, track_name)
                if m3u:
                    m3u.write(
                        "tracks/%s_%s/%s\n" %
                        (artist_name.lower(), album_name.lower(), track_name))
                if not os.path.exists(dst_path):
                    self._copyfile(track_path, dst_path)
                else:
                    self._done += 1
                self._done += 1
                self._fraction = self._done / self._total
            if m3u:
                m3u.close()
Example #30
0
 def __upgrade_3(self, db):
     """
         Add a sorted field to artists
     """
     with SqlCursor(db, True) as sql:
         sql.execute("ALTER TABLE artists ADD sortname TEXT")
         result = sql.execute("SELECT DISTINCT artists.rowid,\
                               artists.name\
                               FROM artists")
         for row in result:
             translated = translate_artist_name(row[1])
             sql.execute("UPDATE artists SET name=? WHERE rowid=?",
                         (translated, row[0]))
             sql.execute("UPDATE artists SET sortname=? WHERE rowid=?",
                         (row[1], row[0]))
Example #31
0
    def get_artist_name(self, album_id):
        """
            Get artist name
            @param Album id as int
            @return Artist name as string
        """
        with SqlCursor(Lp().db) as sql:
            result = sql.execute("SELECT artists.name from artists, albums\
                                  WHERE albums.rowid=? AND albums.artist_id ==\
                                  artists.rowid", (album_id,))
            v = result.fetchone()
            if v is not None:
                return translate_artist_name(v[0])

        return _("Compilation")
Example #32
0
	def show(self):
		self._model.clear()
		tracks = self._player.get_playlist()
		if len(tracks) > 0:
			for track_id in tracks:
				track_name = self._db.get_track_name(track_id)
				album_id = self._db.get_album_id_by_track_id(track_id)
				artist_id = self._db.get_artist_id_by_album_id(album_id)
				artist_name = self._db.get_artist_name_by_id(artist_id)
				artist_name = translate_artist_name(artist_name)
				art = self._art.get_small(album_id)
				self._model.append([art, artist_name + " - " + track_name, track_id])
			self._row_signal = self._model.connect("row-deleted", self._reordered_playlist)
		else:
			self._model.append([None, _("Right click on a song to add it to playlist"), None])
		Gtk.Popover.show(self)
Example #33
0
 def add(self, value):
     self._updating = True
     found = False
     for item in self._model:
         if value[0] == item[0]:
             found = True
             break
     if not found:
         if self._is_artists:
             string = translate_artist_name(value[1])
         else:
             string = value[1]
         self._model.append([value[0],
                             string,
                             self._get_pixbuf(value[0])])
     self._updating = False
Example #34
0
    def get_artist_name(self, album_id, sql=None):
        """
            Get artist name
            @param Album id as int
            @return Artist name as string
        """
        if not sql:
            sql = Lp.sql
        result = sql.execute("SELECT artists.name from artists, albums\
                              WHERE albums.rowid=? AND albums.artist_id ==\
                              artists.rowid", (album_id,))
        v = result.fetchone()
        if v:
            return translate_artist_name(v[0])

        return _("Compilation")
Example #35
0
    def get_name(self, artist_id):
        """
            Get artist name
            @param Artist id as int
            @return Artist name as string
        """
        with SqlCursor(Lp().db) as sql:
            if artist_id == Type.COMPILATIONS:
                return _("Many artists")

            result = sql.execute("SELECT name from artists WHERE rowid=?",
                                 (artist_id,))
            v = result.fetchone()
            if v is not None:
                return translate_artist_name(v[0])
            return _("Unknown")
Example #36
0
 def _upgrade_3(self):
     """
         Add a sorted field to artists
     """
     with SqlCursor(self._db) as sql:
         sql.execute("ALTER TABLE artists ADD sortname TEXT")
         result = sql.execute("SELECT DISTINCT artists.rowid,\
                               artists.name\
                               FROM artists")
         for row in result:
             translated = translate_artist_name(row[1])
             sql.execute("UPDATE artists SET name=? WHERE rowid=?",
                         (translated, row[0]))
             sql.execute("UPDATE artists SET sortname=? WHERE rowid=?",
                         (row[1], row[0]))
         sql.commit()
Example #37
0
 def _add_value(self, value):
     found = False
     for item in self._model:
         if value[0] == item[0]:
             found = True
             break
     if not found:
         if self._is_artists:
             string = translate_artist_name(value[1])
         else:
             string = value[1]
         self._model.append([value[0],
                             string,
                             self._get_icon_name(value[0])])
         if value[0] == self._to_select_id:
             self.select_id(self._to_select_id)
Example #38
0
	def _update_track(self, obj, track_id):
		album_id = Objects["tracks"].get_album_id(track_id)
		album = Objects["albums"].get_name(album_id)
		artist = Objects["tracks"].get_artist_name(track_id)
		artist = translate_artist_name(artist)
		title = Objects["tracks"].get_name(track_id)
		
		self._notification.set_hint('image-path', GLib.Variant('s', Objects["art"].get_path(album_id, ART_SIZE_BIG)))
		self._notification.update(title,
								  # TRANSLATORS: by refers to the artist, from to the album
								  _("by %s, from %s") % ('<b>' + artist + '</b>',
														 '<i>' + album + '</i>'),
								  'lollypop')
		try:
			self._notification.show()
		except:
			pass
Example #39
0
	def do_show(self):
		size_setting = Objects["settings"].get_value('window-size')
		if isinstance(size_setting[1], int):
			self.set_property('height-request', size_setting[1]*0.7)
		else:
			self.set_property('height-request', 600)

		for track_id in Objects["player"].get_queue():
			album_id = Objects["tracks"].get_album_id(track_id)
			artist_id = Objects["albums"].get_artist_id(album_id)
			artist_name = Objects["artists"].get_name(artist_id)
			track_name = Objects["tracks"].get_name(track_id)
			art = Objects["art"].get(album_id, ART_SIZE_MEDIUM)
			self._model.append([art, "<b>"+escape(translate_artist_name(artist_name)) + "</b>\n" + 
								escape(track_name), self._del_pixbuf, track_id])

		Gtk.Popover.do_show(self)
Example #40
0
    def __init__(self, album_id):
        AlbumWidget.__init__(self, album_id)

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/AlbumSimpleWidget.ui')
        builder.connect_signals(self)
        self._cover = builder.get_object('cover')

        album_name = Objects.albums.get_name(album_id)
        title = builder.get_object('title')
        title.set_label(album_name)
        artist_name = Objects.albums.get_artist_name(album_id)
        artist_name = translate_artist_name(artist_name)
        artist = builder.get_object('artist')
        artist.set_label(artist_name)

        self.add(builder.get_object('widget'))
        self.set_cover()
Example #41
0
    def get_name(self, artist_id, sql=None):
        """
            Get artist name
            @param Artist id as int
            @return Artist name as string
        """
        if not sql:
            sql = Lp.sql
        if artist_id == Type.COMPILATIONS:
            return _("Many artists")

        result = sql.execute("SELECT name from artists WHERE rowid=?",
                             (artist_id, ))
        v = result.fetchone()
        if v:
            return translate_artist_name(v[0])

        return _("Unknown")
Example #42
0
    def _add_tracks(self, tracks, widget, pos):
        if not tracks:
            return

        track_id = tracks.pop(0)
        if track_id == -1:
            return

        (title, filepath, length, album_id) =\
            Objects.tracks.get_infos(track_id)

        artist_name = ""
        for artist_id in Objects.tracks.get_artist_ids(track_id):
            artist_name += translate_artist_name(
                Objects.artists.get_name(artist_id)) + ", "
        title = "<b>%s</b>\n%s" % (escape(artist_name[:-2]), escape(title))

        widget.add_track(track_id, pos, title, length, None, True)
        GLib.idle_add(self._add_tracks, tracks, widget, pos + 1)
Example #43
0
    def _add_item(self, values, time):
        if time != self._pop_time:
            del values
            values = None
            return
        elif not values:
            self._signal_id = self._view.connect('cursor-changed',
                                                 self._new_item_selected)
            self.emit("populated")
            del values
            values = None
            self._pop_time = 0
            return

        (object_id, string) = values.pop(0)
        # Translating artist@@@@the => The artist
        if self._is_artists:
            string = translate_artist_name(string)

        self._model.append([object_id, string, self._get_pixbuf(object_id)])
        GLib.idle_add(self._add_item, values, time)
Example #44
0
    def __init__(self, artist_id, show_artist_details):
        View.__init__(self)
        self._artist_id = artist_id
        self._signal_id = None

        if show_artist_details:
            builder = Gtk.Builder()
            builder.add_from_resource('/org/gnome/Lollypop/ArtistView.ui')
            self.attach(builder.get_object('ArtistView'), 0, 0, 1, 1)
            artist_name = Objects.artists.get_name(artist_id)
            artist_name = translate_artist_name(artist_name)
            builder.get_object('artist').set_label(artist_name)

        self._show_menu = show_artist_details

        self._albumbox = Gtk.Grid()
        self._albumbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self._albumbox.show()

        self._scrolledWindow.set_property('expand', True)
        self._viewport.add(self._albumbox)
        self.add(self._scrolledWindow)
Example #45
0
    def _remove_from_device(self, playlists, sql):
        tracks_path = []
        tracks_id = []

        # Get tracks ids
        for playlist in playlists:
            tracks_id += Objects.playlists.get_tracks_id(playlist, sql)

        # Get tracks paths
        for track_id in tracks_id:
            if not self._syncing:
                self._fraction = 1.0
                self._in_thread = False
                return
            album_id = Objects.tracks.get_album_id(track_id, sql)
            album_name = Objects.albums.get_name(album_id, sql)
            artist_name = translate_artist_name(
                Objects.albums.get_artist_name(album_id, sql))
            track_path = Objects.tracks.get_path(track_id, sql)
            album_path = "%s/tracks/%s_%s" % (self._path, artist_name.lower(),
                                              album_name.lower())
            track_name = os.path.basename(track_path)
            dst_path = "%s/%s" % (album_path, track_name)
            tracks_path.append(dst_path)

        # Delete file on device and not in playlists
        for root, dirs, files in os.walk("%s/tracks" % self._path):
            for f in files:
                if not self._syncing:
                    self._fraction = 1.0
                    self._in_thread = False
                    return
                if f != "cover.jpg":
                    filepath = os.path.join(root, f)
                    if filepath not in tracks_path:
                        self._delete(filepath)
                self._done += 1
                self._fraction = self._done / self._total
Example #46
0
    def __init__(self, album_id):
        Gtk.Grid.__init__(self)
        self._album_id = album_id

        self.set_property("margin", 5)

        self.set_orientation(Gtk.Orientation.VERTICAL)
        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Lollypop/AlbumWidget.ui')

        self._cover = builder.get_object('cover')
        self._cover.set_from_pixbuf(Objects.art.get(album_id, ArtSize.BIG))

        album_name = Objects.albums.get_name(album_id)
        title = builder.get_object('title')
        title.set_label(album_name)
        artist_name = Objects.albums.get_artist_name(album_id)
        artist_name = translate_artist_name(artist_name)
        artist = builder.get_object('artist')
        artist.set_label(artist_name)

        self.add(self._cover)
        self.add(title)
        self.add(artist)
Example #47
0
 def set_artist(self, name):
     self._artist.set_text(translate_artist_name(name))