void MusicBrainzClient::requestFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); if (!reply) return; reply->deleteLater(); if (!m_requests.contains(reply)) return; int id = m_requests.take(reply); ResultList ret; if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) { emit(networkError( reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), "Musicbrainz")); return; } QXmlStreamReader reader(reply); while (!reader.atEnd()) { if (reader.readNext() == QXmlStreamReader::StartElement && reader.name() == "recording") { ResultList tracks = parseTrack(reader); foreach (const Result& track, tracks) { if (!track.m_title.isEmpty()) { ret << track; } } } }
void MusicDNSXmlParser::parseElement( const QDomElement &e ) { QString elementName = e.tagName(); if( elementName == "track" ) parseTrack( e ); else parseChildren( e ); }
bool MidiParser::doParse() { if (!parseHeader()) return false; if (format == 0xF0) return parseSysex(); qDebug() << "MidiParser: MIDI file format" << format; switch(format) { case 0: if (numberOfTracks != 1) { qDebug() << "MidiParser: MIDI file format error: MIDI files format 0 must have 1 MIDI track, not" << numberOfTracks; return false; } return parseTrack(midiEventList); case 1: if (numberOfTracks > 0) { QVector<MidiEventList> trackList(numberOfTracks); for (uint i = 0; i < numberOfTracks; i++) { qDebug() << "MidiParser: Parsing & merging MIDI track" << i + 1; if (!parseTrack(trackList[i])) return false; } mergeMidiEventLists(trackList); return true; } qDebug() << "MidiParser: MIDI file format error: MIDI files format 1 must have at least 1 MIDI track"; return false; case 2: for (uint i = 0; i < numberOfTracks; i++) { qDebug() << "MidiParser: Parsing & appending MIDI track" << i + 1; MidiEventList list; if (!parseTrack(list)) return false; midiEventList += list; } return true; default: qDebug() << "MidiParser: MIDI file format error: unknown MIDI file format" << format; return false; } }
void ITunesFeature::parseTracks(QXmlStreamReader &xml) { QSqlQuery query(m_database); query.prepare("INSERT INTO itunes_library (id, artist, title, album, year, genre, comment, tracknumber," "bpm, bitrate," "duration, location," "rating ) " "VALUES (:id, :artist, :title, :album, :year, :genre, :comment, :tracknumber," ":bpm, :bitrate," ":duration, :location," ":rating )"); bool in_container_dictionary = false; bool in_track_dictionary = false; qDebug() << "Parse iTunes music collection"; //read all sunsequent <dict> until we reach the closing ENTRY tag while (!xml.atEnd() && !m_cancelImport) { xml.readNext(); if (xml.isStartElement()) { if (xml.name() == "dict") { if (!in_track_dictionary && !in_container_dictionary) { in_container_dictionary = true; continue; } else if (in_container_dictionary && !in_track_dictionary) { //We are in a <dict> tag that holds track information in_track_dictionary = true; //Parse track here parseTrack(xml, query); } } } if (xml.isEndElement() && xml.name() == "dict") { if (in_track_dictionary && in_container_dictionary) { in_track_dictionary = false; continue; } else if (in_container_dictionary && !in_track_dictionary) { // Done parsing tracks. in_container_dictionary = false; break; } } } }
/** \fn LookupMainAtoms \brief Search main atoms to ease job for other part */ uint8_t MP4Header::lookupMainAtoms(void *ztom) { adm_atom *tom=(adm_atom *)ztom; adm_atom *moov; ADMAtoms id; uint32_t container; printf("Analyzing file and atoms\n"); if(!ADM_mp4SimpleSearchAtom(tom, ADM_MP4_MOOV,&moov)) { adm_printf(ADM_PRINT_ERROR,"Cannot locate moov atom\n"); return 0; } ADM_assert(moov); while(!moov->isDone()) { adm_atom son(moov); if(!ADM_mp4SearchAtomName(son.getFCC(), &id,&container)) { adm_printf(ADM_PRINT_DEBUG,"Found atom %s unknown\n",fourCC::tostringBE(son.getFCC())); } else { switch( id) { case ADM_MP4_MVHD: parseMvhd(&son);break; case ADM_MP4_TRACK: if(!parseTrack(&son)) { printf("Parse Track failed\n"); } ; break; default : adm_printf(ADM_PRINT_DEBUG,"atom %s not handled\n",fourCC::tostringBE(son.getFCC())); break; } } son.skipAtom(); } delete moov; printf("Done finding main atoms\n"); return 1; }
Boolean MatroskaFileParser::parse() { Boolean areDone = False; try { do { switch (fCurrentParseState) { case PARSING_START_OF_FILE: { areDone = parseStartOfFile(); break; } case LOOKING_FOR_TRACKS: { lookForNextTrack(); break; } case PARSING_TRACK: { areDone = parseTrack(); if (areDone && fOurFile.fCuesOffset > 0) { // We've finished parsing the 'Track' information. There are also 'Cues' in the file, so parse those before finishing: // Seek to the specified position in the file. We were already told that the 'Cues' begins there: #ifdef DEBUG fprintf(stderr, "Seeking to file position %llu (the previously-reported location of 'Cues')\n", fOurFile.fCuesOffset); #endif seekToFilePosition(fOurFile.fCuesOffset); fCurrentParseState = PARSING_CUES; areDone = False; } break; } case PARSING_CUES: { areDone = parseCues(); break; } case LOOKING_FOR_CLUSTER: { if (fOurFile.fClusterOffset > 0) { // Optimization: Seek to the specified position in the file. We were already told that the 'Cluster' begins there: #ifdef DEBUG fprintf(stderr, "Optimization: Seeking to file position %llu (the previously-reported location of a 'Cluster')\n", fOurFile.fClusterOffset); #endif seekToFilePosition(fOurFile.fClusterOffset); } fCurrentParseState = LOOKING_FOR_BLOCK; break; } case LOOKING_FOR_BLOCK: { lookForNextBlock(); break; } case PARSING_BLOCK: { parseBlock(); break; } case DELIVERING_FRAME_WITHIN_BLOCK: { if (!deliverFrameWithinBlock()) return False; break; } case DELIVERING_FRAME_BYTES: { deliverFrameBytes(); return False; // Halt parsing for now. A new 'read' from downstream will cause parsing to resume. break; } } } while (!areDone); return True; } catch (int /*e*/) { #ifdef DEBUG fprintf(stderr, "MatroskaFileParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n"); #endif return False; // the parsing got interrupted } }
TreeItem* TraktorFeature::importLibrary(QString file) { //Give thread a low priority QThread* thisThread = QThread::currentThread(); thisThread->setPriority(QThread::LowestPriority); //Invisible root item of Traktor's child model TreeItem* root = NULL; //Delete all table entries of Traktor feature ScopedTransaction transaction(m_database); clearTable("traktor_playlist_tracks"); clearTable("traktor_library"); clearTable("traktor_playlists"); transaction.commit(); transaction.transaction(); QSqlQuery query(m_database); query.prepare("INSERT INTO traktor_library (artist, title, album, year," "genre,comment,tracknumber,bpm, bitrate,duration, location," "rating,key) VALUES (:artist, :title, :album, :year,:genre," ":comment, :tracknumber,:bpm, :bitrate,:duration, :location," ":rating,:key)"); //Parse Trakor XML file using SAX (for performance) QFile traktor_file(file); if (!traktor_file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Cannot open Traktor music collection"; return NULL; } QXmlStreamReader xml(&traktor_file); bool inCollectionTag = false; //TODO(XXX) is this still needed to parse the library correctly? bool inEntryTag = false; bool inPlaylistsTag = false; bool isRootFolderParsed = false; int nAudioFiles = 0; while (!xml.atEnd() && !m_cancelImport) { xml.readNext(); if (xml.isStartElement()) { if (xml.name() == "COLLECTION") { inCollectionTag = true; } // Each "ENTRY" tag in <COLLECTION> represents a track if (inCollectionTag && xml.name() == "ENTRY" ) { inEntryTag = true; //parse track parseTrack(xml, query); ++nAudioFiles; //increment number of files in the music collection } if (xml.name() == "PLAYLISTS") { inPlaylistsTag = true; } if (inPlaylistsTag && !isRootFolderParsed && xml.name() == "NODE") { QXmlStreamAttributes attr = xml.attributes(); QString nodetype = attr.value("TYPE").toString(); QString name = attr.value("NAME").toString(); if (nodetype == "FOLDER" && name == "$ROOT") { //process all playlists root = parsePlaylists(xml); isRootFolderParsed = true; } } } if (xml.isEndElement()) { if (xml.name() == "COLLECTION") { inCollectionTag = false; } if (xml.name() == "ENTRY" && inCollectionTag) { inEntryTag = false; } if (xml.name() == "PLAYLISTS" && inPlaylistsTag) { inPlaylistsTag = false; } } } if (xml.hasError()) { // do error handling qDebug() << "Cannot process Traktor music collection"; if (root) delete root; return NULL; } qDebug() << "Found: " << nAudioFiles << " audio files in Traktor"; //initialize TraktorTableModel transaction.commit(); return root; }