Skip to content

Commit

Permalink
MythMusic: fix a mix up with the genre handling in the freedb cd lookup
Browse files Browse the repository at this point in the history
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 :(
  • Loading branch information
Paul Harrison committed May 11, 2013
1 parent fa9c534 commit 3e5225e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
23 changes: 12 additions & 11 deletions mythplugins/mythmusic/mythmusic/cddb.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 + " : " +
Expand All @@ -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);
Expand All @@ -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) +
Expand Down Expand Up @@ -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));
}
}
Expand All @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions mythplugins/mythmusic/mythmusic/cddb.h
Expand Up @@ -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)
{}
};
Expand Down Expand Up @@ -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;
Expand All @@ -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; }

Expand Down
15 changes: 10 additions & 5 deletions mythplugins/mythmusic/mythmusic/cddecoder.cpp
Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3e5225e

Please sign in to comment.