Esempio n. 1
0
	Artist* Track::GetArtist( int index )
	{
		Artist* pArtist = m_pSession->CreateArtist();
		pArtist->Load( sp_track_artist( m_pTrack, index ) );

		return pArtist;
	}
Esempio n. 2
0
void SkView::onDraw(SkCanvas* canvas) {
	Artist* artist = this->getArtist();

	if (artist) {
		artist->draw(this, canvas);
    }
}
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();

}
Esempio n. 4
0
void UniversalMusicScraper::onArtistRelsFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Artist *artist = reply->property("storage").value<Storage*>()->artist();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    reply->deleteLater();
    if (!artist)
        return;

    if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302 ||
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301) {
        qDebug() << "Got redirect" << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        reply = qnam()->get(QNetworkRequest(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl()));
        reply->setProperty("storage", Storage::toVariant(reply, artist));
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(onArtistRelsFinished()));
        return;
    }

    QString discogsUrl;
    if (reply->error() == QNetworkReply::NoError) {
        QString msg = QString::fromUtf8(reply->readAll());
        QDomDocument domDoc;
        domDoc.setContent(msg);
        for (int i=0, n=domDoc.elementsByTagName("relation").count() ; i<n ; ++i) {
            QDomElement elem = domDoc.elementsByTagName("relation").at(i).toElement();
            if (elem.attribute("type") == "allmusic" && elem.elementsByTagName("target").count() > 0) {
                QString url = elem.elementsByTagName("target").at(0).toElement().text();
                QRegExp rx("allmusic\\.com/artist/(.*)$");
                if (rx.indexIn(url) != -1)
                    artist->setAllMusicId(rx.cap(1));
            }
            if (elem.attribute("type") == "discogs" && elem.elementsByTagName("target").count() > 0)
                discogsUrl = elem.elementsByTagName("target").at(0).toElement().text();
        }
    }

    if (!m_artistDownloads.contains(artist))
        m_artistDownloads.insert(artist, QList<DownloadElement>());
    m_artistDownloads[artist].clear();

    appendDownloadElement(artist, "theaudiodb", "tadb_data", QUrl(QString("http://www.theaudiodb.com/api/v1/json/%1/artist-mb.php?i=%2").arg(m_tadbApiKey).arg(artist->mbId())));
    appendDownloadElement(artist, "theaudiodb", "tadb_discography", QUrl(QString("http://www.theaudiodb.com/api/v1/json/%1/discography-mb.php?s=%2").arg(m_tadbApiKey).arg(artist->mbId())));
    if (!artist->allMusicId().isEmpty()) {
        appendDownloadElement(artist, "allmusic", "am_data", QUrl(QString("http://www.allmusic.com/artist/%1").arg(artist->allMusicId())));
        appendDownloadElement(artist, "allmusic", "am_biography", QUrl(QString("http://www.allmusic.com/artist/%1/biography").arg(artist->allMusicId())));
    }
    if (!discogsUrl.isEmpty())
        appendDownloadElement(artist, "discogs", "discogs_data", QUrl(discogsUrl + "?type=Releases&subtype=Albums"));

    foreach (DownloadElement elem, m_artistDownloads[artist]) {
        QNetworkRequest request(elem.url);
        request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0");
        QNetworkReply *reply = qnam()->get(request);
        new NetworkReplyWatcher(this, reply);
        reply->setProperty("storage", Storage::toVariant(reply, artist));
        reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
        connect(reply, SIGNAL(finished()), this, SLOT(onArtistLoadFinished()));
    }
Esempio n. 5
0
void ArtistListPrivate::loadArtists(const QVariantList &artists) {
    Q_Q(ArtistList);

    foreach (QVariant artist, artists) {
        Artist *a = new Artist;
        a->d_func()->loadArtist(artist.toMap());
        m_artists.append(a);
    }
	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());
	}
Esempio n. 7
0
bool FArtistsAdd::get(Artist &value)
{
    this->ui->eName->setText(value.Name());

    if (this->exec() == QDialog::Accepted) {
        value.setName(this->ui->eName->text());
        return true;
    }

    return false;
}
Esempio n. 8
0
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 
LfmListModel::addArtist( const Artist& a_artist )
{
    Artist* artist = new Artist;
    *artist = a_artist;
    LfmItem* item = new LfmItem( artist );
    item->loadImage( artist->imageUrl( lastfm::Small, true ));

    beginInsertRows( QModelIndex(), rowCount(), rowCount());
    m_items << item;
    connect( item, SIGNAL(updated()), SLOT( itemUpdated()));
    endInsertRows();   
}
	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());
	}
Esempio n. 11
0
/**************************************************************************
	parameters: -
	return value: -

	Destructor, deletes all dynamically allocated parts of an instance 
	of the class. As well as, the instance.
**************************************************************************/
Artist::Artist(Artist& a)
{
	cout << "Please enter a new first name: ";
	getline(cin, firstName);

	lastName = a.getLastName();
	numberOfPaintings = a.getNumberOfPaintings();

	pList = new PaintingList();
	next = NULL;
	
	int i;
	PaintingList * pl = a.getPaintingList();
	Painting * p = pl->getHead();
	for(i = 0; i < numberOfPaintings; i++, p = p->getNext())
	{	
		pList->appendToTail(p->copy());
	}
}
void cmd_line(Shell &shell, int argc, const ShellArguments &argv){
  if(argc != 5){
    return;
  }

  long start[] = {atol(argv[1]), atol(argv[2])};
  long end[] = {atol(argv[3]), atol(argv[4])};
  artist.line(start, end);

  shell.write('x');
}
Esempio n. 13
0
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);
    }
Esempio n. 14
0
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);

}
Esempio n. 15
0
bool DAOCollection::openCollection(QString path)
{

    QDomDocument doc;
    //********************************
    // Read the DOM tree form file
    //********************************
    QFile f(path);

    // We open the xml document
    if (!f.open(QIODevice::ReadOnly) || !doc.setContent(&f))
            return false;


    //********************************
    // Parse the DOM tree
    //********************************
    // The root node is supposed to be a "stone" tag, we retrieve its name
    QDomElement root=doc.documentElement();


    // We traverse its children
    QDomElement child=root.firstChild().toElement();
    while(!child.isNull())
    {
      // We know how to treat appearance and geometry
      if (child.tagName() == "artist")
      {
        Artist * a = new Artist(child.attribute("id"),mCollection.getCollectionId(),child.attribute("name"),child.attribute("infos"),QUrl(child.attribute("image")));
        // We traverse children
        QDomElement albums=child.firstChild().toElement();
        while(!albums.isNull())
        {

            if (albums.tagName() == "album")
            {
                Album * ab = new Album(child.attribute("id"),mCollection.getCollectionId(),albums.attribute("title"),a,QUrl(albums.attribute("image")));

                QDomElement songs=albums.firstChild().toElement();
                while(!songs.isNull())
                {
                    if (songs.tagName() == "song")
                    {
                    Song * s = new Song(child.attribute("id"),mCollection.getCollectionId(),songs.attribute("title"),1000,ab,QUrl());
                    ab->addSong(s);
                    }
                    songs = songs.nextSiblingElement();
                }
                a->addAlbum(ab);

            }


            albums = albums.nextSiblingElement();

        }

        mCollection.addArtist(a);
      }

    child = child.nextSiblingElement();
    }
        return true;
}
Esempio n. 16
0
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();
}
void cmd_origin(Shell &shell, int argc, const ShellArguments &argv){
  artist.origin();

  shell.write('x');
}
void LibraryItemDelegateArtists::paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{

	if(!index.isValid()) return;

		QLabel label;

		QRect rect(option.rect);

		painter->save();
		painter->translate(0, 0);



		if(index.column() == 0){
			int num_albums = index.model()->data(index, Qt::WhatsThisRole).toInt();

			if(num_albums <= 1)
				label.setPixmap(QPixmap(Helper::getIconPath() + "play_small.png"));
			else
				label.setPixmap(QPixmap(Helper::getIconPath() + "fwd_orange.png"));

			label.setContentsMargins(2, 0, 2, 2);
		}

		else if(index.column() == 1){

			QStringList list = index.model()->data(index, Qt::WhatsThisRole).toStringList();
			Artist artist;
			artist.fromStringList(list);

			QString text = "<b>" + artist.name + "</b>";
			label.setText(text);
			label.setContentsMargins(2, 0, 2, 2);
		}

		else if(index.column() == 2){
			QString text = index.model()->data(index, Qt::WhatsThisRole).toString();
			label.setText(text + " tracks");
			label.setContentsMargins(2, 0, 4, 2);
			label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
		}

		QString style;
		QString fg_color;

		bool is_selected = ((option.state & QStyle::State_Selected) != 0);

		QPalette palette = _parent->palette();
		QColor col_background = palette.color(QPalette::Active, QPalette::Background);
		QColor col_highlight = palette.color(QPalette::Active, QPalette::Highlight);
		//QColor col_highlight_lighter = palette.color(QPalette::Active, QPalette::Highlight).light();

		int val_bg = col_background.lightness();
		int val_sel = col_highlight.lightness();

		if(!is_selected){

			if(val_bg > 96) fg_color = " color: #202020";
			else fg_color = " color: #D8D8D8; ";

			style = QString("background-color: transparent; ") + fg_color;
		}

		else {
			if(val_sel > 96) fg_color = " color: #202020";
			else fg_color = " color: #D8D8D8; ";

			style = QString("background-color: " + col_highlight.name() + ";") + fg_color;
		}


		label.setAlignment( Qt::AlignVCenter );
		label.setStyleSheet(style);
		label.setFixedHeight(_parent->rowHeight(index.row())-1);
		label.setFixedWidth(_parent->columnWidth(index.column()));
		label.setContentsMargins(2, 0, 2, 0);

		label.setStyleSheet(style);
		label.render(painter, rect.topLeft() );

		painter->restore();

}
Esempio n. 19
0
void Discogs::handleRelease( QNetworkReply* reply ){

    Album album;
    QNetworkRequest request = reply->request();
    QString key = request.attribute(QNetworkRequest::User).toString();

    if( albums_.contains(key) ){
        album = albums_[key];
        //album.setArtists( QStringList() );
        //album.setSongs( QList<Song>() );
    }


    //cover->setText("");
    QString err;
    QByteArray response(reply->readAll());
    QXmlStreamReader xml(response);

    QList<Artist> Artists;
    QList<QUrl> images;
    QStringList artists,roles;
    QList<Song> songs;
    while (!xml.atEnd()) {
        xml.readNext();
        //qDebug()<<xml.name();

        if( xml.name() == "release" && xml.attributes().hasAttribute("id") ){
            QString id = xml.attributes().value("id").toString();
            album.setRelease(id);
        }

        if(xml.tokenType() == QXmlStreamReader::StartElement){
            if( xml.attributes().hasAttribute("stat") ){
                QString stat = xml.attributes().value("stat").toString();
                if(stat=="fail"){
                    while(xml.readNextStartElement()){
                        if( xml.name() == "error" ){
                            err.append(xml.readElementText()+"\n");
                        }else{
                            xml.skipCurrentElement();
                        }
                    }
                }
            }
            if( xml.attributes().hasAttribute("requests") ){
                //&nSearches = xml.attributes().value("requests").toString().toInt();
                //info->setText(QString::number(nSearches)+" searches performed within the last 24 hours");
            }
            if(xml.name() == "images"){
                xml.readNext();
                while(xml.name()=="image"){
                    if( xml.attributes().hasAttribute("uri") ){
                        images.append( QUrl( xml.attributes().value("uri").toString() ) );
                        //qDebug()<<"found image "<<xml.attributes().value("uri").toString();
                    }
                    xml.readNext();
                }
            }
            if(xml.name() == "artists"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "artist"){
                        while(xml.readNextStartElement()){
                            if(xml.name() == "name"){
                                artists.append( xml.readElementText() );
                            }else{
                                xml.skipCurrentElement();
                            }
                        }
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "extraartists"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "artist"){
                        //QString name;QString role;
                        Artist a;
                        while(xml.readNextStartElement()){
                            if(xml.name() == "name"){
                                a.setName( xml.readElementText() );
                            }else if(xml.name() == "role"){
                                a.setRole( xml.readElementText() );
                            }else{
                                xml.skipCurrentElement();
                            }
                            Artists.append(a);
                        }
                        //qDebug()<<role+": "+name;
                        //album.roles.append( role+": "+name );
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "formats"){
                while(xml.readNextStartElement()){
                    if( xml.name()=="format" && xml.attributes().hasAttribute("name") ){
                        QString sep=", ";
                        if(album.format().isEmpty()){
                            sep="";
                        }
                        album.setFormat( album.format() + sep + xml.attributes().value("name").toString() );
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "title"){
                album.setTitle( xml.readElementText() );
            }
            if(xml.name() == "labels"){
                xml.readNext();
                while(xml.name()=="label"){
                    if( xml.attributes().hasAttribute("name") ){
                        QString sep=", ";
                        if(album.label().isEmpty()){
                            sep="";
                        }
                        album.setLabel( album.label()+sep+xml.attributes().value("name").toString() );
                    }
                    xml.readNext();
                }
            }
            if(xml.name() == "genres"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "genre"){
                        QString sep=", ";
                        if(album.genre().isEmpty()){
                            sep="";
                        }
                        album.setGenre( album.genre() + sep + xml.readElementText() );
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "styles"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "style"){
                        QString sep=", ";
                        if(album.style().isEmpty()){
                            sep="";
                        }
                        album.setStyle( album.style() + sep + xml.readElementText() );
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
            if(xml.name() == "country"){
                album.setCountry( xml.readElementText() );
            }
            if(xml.name() == "released"){
                album.setYear( xml.readElementText().toInt() );
            }
            if(xml.name() == "notes"){
                album.setNotes( xml.readElementText() );
            }
            if(xml.name() == "tracklist"){
                while(xml.readNextStartElement()){
                    if(xml.name() == "track"){
                        Song s;
                        while(xml.readNextStartElement()){
                            //qDebug()<<xml.name()<<xml.readElementText();
                            if(xml.name() == "position"){
                                s.setTrack( xml.readElementText() );
                            }else if(xml.name() == "title"){
                                s.setTitle( xml.readElementText() );
                            }else if(xml.name() == "duration"){
                                QStringList tmp = xml.readElementText().split(":");
                                int sum=0;
                                for(int j=0;j<tmp.size();j++){
                                    sum = sum + ( tmp[j].toInt()*pow(60,tmp.size()-j-1) );
                                }
                                s.setLength(sum);
                            }else{
                                xml.skipCurrentElement();
                            }
                        }
                        songs.append(s);
                    }else{
                        xml.skipCurrentElement();
                    }
                }
            }
        }
    }

    //fix/compress roles for artists
    //QList<artist> newArtists;
    while( Artists.size()>0 ){
        QString role = Artists[0].role();
        if(role.isEmpty()){
            Artists.removeAt(0);
            continue;
        }
        Artist a;a.setRole(role);a.setName(Artists[0].name());
        //qDebug()<<role;
        for(int j=Artists.size()-1;j>=1;j--){
            if( Artists[j].role()==role ){
                if( !a.name().contains( Artists[j].name() ) ){
                    a.setName(a.name()+"/"+Artists[j].name());
                    //qDebug()<<a.name;
                }
                Artists.removeAt(j);
            }
        }
        Artists.removeAt(0);
        roles.append( a.role()+": "+a.name() );
        //newArtists.append(a);
    }

    //remove html links from notes
    QString notes = album.notes();
    while(1){
        int ind = notes.indexOf("<a href");
        if(ind==-1){
            break;
        }
        int ind2 = notes.indexOf(">",ind);
        notes.remove(ind,ind2-ind+1);
    }
    notes.remove("</a>",Qt::CaseInsensitive);
    album.setNotes(notes);

    if( reply->error() || !err.isEmpty() ){
        if( reply->error() ){
            err = reply->errorString()+":\n"+err;
        }
        QMessageBox::critical(0, "Error",
                              err, QMessageBox::Ok, QMessageBox::Ok);
    }

    album.setArtists(artists);
    album.setRoles(roles);
    album.setImages(images);
    album.setSongs(songs);

    albums_.insert(album.key(),album);
    reply->deleteLater();

    /*
    if(images.size()>0){
        //qDebug()<<"starting image downloading for album "+album.title()<<", images: "<<images;
        QNetworkRequest coverRequest(images[0]);        
        coverRequest.setAttribute(QNetworkRequest::User,album.key());
        QNetworkAccessManager *coverManager = new QNetworkAccessManager;
        connect(coverManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleCover(QNetworkReply*)));
        coverManager->get(coverRequest);
    }else {
        */
        nDownloaded_++;
        qDebug()<<"downloaded album "<<album.title();
        if( downloadImmediately_ && nDownloaded_==albums_.size() ){
            emit albumsDownloaded( albums_ );
        }
        if(!downloadImmediately_){
            emit albumDownloaded( album );
        }
    //}


}
Esempio n. 20
0
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;
}
ArtistData::ArtistData(const Artist &artist, const string &nation) :
  m_playcount(artist.Playcount()), m_nation(nation), m_name(artist.Name()),
  m_url(artist.Url())
{
}