From dbc19ad71cbac5166aa0b82c97b726b464f4fdca Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 6 Jul 2017 10:33:13 +0200 Subject: Implemented MusicBrainz lookup Wow, what a convoluted api, to say the least... They have documentation, which is good, but the query syntax definitely needs more explaining, foremost how to encode non-ASCII characters and names with whitspaces... Well, it kinda works, but the Other Albums sections can be waaaaay off... --- playerwidget.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index c00db32..6eb5821 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -35,11 +36,14 @@ #include "indexerdialog.h" #include "globals.h" #include "helper.h" +#include "webdownloader.h" PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0){ mStarting = true; setupGui(); createActions(); + mWebDownloader = new WebDownloader(this); + connect(mWebDownloader, &WebDownloader::done, this, &PlayerWidget::webDlDone); mStarting = false; } @@ -203,7 +207,8 @@ void PlayerWidget::setupGui(){ //misc info QString leftInfoGBS = QString(tr("%1 Misc. %1")).arg(QChar(0x26A5)); QGroupBox *leftInfoGB = new QGroupBox(leftInfoGBS); - mLeftTE = new QTextEdit; + mLeftTE = new QTextBrowser; + mLeftTE->setOpenExternalLinks(true); mLeftTE->setFont(QFont("courier")); mLeftTE->setReadOnly(true); QVBoxLayout *leftInfoL = new QVBoxLayout; @@ -354,8 +359,10 @@ void PlayerWidget::createActions(){ helpA->setMenu(helpM); QAction *miscPrintA = new QAction(QIcon(":/clean_tampon.png"), tr("List selected"), this); connect(miscPrintA, &QAction::triggered, this, &PlayerWidget::printList); - QAction *miscMusicBrainzA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); - connect(miscMusicBrainzA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainz); + QAction *miscMusicBrainzRightA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); + connect(miscMusicBrainzRightA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainzRight); + QAction *miscMusicBrainzLeftA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); + connect(miscMusicBrainzLeftA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainzLeft); mView->addAction(addToPlayListA); mView->addAction(addToPlayListAndClearA); mView->addAction(Helper::createSeparator(this)); @@ -367,13 +374,14 @@ void PlayerWidget::createActions(){ mView->addAction(mDeleteFilesA); mView->addAction(Helper::createSeparator(this)); mView->addAction(miscPrintA); + mView->addAction(miscMusicBrainzLeftA); mView->addAction(Helper::createSeparator(this)); mView->addAction(mRefreshA); mView->addAction(Helper::createSeparator(this)); mView->addAction(randomPlayA); mPlayListView->addAction(removeFromPlayListA); mPlayListView->addAction(Helper::createSeparator(this)); - mPlayListView->addAction(miscMusicBrainzA); + mPlayListView->addAction(miscMusicBrainzRightA); mPlayListView->addAction(Helper::createSeparator(this)); mPlayListView->addAction(shufflePlayistA); mPlayListView->addAction(clearPlayListA); @@ -959,6 +967,8 @@ void PlayerWidget::addSong(const QModelIndex &idx){ len = Helper::lengthInSeconds(idx.data(FullPathRole).toString()); } item->setData(len, LengthRole); + item->setData(artist, ArtistRole); + item->setData(album, AlbumRole); root->appendRow(item); mPlayListLength += len; } @@ -1179,6 +1189,8 @@ void PlayerWidget::randomPlay(){ item->setIcon(songIcon); item->setData(randomQ.value(2), FullPathRole); item->setData(randomQ.value(6), LengthRole); + item->setData(randomQ.value(4), ArtistRole); + item->setData(randomQ.value(5), AlbumRole); mPlayListLength += randomQ.value(6).toInt(); root->appendRow(item); } @@ -1213,11 +1225,45 @@ void PlayerWidget::printList(){ output.append(t); } } - mLeftTE->setText(output); + mLeftTE->clear(); + mLeftTE->setPlainText(output); } -void PlayerWidget::searchMusicbrainz(){ +void PlayerWidget::searchMusicbrainzRight(){ + QModelIndex idx = mPlayListView->selectionModel()->currentIndex(); + if(!idx.isValid()){ + return; + } + QString artist = idx.data(ArtistRole).toString(); + QString album = idx.data(AlbumRole).toString(); + mWebDownloader->fetchData(artist, album); +} + +void PlayerWidget::searchMusicbrainzLeft(){ + QModelIndex idx = mView->selectionModel()->currentIndex(); + if(!idx.isValid()){ + return; + } + QString artist = idx.data(ArtistRole).toString().toLower(); + QString album = idx.data(AlbumRole).toString().toLower(); + mWebDownloader->fetchData(artist, album); +} + +void PlayerWidget::webDlDone(){ + QString text(tr("Musicbrainz:
    ")); + text.append(QString(tr("
  • Artist: %1
  • ")).arg(mWebDownloader->artist())); + text.append(QString(tr("
  • Album: %1
  • ")).arg(mWebDownloader->album())); + foreach(QString rg, mWebDownloader->data()){ + text.append(QString("
  • %1
  • ").arg(rg)); + } + text.append("
"); + text.append(tr("Other Albums
    ")); + for(QMap::const_iterator it = mWebDownloader->otherData().constBegin(); it != mWebDownloader->otherData().constEnd(); ++it){ + text.append(QString("
  • %2
  • ").arg(it.value()).arg(it.key())); + } + text.append("
"); + mLeftTE->setText(text); } void PlayerWidget::play(const QString &fullPath){ -- cgit v1.2.3-70-g09d2