[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / music / Song.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "Song.h"
22 #include "music/tags/MusicInfoTag.h"
23 #include "utils/Variant.h"
24
25 using namespace std;
26 using namespace MUSIC_INFO;
27
28 CSong::CSong(CMusicInfoTag& tag)
29 {
30   SYSTEMTIME stTime;
31   tag.GetReleaseDate(stTime);
32   strTitle = tag.GetTitle();
33   genre = tag.GetGenre();
34   strFileName = tag.GetURL();
35   artist = tag.GetArtist();
36   strAlbum = tag.GetAlbum();
37   albumArtist = tag.GetAlbumArtist();
38   strMusicBrainzTrackID = tag.GetMusicBrainzTrackID();
39   strMusicBrainzArtistID = tag.GetMusicBrainzArtistID();
40   strMusicBrainzAlbumID = tag.GetMusicBrainzAlbumID();
41   strMusicBrainzAlbumArtistID = tag.GetMusicBrainzAlbumArtistID();
42   strMusicBrainzTRMID = tag.GetMusicBrainzTRMID();
43   strComment = tag.GetComment();
44   rating = tag.GetRating();
45   iYear = stTime.wYear;
46   iTrack = tag.GetTrackAndDiskNumber();
47   iDuration = tag.GetDuration();
48   bCompilation = tag.GetCompilation();
49   embeddedArt = tag.GetCoverArtInfo();
50   strThumb = "";
51   iStartOffset = 0;
52   iEndOffset = 0;
53   idSong = -1;
54   iTimesPlayed = 0;
55   iKaraokeNumber = 0;
56   iKaraokeDelay = 0;         //! Karaoke song lyrics-music delay in 1/10 seconds.
57   iAlbumId = -1;
58 }
59
60 CSong::CSong()
61 {
62   Clear();
63 }
64
65 void CSong::Serialize(CVariant& value) const
66 {
67   value["filename"] = strFileName;
68   value["title"] = strTitle;
69   value["artist"] = artist;
70   value["album"] = strAlbum;
71   value["albumartist"] = albumArtist;
72   value["genre"] = genre;
73   value["duration"] = iDuration;
74   value["track"] = iTrack;
75   value["year"] = iYear;
76   value["musicbrainztrackid"] = strMusicBrainzTrackID;
77   value["musicbrainzartistid"] = strMusicBrainzArtistID;
78   value["musicbrainzalbumid"] = strMusicBrainzAlbumID;
79   value["musicbrainzalbumartistid"] = strMusicBrainzAlbumArtistID;
80   value["musicbrainztrmid"] = strMusicBrainzTRMID;
81   value["comment"] = strComment;
82   value["rating"] = rating;
83   value["timesplayed"] = iTimesPlayed;
84   value["lastplayed"] = lastPlayed.IsValid() ? lastPlayed.GetAsDBDateTime() : "";
85   value["karaokenumber"] = (int64_t) iKaraokeNumber;
86   value["albumid"] = iAlbumId;
87 }
88
89 void CSong::Clear()
90 {
91   strFileName.Empty();
92   strTitle.Empty();
93   artist.clear();
94   strAlbum.Empty();
95   albumArtist.clear();
96   genre.clear();
97   strThumb.Empty();
98   strMusicBrainzTrackID.Empty();
99   strMusicBrainzArtistID.Empty();
100   strMusicBrainzAlbumID.Empty();
101   strMusicBrainzAlbumArtistID.Empty();
102   strMusicBrainzTRMID.Empty();
103   strComment.Empty();
104   rating = '0';
105   iTrack = 0;
106   iDuration = 0;
107   iYear = 0;
108   iStartOffset = 0;
109   iEndOffset = 0;
110   idSong = -1;
111   iTimesPlayed = 0;
112   lastPlayed.Reset();
113   iKaraokeNumber = 0;
114   strKaraokeLyrEncoding.Empty();
115   iKaraokeDelay = 0;
116   iAlbumId = -1;
117   bCompilation = false;
118   embeddedArt.clear();
119 }
120
121 bool CSong::HasArt() const
122 {
123   if (!strThumb.empty()) return true;
124   if (!embeddedArt.empty()) return true;
125   return false;
126 }
127
128 bool CSong::ArtMatches(const CSong &right) const
129 {
130   return (right.strThumb == strThumb &&
131           embeddedArt.matches(right.embeddedArt));
132 }
133
134 CSongMap::CSongMap()
135 {
136 }
137
138 std::map<CStdString, CSong>::const_iterator CSongMap::Begin()
139 {
140   return m_map.begin();
141 }
142
143 std::map<CStdString, CSong>::const_iterator CSongMap::End()
144 {
145   return m_map.end();
146 }
147
148 void CSongMap::Add(const CStdString &file, const CSong &song)
149 {
150   CStdString lower = file;
151   lower.ToLower();
152   m_map.insert(pair<CStdString, CSong>(lower, song));
153 }
154
155 CSong* CSongMap::Find(const CStdString &file)
156 {
157   CStdString lower = file;
158   lower.ToLower();
159   map<CStdString, CSong>::iterator it = m_map.find(lower);
160   if (it == m_map.end())
161     return NULL;
162   return &(*it).second;
163 }
164
165 void CSongMap::Clear()
166 {
167   m_map.erase(m_map.begin(), m_map.end());
168 }
169
170 int CSongMap::Size()
171 {
172   return (int)m_map.size();
173 }
174