int MagnatuneXmlParser::parse(QXmlStreamReader &xml) { QList<Song> *songList=new QList<Song>(); while (!xml.atEnd()) { xml.readNext(); if (QXmlStreamReader::StartElement==xml.tokenType() && QLatin1String("Track")==xml.name()) { songList->append(parseSong(xml)); if (songList->count()>50) { emit songs(songList); songList=new QList<Song>(); } } } if (songList->isEmpty()) { delete songList; } else { emit songs(songList); } return artists.count(); }
QList<Song *> * MPDParseUtils::parseSongs(const QByteArray * const data) { QList<Song *> *songs = new QList<Song *>; QByteArray song; QList<QByteArray> lines = data->split('\n'); int amountOfLines = lines.size(); for(int i = 0; i < amountOfLines; i++) { song += lines.at(i); song += "\n"; if(i == lines.size() - 1 || lines.at(i + 1).startsWith("file:")) { songs->append(parseSong(&song)); song.clear(); } } return songs; }
QList<MusicLibraryItemArtist *> * MPDParseUtils::parseLibraryItems(const QByteArray * const data) { QList<MusicLibraryItemArtist *> *artists = new QList<MusicLibraryItemArtist *>; QByteArray currentItem; MusicLibraryItemArtist *artistItem = NULL; MusicLibraryItemAlbum *albumItem = NULL; MusicLibraryItemSong *songItem = NULL; Song *currentSong; bool found = false; QList<QByteArray> lines = data->split('\n'); int amountOfLines = lines.size(); for(int i = 0; i < amountOfLines; i++) { currentItem += lines.at(i); currentItem += "\n"; if(i == lines.size() - 1 || lines.at(i + 1).startsWith("file:")) { currentSong = parseSong(¤tItem); currentItem.clear(); if(currentSong->isEmpty()) { delete currentSong; continue; } currentSong->fillEmptyFields(); int amountOfArtists = artists->size(); // Check if artist already exists for(int i = 0; i < amountOfArtists; i++) { if(artists->at(i)->data(0) == currentSong->artist) { artistItem = artists->at(i); found = true; } } if(!found) { artistItem = new MusicLibraryItemArtist(currentSong->artist); artists->append(artistItem); } found = false; int amountOfAlbums = artistItem->childCount(); // Check if album already exists for(int i = 0; i < amountOfAlbums; i++) { if(artistItem->child(i)->data(0) == currentSong->album) { albumItem = static_cast<MusicLibraryItemAlbum *>(artistItem->child(i)); found = true; } } if(!found) { albumItem = new MusicLibraryItemAlbum(currentSong->album, artistItem); artistItem->appendChild(albumItem); } found = false; // Add song to album (possibly in track order) songItem = new MusicLibraryItemSong(currentSong->title, albumItem); songItem->setFile(currentSong->file); songItem->setTrack(currentSong->track); songItem->setDisc(currentSong->disc); albumItem->appendChild(songItem); delete currentSong; } } return artists; }