2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "song.h"
|
2010-08-03 21:29:49 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-01-16 18:17:00 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <taglib/aifffile.h>
|
|
|
|
#include <taglib/asffile.h>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <taglib/fileref.h>
|
|
|
|
#include <taglib/flacfile.h>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <taglib/id3v2tag.h>
|
2010-03-07 23:46:41 +01:00
|
|
|
#include <taglib/mp4file.h>
|
|
|
|
#include <taglib/mpcfile.h>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <taglib/mpegfile.h>
|
|
|
|
#include <taglib/oggfile.h>
|
|
|
|
#include <taglib/oggflacfile.h>
|
2010-03-07 23:46:41 +01:00
|
|
|
#include <taglib/speexfile.h>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <taglib/tag.h>
|
2010-03-29 15:15:47 +02:00
|
|
|
#include <taglib/textidentificationframe.h>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <taglib/trueaudiofile.h>
|
|
|
|
#include <taglib/tstring.h>
|
|
|
|
#include <taglib/vorbisfile.h>
|
|
|
|
#include <taglib/wavfile.h>
|
2010-03-29 15:15:47 +02:00
|
|
|
#include <taglib/xiphcomment.h>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "radio/fixlastfm.h"
|
2009-12-26 23:15:57 +01:00
|
|
|
#include <lastfm/Track>
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QSqlQuery>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <QtConcurrentRun>
|
2010-05-10 15:46:06 +02:00
|
|
|
#include <QTextCodec>
|
2010-08-03 21:29:49 +02:00
|
|
|
#include <QTime>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QVariant>
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
using boost::scoped_ptr;
|
|
|
|
|
2010-03-03 15:29:53 +01:00
|
|
|
#include "albumcoverloader.h"
|
2010-08-03 21:29:49 +02:00
|
|
|
#include "encoding.h"
|
|
|
|
#include "utilities.h"
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "engines/enginebase.h"
|
2010-08-03 20:57:17 +02:00
|
|
|
#include "library/sqlrow.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "widgets/trackslider.h"
|
2010-01-15 22:57:22 +01:00
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
static QStringList Prepend(const QString& text, const QStringList& list) {
|
|
|
|
QStringList ret(list);
|
|
|
|
for (int i=0 ; i<ret.count() ; ++i)
|
|
|
|
ret[i].prepend(text);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QStringList Updateify(const QStringList& list) {
|
|
|
|
QStringList ret(list);
|
|
|
|
for (int i=0 ; i<ret.count() ; ++i)
|
|
|
|
ret[i].prepend(ret[i] + " = :");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList Song::kColumns = QStringList()
|
|
|
|
<< "title" << "album" << "artist" << "albumartist" << "composer" << "track"
|
|
|
|
<< "disc" << "bpm" << "year" << "genre" << "comment" << "compilation"
|
|
|
|
<< "length" << "bitrate" << "samplerate" << "directory" << "filename"
|
|
|
|
<< "mtime" << "ctime" << "filesize" << "sampler" << "art_automatic"
|
|
|
|
<< "art_manual" << "filetype" << "playcount" << "lastplayed" << "rating"
|
|
|
|
<< "forced_compilation_on" << "forced_compilation_off"
|
|
|
|
<< "effective_compilation";
|
|
|
|
|
|
|
|
const QString Song::kColumnSpec = Song::kColumns.join(", ");
|
|
|
|
const QString Song::kBindSpec = Prepend(":", Song::kColumns).join(", ");
|
|
|
|
const QString Song::kUpdateSpec = Updateify(Song::kColumns).join(", ");
|
|
|
|
|
2010-06-20 18:30:10 +02:00
|
|
|
|
|
|
|
const QStringList Song::kFtsColumns = QStringList()
|
|
|
|
<< "ftstitle" << "ftsalbum" << "ftsartist" << "ftsalbumartist"
|
|
|
|
<< "ftscomposer" << "ftsgenre" << "ftscomment";
|
|
|
|
|
|
|
|
const QString Song::kFtsColumnSpec = Song::kFtsColumns.join(", ");
|
|
|
|
const QString Song::kFtsBindSpec = Prepend(":", Song::kFtsColumns).join(", ");
|
|
|
|
const QString Song::kFtsUpdateSpec = Updateify(Song::kFtsColumns).join(", ");
|
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
QString Song::JoinSpec(const QString& table) {
|
|
|
|
return Prepend(table + ".", kColumns).join(", ");
|
|
|
|
}
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2010-07-31 16:14:03 +02:00
|
|
|
QString Song::TextForFiletype(FileType type) {
|
|
|
|
switch (type) {
|
|
|
|
case Song::Type_Asf: return QObject::tr("ASF");
|
|
|
|
case Song::Type_Flac: return QObject::tr("FLAC");
|
|
|
|
case Song::Type_Mp4: return QObject::tr("MP4");
|
|
|
|
case Song::Type_Mpc: return QObject::tr("MPC");
|
|
|
|
case Song::Type_Mpeg: return QObject::tr("MP3"); // Not technically correct
|
|
|
|
case Song::Type_OggFlac: return QObject::tr("Ogg FLAC");
|
|
|
|
case Song::Type_OggSpeex: return QObject::tr("Ogg Speex");
|
|
|
|
case Song::Type_OggVorbis: return QObject::tr("Ogg Vorbis");
|
|
|
|
case Song::Type_Aiff: return QObject::tr("AIFF");
|
|
|
|
case Song::Type_Wav: return QObject::tr("WAV");
|
|
|
|
case Song::Type_TrueAudio: return QObject::tr("TrueAudio");
|
|
|
|
|
|
|
|
case Song::Type_Stream: return QObject::tr("Stream");
|
|
|
|
|
|
|
|
case Song::Type_Unknown:
|
|
|
|
default:
|
|
|
|
return QObject::tr("Unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-29 15:15:47 +02:00
|
|
|
static TagLib::String QStringToTaglibString(const QString& s);
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
TagLibFileRefFactory Song::kDefaultFactory;
|
|
|
|
|
2010-08-08 14:35:23 +02:00
|
|
|
QMutex Song::taglib_mutex_;
|
|
|
|
|
2010-06-02 14:31:40 +02:00
|
|
|
|
2010-03-07 23:46:41 +01:00
|
|
|
Song::Private::Private()
|
2009-12-24 20:16:07 +01:00
|
|
|
: valid_(false),
|
|
|
|
id_(-1),
|
|
|
|
track_(-1),
|
|
|
|
disc_(-1),
|
|
|
|
bpm_(-1),
|
|
|
|
year_(-1),
|
|
|
|
compilation_(false),
|
2010-02-27 21:12:22 +01:00
|
|
|
sampler_(false),
|
2010-03-21 00:59:39 +01:00
|
|
|
forced_compilation_on_(false),
|
|
|
|
forced_compilation_off_(false),
|
2009-12-24 20:16:07 +01:00
|
|
|
length_(-1),
|
|
|
|
bitrate_(-1),
|
|
|
|
samplerate_(-1),
|
|
|
|
directory_id_(-1),
|
|
|
|
mtime_(-1),
|
|
|
|
ctime_(-1),
|
2010-03-07 23:46:41 +01:00
|
|
|
filesize_(-1),
|
|
|
|
filetype_(Type_Unknown)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
TagLib::FileRef* TagLibFileRefFactory::GetFileRef(const QString& filename) {
|
|
|
|
return new TagLib::FileRef(QFile::encodeName(filename).constData());
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:57:22 +01:00
|
|
|
Song::Song()
|
2010-03-07 23:46:41 +01:00
|
|
|
: d(new Private),
|
2010-03-06 21:08:01 +01:00
|
|
|
factory_(&kDefaultFactory)
|
2010-01-15 22:57:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Song::Song(const Song &other)
|
2010-03-06 21:08:01 +01:00
|
|
|
: d(other.d),
|
|
|
|
factory_(&kDefaultFactory)
|
2010-01-15 22:57:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
Song::Song(FileRefFactory* factory)
|
2010-03-07 23:46:41 +01:00
|
|
|
: d(new Private),
|
2010-03-06 21:08:01 +01:00
|
|
|
factory_(factory) {
|
|
|
|
}
|
|
|
|
|
2010-03-09 18:17:32 +01:00
|
|
|
void Song::Init(const QString& title, const QString& artist, const QString& album, int length) {
|
2010-03-07 16:26:54 +01:00
|
|
|
d->valid_ = true;
|
|
|
|
d->title_ = title;
|
|
|
|
d->artist_ = artist;
|
2010-03-09 18:17:32 +01:00
|
|
|
d->album_ = album;
|
2010-03-07 16:26:54 +01:00
|
|
|
d->length_ = length;
|
|
|
|
}
|
|
|
|
|
2010-06-03 17:16:15 +02:00
|
|
|
QString Song::Decode(const TagLib::String& tag, const QTextCodec* codec) {
|
2010-06-03 17:22:30 +02:00
|
|
|
if (codec && tag.isLatin1()) { // Never override UTF-8.
|
2010-06-03 14:36:43 +02:00
|
|
|
const std::string fixed = QString::fromUtf8(tag.toCString(true)).toStdString();
|
|
|
|
return codec->toUnicode(fixed.c_str()).trimmed();
|
|
|
|
} else {
|
|
|
|
return TStringToQString(tag).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void Song::InitFromFile(const QString& filename, int directory_id) {
|
2010-08-03 15:37:47 +02:00
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
|
|
|
if (qApp->thread() == QThread::currentThread())
|
|
|
|
qWarning() << Q_FUNC_INFO << "on GUI thread!";
|
|
|
|
#endif
|
2010-01-15 22:57:22 +01:00
|
|
|
d->filename_ = filename;
|
|
|
|
d->directory_id_ = directory_id;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-08-08 14:35:23 +02:00
|
|
|
QMutexLocker l(&taglib_mutex_);
|
2010-03-06 21:08:01 +01:00
|
|
|
scoped_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(filename));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
if(fileref->isNull())
|
2009-12-24 20:16:07 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
QFileInfo info(filename);
|
2010-03-19 11:39:22 +01:00
|
|
|
d->basefilename_ = info.fileName();
|
2010-01-15 22:57:22 +01:00
|
|
|
d->filesize_ = info.size();
|
|
|
|
d->mtime_ = info.lastModified().toTime_t();
|
|
|
|
d->ctime_ = info.created().toTime_t();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-06-03 14:36:43 +02:00
|
|
|
// This is single byte encoding, therefore can't be CJK.
|
|
|
|
UniversalEncodingHandler detector(NS_FILTER_NON_CJK);
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
TagLib::Tag* tag = fileref->tag();
|
2010-06-03 14:36:43 +02:00
|
|
|
QTextCodec* codec = NULL;
|
2009-12-24 20:16:07 +01:00
|
|
|
if (tag) {
|
2010-06-03 15:26:46 +02:00
|
|
|
codec = detector.Guess(*fileref);
|
2010-06-03 14:36:43 +02:00
|
|
|
d->title_ = Decode(tag->title(), codec);
|
|
|
|
d->artist_ = Decode(tag->artist(), codec);
|
|
|
|
d->album_ = Decode(tag->album(), codec);
|
|
|
|
d->comment_ = Decode(tag->comment(), codec);
|
|
|
|
d->genre_ = Decode(tag->genre(), codec);
|
2010-01-15 22:57:22 +01:00
|
|
|
d->year_ = tag->year();
|
|
|
|
d->track_ = tag->track();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-01-15 22:57:22 +01:00
|
|
|
d->valid_ = true;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString disc;
|
|
|
|
QString compilation;
|
2010-03-06 21:08:01 +01:00
|
|
|
if (TagLib::MPEG::File* file = dynamic_cast<TagLib::MPEG::File*>(fileref->file())) {
|
2009-12-24 20:16:07 +01:00
|
|
|
if (file->ID3v2Tag()) {
|
|
|
|
if (!file->ID3v2Tag()->frameListMap()["TPOS"].isEmpty())
|
|
|
|
disc = TStringToQString(file->ID3v2Tag()->frameListMap()["TPOS"].front()->toString()).trimmed();
|
|
|
|
|
|
|
|
if (!file->ID3v2Tag()->frameListMap()["TBPM"].isEmpty())
|
2010-01-15 22:57:22 +01:00
|
|
|
d->bpm_ = TStringToQString(file->ID3v2Tag()->frameListMap()["TBPM"].front()->toString()).trimmed().toFloat();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (!file->ID3v2Tag()->frameListMap()["TCOM"].isEmpty())
|
2010-06-03 14:36:43 +02:00
|
|
|
d->composer_ = Decode(file->ID3v2Tag()->frameListMap()["TCOM"].front()->toString(), codec);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (!file->ID3v2Tag()->frameListMap()["TPE2"].isEmpty()) // non-standard: Apple, Microsoft
|
2010-06-03 14:36:43 +02:00
|
|
|
d->albumartist_ = Decode(file->ID3v2Tag()->frameListMap()["TPE2"].front()->toString(), codec);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (!file->ID3v2Tag()->frameListMap()["TCMP"].isEmpty())
|
|
|
|
compilation = TStringToQString(file->ID3v2Tag()->frameListMap()["TCMP"].front()->toString()).trimmed();
|
2010-07-19 13:40:30 +02:00
|
|
|
|
2010-07-19 19:55:02 +02:00
|
|
|
if (!file->ID3v2Tag()->frameListMap()["APIC"].isEmpty())
|
|
|
|
d->art_automatic_ = AlbumCoverLoader::kEmbeddedCover;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-06 21:08:01 +01:00
|
|
|
else if (TagLib::Ogg::Vorbis::File* file = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref->file())) {
|
2009-12-24 20:16:07 +01:00
|
|
|
if (file->tag()) {
|
|
|
|
if ( !file->tag()->fieldListMap()["COMPOSER"].isEmpty() )
|
2010-06-03 14:36:43 +02:00
|
|
|
d->composer_ = Decode(file->tag()->fieldListMap()["COMPOSER"].front(), codec);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-07-24 16:49:49 +02:00
|
|
|
if ( !file->tag()->fieldListMap()["ALBUMARTIST"].isEmpty() )
|
|
|
|
d->albumartist_ = Decode(file->tag()->fieldListMap()["ALBUMARTIST"].front(), codec);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
if ( !file->tag()->fieldListMap()["BPM"].isEmpty() )
|
2010-01-15 22:57:22 +01:00
|
|
|
d->bpm_ = TStringToQString(file->tag()->fieldListMap()["BPM"].front()).trimmed().toFloat();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if ( !file->tag()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
|
|
|
disc = TStringToQString(file->tag()->fieldListMap()["DISCNUMBER"].front()).trimmed();
|
|
|
|
|
|
|
|
if ( !file->tag()->fieldListMap()["COMPILATION"].isEmpty() )
|
|
|
|
compilation = TStringToQString(file->tag()->fieldListMap()["COMPILATION"].front()).trimmed();
|
|
|
|
}
|
|
|
|
}
|
2010-03-06 21:08:01 +01:00
|
|
|
else if (TagLib::FLAC::File* file = dynamic_cast<TagLib::FLAC::File*>(fileref->file())) {
|
2009-12-24 20:16:07 +01:00
|
|
|
if ( file->xiphComment() ) {
|
|
|
|
if (!file->xiphComment()->fieldListMap()["COMPOSER"].isEmpty())
|
2010-06-03 14:36:43 +02:00
|
|
|
d->composer_ = Decode(file->xiphComment()->fieldListMap()["COMPOSER"].front(), codec);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-07-24 16:49:49 +02:00
|
|
|
if (!file->xiphComment()->fieldListMap()["ALBUMARTIST"].isEmpty())
|
|
|
|
d->albumartist_ = Decode(file->xiphComment()->fieldListMap()["ALBUMARTIST"].front(), codec);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
if (!file->xiphComment()->fieldListMap()["BPM"].isEmpty() )
|
2010-01-15 22:57:22 +01:00
|
|
|
d->bpm_ = TStringToQString( file->xiphComment()->fieldListMap()["BPM"].front() ).trimmed().toFloat();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (!file->xiphComment()->fieldListMap()["DISCNUMBER"].isEmpty() )
|
|
|
|
disc = TStringToQString( file->xiphComment()->fieldListMap()["DISCNUMBER"].front() ).trimmed();
|
|
|
|
|
|
|
|
if (!file->xiphComment()->fieldListMap()["COMPILATION"].isEmpty() )
|
|
|
|
compilation = TStringToQString( file->xiphComment()->fieldListMap()["COMPILATION"].front() ).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !disc.isEmpty() ) {
|
|
|
|
int i = disc.indexOf('/');
|
|
|
|
if ( i != -1 )
|
|
|
|
// disc.right( i ).toInt() is total number of discs, we don't use this at the moment
|
2010-01-15 22:57:22 +01:00
|
|
|
d->disc_ = disc.left( i ).toInt();
|
2009-12-24 20:16:07 +01:00
|
|
|
else
|
2010-01-15 22:57:22 +01:00
|
|
|
d->disc_ = disc.toInt();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( compilation.isEmpty() ) {
|
|
|
|
// well, it wasn't set, but if the artist is VA assume it's a compilation
|
2010-01-15 22:57:22 +01:00
|
|
|
if ( d->artist_.toLower() == "various artists" )
|
|
|
|
d->compilation_ = true;
|
2009-12-24 20:16:07 +01:00
|
|
|
} else {
|
|
|
|
int i = compilation.toInt();
|
2010-01-15 22:57:22 +01:00
|
|
|
d->compilation_ = (i == 1);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
if (fileref->audioProperties()) {
|
|
|
|
d->bitrate_ = fileref->audioProperties()->bitrate();
|
|
|
|
d->length_ = fileref->audioProperties()->length();
|
|
|
|
d->samplerate_ = fileref->audioProperties()->sampleRate();
|
2010-01-17 20:03:54 +01:00
|
|
|
}
|
2010-03-07 23:46:41 +01:00
|
|
|
|
|
|
|
// Get the filetype if we can
|
|
|
|
GuessFileType(fileref.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Song::GuessFileType(TagLib::FileRef* fileref) {
|
2010-03-16 16:09:08 +01:00
|
|
|
#ifdef TAGLIB_WITH_ASF
|
2010-03-07 23:46:41 +01:00
|
|
|
if (dynamic_cast<TagLib::ASF::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Asf;
|
2010-03-16 16:09:08 +01:00
|
|
|
#endif
|
2010-03-07 23:46:41 +01:00
|
|
|
if (dynamic_cast<TagLib::FLAC::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Flac;
|
2010-03-16 16:09:08 +01:00
|
|
|
#ifdef TAGLIB_WITH_MP4
|
2010-03-07 23:46:41 +01:00
|
|
|
if (dynamic_cast<TagLib::MP4::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Mp4;
|
2010-03-16 16:09:08 +01:00
|
|
|
#endif
|
2010-03-07 23:46:41 +01:00
|
|
|
if (dynamic_cast<TagLib::MPC::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Mpc;
|
|
|
|
if (dynamic_cast<TagLib::MPEG::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Mpeg;
|
|
|
|
if (dynamic_cast<TagLib::Ogg::FLAC::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_OggFlac;
|
|
|
|
if (dynamic_cast<TagLib::Ogg::Speex::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_OggSpeex;
|
|
|
|
if (dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_OggVorbis;
|
|
|
|
if (dynamic_cast<TagLib::RIFF::AIFF::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Aiff;
|
|
|
|
if (dynamic_cast<TagLib::RIFF::WAV::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_Wav;
|
|
|
|
if (dynamic_cast<TagLib::TrueAudio::File*>(fileref->file()))
|
|
|
|
d->filetype_ = Type_TrueAudio;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-08-03 20:57:17 +02:00
|
|
|
void Song::InitFromQuery(const SqlRow& q, int col) {
|
2010-08-03 15:37:47 +02:00
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
|
|
|
if (qApp->thread() == QThread::currentThread())
|
|
|
|
qWarning() << Q_FUNC_INFO << "on GUI thread!";
|
|
|
|
#endif
|
2010-03-03 19:38:20 +01:00
|
|
|
|
2010-01-15 22:57:22 +01:00
|
|
|
d->valid_ = true;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#define tostr(n) (q.value(n).isNull() ? QString::null : q.value(n).toString())
|
|
|
|
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
|
|
|
|
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
|
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
d->id_ = toint(col + 0);
|
|
|
|
d->title_ = tostr(col + 1);
|
|
|
|
d->album_ = tostr(col + 2);
|
|
|
|
d->artist_ = tostr(col + 3);
|
|
|
|
d->albumartist_ = tostr(col + 4);
|
|
|
|
d->composer_ = tostr(col + 5);
|
|
|
|
d->track_ = toint(col + 6);
|
|
|
|
d->disc_ = toint(col + 7);
|
|
|
|
d->bpm_ = tofloat(col + 8);
|
|
|
|
d->year_ = toint(col + 9);
|
|
|
|
d->genre_ = tostr(col + 10);
|
|
|
|
d->comment_ = tostr(col + 11);
|
|
|
|
d->compilation_ = q.value(col + 12).toBool();
|
|
|
|
|
|
|
|
d->length_ = toint(col + 13);
|
|
|
|
d->bitrate_ = toint(col + 14);
|
|
|
|
d->samplerate_ = toint(col + 15);
|
|
|
|
|
|
|
|
d->directory_id_ = toint(col + 16);
|
|
|
|
d->filename_ = tostr(col + 17);
|
2010-03-19 11:39:22 +01:00
|
|
|
d->basefilename_ = QFileInfo(d->filename_).fileName();
|
2010-05-10 16:19:43 +02:00
|
|
|
d->mtime_ = toint(col + 18);
|
|
|
|
d->ctime_ = toint(col + 19);
|
|
|
|
d->filesize_ = toint(col + 20);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
d->sampler_ = q.value(col + 21).toBool();
|
2010-02-27 21:12:22 +01:00
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
d->art_automatic_ = q.value(col + 22).toString();
|
|
|
|
d->art_manual_ = q.value(col + 23).toString();
|
2010-02-28 01:35:20 +01:00
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
d->filetype_ = FileType(q.value(col + 24).toInt());
|
2010-03-07 23:46:41 +01:00
|
|
|
// playcount = 25
|
|
|
|
// lastplayed = 26
|
|
|
|
// rating = 27
|
|
|
|
|
2010-05-10 16:19:43 +02:00
|
|
|
d->forced_compilation_on_ = q.value(col + 28).toBool();
|
|
|
|
d->forced_compilation_off_ = q.value(col + 29).toBool();
|
2010-03-21 00:59:39 +01:00
|
|
|
|
2010-03-21 22:17:01 +01:00
|
|
|
// effective_compilation = 30
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#undef tostr
|
|
|
|
#undef toint
|
|
|
|
#undef tofloat
|
|
|
|
}
|
|
|
|
|
2009-12-26 23:15:57 +01:00
|
|
|
void Song::InitFromLastFM(const lastfm::Track& track) {
|
2010-01-15 22:57:22 +01:00
|
|
|
d->valid_ = true;
|
2010-03-07 23:46:41 +01:00
|
|
|
d->filetype_ = Type_Stream;
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2010-01-15 22:57:22 +01:00
|
|
|
d->title_ = track.title();
|
|
|
|
d->album_ = track.album();
|
|
|
|
d->artist_ = track.artist();
|
|
|
|
d->track_ = track.trackNumber();
|
|
|
|
d->length_ = track.duration();
|
2009-12-26 23:15:57 +01:00
|
|
|
}
|
|
|
|
|
2010-07-04 22:52:45 +02:00
|
|
|
#ifdef HAVE_LIBGPOD
|
2010-08-08 19:41:06 +02:00
|
|
|
void Song::InitFromItdb(const Itdb_Track* track) {
|
2010-07-04 22:52:45 +02:00
|
|
|
d->valid_ = true;
|
|
|
|
|
|
|
|
d->title_ = QString::fromUtf8(track->title);
|
|
|
|
d->album_ = QString::fromUtf8(track->album);
|
|
|
|
d->artist_ = QString::fromUtf8(track->artist);
|
|
|
|
d->albumartist_ = QString::fromUtf8(track->albumartist);
|
|
|
|
d->composer_ = QString::fromUtf8(track->composer);
|
|
|
|
d->track_ = track->track_nr;
|
|
|
|
d->disc_ = track->cd_nr;
|
|
|
|
d->bpm_ = track->BPM;
|
|
|
|
d->year_ = track->year;
|
|
|
|
d->genre_ = QString::fromUtf8(track->genre);
|
|
|
|
d->comment_ = QString::fromUtf8(track->comment);
|
|
|
|
d->compilation_ = track->compilation;
|
|
|
|
d->length_ = track->tracklen / 1000;
|
|
|
|
d->bitrate_ = track->bitrate;
|
|
|
|
d->samplerate_ = track->samplerate;
|
|
|
|
d->mtime_ = track->time_modified;
|
|
|
|
d->ctime_ = track->time_added;
|
|
|
|
d->filesize_ = track->size;
|
|
|
|
d->filetype_ = track->type2 ? Type_Mpeg : Type_Mp4;
|
|
|
|
|
|
|
|
d->filename_ = QString::fromLocal8Bit(track->ipod_path);
|
2010-08-08 19:41:06 +02:00
|
|
|
d->filename_.replace(':', '/');
|
2010-07-04 22:52:45 +02:00
|
|
|
d->basefilename_ = QFileInfo(d->filename_).fileName();
|
|
|
|
}
|
2010-07-24 18:58:14 +02:00
|
|
|
|
|
|
|
void Song::ToItdb(Itdb_Track *track) const {
|
2010-08-08 19:45:57 +02:00
|
|
|
track->title = strdup(d->title_.toUtf8().constData());
|
|
|
|
track->album = strdup(d->album_.toUtf8().constData());
|
|
|
|
track->artist = strdup(d->artist_.toUtf8().constData());
|
|
|
|
track->albumartist = strdup(d->albumartist_.toUtf8().constData());
|
|
|
|
track->composer = strdup(d->composer_.toUtf8().constData());
|
2010-07-24 18:58:14 +02:00
|
|
|
track->track_nr = d->track_;
|
|
|
|
track->cd_nr = d->disc_;
|
|
|
|
track->BPM = d->bpm_;
|
|
|
|
track->year = d->year_;
|
2010-08-08 19:45:57 +02:00
|
|
|
track->genre = strdup(d->genre_.toUtf8().constData());
|
|
|
|
track->comment = strdup(d->comment_.toUtf8().constData());
|
2010-07-24 18:58:14 +02:00
|
|
|
track->compilation = d->compilation_;
|
|
|
|
track->tracklen = d->length_ * 1000;
|
|
|
|
track->bitrate = d->bitrate_;
|
|
|
|
track->samplerate = d->samplerate_;
|
|
|
|
track->time_modified = d->mtime_;
|
|
|
|
track->time_added = d->ctime_;
|
|
|
|
track->size = d->filesize_;
|
2010-08-08 19:41:06 +02:00
|
|
|
track->type1 = 0;
|
2010-07-24 18:58:14 +02:00
|
|
|
track->type2 = d->filetype_ == Type_Mp4 ? 0 : 1;
|
2010-08-08 19:41:06 +02:00
|
|
|
track->mediatype = 1; // Audio
|
2010-07-24 18:58:14 +02:00
|
|
|
}
|
2010-07-04 22:52:45 +02:00
|
|
|
#endif
|
|
|
|
|
2010-04-21 16:04:40 +02:00
|
|
|
void Song::MergeFromSimpleMetaBundle(const Engine::SimpleMetaBundle &bundle) {
|
2010-02-03 23:20:31 +01:00
|
|
|
d->valid_ = true;
|
|
|
|
|
2010-04-21 16:04:40 +02:00
|
|
|
if (!bundle.title.isEmpty()) d->title_ = bundle.title;
|
|
|
|
if (!bundle.artist.isEmpty()) d->artist_ = bundle.artist;
|
|
|
|
if (!bundle.album.isEmpty()) d->album_ = bundle.album;
|
|
|
|
if (!bundle.comment.isEmpty()) d->comment_ = bundle.comment;
|
|
|
|
if (!bundle.genre.isEmpty()) d->genre_ = bundle.genre;
|
|
|
|
if (!bundle.bitrate.isEmpty()) d->bitrate_ = bundle.bitrate.toInt();
|
|
|
|
if (!bundle.samplerate.isEmpty()) d->samplerate_ = bundle.samplerate.toInt();
|
|
|
|
if (!bundle.length.isEmpty()) d->length_ = bundle.length.toInt();
|
|
|
|
if (!bundle.year.isEmpty()) d->year_ = bundle.year.toInt();
|
|
|
|
if (!bundle.tracknr.isEmpty()) d->track_ = bundle.tracknr.toInt();
|
2010-02-03 23:20:31 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void Song::BindToQuery(QSqlQuery *query) const {
|
2010-07-24 17:13:09 +02:00
|
|
|
#define strval(x) (x.isNull() ? "" : x)
|
|
|
|
#define intval(x) (x <= 0 ? -1 : x)
|
2010-06-18 02:11:15 +02:00
|
|
|
#define notnullintval(x) (x == -1 ? QVariant() : x)
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-28 01:35:20 +01:00
|
|
|
// Remember to bind these in the same order as kBindSpec
|
|
|
|
|
2010-07-24 17:13:09 +02:00
|
|
|
query->bindValue(":title", strval(d->title_));
|
|
|
|
query->bindValue(":album", strval(d->album_));
|
|
|
|
query->bindValue(":artist", strval(d->artist_));
|
|
|
|
query->bindValue(":albumartist", strval(d->albumartist_));
|
|
|
|
query->bindValue(":composer", strval(d->composer_));
|
2010-01-15 22:57:22 +01:00
|
|
|
query->bindValue(":track", intval(d->track_));
|
|
|
|
query->bindValue(":disc", intval(d->disc_));
|
|
|
|
query->bindValue(":bpm", intval(d->bpm_));
|
|
|
|
query->bindValue(":year", intval(d->year_));
|
2010-07-24 17:13:09 +02:00
|
|
|
query->bindValue(":genre", strval(d->genre_));
|
|
|
|
query->bindValue(":comment", strval(d->comment_));
|
2010-01-15 22:57:22 +01:00
|
|
|
query->bindValue(":compilation", d->compilation_ ? 1 : 0);
|
|
|
|
|
|
|
|
query->bindValue(":length", intval(d->length_));
|
|
|
|
query->bindValue(":bitrate", intval(d->bitrate_));
|
|
|
|
query->bindValue(":samplerate", intval(d->samplerate_));
|
|
|
|
|
2010-06-18 02:11:15 +02:00
|
|
|
query->bindValue(":directory_id", notnullintval(d->directory_id_));
|
2010-01-15 22:57:22 +01:00
|
|
|
query->bindValue(":filename", d->filename_);
|
2010-06-18 02:11:15 +02:00
|
|
|
query->bindValue(":mtime", notnullintval(d->mtime_));
|
|
|
|
query->bindValue(":ctime", notnullintval(d->ctime_));
|
|
|
|
query->bindValue(":filesize", notnullintval(d->filesize_));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-27 21:12:22 +01:00
|
|
|
query->bindValue(":sampler", d->sampler_ ? 1 : 0);
|
2010-02-28 01:35:20 +01:00
|
|
|
query->bindValue(":art_automatic", d->art_automatic_);
|
|
|
|
query->bindValue(":art_manual", d->art_manual_);
|
2010-02-27 21:12:22 +01:00
|
|
|
|
2010-03-07 23:46:41 +01:00
|
|
|
query->bindValue(":filetype", d->filetype_);
|
|
|
|
query->bindValue(":playcount", 0); // TODO
|
|
|
|
query->bindValue(":lastplayed", -1); // TODO
|
|
|
|
query->bindValue(":rating", -1);
|
|
|
|
|
2010-03-21 14:50:00 +01:00
|
|
|
query->bindValue(":forced_compilation_on", d->forced_compilation_on_ ? 1 : 0);
|
|
|
|
query->bindValue(":forced_compilation_off", d->forced_compilation_off_ ? 1 : 0);
|
2010-03-21 00:59:39 +01:00
|
|
|
|
2010-03-21 22:17:01 +01:00
|
|
|
query->bindValue(":effective_compilation", is_compilation() ? 1 : 0);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#undef intval
|
2010-06-18 02:11:15 +02:00
|
|
|
#undef notnullintval
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-06-20 18:30:10 +02:00
|
|
|
void Song::BindToFtsQuery(QSqlQuery *query) const {
|
|
|
|
query->bindValue(":ftstitle", d->title_);
|
|
|
|
query->bindValue(":ftsalbum", d->album_);
|
|
|
|
query->bindValue(":ftsartist", d->artist_);
|
|
|
|
query->bindValue(":ftsalbumartist", d->albumartist_);
|
|
|
|
query->bindValue(":ftscomposer", d->composer_);
|
|
|
|
query->bindValue(":ftsgenre", d->genre_);
|
|
|
|
query->bindValue(":ftscomment", d->comment_);
|
|
|
|
}
|
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
void Song::ToLastFM(lastfm::Track* track) const {
|
|
|
|
lastfm::MutableTrack mtrack(*track);
|
|
|
|
|
2010-01-15 22:57:22 +01:00
|
|
|
mtrack.setArtist(d->artist_);
|
|
|
|
mtrack.setAlbum(d->album_);
|
|
|
|
mtrack.setTitle(d->title_);
|
|
|
|
mtrack.setDuration(d->length_);
|
|
|
|
mtrack.setTrackNumber(d->track_);
|
2010-02-22 22:26:49 +01:00
|
|
|
mtrack.setSource(lastfm::Track::Player);
|
2009-12-29 20:22:02 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
QString Song::PrettyTitleWithArtist() const {
|
2010-01-15 22:57:22 +01:00
|
|
|
QString title(d->title_);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (title.isEmpty())
|
2010-01-15 22:57:22 +01:00
|
|
|
title = QFileInfo(d->filename_).baseName();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-24 20:05:49 +01:00
|
|
|
if (is_compilation() && !d->artist_.isEmpty() && !d->artist_.toLower().contains("various"))
|
2010-01-15 22:57:22 +01:00
|
|
|
title = d->artist_ + " - " + title;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Song::PrettyTitle() const {
|
2010-01-15 22:57:22 +01:00
|
|
|
QString title(d->title_);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (title.isEmpty())
|
2010-01-15 22:57:22 +01:00
|
|
|
title = QFileInfo(d->filename_).baseName();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Song::PrettyLength() const {
|
2010-01-15 22:57:22 +01:00
|
|
|
if (d->length_ == -1)
|
2009-12-24 20:16:07 +01:00
|
|
|
return QString::null;
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
return Utilities::PrettyTime(d->length_);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Song::IsMetadataEqual(const Song& other) const {
|
2010-01-15 22:57:22 +01:00
|
|
|
return d->title_ == other.d->title_ &&
|
|
|
|
d->album_ == other.d->album_ &&
|
|
|
|
d->artist_ == other.d->artist_ &&
|
|
|
|
d->albumartist_ == other.d->albumartist_ &&
|
|
|
|
d->composer_ == other.d->composer_ &&
|
|
|
|
d->track_ == other.d->track_ &&
|
|
|
|
d->disc_ == other.d->disc_ &&
|
|
|
|
qFuzzyCompare(d->bpm_, other.d->bpm_) &&
|
|
|
|
d->year_ == other.d->year_ &&
|
|
|
|
d->genre_ == other.d->genre_ &&
|
|
|
|
d->comment_ == other.d->comment_ &&
|
|
|
|
d->compilation_ == other.d->compilation_ &&
|
|
|
|
d->length_ == other.d->length_ &&
|
|
|
|
d->bitrate_ == other.d->bitrate_ &&
|
2010-02-28 01:35:20 +01:00
|
|
|
d->samplerate_ == other.d->samplerate_ &&
|
|
|
|
d->sampler_ == other.d->sampler_ &&
|
|
|
|
d->art_automatic_ == other.d->art_automatic_ &&
|
|
|
|
d->art_manual_ == other.d->art_manual_;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
2010-03-29 15:28:29 +02:00
|
|
|
void Song::SetTextFrame(const QString& id, const QString& value,
|
|
|
|
TagLib::ID3v2::Tag* tag) {
|
2010-03-29 15:15:47 +02:00
|
|
|
TagLib::ByteVector id_vector = id.toUtf8().constData();
|
|
|
|
|
|
|
|
// Remove the frame if it already exists
|
|
|
|
while (tag->frameListMap().contains(id_vector) &&
|
|
|
|
tag->frameListMap()[id_vector].size() != 0) {
|
|
|
|
tag->removeFrame(tag->frameListMap()[id_vector].front());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and add a new frame
|
|
|
|
TagLib::ID3v2::TextIdentificationFrame* frame =
|
|
|
|
new TagLib::ID3v2::TextIdentificationFrame(id.toUtf8().constData(),
|
|
|
|
TagLib::String::UTF8);
|
|
|
|
frame->setText(QStringToTaglibString(value));
|
|
|
|
tag->addFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
TagLib::String QStringToTaglibString(const QString& s) {
|
|
|
|
return TagLib::String(s.toUtf8().constData(), TagLib::String::UTF8);
|
|
|
|
}
|
|
|
|
|
2010-06-25 01:36:39 +02:00
|
|
|
bool Song::IsEditable() const {
|
|
|
|
return d->valid_ && !d->filename_.isNull() &&
|
|
|
|
d->filetype_ != Type_Stream && d->filetype_ != Type_Unknown;
|
|
|
|
}
|
|
|
|
|
2010-01-16 17:12:47 +01:00
|
|
|
bool Song::Save() const {
|
|
|
|
if (d->filename_.isNull())
|
|
|
|
return false;
|
|
|
|
|
2010-08-08 14:35:23 +02:00
|
|
|
QMutexLocker l(&taglib_mutex_);
|
2010-03-29 15:15:47 +02:00
|
|
|
scoped_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(d->filename_));
|
2010-02-23 15:52:22 +01:00
|
|
|
|
2010-04-27 19:37:26 +02:00
|
|
|
if (!fileref || fileref->isNull()) // The file probably doesn't exist
|
|
|
|
return false;
|
|
|
|
|
2010-03-29 15:15:47 +02:00
|
|
|
fileref->tag()->setTitle(QStringToTaglibString(d->title_));
|
|
|
|
fileref->tag()->setArtist(QStringToTaglibString(d->artist_));
|
|
|
|
fileref->tag()->setAlbum(QStringToTaglibString(d->album_));
|
|
|
|
fileref->tag()->setGenre(QStringToTaglibString(d->genre_));
|
|
|
|
fileref->tag()->setComment(QStringToTaglibString(d->comment_));
|
|
|
|
fileref->tag()->setYear(d->year_);
|
|
|
|
fileref->tag()->setTrack(d->track_);
|
2010-01-16 17:12:47 +01:00
|
|
|
|
2010-03-29 15:15:47 +02:00
|
|
|
if (TagLib::MPEG::File* file = dynamic_cast<TagLib::MPEG::File*>(fileref->file())) {
|
|
|
|
TagLib::ID3v2::Tag* tag = file->ID3v2Tag(true);
|
2010-03-29 15:28:29 +02:00
|
|
|
SetTextFrame("TPOS", d->disc_ <= 0 -1 ? QString() : QString::number(d->disc_), tag);
|
|
|
|
SetTextFrame("TBPM", d->bpm_ <= 0 -1 ? QString() : QString::number(d->bpm_), tag);
|
|
|
|
SetTextFrame("TCOM", d->composer_, tag);
|
|
|
|
SetTextFrame("TPE2", d->albumartist_, tag);
|
|
|
|
SetTextFrame("TCMP", d->compilation_ ? "1" : "0", tag);
|
2010-03-29 15:15:47 +02:00
|
|
|
}
|
|
|
|
else if (TagLib::Ogg::Vorbis::File* file = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref->file())) {
|
|
|
|
TagLib::Ogg::XiphComment* tag = file->tag();
|
|
|
|
tag->addField("COMPOSER", QStringToTaglibString(d->composer_), true);
|
|
|
|
tag->addField("BPM", QStringToTaglibString(d->bpm_ <= 0 -1 ? QString() : QString::number(d->bpm_)), true);
|
|
|
|
tag->addField("DISCNUMBER", QStringToTaglibString(d->disc_ <= 0 -1 ? QString() : QString::number(d->disc_)), true);
|
|
|
|
tag->addField("COMPILATION", QStringToTaglibString(d->compilation_ ? "1" : "0"), true);
|
|
|
|
}
|
|
|
|
else if (TagLib::FLAC::File* file = dynamic_cast<TagLib::FLAC::File*>(fileref->file())) {
|
|
|
|
TagLib::Ogg::XiphComment* tag = file->xiphComment();
|
|
|
|
tag->addField("COMPOSER", QStringToTaglibString(d->composer_), true);
|
|
|
|
tag->addField("BPM", QStringToTaglibString(d->bpm_ <= 0 -1 ? QString() : QString::number(d->bpm_)), true);
|
|
|
|
tag->addField("DISCNUMBER", QStringToTaglibString(d->disc_ <= 0 -1 ? QString() : QString::number(d->disc_)), true);
|
|
|
|
tag->addField("COMPILATION", QStringToTaglibString(d->compilation_ ? "1" : "0"), true);
|
|
|
|
}
|
2010-02-23 15:52:22 +01:00
|
|
|
|
2010-03-29 15:15:47 +02:00
|
|
|
bool ret = fileref->save();
|
2010-02-10 14:15:18 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
2010-01-16 18:17:00 +01:00
|
|
|
if (ret) {
|
|
|
|
// Linux: inotify doesn't seem to notice the change to the file unless we
|
|
|
|
// change the timestamps as well. (this is what touch does)
|
|
|
|
utimensat(0, QFile::encodeName(d->filename_).constData(), NULL, 0);
|
|
|
|
}
|
2010-02-10 14:15:18 +01:00
|
|
|
#endif // Q_OS_LINUX
|
2010-01-16 18:17:00 +01:00
|
|
|
|
|
|
|
return ret;
|
2010-01-16 17:12:47 +01:00
|
|
|
}
|
2010-08-02 16:00:43 +02:00
|
|
|
|
|
|
|
bool Song::Save(const Song& song) {
|
|
|
|
return song.Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
QFuture<bool> Song::BackgroundSave() const {
|
|
|
|
QFuture<bool> future = QtConcurrent::run(&Song::Save, Song(*this));
|
|
|
|
return future;
|
|
|
|
}
|