Example #1
0
	def library_populate_data_songs(self, genre, artist, album, year):
		bd = []
		if genre is not None:
			songs, _playtime, _num_songs = self.library_return_search_items(genre=genre, artist=artist, album=album, year=year)
		else:
			songs, _playtime, _num_songs = self.library_return_search_items(artist=artist, album=album, year=year)
		for song in songs:
			data = self.library_set_data(path=mpdh.get(song, 'file'))
			track = mpdh.getnum(song, 'track', '99', False, 2)
			disc = mpdh.getnum(song, 'disc', '99', False, 2)
			try:
				bd += [('f' + disc + track + misc.lower_no_the(mpdh.get(song, 'title')), [self.sonatapb, data, self.parse_formatting(self.config.libraryformat, song, True)])]
			except:
				bd += [('f' + disc + track + unicode(mpdh.get(song, 'file')).lower(), [self.sonatapb, data, self.parse_formatting(self.config.libraryformat, song, True)])]
		return bd
Example #2
0
    def sort(self, mode, column=None):
        if self.connected():
            if not self.currentdata:
                return

            while gtk.events_pending():
                gtk.main_iteration()
            songs = []
            track_num = 0

            if mode[0:3] == "col":
                col_num = int(mode.replace("col", ""))
                if column.get_sort_indicator():
                    # If this column was already sorted, reverse list:
                    self.column_sorted = (column, self.column_sorted[1])
                    self.on_sort_reverse(None)
                    return
                else:
                    self.column_sorted = (column, gtk.SORT_DESCENDING)
                mode = "col"

                # If the first tag in the format is song length, we will make sure to compare
                # the same number of items in the song length string (e.g. always use
                # ##:##:##) and pad the first item to two (e.g. #:##:## -> ##:##:##)
            custom_sort = False
            if mode == "col":
                custom_sort, custom_pos = self.sort_get_first_format_tag(self.config.currentformat, col_num, "L")

            for track in self.current_songs:
                record = {}
                # Those items that don't have the specified tag will be put at
                # the end of the list (hence the 'zzzzzzz'):
                zzz = "zzzzzzzz"
                if mode == "artist":
                    record["sortby"] = (
                        misc.lower_no_the(mpdh.get(track, "artist", zzz)),
                        mpdh.get(track, "album", zzz).lower(),
                        mpdh.getnum(track, "disc", "0", True, 0),
                        mpdh.getnum(track, "track", "0", True, 0),
                    )
                elif mode == "album":
                    record["sortby"] = (
                        mpdh.get(track, "album", zzz).lower(),
                        mpdh.getnum(track, "disc", "0", True, 0),
                        mpdh.getnum(track, "track", "0", True, 0),
                    )
                elif mode == "file":
                    record["sortby"] = mpdh.get(track, "file", zzz).lower().split("/")[-1]
                elif mode == "dirfile":
                    record["sortby"] = mpdh.get(track, "file", zzz).lower()
                elif mode == "col":
                    # Sort by column:
                    record["sortby"] = misc.unbold(
                        self.currentdata.get_value(self.currentdata.get_iter((track_num, 0)), col_num).lower()
                    )
                    if custom_sort:
                        record["sortby"] = self.sanitize_songlen_for_sorting(record["sortby"], custom_pos)
                else:
                    record["sortby"] = mpdh.get(track, mode, zzz).lower()
                record["id"] = int(track["id"])
                songs.append(record)
                track_num = track_num + 1

            songs.sort(key=lambda x: x["sortby"])

            pos = 0
            mpdh.call(self.client, "command_list_ok_begin")
            for item in songs:
                mpdh.call(self.client, "moveid", item["id"], pos)
                pos += 1
            mpdh.call(self.client, "command_list_end")
            self.iterate_now()

            self.header_update_column_indicators()
Example #3
0
    def sort(self, mode, column=None):
        if self.connected():
            if not self.currentdata:
                return

            while gtk.events_pending():
                gtk.main_iteration()
            songs = []
            track_num = 0

            if mode[0:3] == 'col':
                col_num = int(mode.replace('col', ''))
                if column.get_sort_indicator():
                    # If this column was already sorted, reverse list:
                    self.column_sorted = (column, self.column_sorted[1])
                    self.on_sort_reverse(None)
                    return
                else:
                    self.column_sorted = (column, gtk.SORT_DESCENDING)
                mode = "col"

            # If the first tag in the format is song length, we will make sure to compare
            # the same number of items in the song length string (e.g. always use
            # ##:##:##) and pad the first item to two (e.g. #:##:## -> ##:##:##)
            custom_sort = False
            if mode == 'col':
                custom_sort, custom_pos = self.sort_get_first_format_tag(
                    self.config.currentformat, col_num, 'L')

            for track in self.current_songs:
                record = {}
                # Those items that don't have the specified tag will be put at
                # the end of the list (hence the 'zzzzzzz'):
                zzz = 'zzzzzzzz'
                if mode == 'artist':
                    record["sortby"] = (misc.lower_no_the(
                        mpdh.get(track, 'artist',
                                 zzz)), mpdh.get(track, 'album', zzz).lower(),
                                        mpdh.getnum(track, 'disc', '0', True,
                                                    0),
                                        mpdh.getnum(track, 'track', '0', True,
                                                    0))
                elif mode == 'album':
                    record["sortby"] = (mpdh.get(track, 'album', zzz).lower(),
                                        mpdh.getnum(track, 'disc', '0', True,
                                                    0),
                                        mpdh.getnum(track, 'track', '0', True,
                                                    0))
                elif mode == 'file':
                    record["sortby"] = mpdh.get(track, 'file',
                                                zzz).lower().split('/')[-1]
                elif mode == 'dirfile':
                    record["sortby"] = mpdh.get(track, 'file', zzz).lower()
                elif mode == 'col':
                    # Sort by column:
                    record["sortby"] = misc.unbold(
                        self.currentdata.get_value(
                            self.currentdata.get_iter((track_num, 0)),
                            col_num).lower())
                    if custom_sort:
                        record["sortby"] = self.sanitize_songlen_for_sorting(
                            record["sortby"], custom_pos)
                else:
                    record["sortby"] = mpdh.get(track, mode, zzz).lower()
                record["id"] = int(track["id"])
                songs.append(record)
                track_num = track_num + 1

            songs.sort(key=lambda x: x["sortby"])

            pos = 0
            mpdh.call(self.client, 'command_list_ok_begin')
            for item in songs:
                mpdh.call(self.client, 'moveid', item["id"], pos)
                pos += 1
            mpdh.call(self.client, 'command_list_end')
            self.iterate_now()

            self.header_update_column_indicators()
Example #4
0
	def library_populate_data(self, genre=None, artist=None, album=None, year=None):
		# Create treeview model info
		bd = []
		if genre is not None and artist is None and album is None:
			# Artists within a genre
			artists = self.library_return_list_items('artist', genre=genre)
			if len(artists) > 0:
				if not self.NOTAG in artists:
					artists.append(self.NOTAG)
				for artist in artists:
					playtime, num_songs = self.library_return_count(genre=genre, artist=artist)
					if num_songs > 0:
						display = misc.escape_html(artist)
						display += self.add_display_info(num_songs, int(playtime)/60)
						data = self.library_set_data(genre=genre, artist=artist)
						bd += [(misc.lower_no_the(artist), [self.artistpb, data, display])]
		elif artist is not None and album is None:
			# Albums/songs within an artist and possibly genre
			# Albums first:
			if genre is not None:
				albums = self.library_return_list_items('album', genre=genre, artist=artist)
			else:
				albums = self.library_return_list_items('album', artist=artist)
			for album in albums:
				if genre is not None: 
					years = self.library_return_list_items('date', genre=genre, artist=artist, album=album)
				else:
					years = self.library_return_list_items('date', artist=artist, album=album)
				if not self.NOTAG in years:
					years.append(self.NOTAG)
				for year in years:
					if genre is not None: 
						playtime, num_songs = self.library_return_count(genre=genre, artist=artist, album=album, year=year)
						if num_songs > 0:
							files = self.library_return_list_items('file', genre=genre, artist=artist, album=album, year=year)
							path = os.path.dirname(files[0])
							data = self.library_set_data(genre=genre, artist=artist, album=album, year=year, path=path)
					else:
						playtime, num_songs = self.library_return_count(artist=artist, album=album, year=year)
						if num_songs > 0:
							files = self.library_return_list_items('file', artist=artist, album=album, year=year)
							path = os.path.dirname(files[0])
							data = self.library_set_data(artist=artist, album=album, year=year, path=path)
					if num_songs > 0:
						cache_data = self.library_set_data(artist=artist, album=album, path=path)
						display = misc.escape_html(album)
						if year and len(year) > 0 and year != self.NOTAG:
							display += " <span weight='light'>(" + misc.escape_html(year) + ")</span>"
						display += self.add_display_info(num_songs, int(playtime)/60)
						ordered_year = year
						if ordered_year == self.NOTAG:
							ordered_year = '9999'
						pb = self.artwork.get_library_artwork_cached_pb(cache_data, self.albumpb)
						bd += [(ordered_year + misc.lower_no_the(album), [pb, data, display])]
			# Now, songs not in albums:
			bd += self.library_populate_data_songs(genre, artist, self.NOTAG, None)
		else:
			# Songs within an album, artist, year, and possibly genre
			bd += self.library_populate_data_songs(genre, artist, album, year)
		if len(bd) > 0:
			bd = self.library_populate_add_parent_rows() + bd
		bd.sort(locale.strcoll, key=misc.first_of_2tuple)
		return bd
Example #5
0
	def library_populate_toplevel_data(self, genreview=False, artistview=False, albumview=False):
		bd = self.library_get_toplevel_cache(genreview, artistview, albumview)
		if bd is not None:
			# We have our cached data, woot.
			return bd
		bd = []
		if genreview or artistview:
			# Only for artist/genre views, album view is handled differently
			# since multiple artists can have the same album name
			if genreview: 
				items = self.library_return_list_items('genre')
				pb = self.genrepb
			else:
				items = self.library_return_list_items('artist')
				pb = self.artistpb
			if not (self.NOTAG in items):
				items.append(self.NOTAG)
			for item in items:
				if genreview: 
					playtime, num_songs = self.library_return_count(genre=item)
					data = self.library_set_data(genre=item)
				else:
					playtime, num_songs = self.library_return_count(artist=item)
					data = self.library_set_data(artist=item)
				display = misc.escape_html(item)
				display += self.add_display_info(num_songs, int(playtime)/60)
				bd += [(misc.lower_no_the(item), [pb, data, display])]
		elif albumview:
			albums = []
			untagged_found = False
			for item in mpdh.call(self.client, 'listallinfo', '/'):
				if 'file' in item and 'album' in item:
					album = mpdh.get(item, 'album')
					artist = mpdh.get(item, 'artist', self.NOTAG)
					year = mpdh.get(item, 'date', self.NOTAG)
					filepath = os.path.dirname(mpdh.get(item, 'file'))
					data = self.library_set_data(album=album, artist=artist, year=year, path=filepath)
					albums.append(data)
					if album == self.NOTAG:
						untagged_found = True
			if not untagged_found:
				albums.append(self.library_set_data(album=self.NOTAG))
			albums = misc.remove_list_duplicates(albums, case=False)
			albums = self.list_identify_VA_albums(albums)
			for item in albums:
				album, artist, year, path = self.library_get_data(item, 'album', 'artist', 'year', 'path')
				playtime, num_songs = self.library_return_count(artist=artist, album=album, year=year)
				if num_songs > 0:
					data = self.library_set_data(artist=artist, album=album, year=year, path=path)
					cache_data = self.library_set_data(artist=artist, album=album, path=path)
					display = misc.escape_html(album)
					if artist and year and len(artist) > 0 and len(year) > 0 and artist != self.NOTAG and year != self.NOTAG:
						display += " <span weight='light'>(" + misc.escape_html(artist) + ", " + misc.escape_html(year) + ")</span>"
					elif artist and len(artist) > 0 and artist != self.NOTAG:
						display += " <span weight='light'>(" + misc.escape_html(artist) + ")</span>"
					elif year and len(year) > 0 and year != self.NOTAG:
						display += " <span weight='light'>(" + misc.escape_html(year) + ")</span>"
					display += self.add_display_info(num_songs, int(playtime)/60)
					pb = self.artwork.get_library_artwork_cached_pb(cache_data, self.albumpb)
					bd += [(misc.lower_no_the(album), [pb, data, display])]
		bd.sort(locale.strcoll, key=misc.first_of_2tuple)
		if genreview:
			self.lib_view_genre_cache = bd
		elif artistview:
			self.lib_view_artist_cache = bd
		elif albumview:
			self.lib_view_album_cache = bd
		return bd