def reloadCovers(self, progressWidget): forceReload = False artist_dir = xdg.get_thumbnail_dir("artist") album_dir = xdg.get_thumbnail_dir("album") if BDD.network_is_connected.isSet(): bdd = BDD() bdd.execute_with_filters("SELECT DISTINCT artist, album FROM tracks ", "music") rows = bdd.c.fetchall() length = float(len(rows)) i = 0 progressWidget.setFraction(0) while i < len(rows): artist_name = rows[i][0] dest_path = os.path.join(artist_dir + "/medium", artist_name.replace("/", " ")) # + '.jpg') if forceReload or not os.path.isfile(dest_path): artist = BDD.network.get_artist(artist_name) cover = artist.get_cover_image(1) os.path if cover is not None: # extension = os.path.splitext(f)[1] urlretrieve(cover, dest_path) else: logger.debug("No cover url for artist " + artist_name) while i < len(rows) and artist_name == rows[i][0]: album_name = rows[i][1] dest_path = os.path.join(album_dir + "/medium", album_name.replace("/", " ")) # + '.jpg') if forceReload or not os.path.isfile(dest_path): try: album = BDD.network.get_album(artist_name, album_name) cover = album.get_cover_image(1) except WSError: logger.debug("Error : No album " + album_name) if cover is not None: urlretrieve(cover, dest_path) else: logger.debug("No cover url for album " + album_name) i += 1 progressWidget.setFraction(i / length) else: logger.debug("Can't retrieve covers : Network not connected") progressWidget.emitDone()
def data(self, index, role): if not index.isValid(): return None item = index.internalPointer() if role == Qt.DisplayRole: if index.column() == 1: return item.label elif index.column() == 2: return item.playcount elif index.column() == 3: return item.rating elif index.column() == 4: return item.rounded_burn elif role == Qt.DecorationRole and index.column() == 0: if(item.icon is None): try: path = os.path.join(xdg.get_thumbnail_dir(item.type + '/medium'), item.label.replace ('/', ' ')) # + '.jpg') item.icon = QtGui.QPixmap(path) if(item.icon.isNull()): item.icon = icons[item.type] else: item.icon = item.icon.scaled(icon_size, icon_size, Qt.KeepAspectRatio, Qt.SmoothTransformation) #scaledToHeight(icon_size) except: item.icon = icons[item.label] return item.icon return None
def getThumbnailPath(self, size='128'): if(self.thumbnail_ID != 0): thumbnail_path = xdg.get_thumbnail_dir(self.module + '/128/') path = thumbnail_path + str(self.thumbnail_ID) + '.jpg' else: path = None return path
def __init__(self, module): self.module = module #self.elementSelector = elementSelector self.categories = {} self.universes = {} self.filters = {} self.THUMBNAIL_DIR = xdg.get_thumbnail_dir(self.module + os.sep + '128' + os.sep) self.notLoading = threading.Event() self.notLoading.set()
def getIcon(track_line, level): ''' @param track_line : la ligne de la piste dans le tableau self.tracks[mode] @level : le niveau de profondeur dans le mode d'affichage ex de mode ('artist, 'album', 'title') level 0 = artist, level 2 = title, etc... ''' try: path = os.path.join(xdg.get_thumbnail_dir(mode[level] + '/medium'), track_line[indices[mode[level]]].replace ('/', ' ') + '.jpg') icon = QtGui.QIImage(path).scaled(icon_size) except: icon = icons[mode[level]] return icon