From cb979e162bc4795df4b4cf8f4688836e62e46446 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Jun 2021 19:33:00 -0700 Subject: [PATCH] If an album has no cover, use the generic image --- playtypus/threads.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/playtypus/threads.py b/playtypus/threads.py index cd2468d..e89e159 100644 --- a/playtypus/threads.py +++ b/playtypus/threads.py @@ -2,6 +2,7 @@ The :mod:`threads` module contains functions to make working with QThreads easier """ import requests +import qtawesome as qta from PyQt5 import QtCore, QtGui, QtWidgets @@ -66,9 +67,12 @@ class AlbumWorker(ThreadWorker): } album_item = QtWidgets.QListWidgetItem(self.ALBUM_TEMPLATE.format(**details)) self.window.albumListWidget.addItem(album_item) - artwork_worker = AlbumArtWorker() - artwork_worker.album_item = album_item - artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop'] - self.window.run_thread(artwork_worker, 'album-{}'.format(album['title'])) + if album['cover'] and album['cover'].get('urls') and album['cover']['urls'].get('medium_square_crop'): + artwork_worker = AlbumArtWorker() + artwork_worker.album_item = album_item + artwork_worker.artwork_url = album['cover']['urls']['medium_square_crop'] + self.window.run_thread(artwork_worker, 'album-{}'.format(album['title'])) + else: + album_item.setIcon(qta.icon('mdi.album')) self.window.update_album_total(self.window.albumListWidget.count()) self.quit.emit()