void CollectionScanner::processArtist(FileInfo *file) { Artist *artist = new Artist(); const QString artistTag = file->getTags()->artist; artist->setName(DataUtils::cleanTag(artistTag)); artist->setProperty("originalHash", artist->getHash()); // qDebug() << "Processing artist:" << artist->getName() << artist->getHash(); if (filesWaitingForArtists.contains(artist->getHash())) { qDebug() << "ERROR Processing artist multiple times!" << artist->getName(); } if (loadedArtists.contains(artist->getHash())) { qDebug() << "ERROR Artist already processed!" << artist->getName(); } // add this file to filesWaitingForArtists // this also acts as a lock for other files // when the info is ready, all waiting files will be processed QList<FileInfo *> files; files.append(file); filesWaitingForArtists.insert(artist->getHash(), files); connect(artist, SIGNAL(gotInfo()), SLOT(gotArtistInfo())); artist->fetchInfo(); }
void testReleaseArtist() { Metadata *md = MbXmlParser().parse(get_file_contents("../test-data/valid/release/Under_the_Pink_1.xml")); Release *release = md->getRelease(); CPPUNIT_ASSERT(release); Artist *artist = release->getArtist(); CPPUNIT_ASSERT(artist); CPPUNIT_ASSERT_EQUAL(string("http://musicbrainz.org/artist/c0b2500e-0cef-4130-869d-732b23ed9df5"), artist->getId()); CPPUNIT_ASSERT_EQUAL(string("Tori Amos"), artist->getName()); }
void AlbumInfo::setAlbum(Album *album) { if (!album) { clear(); return; } titleLabel->setText(album->getTitle()); QString wiki = album->getWiki(); if (wiki.isEmpty()) { wikiLabel->clear(); } else { int split = wiki.indexOf('\n', 512); if (split == -1) { split = wiki.indexOf(". ", 512); } QString html = "<html><style>a { color: white }</style><body>" + wiki.left(split); if (split != -1) { Artist *artist = album->getArtist(); QString url = "http://www.last.fm/music/" + (artist ? artist->getName() : "_") + "/" + album->getTitle() + "/+wiki"; html += QString(" <a href='%1'>%2</a>").arg(url, tr("Read more")); } html += "</body></html>"; wikiLabel->setText(html); } QImage photo = album->getPhoto(); if (photo.isNull()) { photoLabel->clear(); photoLabel->hide(); } else { photoLabel->setPixmap(QPixmap::fromImage(photo)); photoLabel->show(); } QString query; if (album->getArtist()) query = album->getArtist()->getName() + " - "; query += album->getTitle(); buyOnAmazonButton->setProperty("query", query); buyOnAmazonButton->show(); /* QString qry("SELECT id FROM tracks where album=%1 order by track, title"); qry = qry.arg(album->getId()); qDebug() << qry; trackListModel->setQuery(qry, Database::instance().getConnection()); if (trackListModel->lastError().isValid()) qDebug() << trackListModel->lastError(); trackListView->setMinimumHeight(trackListView->maximumViewportSize().height()); */ }
void CollectionScanner::gotArtistInfo() { // get the Artist that sent the signal Artist *artist = static_cast<Artist *>(sender()); if (!artist) { qDebug() << "Cannot get sender"; return; } // qDebug() << "got info for" << artist->getName(); int artistId = Artist::idForName(artist->getName()); if (artistId < 0) { // qDebug() << "We have a new promising artist:" << artist->getName(); artist->insert(); // TODO last insert id artistId = Artist::idForName(artist->getName()); } else { qDebug() << "Updating artist" << artist->getName(); artist->update(); } artist->setId(artistId); // now that we have an id, let's enqueue the cover image download QString imageUrl = artist->property("imageUrl").toString(); if (!imageUrl.isEmpty()) ImageDownloader::enqueue(artistId, ImageDownloader::ArtistType, imageUrl); const QString hash = artist->property("originalHash").toString(); QList<FileInfo *> files = filesWaitingForArtists.value(hash); filesWaitingForArtists.remove(hash); loadedArtists.insert(hash, artist); // if (hash != artist->getHash()) loadedArtists.insert(artist->getHash(), artist); // continue the processing of blocked files // qDebug() << files.size() << "files were waiting for artist" << artist->getName(); foreach (FileInfo *file, files) { file->setArtist(artist); // qDebug() << "ready for album" << file->getFileInfo().baseName(); giveThisFileAnAlbum(file); }
void testReleaseTracksVA() { Metadata *md = MbXmlParser().parse(get_file_contents("../test-data/valid/release/Mission_Impossible_2.xml")); Release *release = md->getRelease(); CPPUNIT_ASSERT(release); TrackList &tracks = release->getTracks(); CPPUNIT_ASSERT_EQUAL(16, int(tracks.size())); Artist *artist = tracks[1]->getArtist(); CPPUNIT_ASSERT(artist); CPPUNIT_ASSERT_EQUAL(string("1981"), artist->getBeginDate()); CPPUNIT_ASSERT_EQUAL(string("Metallica"), artist->getName()); CPPUNIT_ASSERT_EQUAL(string("Metallica"), artist->getSortName()); CPPUNIT_ASSERT_EQUAL(Artist::TYPE_GROUP, artist->getType()); }
void LastFm::scrobble(Track* track) { if (!track) return; if (sessionKey.isEmpty()) { qWarning() << "Not authenticated to Last.fm"; return; } QUrl url(WS); QMap<QString, QString> params; params["method"] = "track.scrobble"; params["timestamp"] = QString::number(track->getStartTime()); params["track"] = track->getTitle(); Artist* artist = track->getArtist(); if (!artist) { qDebug() << __FUNCTION__ << "Missing artist for" << track; return; } params["artist"] = artist->getName(); Album* album = track->getAlbum(); if (album) params["album"] = album->getTitle(); if (track->getNumber()) params["trackNumber"] = QString::number(track->getNumber()); if (track->getLength()) params["duration"] = QString::number(track->getLength()); params["api_key"] = Constants::LASTFM_API_KEY; params["sk"] = sessionKey; sign(params); The::http()->post(url, params); }
void PlaylistItemDelegate::paintAlbumHeader( QPainter* painter, const QStyleOptionViewItem& option, QRect line, Track* track) const { QString headerTitle; Album *album = track->getAlbum(); if (album) headerTitle = album->getTitle(); Artist *artist = track->getArtist(); if (artist) headerTitle += " - " + artist->getName(); painter->save(); // cover background /* QImage p = album->getPhoto(); if (!p.isNull()) { painter->drawTiledPixmap(line, QPixmap::fromImage(p)); QLinearGradient linearGrad(0, 0, 0, line.height()); linearGrad.setColorAt(0, QColor(0,0,0, 96)); linearGrad.setColorAt(1, QColor(0,0,0, 64)); painter->fillRect(line, QBrush(linearGrad)); } else { QLinearGradient linearGrad(0, 0, 0, line.height()); linearGrad.setColorAt(0, option.palette.color(QPalette::Mid)); linearGrad.setColorAt(1, option.palette.midlight().color()); painter->fillRect(line, QBrush(linearGrad)); }*/ QLinearGradient linearGrad(0, 0, 0, line.height()); #ifdef APP_MAC linearGrad.setColorAt(0, QColor(0x99, 0x99, 0x99, 0xFF)); linearGrad.setColorAt(1, QColor(0xCC, 0xCC, 0xCC, 0xFF)); #else linearGrad.setColorAt(0, option.palette.color(QPalette::Mid)); linearGrad.setColorAt(1, option.palette.color(QPalette::Midlight)); #endif painter->fillRect(line, QBrush(linearGrad)); // borders // painter->setPen(option.palette.color(QPalette::Light)); // painter->drawLine(0, 0, line.width(), 0); painter->setPen(option.palette.color(QPalette::Mid)); painter->drawLine(0, line.height()-1, line.width(), line.height()-1); // font QFont boldFont = painter->font(); boldFont.setBold(true); painter->setFont(boldFont); // text size QSize trackStringSize(QFontMetrics(painter->font()).size(Qt::TextSingleLine, headerTitle)); QPoint textLoc(PADDING*6, 0); QRect trackTextBox(textLoc.x(), textLoc.y(), trackStringSize.width(), line.height()); // text shadow painter->setPen(QColor(0, 0, 0, 64)); painter->drawText(trackTextBox.translated(0, -1), Qt::AlignLeft | Qt::AlignVCenter, headerTitle); // text painter->setPen(option.palette.color(QPalette::Light)); painter->drawText(trackTextBox, Qt::AlignLeft | Qt::AlignVCenter, headerTitle); // album length if (album) { // TODO this is the album duration, but not necessarily what we have in the playlist int totalLength = Track::getTotalLength(album->getTracks()); QString albumLength; if (totalLength > 3600) albumLength = QTime().addSecs(totalLength).toString("h:mm:ss"); else albumLength = QTime().addSecs(totalLength).toString("m:ss"); QFont normalFont = painter->font(); normalFont.setBold(false); // normalFont.setPointSize(boldFont.pointSize()*.9); painter->setFont(normalFont); painter->drawText(line.translated(-PADDING, 0), Qt::AlignRight | Qt::AlignVCenter, albumLength); } // TODO album year painter->restore(); }
int main(int argc, char **argv) { if (argc < 1) { cout << "Usage: cdlookup [device]" << endl; return 1; } string device; if (argc > 1) device = argv[1]; Disc *disc; try { disc = readDisc(device); } catch (DiscError &e) { cout << "Error: " << e.what() << endl; return 1; } string discId = disc->getId(); delete disc; cout << "Disc Id: " << discId << endl << endl; Query q; ReleaseResultList results; try { ReleaseFilter f = ReleaseFilter().discId(discId); results = q.getReleases(&f); } catch (WebServiceError &e) { cout << "Error: " << e.what() << endl; return 1; } for (ReleaseResultList::iterator i = results.begin(); i != results.end(); i++) { ReleaseResult *result = *i; Release *release; try { release = q.getReleaseById(result->getRelease()->getId(), &ReleaseIncludes().tracks().artist()); } catch (WebServiceError &e) { cout << "Error: " << e.what() << endl; continue; } cout << "Id : " << release->getId() << endl; cout << "Title : " << release->getTitle() << endl; cout << "Tracks : "; int trackno = 1; for (TrackList::iterator j = release->getTracks().begin(); j != release->getTracks().end(); j++) { Track *track = *j; Artist *artist = track->getArtist(); if (!artist) artist = release->getArtist(); cout << trackno++ << ". " << artist->getName() << " / " << track->getTitle() << endl; cout << " "; } cout << endl; delete result; } return 0; }