From 3e5225e69069364bd63e319386343051db6391b2 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Sat, 11 May 2013 19:57:18 +0100 Subject: [PATCH] MythMusic: fix a mix up with the genre handling in the freedb cd lookup There's a slight difference between the output from freedb and the MusicBrainz freedb gataway when doing a read operation which was causing the genre to get mangled. This also changes things so both the genre from the query and the read are saved and we use the first non generic one we find which for MB will always be from the query since MB doesn't support genre's so always gives us 'Unknown' in the read :( --- mythplugins/mythmusic/mythmusic/cddb.cpp | 23 ++++++++++--------- mythplugins/mythmusic/mythmusic/cddb.h | 13 ++++++----- mythplugins/mythmusic/mythmusic/cddecoder.cpp | 15 ++++++++---- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/mythplugins/mythmusic/mythmusic/cddb.cpp b/mythplugins/mythmusic/mythmusic/cddb.cpp index 63cabd55e2b..d86906a28b5 100644 --- a/mythplugins/mythmusic/mythmusic/cddb.cpp +++ b/mythplugins/mythmusic/mythmusic/cddb.cpp @@ -238,7 +238,7 @@ bool Cddb::Read(Album& album, const QString& genre, discid_t discID) } album = cddb; - album.genre = cddb.section(' ', 0, 0); + album.discGenre = genre; album.discID = discID; // Success - add to cache @@ -302,10 +302,11 @@ void Cddb::Alias(const Album& album, discid_t discID) */ Cddb::Album& Cddb::Album::operator =(const QString& rhs) { - genre.clear(); + discGenre.clear(); discID = 0; artist.clear(); title.clear(); + genre.clear(); year = 0; submitter = "MythTV " MYTH_BINARY_VERSION; rev = 1; @@ -462,7 +463,7 @@ Cddb::Album::operator QString() const ret += "DISCID=" + QString::number(discID,16) + '\n'; ret += "DTITLE=" + artist.toUtf8() + " / " + title + '\n'; ret += "DYEAR=" + (year ? QString::number(year) : "")+ '\n'; - ret += "DGENRE=" + genre.toLower().toUtf8() + '\n'; + ret += "DGENRE=" + genre.toUtf8() + '\n'; for (int t = 0; t < tracks.size(); ++t) ret += "TTITLE" + QString::number(t) + "=" + tracks[t].title.toUtf8() + '\n'; @@ -501,7 +502,7 @@ bool Dbase::Search(Cddb::Matches& res, const Cddb::discid_t discID) if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { Cddb::Album a = QTextStream(&file).readAll(); - a.genre = genre; + a.discGenre = genre; a.discID = discID; LOG(VB_MEDIA, LOG_INFO, QString("LocalCDDB found %1 in "). arg(discID,0,16) + genre + " : " + @@ -522,12 +523,12 @@ bool Dbase::Search(Cddb::Album& a, const QString& genre, const Cddb::discid_t di { if (CacheGet(a, genre, discID)) return true; - + QFile file(GetDB() + '/' + genre.toLower() + '/' + QString::number(discID,16)); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { a = QTextStream(&file).readAll(); - a.genre = genre.toLower(); + a.discGenre = genre.toLower(); a.discID = discID; LOG(VB_MEDIA, LOG_INFO, QString("LocalCDDB matched %1 ").arg(discID,0,16) + genre + " to " + a.artist + " / " + a.title); @@ -544,8 +545,8 @@ bool Dbase::Write(const Cddb::Album& album) { CachePut(album); - const QString genre = !album.genre.isEmpty() ? - album.genre.toLower().toUtf8() : "misc"; + const QString genre = !album.discGenre.isEmpty() ? + album.discGenre.toLower().toUtf8() : "misc"; LOG(VB_MEDIA, LOG_INFO, "WriteDB " + genre + QString(" %1 ").arg(album.discID,0,16) + @@ -600,10 +601,10 @@ bool Dbase::CacheGet(Cddb::Matches& res, const Cddb::discid_t discID) ret = true; res.discID = discID; LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CacheGet found %1 "). - arg(discID,0,16) + it->genre + " " + it->artist + " / " + it->title); + arg(discID,0,16) + it->discGenre + " " + it->artist + " / " + it->title); // If it's marker for 'no match' then genre is empty - if (!it->genre.isEmpty()) + if (!it->discGenre.isEmpty()) res.matches.push_back(Cddb::Match(*it)); } } @@ -614,7 +615,7 @@ bool Dbase::CacheGet(Cddb::Matches& res, const Cddb::discid_t discID) bool Dbase::CacheGet(Cddb::Album& album, const QString& genre, const Cddb::discid_t discID) { const Cddb::Album& a = s_cache[ discID]; - if (a.discID && a.genre == genre) + if (a.discID && a.discGenre == genre) { album = a; return true; diff --git a/mythplugins/mythmusic/mythmusic/cddb.h b/mythplugins/mythmusic/mythmusic/cddb.h index 06080e24e1f..3b77a39fc17 100644 --- a/mythplugins/mythmusic/mythmusic/cddb.h +++ b/mythplugins/mythmusic/mythmusic/cddb.h @@ -16,19 +16,19 @@ struct Cddb // A CDDB query match struct Match { - QString genre; + QString discGenre; discid_t discID; QString artist; QString title; Match() : discID(0) {} Match(const char *g, discid_t d, const char *a, const char *t) : - genre(g), discID(d), artist(a), title(t) + discGenre(g), discID(d), artist(a), title(t) {} Match(const QString &g, discid_t d, const QString &a, const QString &t) : - genre(g), discID(d), artist(a), title(t) + discGenre(g), discID(d), artist(a), title(t) {} - Match(const Album& a) : genre(a.genre), discID(a.discID), + Match(const Album& a) : discGenre(a.discGenre), discID(a.discID), artist(a.artist), title(a.title) {} }; @@ -60,10 +60,11 @@ struct Cddb // CDDB detail result struct Album { - QString genre; + QString discGenre; // the genre used in the query to differentiate similar discID's discid_t discID; QString artist; QString title; + QString genre; // the genre from the DGENRE= item int year; QString submitter; int rev; @@ -76,7 +77,7 @@ struct Cddb Toc toc; Album(discid_t d = 0, const char* g = 0) : - genre(g), discID(d), year(0), rev(1), isCompilation(false) {} + discGenre(g), discID(d), year(0), rev(1), isCompilation(false) {} Album(const QString& s) { *this = s; } diff --git a/mythplugins/mythmusic/mythmusic/cddecoder.cpp b/mythplugins/mythmusic/mythmusic/cddecoder.cpp index 83c4fc35f44..ac793b283f8 100644 --- a/mythplugins/mythmusic/mythmusic/cddecoder.cpp +++ b/mythplugins/mythmusic/mythmusic/cddecoder.cpp @@ -730,7 +730,7 @@ MusicMetadata *CdDecoder::getMetadata() for (Cddb::Matches::match_t::const_iterator it = select; it != r.matches.end(); ++it) { - QString g = it->genre.toLower(); + QString g = it->discGenre.toLower(); if (g != "misc" && g != "data") { select = it; @@ -740,14 +740,19 @@ MusicMetadata *CdDecoder::getMetadata() } Cddb::Album info; - if (Cddb::Read(info, select->genre, select->discID)) + if (Cddb::Read(info, select->discGenre, select->discID)) { isCompilation = info.isCompilation; - if (info.genre.toLower() != "misc") - genre = info.genre; + + if (info.genre.toLower() != "unknown") + genre = info.genre[0].toTitleCase() + info.genre.mid(1); + else + genre = info.discGenre[0].toTitleCase() + info.discGenre.mid(1);; + album = info.title; compilation_artist = info.artist; year = info.year; + if (info.tracks.size() >= tracknum) { const Cddb::Track& track = info.tracks[tracknum - 1]; @@ -798,7 +803,7 @@ void CdDecoder::commitMetadata(MusicMetadata *mdata) Cddb::discid_t discID = Cddb::Discid(secs, toc.data(), toc.size() - 1); Cddb::Album album(discID, mdata->Genre().toLower().toUtf8()); - if (!Cddb::Read(album, album.genre, discID)) + if (!Cddb::Read(album, album.discGenre, discID)) album.toc = toc; album.isCompilation = mdata->Compilation();