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/>.
21 #include "utils/log.h"
22 #include "video/VideoDatabase.h"
23 #include "video/VideoInfoTag.h"
25 #include "RecentlyAddedJob.h"
26 #include "guilib/GUIWindow.h"
27 #include "guilib/GUIWindowManager.h"
28 #include "guilib/WindowIDs.h"
29 #include "music/MusicDatabase.h"
30 #include "music/tags/MusicInfoTag.h"
31 #include "utils/Variant.h"
32 #include "utils/StringUtils.h"
33 #include "settings/AdvancedSettings.h"
34 #include "music/MusicThumbLoader.h"
35 #include "video/VideoThumbLoader.h"
39 CRecentlyAddedJob::CRecentlyAddedJob(int flag)
44 bool CRecentlyAddedJob::UpdateVideo()
46 CGUIWindow* home = g_windowManager.GetWindow(WINDOW_HOME);
51 CLog::Log(LOGDEBUG, "CRecentlyAddedJob::UpdateVideos() - Running RecentlyAdded home screen update");
55 CVideoDatabase videodatabase;
56 CVideoThumbLoader loader;
57 loader.OnLoaderStart();
61 if (videodatabase.GetRecentlyAddedMoviesNav("videodb://recentlyaddedmovies/", items, NUM_ITEMS))
63 for (; i < items.Size(); ++i)
65 CFileItemPtr item = items.Get(i);
66 CStdString value = StringUtils::Format("%i", i + 1);
67 CStdString strRating = StringUtils::Format("%.1f", item->GetVideoInfoTag()->m_fRating);;
69 home->SetProperty("LatestMovie." + value + ".Title" , item->GetLabel());
70 home->SetProperty("LatestMovie." + value + ".Rating" , strRating);
71 home->SetProperty("LatestMovie." + value + ".Year" , item->GetVideoInfoTag()->m_iYear);
72 home->SetProperty("LatestMovie." + value + ".Plot" , item->GetVideoInfoTag()->m_strPlot);
73 home->SetProperty("LatestMovie." + value + ".RunningTime" , item->GetVideoInfoTag()->GetDuration() / 60);
74 home->SetProperty("LatestMovie." + value + ".Path" , item->GetVideoInfoTag()->m_strFileNameAndPath);
75 home->SetProperty("LatestMovie." + value + ".Trailer" , item->GetVideoInfoTag()->m_strTrailer);
77 if (!item->HasArt("thumb"))
78 loader.LoadItem(item.get());
80 home->SetProperty("LatestMovie." + value + ".Thumb" , item->GetArt("thumb"));
81 home->SetProperty("LatestMovie." + value + ".Fanart" , item->GetArt("fanart"));
84 for (; i < NUM_ITEMS; ++i)
86 CStdString value = StringUtils::Format("%i", i + 1);
87 home->SetProperty("LatestMovie." + value + ".Title" , "");
88 home->SetProperty("LatestMovie." + value + ".Thumb" , "");
89 home->SetProperty("LatestMovie." + value + ".Rating" , "");
90 home->SetProperty("LatestMovie." + value + ".Year" , "");
91 home->SetProperty("LatestMovie." + value + ".Plot" , "");
92 home->SetProperty("LatestMovie." + value + ".RunningTime" , "");
93 home->SetProperty("LatestMovie." + value + ".Path" , "");
94 home->SetProperty("LatestMovie." + value + ".Trailer" , "");
95 home->SetProperty("LatestMovie." + value + ".Fanart" , "");
99 CFileItemList TVShowItems;
101 if (videodatabase.GetRecentlyAddedEpisodesNav("videodb://recentlyaddedepisodes/", TVShowItems, NUM_ITEMS))
103 for (; i < TVShowItems.Size(); ++i)
105 CFileItemPtr item = TVShowItems.Get(i);
106 int EpisodeSeason = item->GetVideoInfoTag()->m_iSeason;
107 int EpisodeNumber = item->GetVideoInfoTag()->m_iEpisode;
108 CStdString EpisodeNo = StringUtils::Format("s%02de%02d", EpisodeSeason, EpisodeNumber);
109 CStdString value = StringUtils::Format("%i", i + 1);
110 CStdString strRating = StringUtils::Format("%.1f", item->GetVideoInfoTag()->m_fRating);
112 CFileItem show(item->GetVideoInfoTag()->m_strShowPath, true);
114 home->SetProperty("LatestEpisode." + value + ".ShowTitle" , item->GetVideoInfoTag()->m_strShowTitle);
115 home->SetProperty("LatestEpisode." + value + ".EpisodeTitle" , item->GetVideoInfoTag()->m_strTitle);
116 home->SetProperty("LatestEpisode." + value + ".Rating" , strRating);
117 home->SetProperty("LatestEpisode." + value + ".Plot" , item->GetVideoInfoTag()->m_strPlot);
118 home->SetProperty("LatestEpisode." + value + ".EpisodeNo" , EpisodeNo);
119 home->SetProperty("LatestEpisode." + value + ".EpisodeSeason" , EpisodeSeason);
120 home->SetProperty("LatestEpisode." + value + ".EpisodeNumber" , EpisodeNumber);
121 home->SetProperty("LatestEpisode." + value + ".Path" , item->GetVideoInfoTag()->m_strFileNameAndPath);
123 if (!item->HasArt("thumb"))
124 loader.LoadItem(item.get());
126 std::string seasonThumb;
127 if (item->GetVideoInfoTag()->m_iIdSeason > 0)
128 seasonThumb = videodatabase.GetArtForItem(item->GetVideoInfoTag()->m_iIdSeason, "season", "thumb");
130 home->SetProperty("LatestEpisode." + value + ".Thumb" , item->GetArt("thumb"));
131 home->SetProperty("LatestEpisode." + value + ".ShowThumb" , item->GetArt("tvshow.thumb"));
132 home->SetProperty("LatestEpisode." + value + ".SeasonThumb" , seasonThumb);
133 home->SetProperty("LatestEpisode." + value + ".Fanart" , item->GetArt("fanart"));
136 for (; i < NUM_ITEMS; ++i)
138 CStdString value = StringUtils::Format("%i", i + 1);
139 home->SetProperty("LatestEpisode." + value + ".ShowTitle" , "");
140 home->SetProperty("LatestEpisode." + value + ".EpisodeTitle" , "");
141 home->SetProperty("LatestEpisode." + value + ".Rating" , "");
142 home->SetProperty("LatestEpisode." + value + ".Plot" , "");
143 home->SetProperty("LatestEpisode." + value + ".EpisodeNo" , "");
144 home->SetProperty("LatestEpisode." + value + ".EpisodeSeason" , "");
145 home->SetProperty("LatestEpisode." + value + ".EpisodeNumber" , "");
146 home->SetProperty("LatestEpisode." + value + ".Path" , "");
147 home->SetProperty("LatestEpisode." + value + ".Thumb" , "");
148 home->SetProperty("LatestEpisode." + value + ".ShowThumb" , "");
149 home->SetProperty("LatestEpisode." + value + ".SeasonThumb" , "");
150 home->SetProperty("LatestEpisode." + value + ".Fanart" , "");
154 CFileItemList MusicVideoItems;
156 if (videodatabase.GetRecentlyAddedMusicVideosNav("videodb://recentlyaddedmusicvideos/", MusicVideoItems, NUM_ITEMS))
158 for (; i < MusicVideoItems.Size(); ++i)
160 CFileItemPtr item = MusicVideoItems.Get(i);
161 CStdString value = StringUtils::Format("%i", i + 1);
163 home->SetProperty("LatestMusicVideo." + value + ".Title" , item->GetLabel());
164 home->SetProperty("LatestMusicVideo." + value + ".Year" , item->GetVideoInfoTag()->m_iYear);
165 home->SetProperty("LatestMusicVideo." + value + ".Plot" , item->GetVideoInfoTag()->m_strPlot);
166 home->SetProperty("LatestMusicVideo." + value + ".RunningTime" , item->GetVideoInfoTag()->GetDuration() / 60);
167 home->SetProperty("LatestMusicVideo." + value + ".Path" , item->GetVideoInfoTag()->m_strFileNameAndPath);
168 home->SetProperty("LatestMusicVideo." + value + ".Artist" , StringUtils::Join(item->GetVideoInfoTag()->m_artist, g_advancedSettings.m_videoItemSeparator));
170 if (!item->HasArt("thumb"))
171 loader.LoadItem(item.get());
173 home->SetProperty("LatestMusicVideo." + value + ".Thumb" , item->GetArt("thumb"));
174 home->SetProperty("LatestMusicVideo." + value + ".Fanart" , item->GetArt("fanart"));
177 for (; i < NUM_ITEMS; ++i)
179 CStdString value = StringUtils::Format("%i", i + 1);
180 home->SetProperty("LatestMusicVideo." + value + ".Title" , "");
181 home->SetProperty("LatestMusicVideo." + value + ".Thumb" , "");
182 home->SetProperty("LatestMusicVideo." + value + ".Year" , "");
183 home->SetProperty("LatestMusicVideo." + value + ".Plot" , "");
184 home->SetProperty("LatestMusicVideo." + value + ".RunningTime" , "");
185 home->SetProperty("LatestMusicVideo." + value + ".Path" , "");
186 home->SetProperty("LatestMusicVideo." + value + ".Artist" , "");
187 home->SetProperty("LatestMusicVideo." + value + ".Fanart" , "");
190 videodatabase.Close();
194 bool CRecentlyAddedJob::UpdateMusic()
196 CGUIWindow* home = g_windowManager.GetWindow(WINDOW_HOME);
201 CLog::Log(LOGDEBUG, "CRecentlyAddedJob::UpdateMusic() - Running RecentlyAdded home screen update");
204 CFileItemList musicItems;
205 CMusicDatabase musicdatabase;
206 CMusicThumbLoader loader;
207 loader.OnLoaderStart();
209 musicdatabase.Open();
211 if (musicdatabase.GetRecentlyAddedAlbumSongs("musicdb://songs/", musicItems, NUM_ITEMS))
214 CStdString strAlbumThumb;
215 CStdString strAlbumFanart;
216 for (; i < musicItems.Size(); ++i)
218 CFileItemPtr item = musicItems.Get(i);
219 CStdString value = StringUtils::Format("%i", i + 1);
221 CStdString strRating;
222 CStdString strAlbum = item->GetMusicInfoTag()->GetAlbum();
223 CStdString strArtist = StringUtils::Join(item->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator);
225 if (idAlbum != item->GetMusicInfoTag()->GetAlbumId())
227 strAlbumThumb.clear();
228 strAlbumFanart.clear();
229 idAlbum = item->GetMusicInfoTag()->GetAlbumId();
231 if (loader.LoadItem(item.get()))
233 strAlbumThumb = item->GetArt("thumb");
234 strAlbumFanart = item->GetArt("fanart");
238 strRating = StringUtils::Format("%c", item->GetMusicInfoTag()->GetRating());
240 home->SetProperty("LatestSong." + value + ".Title" , item->GetMusicInfoTag()->GetTitle());
241 home->SetProperty("LatestSong." + value + ".Year" , item->GetMusicInfoTag()->GetYear());
242 home->SetProperty("LatestSong." + value + ".Artist" , strArtist);
243 home->SetProperty("LatestSong." + value + ".Album" , strAlbum);
244 home->SetProperty("LatestSong." + value + ".Rating" , strRating);
245 home->SetProperty("LatestSong." + value + ".Path" , item->GetMusicInfoTag()->GetURL());
246 home->SetProperty("LatestSong." + value + ".Thumb" , strAlbumThumb);
247 home->SetProperty("LatestSong." + value + ".Fanart" , strAlbumFanart);
250 for (; i < NUM_ITEMS; ++i)
252 CStdString value = StringUtils::Format("%i", i + 1);
253 home->SetProperty("LatestSong." + value + ".Title" , "");
254 home->SetProperty("LatestSong." + value + ".Year" , "");
255 home->SetProperty("LatestSong." + value + ".Artist" , "");
256 home->SetProperty("LatestSong." + value + ".Album" , "");
257 home->SetProperty("LatestSong." + value + ".Rating" , "");
258 home->SetProperty("LatestSong." + value + ".Path" , "");
259 home->SetProperty("LatestSong." + value + ".Thumb" , "");
260 home->SetProperty("LatestSong." + value + ".Fanart" , "");
266 if (musicdatabase.GetRecentlyAddedAlbums(albums, NUM_ITEMS))
268 for (; i < (int)albums.size(); ++i)
270 CAlbum& album=albums[i];
271 CStdString value = StringUtils::Format("%i", i + 1);
272 CStdString strThumb = musicdatabase.GetArtForItem(album.idAlbum, "album", "thumb");
273 CStdString strFanart = musicdatabase.GetArtistArtForItem(album.idAlbum, "album", "fanart");
274 CStdString strDBpath = StringUtils::Format("musicdb://albums/%i/", album.idAlbum);
275 CStdString strSQLAlbum = StringUtils::Format("idAlbum=%i", album.idAlbum);
276 CStdString strArtist = musicdatabase.GetSingleValue("albumview", "strArtists", strSQLAlbum);
278 home->SetProperty("LatestAlbum." + value + ".Title" , album.strAlbum);
279 home->SetProperty("LatestAlbum." + value + ".Year" , album.iYear);
280 home->SetProperty("LatestAlbum." + value + ".Artist" , strArtist);
281 home->SetProperty("LatestAlbum." + value + ".Rating" , album.iRating);
282 home->SetProperty("LatestAlbum." + value + ".Path" , strDBpath);
283 home->SetProperty("LatestAlbum." + value + ".Thumb" , strThumb);
284 home->SetProperty("LatestAlbum." + value + ".Fanart" , strFanart);
287 for (; i < NUM_ITEMS; ++i)
289 CStdString value = StringUtils::Format("%i", i + 1);
290 home->SetProperty("LatestAlbum." + value + ".Title" , "");
291 home->SetProperty("LatestAlbum." + value + ".Year" , "");
292 home->SetProperty("LatestAlbum." + value + ".Artist" , "");
293 home->SetProperty("LatestAlbum." + value + ".Rating" , "");
294 home->SetProperty("LatestAlbum." + value + ".Path" , "");
295 home->SetProperty("LatestAlbum." + value + ".Thumb" , "");
296 home->SetProperty("LatestAlbum." + value + ".Fanart" , "");
299 musicdatabase.Close();
303 bool CRecentlyAddedJob::UpdateTotal()
305 CGUIWindow* home = g_windowManager.GetWindow(WINDOW_HOME);
310 CLog::Log(LOGDEBUG, "CRecentlyAddedJob::UpdateTotal() - Running RecentlyAdded home screen update");
312 CVideoDatabase videodatabase;
313 CMusicDatabase musicdatabase;
315 musicdatabase.Open();
316 int MusSongTotals = atoi(musicdatabase.GetSingleValue("songview" , "count(1)"));
317 int MusAlbumTotals = atoi(musicdatabase.GetSingleValue("songview" , "count(distinct strAlbum)"));
318 int MusArtistTotals = atoi(musicdatabase.GetSingleValue("songview" , "count(distinct strArtists)"));
319 musicdatabase.Close();
321 videodatabase.Open();
322 int tvShowCount = atoi(videodatabase.GetSingleValue("tvshowview" , "count(1)"));
323 int movieTotals = atoi(videodatabase.GetSingleValue("movieview" , "count(1)"));
324 int movieWatched = atoi(videodatabase.GetSingleValue("movieview" , "count(playCount)"));
325 int MusVidTotals = atoi(videodatabase.GetSingleValue("musicvideoview" , "count(1)"));
326 int MusVidWatched = atoi(videodatabase.GetSingleValue("musicvideoview" , "count(playCount)"));
327 int EpWatched = atoi(videodatabase.GetSingleValue("tvshowview" , "sum(watchedcount)"));
328 int EpCount = atoi(videodatabase.GetSingleValue("tvshowview" , "sum(totalcount)"));
329 int TvShowsWatched = atoi(videodatabase.GetSingleValue("tvshowview" , "sum(watchedcount = totalcount)"));
330 videodatabase.Close();
332 home->SetProperty("TVShows.Count" , tvShowCount);
333 home->SetProperty("TVShows.Watched" , TvShowsWatched);
334 home->SetProperty("TVShows.UnWatched" , tvShowCount - TvShowsWatched);
335 home->SetProperty("Episodes.Count" , EpCount);
336 home->SetProperty("Episodes.Watched" , EpWatched);
337 home->SetProperty("Episodes.UnWatched" , EpCount-EpWatched);
338 home->SetProperty("Movies.Count" , movieTotals);
339 home->SetProperty("Movies.Watched" , movieWatched);
340 home->SetProperty("Movies.UnWatched" , movieTotals - movieWatched);
341 home->SetProperty("MusicVideos.Count" , MusVidTotals);
342 home->SetProperty("MusicVideos.Watched" , MusVidWatched);
343 home->SetProperty("MusicVideos.UnWatched" , MusVidTotals - MusVidWatched);
344 home->SetProperty("Music.SongsCount" , MusSongTotals);
345 home->SetProperty("Music.AlbumsCount" , MusAlbumTotals);
346 home->SetProperty("Music.ArtistsCount" , MusArtistTotals);
352 bool CRecentlyAddedJob::DoWork()
356 ret &= UpdateMusic();
359 ret &= UpdateVideo();
362 ret &= UpdateTotal();