Пример #1
0
bool Locutus::parseFile() {
	if (file_queue.size() <= 0)
		return false;
	string filename(*file_queue.begin());
	Debug::info() << filename << endl;
	file_queue.pop_front();
	Metafile *mf = new Metafile(filename);
	if (!database->loadMetafile(mf)) {
		if (mf->readFromFile()) {
			/* save file to cache */
			database->saveMetafile(*mf);
		} else {
			/* unable to read this file */
			delete mf;
			return false;
		}
	}
	map<string, int>::iterator g = groups.find(mf->getGroup());
	if (g == groups.end())
		groups[mf->getGroup()] = 1;
	else
		++(g->second);
	++total_files;
	delete mf;
	return true;
}
Пример #2
0
bool PostgreSQL::saveMetafile(const Metafile& metafile, const string& old_filename) {
    ostringstream query;
    string e_filename = escapeString(metafile.filename);
    string e_album = escapeString(metafile.album);
    string e_albumartist = escapeString(metafile.albumartist);
    string e_albumartistsort = escapeString(metafile.albumartistsort);
    string e_artist = escapeString(metafile.artist);
    string e_artistsort = escapeString(metafile.artistsort);
    string e_musicbrainz_albumartistid = escapeString(metafile.musicbrainz_albumartistid);
    string e_musicbrainz_albumid = escapeString(metafile.musicbrainz_albumid);
    string e_musicbrainz_artistid = escapeString(metafile.musicbrainz_artistid);
    string e_musicbrainz_trackid = escapeString(metafile.musicbrainz_trackid);
    string e_title = escapeString(metafile.title);
    string e_tracknumber = escapeString(metafile.tracknumber);
    string e_released = escapeString(metafile.released);
    string e_genre = escapeString(metafile.genre);
    string e_group = escapeString(metafile.getGroup());
    string e_track_id;
    if (metafile.matched) {
        e_track_id = "(SELECT track_id FROM track WHERE mbid = '";
        e_track_id.append(e_musicbrainz_trackid);
        e_track_id.append("')");
    } else {
        e_track_id = "NULL";
    }
    string e_old_filename;
    if (old_filename == "") {
        e_old_filename = e_filename;
        query.str("");
        query << "INSERT INTO file(filename, duration, channels, bitrate, samplerate, album, albumartist, albumartistsort, artist, artistsort, musicbrainz_albumartistid, musicbrainz_albumid, musicbrainz_artistid, musicbrainz_trackid, title, tracknumber, released, genre, pinned, groupname, duplicate, user_changed, track_id, checked) SELECT";
        query << " '" << e_filename << "'";
        query << ", " << metafile.duration;
        query << ", " << metafile.channels;
        query << ", " << metafile.bitrate;
        query << ", " << metafile.samplerate;
        query << ", '" << e_album << "'";
        query << ", '" << e_albumartist << "'";
        query << ", '" << e_albumartistsort << "'";
        query << ", '" << e_artist << "'";
        query << ", '" << e_artistsort << "'";
        query << ", '" << e_musicbrainz_albumartistid << "'";
        query << ", '" << e_musicbrainz_albumid << "'";
        query << ", '" << e_musicbrainz_artistid << "'";
        query << ", '" << e_musicbrainz_trackid << "'";
        query << ", '" << e_title << "'";
        query << ", '" << e_tracknumber << "'";
        query << ", '" << e_released << "'";
        query << ", '" << e_genre << "'";
        query << ", " << (metafile.pinned ? "true" : "false");
        query << ", '" << e_group << "'";
        query << ", " << (metafile.duplicate ? "true" : "false");
        query << ", false";
        query << ", " << e_track_id;
        query << ", true";
        query << " WHERE NOT EXISTS";
        query << " (SELECT true FROM file WHERE filename = '" << e_filename << "')";
        if (!doQuery(query.str()))
            return false;
    } else {
        e_old_filename = escapeString(old_filename);
    }
    query.str("");
    query << "UPDATE file SET";
    query << " filename = '" << e_filename << "'";
    query << ", last_updated = now()";
    query << ", duration = " << metafile.duration;
    query << ", channels = " << metafile.channels;
    query << ", bitrate = " << metafile.bitrate;
    query << ", samplerate = " << metafile.samplerate;
    query << ", album = '" << e_album << "'";
    query << ", albumartist = '" << e_albumartist << "'";
    query << ", albumartistsort = '" << e_albumartistsort << "'";
    query << ", artist = '" << e_artist << "'";
    query << ", artistsort = '" << e_artistsort << "'";
    query << ", musicbrainz_albumartistid = '" << e_musicbrainz_albumartistid << "'";
    query << ", musicbrainz_albumid = '" << e_musicbrainz_albumid << "'";
    query << ", musicbrainz_artistid = '" << e_musicbrainz_artistid << "'";
    query << ", musicbrainz_trackid = '" << e_musicbrainz_trackid << "'";
    query << ", title = '" << e_title << "'";
    query << ", tracknumber = '" << e_tracknumber << "'";
    query << ", released = '" << e_released << "'";
    query << ", genre = '" << e_genre << "'";
    query << ", pinned = " << (metafile.pinned ? "true" : "false");
    query << ", groupname = '" << e_group << "'";
    query << ", duplicate = " << (metafile.duplicate ? "true" : "false");
    query << ", user_changed = false";
    query << ", track_id = " << e_track_id;
    query << ", checked = true";
    query << " WHERE filename = '" << e_old_filename << "'";
    return doQuery(query.str());
}