changed: Add logic to properly handle subtitles for stacked files
[vuplus_xbmc] / xbmc / music / Song.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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 #include "FileItem.h"
25 #include "settings/AdvancedSettings.h"
26 #include "utils/StringUtils.h"
27
28 using namespace std;
29 using namespace MUSIC_INFO;
30
31 CSong::CSong(CFileItem& item)
32 {
33   CMusicInfoTag& tag = *item.GetMusicInfoTag();
34   SYSTEMTIME stTime;
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)
42   {
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);
48   }
49   strAlbum = tag.GetAlbum();
50   albumArtist = tag.GetAlbumArtist();
51   strMusicBrainzTrackID = tag.GetMusicBrainzTrackID();
52   strComment = tag.GetComment();
53   rating = tag.GetRating();
54   iYear = stTime.wYear;
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;
63   idSong = -1;
64   iTimesPlayed = 0;
65   iKaraokeNumber = 0;
66   iKaraokeDelay = 0;         //! Karaoke song lyrics-music delay in 1/10 seconds.
67   idAlbum = -1;
68 }
69
70 CSong::CSong()
71 {
72   Clear();
73 }
74
75 void CSong::Serialize(CVariant& value) const
76 {
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;
93 }
94
95 void CSong::Clear()
96 {
97   strFileName.clear();
98   strTitle.clear();
99   artist.clear();
100   strAlbum.clear();
101   albumArtist.clear();
102   genre.clear();
103   strThumb.clear();
104   strMusicBrainzTrackID.clear();
105   strComment.clear();
106   rating = '0';
107   iTrack = 0;
108   iDuration = 0;
109   iYear = 0;
110   iStartOffset = 0;
111   iEndOffset = 0;
112   idSong = -1;
113   iTimesPlayed = 0;
114   lastPlayed.Reset();
115   iKaraokeNumber = 0;
116   strKaraokeLyrEncoding.clear();
117   iKaraokeDelay = 0;
118   idAlbum = -1;
119   bCompilation = false;
120   embeddedArt.clear();
121 }
122
123 bool CSong::HasArt() const
124 {
125   if (!strThumb.empty()) return true;
126   if (!embeddedArt.empty()) return true;
127   return false;
128 }
129
130 bool CSong::ArtMatches(const CSong &right) const
131 {
132   return (right.strThumb == strThumb &&
133           embeddedArt.matches(right.embeddedArt));
134 }