Commit a2d2a670 authored by Richard Lärkäng's avatar Richard Lärkäng
Browse files

Read year on Musicbrainz lookups

Add code for reading the year when looking up releases from Musicbrainz.
Added a test-case (musicbrainztest-fulldata), where the date
is "2011-04-29", which should be parsed as only "2011".

Also, while adding the test case, I ran into a bug, the titles
and track artists were always taken from the recording, while
ones from the "release credits" are preferred, fixed this as well,
and updated the other tests to reflect the fixes.

BUG: 300091
parent 35880a3b
......@@ -124,6 +124,19 @@ namespace KCDDB
info.set(Title, title);
info.set(Artist, artistFromCreditList(FullRelease->ArtistCredit()));
QString date = QString::fromUtf8(FullRelease->Date().c_str());
QRegExp yearRe("^(\\d{4,4})(-\\d{1,2}-\\d{1,2})?$");
int year = 0;
if (yearRe.indexIn(date) > -1)
{
QString yearString = yearRe.cap(1);
bool ok;
year=yearString.toInt(&ok);
if (!ok)
year = 0;
}
info.set(Year, year);
MusicBrainz5::CTrackList *TrackList=Medium->TrackList();
if (TrackList)
{
......@@ -132,21 +145,23 @@ namespace KCDDB
MusicBrainz5::CTrack* Track=TrackList->Item(i);
MusicBrainz5::CRecording *Recording=Track->Recording();
/*if (Recording)
kDebug() << "Track: " << Track.Position() << " - '" << Recording->Title() << "'";
else
kDebug() << "Track: " << Track.Position() << " - '" << Track.Title() << "'";*/
TrackInfo& track = info.track(i);
if (Recording)
{
// Prefer title and artist from the track credits, but
// it appears to be empty if same as in Recording
// Noticable in the musicbrainztest-fulldate test,
// where the title on the credits of track 18 are
// "Bara om min älskade väntar", but the recording
// has title "Men bara om min älskade"
if(Recording && Track->ArtistCredit() == 0)
track.set(Artist, artistFromCreditList(Recording->ArtistCredit()));
track.set(Title, QString::fromUtf8(Recording->Title().c_str()));
}
else
{
track.set(Artist, artistFromCreditList(Track->ArtistCredit()));
if(Recording && Track->Title().empty())
track.set(Title, QString::fromUtf8(Recording->Title().c_str()));
else
track.set(Title, QString::fromUtf8(Track->Title().c_str()));
}
}
}
cdInfoList_ << info;
......
......@@ -29,6 +29,7 @@ KCDDB_UNIT_TESTS(
cdinfotest
cachetest
musicbrainztest-severaldiscs
musicbrainztest-fulldate
)
KCDDB_EXECUTABLE_TESTS(
......
......@@ -74,18 +74,18 @@ void AsyncMusicBrainzTest::testLookup()
QCOMPARE(m_info.get(Artist).toString(),QString("Various Artists"));
QCOMPARE(m_info.get(Title).toString(),QString::fromUtf8("Definitivt 50 spänn 10"));
// genre and year not really supported for musicbrainz
// genre not really supported for musicbrainz
QCOMPARE(m_info.get(Genre).toString(),QString());
QCOMPARE(m_info.get(Year).toInt(),0);
QCOMPARE(m_info.get(Year).toInt(),2001);
QCOMPARE(m_info.track(0).get(Title).toString(),QString::fromUtf8("Uphill Struggle"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär?"));
QCOMPARE(m_info.track(2).get(Title).toString(),QString::fromUtf8("Här är jag"));
QCOMPARE(m_info.track(3).get(Title).toString(),QString::fromUtf8("Århundradets fest"));
QCOMPARE(m_info.track(4).get(Title).toString(),QString::fromUtf8("Vem valde mittemellan"));
QCOMPARE(m_info.track(5).get(Title).toString(),QString::fromUtf8("Hippieambulansen"));
QCOMPARE(m_info.track(6).get(Title).toString(),QString::fromUtf8("Jonsson"));
QCOMPARE(m_info.track(7).get(Title).toString(),QString::fromUtf8("Jag lämnar filmen"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString::fromUtf8("39 steg"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString::fromUtf8("39 Steg"));
QCOMPARE(m_info.track(9).get(Title).toString(),QString::fromUtf8("Lyckliga land"));
QCOMPARE(m_info.track(10).get(Title).toString(),QString::fromUtf8("Helpless"));
QCOMPARE(m_info.track(11).get(Title).toString(),QString::fromUtf8("Tunna skivor"));
......
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "musicbrainztest-fulldate.h"
#include "libkcddb/client.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
#include "config-musicbrainz.h"
void MusicBrainzTestFullDate::testLookup()
{
using namespace KCDDB;
#ifndef HAVE_MUSICBRAINZ5
QSKIP("This test requires libmusicbrainz", SkipAll);
#endif
Client c;
c.config().setCacheLookupEnabled(false);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(true);
TrackOffsetList list;
list <<
150 <<
11837 <<
20687 <<
29120 <<
35557 <<
50087 <<
58550 <<
72575 <<
81887 <<
95745 <<
104340 <<
115425 <<
124285 <<
132317 <<
142692 <<
160272 <<
169325 <<
181377 <<
194482 <<
205747 <<
216492 <<
229507 <<
242715 <<
252112 <<
274965 <<
285820 <<
308957 <<
322362 <<
338662 <<
350172 <<
356692;
Result r = c.lookup(list);
QVERIFY(r == Success);
kDebug() << "Client::lookup gave : " << resultToString(r);
CDInfoList response = c.lookupResponse();
kDebug() << "Client::lookup returned : " << response.count() << " entries"
<< endl;
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/release/04319e80-0948-4e89-8180-7cf6f17fc77a for changes
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),30);
QCOMPARE(i.get(Artist).toString(),QString("Troublemakers"));
QCOMPARE(i.get(Title).toString(),QString("30"));
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),2011);
QCOMPARE(i.track(0).get(Title).toString(),QString("30"));
QCOMPARE(i.track(1).get(Title).toString(),QString::fromUtf8("Staden Göteborg"));
QCOMPARE(i.track(2).get(Title).toString(),QString::fromUtf8("Lilla Blå"));
QCOMPARE(i.track(3).get(Title).toString(),QString("Kleptoman"));
QCOMPARE(i.track(4).get(Title).toString(),QString::fromUtf8("Grogg å parabol"));
QCOMPARE(i.track(5).get(Title).toString(),QString("Majorna brinner"));
QCOMPARE(i.track(6).get(Title).toString(),QString::fromUtf8("Utan hjärta stannar Sverige"));
QCOMPARE(i.track(7).get(Title).toString(),QString("Dom e efter mig"));
QCOMPARE(i.track(8).get(Title).toString(),QString("Mammas flickor"));
QCOMPARE(i.track(9).get(Title).toString(),QString("Handgranat"));
QCOMPARE(i.track(10).get(Title).toString(),QString("Stenar o blod"));
QCOMPARE(i.track(11).get(Title).toString(),QString("Enkel Berlin"));
QCOMPARE(i.track(12).get(Title).toString(),QString("Dom ljuger"));
QCOMPARE(i.track(13).get(Title).toString(),QString("Jobba"));
QCOMPARE(i.track(14).get(Title).toString(),QString::fromUtf8("Varför lyser inga stjärnor"));
QCOMPARE(i.track(15).get(Title).toString(),QString("Partytrash"));
QCOMPARE(i.track(16).get(Title).toString(),QString::fromUtf8("Förstod ingenting"));
QCOMPARE(i.track(17).get(Title).toString(),QString::fromUtf8("Bara om min älskade väntar"));
QCOMPARE(i.track(18).get(Title).toString(),QString("Lillebror"));
QCOMPARE(i.track(19).get(Title).toString(),QString("Skandaler"));
QCOMPARE(i.track(20).get(Title).toString(),QString::fromUtf8("Hjältarna skålar i blod"));
QCOMPARE(i.track(21).get(Title).toString(),QString("Bomber o granater"));
QCOMPARE(i.track(22).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär"));
QCOMPARE(i.track(23).get(Title).toString(),QString::fromUtf8("Stjärnorna kvittar det lika"));
QCOMPARE(i.track(24).get(Title).toString(),QString("Naken"));
QCOMPARE(i.track(25).get(Title).toString(),QString::fromUtf8("Månen lyser klar"));
QCOMPARE(i.track(26).get(Title).toString(),QString("Vild o vacker"));
QCOMPARE(i.track(27).get(Title).toString(),QString("Jag fryser"));
QCOMPARE(i.track(28).get(Title).toString(),QString("Ein zwei polizei"));
QCOMPARE(i.track(29).get(Title).toString(),QString::fromUtf8("Jävla idiot"));
for (int j=0; j < 30; j++)
QCOMPARE(i.track(j).get(Artist).toString(),QString("Troublemakers"));
// comments not supported in a simple way
for (int j=0; j < 19; j++)
QCOMPARE(i.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
c.config().setCacheLookupEnabled(true);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(false);
c.lookup(list);
response = c.lookupResponse();
QVERIFY(response.count() > 0);
CDInfo cacheInfo(response.first());
QCOMPARE(i.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(i.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(i.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 19; j++)
{
QCOMPARE(i.track(j).get(Title).toString(),cacheInfo.track(j).get(Title).toString());
QCOMPARE(i.track(j).get(Comment).toString(),cacheInfo.track(j).get(Comment).toString());
}
}
QTEST_KDEMAIN(MusicBrainzTestFullDate, NoGUI)
#include "musicbrainztest-fulldate.moc"
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MUSICBRAINZTESTFULLDATE_H
#define MUSICBRAINZTESTFULLDATE_H
#include <QObject>
class MusicBrainzTestFullDate : public QObject
{
Q_OBJECT
private slots:
void testLookup();
};
#endif
......@@ -76,15 +76,15 @@ void MusicBrainzTestSeveralDiscs::testLookup()
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/tracklist/165651 for changes
// See http://musicbrainz.org/release/4e0655b5-22fc-496e-9c14-2ee1a6027b45 for changes (disc 2)
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),20);
QCOMPARE(i.get(Artist).toString(),QString("Billy Bragg"));
QCOMPARE(i.get(Title).toString(),QString("Must I Paint You a Picture? The Essential Billy Bragg (disc 2)"));
// genre and year not really supported for musicbrainz
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),0);
QCOMPARE(i.get(Year).toInt(),2003);
QCOMPARE(i.track(0).get(Title).toString(),QString("Sexuality"));
QCOMPARE(i.track(1).get(Title).toString(),QString("Cindy of 1000 Lives"));
QCOMPARE(i.track(2).get(Title).toString(),QString("Moving the Goalposts"));
......@@ -103,14 +103,14 @@ void MusicBrainzTestSeveralDiscs::testLookup()
QCOMPARE(i.track(15).get(Title).toString(),QString("All You Fascists Bound to Lose (Blokes version)"));
QCOMPARE(i.track(16).get(Title).toString(),QString("NPWA"));
QCOMPARE(i.track(17).get(Title).toString(),QString("St. Monday"));
QCOMPARE(i.track(18).get(Title).toString(),QString("Some Days I See the Point"));
QCOMPARE(i.track(18).get(Title).toString(),QString("Somedays I See the Point"));
QCOMPARE(i.track(19).get(Title).toString(),QString("Take Down the Union Jack (Band version)"));
for (int j=0; j < 12; j++)
QCOMPARE(i.track(0).get(Artist).toString(),QString("Billy Bragg"));
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg"));
for (int j=12; j < 15; j++)
QCOMPARE(i.track(0).get(Artist).toString(),QString("Billy Bragg"));
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg & Wilco"));
for (int j=15; j < 20; j++)
QCOMPARE(i.track(0).get(Artist).toString(),QString("Billy Bragg"));
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg and The Blokes"));
// comments not supported in a simple way
for (int j=0; j < 19; j++)
QCOMPARE(i.track(j).get(Comment).toString(),QString());
......
......@@ -71,15 +71,15 @@ void MusicBrainzTest::testLookup()
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/showalbum.html?albumid=375639 for changes
// See http://musicbrainz.org/release/68ec4a09-576c-472e-9103-aed99b6a3ffc for changes
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),14);
QCOMPARE(i.get(Artist).toString(),QString("The Liptones"));
QCOMPARE(i.get(Title).toString(),QString("The Latest News"));
// genre and year not really supported for musicbrainz
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),0);
QCOMPARE(i.get(Year).toInt(),2002);
QCOMPARE(i.track(0).get(Title).toString(),QString("Jungle Heat"));
QCOMPARE(i.track(1).get(Title).toString(),QString("It's All I Hear You Say"));
QCOMPARE(i.track(2).get(Title).toString(),QString("Girl for Tonight"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment