Permalink
Browse files

Added max dateAdded to artist and album

  • Loading branch information...
Razzeee committed Jul 28, 2015
1 parent 23c6a43 commit fc513957c77ce34e487ecd13b531674727f550c2
@@ -94,6 +94,7 @@ CAlbum::CAlbum(const CFileItem& item)
iYear = stTime.wYear;
bCompilation = tag.GetCompilation();
iTimesPlayed = 0;
dateAdded.Reset();
releaseType = tag.GetAlbumReleaseType();
}

@@ -171,6 +172,11 @@ void CAlbum::SetReleaseType(const std::string& strReleaseType)
releaseType = ReleaseTypeFromString(strReleaseType);
}

void CAlbum::SetDateAdded(const std::string& strDateAdded)
{
dateAdded.SetFromDBDateTime(strDateAdded);
}

std::string CAlbum::ReleaseTypeToString(CAlbum::ReleaseType releaseType)
{
for (size_t i = 0; i < RELEASE_TYPES_SIZE; i++)
@@ -28,6 +28,7 @@
#include <vector>
#include "Artist.h"
#include "Song.h"
#include "XBDateTime.h"
#include "utils/ScraperUrl.h"

class TiXmlNode;
@@ -36,7 +37,7 @@ class CAlbum
{
public:
CAlbum(const CFileItem& item);
CAlbum() { idAlbum = 0; iRating = 0; iYear = 0; iTimesPlayed = 0; releaseType = Album; };
CAlbum() { idAlbum = 0; iRating = 0; iYear = 0; iTimesPlayed = 0; dateAdded.Reset(); releaseType = Album; };
bool operator<(const CAlbum &a) const;
void MergeScrapedAlbum(const CAlbum& album, bool override = true);

@@ -62,6 +63,7 @@ class CAlbum
iYear=-1;
bCompilation = false;
iTimesPlayed = 0;
dateAdded.Reset();
songs.clear();
infoSongs.clear();
releaseType = Album;
@@ -77,6 +79,7 @@ class CAlbum

std::string GetReleaseType() const;
void SetReleaseType(const std::string& strReleaseType);
void SetDateAdded(const std::string& strDateAdded);

static std::string ReleaseTypeToString(ReleaseType releaseType);
static ReleaseType ReleaseTypeFromString(const std::string& strReleaseType);
@@ -111,6 +114,7 @@ class CAlbum
int iYear;
bool bCompilation;
int iTimesPlayed;
CDateTime dateAdded;
VECSONGS songs; ///< Local songs
VECSONGS infoSongs; ///< Scraped songs
ReleaseType releaseType;
@@ -193,3 +193,8 @@ bool CArtist::Save(TiXmlNode *node, const std::string &tag, const std::string& s
return true;
}

void CArtist::SetDateAdded(const std::string& strDateAdded)
{
dateAdded.SetFromDBDateTime(strDateAdded);
}

@@ -24,6 +24,7 @@
#include <string>
#include <vector>

#include "XBDateTime.h"
#include "utils/ScraperUrl.h"
#include "utils/Fanart.h"

@@ -68,6 +69,7 @@ class CArtist
discography.clear();
idArtist = -1;
strPath.clear();
dateAdded.Reset();
}

/*! \brief Load artist information from an XML file.
@@ -80,6 +82,8 @@ class CArtist
bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
bool Save(TiXmlNode *node, const std::string &tag, const std::string& strPath);

void SetDateAdded(const std::string& strDateAdded);

std::string strArtist;
std::string strMusicBrainzArtistID;
std::vector<std::string> genre;
@@ -96,6 +100,7 @@ class CArtist
CScraperUrl thumbURL;
CFanart fanart;
std::vector<std::pair<std::string,std::string> > discography;
CDateTime dateAdded;
};

class CArtistCredit
@@ -171,6 +171,7 @@ CGUIViewStateMusicDatabase::CGUIViewStateMusicDatabase(const CFileItemList& item
case NODE_TYPE_ARTIST:
{
AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", "%A", "")); // Filename, empty | Artist, empty
AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", "%A", "%a")); // Filename, empty | Artist, dateAdded
SetSortMethod(SortByArtist);

const CViewState *viewState = CViewStateSettings::Get().Get("musicnavartists");
@@ -188,6 +189,8 @@ CGUIViewStateMusicDatabase::CGUIViewStateMusicDatabase(const CFileItemList& item
AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight)); // Filename, empty | Userdefined, Userdefined
// year
AddSortMethod(SortByYear, 562, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));
// album date added
AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight)); // Filename, empty | Userdefined, Userdefined

const CViewState *viewState = CViewStateSettings::Get().Get("musicnavalbums");
SetSortMethod(viewState->m_sortDescription);
@@ -127,8 +127,7 @@ void CMusicDatabase::CreateTables()
" strStyles text, strInstruments text, strBiography text, "
" strDied text, strDisbanded text, strYearsActive text, "
" strImage text, strFanart text, "
" lastScraped varchar(20) default NULL, "
" dateAdded varchar (20) default NULL)");
" lastScraped varchar(20) default NULL)");
CLog::Log(LOGINFO, "create album table");
m_pDS->exec("CREATE TABLE album (idAlbum integer primary key, "
" strAlbum varchar(256), strMusicBrainzAlbumID text, "
@@ -140,7 +139,6 @@ void CMusicDatabase::CreateTables()
" strType text, "
" iRating integer, "
" lastScraped varchar(20) default NULL, "
" dateAdded varchar (20) default NULL, "
" strReleaseType text)");
CLog::Log(LOGINFO, "create album_artist table");
m_pDS->exec("CREATE TABLE album_artist (idArtist integer, idAlbum integer, strJoinPhrase text, boolFeatured integer, iOrder integer, strArtist text)");
@@ -309,7 +307,8 @@ void CMusicDatabase::CreateViews()
" iRating, "
" bCompilation, "
" (SELECT MIN(song.iTimesPlayed) FROM song WHERE song.idAlbum = album.idAlbum) AS iTimesPlayed, "
" strReleaseType "
" strReleaseType, "
" (SELECT MAX(song.dateAdded) FROM song WHERE song.idAlbum = album.idAlbum) AS dateAdded "
"FROM album"
);

@@ -320,7 +319,9 @@ void CMusicDatabase::CreateViews()
" strBorn, strFormed, strGenres,"
" strMoods, strStyles, strInstruments, "
" strBiography, strDied, strDisbanded, "
" strYearsActive, strImage, strFanart "
" strYearsActive, strImage, strFanart, "
" (SELECT MAX(song.dateAdded) FROM song_artist INNER JOIN song ON song.idSong = song_artist.idSong "
" WHERE song_artist.idArtist = artist.idArtist) AS dateAdded "
"FROM artist");

CLog::Log(LOGINFO, "create albumartist view");
@@ -1777,6 +1778,7 @@ CAlbum CMusicDatabase::GetAlbumFromDataset(const dbiplus::sql_record* const reco
album.bCompilation = record->at(offset + album_bCompilation).get_asInt() == 1;
album.iTimesPlayed = record->at(offset + album_iTimesPlayed).get_asInt();
album.SetReleaseType(record->at(offset + album_strReleaseType).get_asString());
album.SetDateAdded(record->at(offset + album_dtDateAdded).get_asString());
return album;
}

@@ -1812,6 +1814,7 @@ CArtist CMusicDatabase::GetArtistFromDataset(const dbiplus::sql_record* const re
artist.strDisbanded = record->at(offset + artist_strDisbanded).get_asString();
artist.yearsActive = StringUtils::Split(record->at(offset + artist_strYearsActive).get_asString(), g_advancedSettings.m_musicItemSeparator);
artist.instruments = StringUtils::Split(record->at(offset + artist_strInstruments).get_asString(), g_advancedSettings.m_musicItemSeparator);
artist.SetDateAdded(record->at(offset + artist_dtDateAdded).get_asString());

if (needThumb)
{
@@ -3862,11 +3865,74 @@ void CMusicDatabase::UpdateTables(int version)
CMediaSettings::Get().SetMusicNeedsUpdate(53);
CSettings::Get().Save();
}
if (version < 54)
{
//Remove dateAdded from artist table
m_pDS->exec("CREATE TABLE artist_new ( idArtist integer primary key, "
" strArtist varchar(256), strMusicBrainzArtistID text, "
" strBorn text, strFormed text, strGenres text, strMoods text, "
" strStyles text, strInstruments text, strBiography text, "
" strDied text, strDisbanded text, strYearsActive text, "
" strImage text, strFanart text, "
" lastScraped varchar(20) default NULL)");
m_pDS->exec("INSERT INTO artist_new "
"(idArtist, strArtist, strMusicBrainzArtistID, "
" strBorn, strFormed, strGenres, strMoods, "
" strStyles , strInstruments , strBiography , "
" strDied, strDisbanded, strYearsActive, "
" strImage, strFanart, lastScraped) "
" SELECT "
" idArtist, "
" strArtist, strMusicBrainzArtistID, "
" strBorn, strFormed, strGenres, strMoods, "
" strStyles, strInstruments, strBiography, "
" strDied, strDisbanded, strYearsActive, "
" strImage, strFanart, lastScraped "
" FROM artist");
m_pDS->exec("DROP TABLE artist");
m_pDS->exec("ALTER TABLE artist_new RENAME TO artist");

//Remove dateAdded from album table
m_pDS->exec("CREATE TABLE album_new (idAlbum integer primary key, "
" strAlbum varchar(256), strMusicBrainzAlbumID text, "
" strArtists text, strGenres text, "
" iYear integer, idThumb integer, "
" bCompilation integer not null default '0', "
" strMoods text, strStyles text, strThemes text, "
" strReview text, strImage text, strLabel text, "
" strType text, "
" iRating integer, "
" lastScraped varchar(20) default NULL, "
" strReleaseType text)");
m_pDS->exec("INSERT INTO album_new "
"(idAlbum, "
" strAlbum, strMusicBrainzAlbumID, "
" strArtists, strGenres, "
" iYear, idThumb, "
" bCompilation, "
" strMoods, strStyles, strThemes, "
" strReview, strImage, strLabel, "
" strType, iRating, lastScraped, "
" strReleaseType) "
" SELECT "
" album.idAlbum, "
" strAlbum, strMusicBrainzAlbumID, "
" strArtists, strGenres, "
" iYear, idThumb, "
" bCompilation, "
" strMoods, strStyles, strThemes, "
" strReview, strImage, strLabel, "
" strType, iRating, lastScraped, "
" strReleaseType"
" FROM album");
m_pDS->exec("DROP TABLE album");
m_pDS->exec("ALTER TABLE album_new RENAME TO album");
}
}

int CMusicDatabase::GetSchemaVersion() const
{
return 53;
return 54;
}

unsigned int CMusicDatabase::GetSongIDs(const Filter &filter, vector<pair<int,int> > &songIDs)
@@ -572,6 +572,7 @@ class CMusicDatabase : public CDatabase
album_bCompilation,
album_iTimesPlayed,
album_strReleaseType,
album_dtDateAdded,
album_enumCount // end of the enum, do not add past here
} AlbumFields;

@@ -605,6 +606,7 @@ class CMusicDatabase : public CDatabase
artist_strYearsActive,
artist_strImage,
artist_strFanart,
artist_dtDateAdded,
artist_enumCount // end of the enum, do not add past here
} ArtistFields;

@@ -530,6 +530,7 @@ void CMusicInfoTag::SetArtist(const CArtist& artist)
SetArtist(artist.strArtist);
SetAlbumArtist(artist.strArtist);
SetGenre(artist.genre);
m_dateAdded = artist.dateAdded;
m_iDbId = artist.idArtist;
m_type = MediaTypeArtist;
m_bLoaded = true;
@@ -549,6 +550,7 @@ void CMusicInfoTag::SetAlbum(const CAlbum& album)
stTime.wYear = album.iYear;
SetReleaseDate(stTime);
SetAlbumReleaseType(album.releaseType);
m_dateAdded = album.dateAdded;
m_iTimesPlayed = album.iTimesPlayed;
m_iDbId = album.idAlbum;
m_type = MediaTypeAlbum;
@@ -74,7 +74,7 @@ std::string DatabaseUtils::GetField(Field field, const MediaType &mediaType, Dat
else if (field == FieldMusicLabel) return "albumview.strLabel";
else if (field == FieldAlbumType) return "albumview.strType";
else if (field == FieldRating) return "albumview.iRating";
else if (field == FieldDateAdded && queryPart == DatabaseQueryPartOrderBy) return "albumview.idalbum"; // only used for order clauses
else if (field == FieldDateAdded) return "albumview.dateAdded";
else if (field == FieldPlaycount) return "albumview.iTimesPlayed";
}
else if (mediaType == MediaTypeSong)
@@ -111,6 +111,7 @@ std::string DatabaseUtils::GetField(Field field, const MediaType &mediaType, Dat
else if (field == FieldBandFormed) return "artistview.strFormed";
else if (field == FieldDisbanded) return "artistview.strDisbanded";
else if (field == FieldDied) return "artistview.strDied";
else if (field == FieldDateAdded) return "artistview.dateAdded";
}
else if (mediaType == MediaTypeMusicVideo)
{
@@ -488,6 +489,7 @@ int DatabaseUtils::GetField(Field field, const MediaType &mediaType, bool asInde
else if (field == FieldAlbumType) return CMusicDatabase::album_strType;
else if (field == FieldRating) return CMusicDatabase::album_iRating;
else if (field == FieldPlaycount) return CMusicDatabase::album_iTimesPlayed;
else if (field == FieldDateAdded) return CMusicDatabase::album_dtDateAdded;
}
else if (mediaType == MediaTypeSong)
{
@@ -522,6 +524,7 @@ int DatabaseUtils::GetField(Field field, const MediaType &mediaType, bool asInde
else if (field == FieldBandFormed) return CMusicDatabase::artist_strFormed;
else if (field == FieldDisbanded) return CMusicDatabase::artist_strDisbanded;
else if (field == FieldDied) return CMusicDatabase::artist_strDied;
else if (field == FieldDateAdded) return CMusicDatabase::artist_dtDateAdded;
}
else if (mediaType == MediaTypeMusicVideo)
{
@@ -44,6 +44,7 @@ class TestDatabaseUtilsHelper
album_strLabel = CMusicDatabase::album_strLabel;
album_strType = CMusicDatabase::album_strType;
album_iRating = CMusicDatabase::album_iRating;
album_dtDateAdded = CMusicDatabase::album_dtDateAdded;

song_idSong = CMusicDatabase::song_idSong;
song_strTitle = CMusicDatabase::song_strTitle;
@@ -75,6 +76,7 @@ class TestDatabaseUtilsHelper
int album_strLabel;
int album_strType;
int album_iRating;
int album_dtDateAdded;

int song_idSong;
int song_strTitle;
@@ -177,13 +179,13 @@ TEST(TestDatabaseUtils, GetField_MediaTypeAlbum)
DatabaseQueryPartSelect);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());

refstr = "albumview.idalbum";
refstr = "albumview.dateAdded";
varstr = DatabaseUtils::GetField(FieldDateAdded, MediaTypeAlbum,
DatabaseQueryPartOrderBy);
DatabaseQueryPartSelect);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());

refstr = "";
varstr = DatabaseUtils::GetField(FieldDateAdded, MediaTypeAlbum,
varstr = DatabaseUtils::GetField(FieldNone, MediaTypeAlbum,
DatabaseQueryPartSelect);
EXPECT_STREQ(refstr.c_str(), varstr.c_str());

@@ -835,6 +837,10 @@ TEST(TestDatabaseUtils, GetFieldIndex_MediaTypeAlbum)
varindex = DatabaseUtils::GetFieldIndex(FieldRating, MediaTypeAlbum);
EXPECT_EQ(refindex, varindex);

refindex = a.album_dtDateAdded;
varindex = DatabaseUtils::GetFieldIndex(FieldDateAdded, MediaTypeAlbum);
EXPECT_EQ(refindex, varindex);

refindex = -1;
varindex = DatabaseUtils::GetFieldIndex(FieldRandom, MediaTypeAlbum);
EXPECT_EQ(refindex, varindex);

0 comments on commit fc51395

Please sign in to comment.