Skip to content

Commit

Permalink
Fix various ways of album cover download (#31)
Browse files Browse the repository at this point in the history
* Avoid undefined artistcount in album view.

When listing albums, it's always for one unique artist,
so artistcount is always 1 in this context.

* Fix cover download.

Ensure that the cache directory for covers
exists.

Also, properly reload the artist image in artist
list when a cover is associated to an artist.

Rewrite the text position on cover with a direct
calculation of the Y position, the anchors solution
with alternating undefined values seems not to work
properly, when a cover is associated to an artist
for instance.

* Fix cover download using Quasar cover providers.

katastrofos.net is now using secure HTTP, replying
with a 301 moved permanently when polled on HTTP only.

Avoid HTML parsing on the result by using the query.php
method instead of the HTML frontend provided by index.php.
  • Loading branch information
dcaliste authored Dec 17, 2023
1 parent 8207963 commit 0b6bddd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion qml/pages/AlbumListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Page {
PullDownMenu {
MenuItem {
text: qsTr("Search artist image")
enabled: artist!==qsTr("Unknown artist") && artistcount==="1"
enabled: artist!==qsTr("Unknown artist")
onClicked: {
coversearch.clearData()
pageStack.push ("CoverDownload.qml", {"artist":artist, "searchingArtist":true, "album":""})
Expand Down
10 changes: 6 additions & 4 deletions qml/pages/CoverArtList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ BackgroundItem
Connections {
target: coversearch
onImageChanged: {
if ((artist===dartist && album==dalbum) || (album===dartist && album==dalbum)) {
if ((artist===dartist && album==dalbum)
|| (album===dartist && album==dalbum)
|| (album===dartist && !dalbum)) {
console.log("Updated: " + artist + " - " + album)
reload()
}
Expand Down Expand Up @@ -113,9 +115,9 @@ BackgroundItem

Label {
id: vtext
anchors.verticalCenter: coverImg.status!=Image.Error && textvisible? undefined : parent.verticalCenter
anchors.bottom: coverImg.status!=Image.Error && textvisible? parent.bottom : undefined
anchors.bottomMargin: coverImg.status!=Image.Error && textvisible? Theme.paddingSmall : undefined
y: coverImg.status!=Image.Error && textvisible
? parent.height - height - Theme.paddingSmall
: (parent.height - height) / 2
anchors.left: parent.left
anchors.leftMargin: Theme.paddingMedium
width: parent.width - Theme.paddingMedium*2
Expand Down
4 changes: 4 additions & 0 deletions src/coversearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//#include <QDeclarativeView>
#include <QDebug>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QJsonDocument>
Expand Down Expand Up @@ -39,6 +40,9 @@ CoverSearch::CoverSearchPrivate::CoverSearchPrivate(CoverSearch * parent) : q(pa
//q->pepe = new WebThread();
//connect (q->pepe, SIGNAL(imgLoaded(QString,int)), parent, SLOT(paintImg(QString,int)) );

// Ensure that download destination exists.
QDir d;
d.mkpath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
}

CoverSearch::CoverSearchPrivate::~CoverSearchPrivate()
Expand Down
14 changes: 3 additions & 11 deletions src/loadwebimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ void WebThread::checkAll()
//QString url = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=7f338c7458e7d1a9a6204221ff904ba1";

// QUASAR
QString url = "http://coverart.katastrophos.net/index.php?";
url += "&artist="+QUrl::toPercentEncoding(artist)+"&album="+QUrl::toPercentEncoding(album)+"&search=Search";

QString url = "https://coverart.katastrophos.net/query.php?";
url += "&artist="+QUrl::toPercentEncoding(artist)+"&album="+QUrl::toPercentEncoding(album)+"&mode=imageurls&limit=1";


//AMAZON - SIMPLE
Expand Down Expand Up @@ -211,16 +210,9 @@ void WebThread::downloaded(QNetworkReply *respuesta)

QString tmp = datos1;


//QUASAR
if (tmp.contains("<ul title=\"Cover Arts\">"))
if (tmp.startsWith("http"))
{
int x = tmp.indexOf("<li><a href=\"");
tmp.remove(0,x+13);
x = tmp.indexOf("\">");
tmp.remove(x,tmp.length()-x);
tmp = tmp.trimmed();

qDebug() << "Link for" << files[0][0] << files[0][1] << tmp;

downloadImage(tmp);
Expand Down

0 comments on commit 0b6bddd

Please sign in to comment.