16#include "config-musicbrainz.h"
17#ifdef HAVE_MUSICBRAINZ5
18#include "musicbrainz/musicbrainzlookup.h"
28 Cache::lookup(
const TrackOffsetList &offsetList,
const Config& c )
30 QString cddbId = CDDB::trackOffsetListToId(offsetList);
32 qCDebug(LIBKCDDB) <<
"Looking up " << cddbId <<
" in CDDB cache";
36 infoList << CDDB::cacheFiles(offsetList, c);
37#ifdef HAVE_MUSICBRAINZ5
38 infoList << MusicBrainzLookup::cacheFiles(offsetList, c);
45 Cache::store(
const TrackOffsetList& offsetList,
const CDInfoList& list,
const Config& c)
47 for (
const CDInfo &info : list) {
48 store(offsetList, info, c);
53 Cache::store(
const TrackOffsetList& offsetList,
const CDInfo& info,
const Config& c)
55 QString discid = info.get(QLatin1String(
"discid" )).toString();
60 const QStringList discids = discid.
split(QLatin1Char(
',' ));
61 if (discids.
count() > 2)
63 for (
const QString &newid : discids) {
64 CDInfo newInfo = info;
65 newInfo.set(QLatin1String(
"discid" ), newid);
66 store(offsetList, newInfo, c);
70 QString source = info.get(QLatin1String(
"source" )).toString();
75 CDInfo newInfo = info;
77 if (source == QLatin1String(
"freedb" ))
79 cacheDir = QLatin1Char(
'/' ) + info.get(QLatin1String(
"category" )).toString() + QLatin1Char(
'/' );
82 else if (source == QLatin1String(
"musicbrainz" ))
84 cacheDir = QLatin1String(
"/musicbrainz/" );
89 if (source != QLatin1String(
"user" ))
90 qCWarning(LIBKCDDB) <<
"Unknown source " << source <<
" for CDInfo";
92 cacheDir = QLatin1String(
"/user/" );
93 QString
id = CDDB::trackOffsetListToId(offsetList);
95 newInfo.set(QLatin1String(
"discid" ),
id);
98 const QStringList cacheLocations = c.cacheLocations();
100 if (!cacheLocations.
isEmpty()) {
101 cacheDir = cacheLocations.
first() + cacheDir;
105 if (!
dir.exists(cacheDir))
107 if (!
dir.mkpath(cacheDir))
109 qCWarning(LIBKCDDB) <<
"Couldn't create cache directory " << cacheDir;
114 qCDebug(LIBKCDDB) <<
"Storing " << cacheFile <<
" in CDDB cache";
116 QFile f(cacheDir + QLatin1Char(
'/' ) + cacheFile);
120#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
121 ts.setCodec(
"UTF-8");
123 ts << newInfo.toString();
127 qDebug() <<
"There's no cache dir defined, not storing it";
KIOCORE_EXPORT QString dir(const QString &fileClass)
qsizetype count() const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const