Fix loading album art

This commit is contained in:
Raoul Snyman 2021-06-16 00:08:24 -07:00
parent f66fea1e90
commit 10ac48b6b9
No known key found for this signature in database
GPG Key ID: 423F9B322D9BEF2C
5 changed files with 30 additions and 20 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_space = true
max_line_length = 120
indent_style = space
[*.py]
indent_size = 4
[*.ui,*.xml]
indent_size = 2

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from time import sleep
import requests
from funksnake import Funkwhale
from PyQt5 import QtCore, QtGui, QtWidgets, QtNetwork
@ -38,20 +37,14 @@ class AlbumArtWorker(ThreadWorker):
self.error.emit('No artwork URL set', 'The artwork_url attribute was not set')
self.quit.emit()
return
reply = window.network_manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl(self.artwork_url)))
while not reply.isFinished():
print(reply.error())
sleep(0.1)
print(reply)
if reply.error() == QtNetwork.QNetworkReply.NoError:
jpeg_data = reply.readAll()
response = requests.get(self.artwork_url)
if response.status_code == 200:
pixmap = QtGui.QPixmap()
pixmap.loadFromData(jpeg_data)
self.albumListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(pixmap), album['title']))
pixmap.loadFromData(response.content)
self.album_item.setIcon(QtGui.QIcon(pixmap))
else:
self.albumListWidget.addItem(QtWidgets.QListWidgetItem(album['title']))
print(response.text)
self.quit.emit()
class AlbumWorker(ThreadWorker):
@ -67,7 +60,6 @@ class AlbumWorker(ThreadWorker):
return
self.window.albumListWidget.clear()
for album in self.window.funkwhale.albums.list()['results']:
# TODO: Cache this
album_item = QtWidgets.QListWidgetItem(album['title'])
self.window.albumListWidget.addItem(album_item)
artwork_worker = AlbumArtWorker()
@ -77,7 +69,6 @@ class AlbumWorker(ThreadWorker):
self.quit.emit()
class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
@ -93,7 +84,7 @@ class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
self.settings.value('funkwhale/username', None),
self.settings.value('funkwhale/password', None))
self.load_albums()
self.load_artists()
# self.load_artists()
def run_thread(self, worker, thread_name):
"""
@ -173,6 +164,9 @@ class MainWindow(QtWidgets.QMainWindow, UiMainWindow):
def load_albums(self):
if not self.funkwhale or not self.funkwhale.token:
return
worker = AlbumWorker()
worker.window = self
self.run_thread(worker, 'get-albums')
def load_artists(self):
if not self.funkwhale or not self.funkwhale.token:

View File

@ -124,9 +124,10 @@ class UiMainWindow(object):
self.albumListWidget = QtWidgets.QListWidget(self.albumPage)
self.albumListWidget.setObjectName("albumListWidget")
self.albumListWidget.setSortingEnabled(True)
# self.albumListWidget.setViewMode(QtWidgets.QListView.IconMode)
# self.albumListWidget.setMovement(QtWidgets.QListView.Static)
# self.albumListWidget.setGridSize(QtCore.QSize(128, 128))
self.albumListWidget.setViewMode(QtWidgets.QListView.IconMode)
self.albumListWidget.setMovement(QtWidgets.QListView.Static)
self.albumListWidget.setIconSize(QtCore.QSize(100, 100))
self.albumListWidget.setGridSize(QtCore.QSize(128, 128))
self.albumPageLayout.addWidget(self.albumListWidget)
self.stackedWidget.addWidget(self.albumPage)
self.artistPage = QtWidgets.QWidget()