2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "music/tags/MusicInfoTag.h"
23 #include "utils/Variant.h"
25 #include "settings/AdvancedSettings.h"
26 #include "utils/StringUtils.h"
29 using namespace MUSIC_INFO;
31 CSong::CSong(CFileItem& item)
33 CMusicInfoTag& tag = *item.GetMusicInfoTag();
35 tag.GetReleaseDate(stTime);
36 strTitle = tag.GetTitle();
37 genre = tag.GetGenre();
38 artist = tag.GetArtist();
39 bool hasMusicBrainzArtist = !tag.GetMusicBrainzArtistID().empty();
40 const vector<string>& artists = hasMusicBrainzArtist ? tag.GetMusicBrainzArtistID() : tag.GetArtist();
41 for (vector<string>::const_iterator it = artists.begin(); it != artists.end(); ++it)
43 CStdString artistName = hasMusicBrainzArtist && !artist.empty() ? artist[0] : *it;
44 CStdString artistId = hasMusicBrainzArtist ? *it : StringUtils::EmptyString;
45 CStdString strJoinPhrase = (it == --artists.end() ? "" : g_advancedSettings.m_musicItemSeparator);
46 CArtistCredit artistCredit(artistName, artistId, strJoinPhrase);
47 artistCredits.push_back(artistCredit);
49 strAlbum = tag.GetAlbum();
50 albumArtist = tag.GetAlbumArtist();
51 strMusicBrainzTrackID = tag.GetMusicBrainzTrackID();
52 strComment = tag.GetComment();
53 rating = tag.GetRating();
55 iTrack = tag.GetTrackAndDiskNumber();
56 iDuration = tag.GetDuration();
57 bCompilation = tag.GetCompilation();
58 embeddedArt = tag.GetCoverArtInfo();
59 strFileName = tag.GetURL().empty() ? item.GetPath() : tag.GetURL();
60 strThumb = item.GetUserMusicThumb(true);
61 iStartOffset = item.m_lStartOffset;
62 iEndOffset = item.m_lEndOffset;
66 iKaraokeDelay = 0; //! Karaoke song lyrics-music delay in 1/10 seconds.
75 void CSong::Serialize(CVariant& value) const
77 value["filename"] = strFileName;
78 value["title"] = strTitle;
79 value["artist"] = artist;
80 value["album"] = strAlbum;
81 value["albumartist"] = albumArtist;
82 value["genre"] = genre;
83 value["duration"] = iDuration;
84 value["track"] = iTrack;
85 value["year"] = iYear;
86 value["musicbrainztrackid"] = strMusicBrainzTrackID;
87 value["comment"] = strComment;
88 value["rating"] = rating;
89 value["timesplayed"] = iTimesPlayed;
90 value["lastplayed"] = lastPlayed.IsValid() ? lastPlayed.GetAsDBDateTime() : "";
91 value["karaokenumber"] = (int64_t) iKaraokeNumber;
92 value["albumid"] = idAlbum;
104 strMusicBrainzTrackID.clear();
116 strKaraokeLyrEncoding.clear();
119 bCompilation = false;
123 bool CSong::HasArt() const
125 if (!strThumb.empty()) return true;
126 if (!embeddedArt.empty()) return true;
130 bool CSong::ArtMatches(const CSong &right) const
132 return (right.strThumb == strThumb &&
133 embeddedArt.matches(right.embeddedArt));