2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "VideoDatabaseDirectory.h"
13 #include "ServiceBroker.h"
14 #include "VideoDatabaseDirectory/QueryParams.h"
15 #include "guilib/LocalizeStrings.h"
16 #include "guilib/TextureManager.h"
17 #include "settings/Settings.h"
18 #include "settings/SettingsComponent.h"
19 #include "utils/Crc32.h"
20 #include "utils/LegacyPathTranslation.h"
21 #include "utils/StringUtils.h"
22 #include "utils/URIUtils.h"
23 #include "video/VideoDatabase.h"
25 using namespace XFILE
;
26 using namespace VIDEODATABASEDIRECTORY
;
28 CVideoDatabaseDirectory::CVideoDatabaseDirectory(void) = default;
30 CVideoDatabaseDirectory::~CVideoDatabaseDirectory(void) = default;
32 bool CVideoDatabaseDirectory::GetDirectory(const CURL
& url
, CFileItemList
&items
)
34 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(url
);
36 items
.m_dwSize
= -1; // No size
37 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
42 bool bResult
= pNode
->GetChilds(items
);
43 for (int i
=0;i
<items
.Size();++i
)
45 CFileItemPtr item
= items
[i
];
46 if (item
->m_bIsFolder
&& !item
->HasArt("icon") && !item
->HasArt("thumb"))
48 std::string strImage
= GetIcon(item
->GetPath());
49 if (!strImage
.empty() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture(strImage
))
50 item
->SetArt("icon", strImage
);
52 if (item
->GetVideoInfoTag())
54 item
->SetDynPath(item
->GetVideoInfoTag()->GetPath());
57 if (items
.HasProperty("customtitle"))
58 items
.SetLabel(items
.GetProperty("customtitle").asString());
60 items
.SetLabel(pNode
->GetLocalizedName());
65 NODE_TYPE
CVideoDatabaseDirectory::GetDirectoryChildType(const std::string
& strPath
)
67 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strPath
);
68 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
71 return NODE_TYPE_NONE
;
73 return pNode
->GetChildType();
76 NODE_TYPE
CVideoDatabaseDirectory::GetDirectoryType(const std::string
& strPath
)
78 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strPath
);
79 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
82 return NODE_TYPE_NONE
;
84 return pNode
->GetType();
87 NODE_TYPE
CVideoDatabaseDirectory::GetDirectoryParentType(const std::string
& strPath
)
89 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strPath
);
90 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
93 return NODE_TYPE_NONE
;
95 CDirectoryNode
* pParentNode
=pNode
->GetParent();
98 return NODE_TYPE_NONE
;
100 return pParentNode
->GetChildType();
103 bool CVideoDatabaseDirectory::GetQueryParams(const std::string
& strPath
, CQueryParams
& params
)
105 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strPath
);
106 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
111 CDirectoryNode::GetDatabaseInfo(strPath
,params
);
115 void CVideoDatabaseDirectory::ClearDirectoryCache(const std::string
& strDirectory
)
117 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strDirectory
);
118 URIUtils::RemoveSlashAtEnd(path
);
120 uint32_t crc
= Crc32::ComputeFromLowerCase(path
);
122 std::string strFileName
= StringUtils::Format("special://temp/archive_cache/{:08x}.fi", crc
);
123 CFile::Delete(strFileName
);
126 bool CVideoDatabaseDirectory::IsAllItem(const std::string
& strDirectory
)
128 if (StringUtils::EndsWith(strDirectory
, "/-1/"))
133 bool CVideoDatabaseDirectory::GetLabel(const std::string
& strDirectory
, std::string
& strLabel
)
137 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strDirectory
);
138 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
139 if (!pNode
|| path
.empty())
142 // first see if there's any filter criteria
144 CDirectoryNode::GetDatabaseInfo(path
, params
);
146 CVideoDatabase videodatabase
;
147 if (!videodatabase
.Open())
151 if (params
.GetGenreId() != -1)
152 strLabel
+= videodatabase
.GetGenreById(params
.GetGenreId());
155 if (params
.GetCountryId() != -1)
156 strLabel
+= videodatabase
.GetCountryById(params
.GetCountryId());
159 if (params
.GetSetId() != -1)
160 strLabel
+= videodatabase
.GetSetById(params
.GetSetId());
163 if (params
.GetTagId() != -1)
164 strLabel
+= videodatabase
.GetTagById(params
.GetTagId());
167 if (params
.GetYear() != -1)
169 std::string strTemp
= std::to_string(params
.GetYear());
170 if (!strLabel
.empty())
175 if (strLabel
.empty())
177 switch (pNode
->GetChildType())
179 case NODE_TYPE_TITLE_MOVIES
:
180 case NODE_TYPE_TITLE_TVSHOWS
:
181 case NODE_TYPE_TITLE_MUSICVIDEOS
:
182 strLabel
= g_localizeStrings
.Get(369); break;
183 case NODE_TYPE_ACTOR
: // Actor
184 strLabel
= g_localizeStrings
.Get(344); break;
185 case NODE_TYPE_GENRE
: // Genres
186 strLabel
= g_localizeStrings
.Get(135); break;
187 case NODE_TYPE_COUNTRY
: // Countries
188 strLabel
= g_localizeStrings
.Get(20451); break;
189 case NODE_TYPE_YEAR
: // Year
190 strLabel
= g_localizeStrings
.Get(562); break;
191 case NODE_TYPE_DIRECTOR
: // Director
192 strLabel
= g_localizeStrings
.Get(20348); break;
193 case NODE_TYPE_SETS
: // Sets
194 strLabel
= g_localizeStrings
.Get(20434); break;
195 case NODE_TYPE_TAGS
: // Tags
196 strLabel
= g_localizeStrings
.Get(20459); break;
197 case NODE_TYPE_MOVIES_OVERVIEW
: // Movies
198 strLabel
= g_localizeStrings
.Get(342); break;
199 case NODE_TYPE_TVSHOWS_OVERVIEW
: // TV Shows
200 strLabel
= g_localizeStrings
.Get(20343); break;
201 case NODE_TYPE_RECENTLY_ADDED_MOVIES
: // Recently Added Movies
202 strLabel
= g_localizeStrings
.Get(20386); break;
203 case NODE_TYPE_RECENTLY_ADDED_EPISODES
: // Recently Added Episodes
204 strLabel
= g_localizeStrings
.Get(20387); break;
205 case NODE_TYPE_STUDIO
: // Studios
206 strLabel
= g_localizeStrings
.Get(20388); break;
207 case NODE_TYPE_MUSICVIDEOS_OVERVIEW
: // Music Videos
208 strLabel
= g_localizeStrings
.Get(20389); break;
209 case NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS
: // Recently Added Music Videos
210 strLabel
= g_localizeStrings
.Get(20390); break;
211 case NODE_TYPE_SEASONS
: // Seasons
212 strLabel
= g_localizeStrings
.Get(33054); break;
213 case NODE_TYPE_EPISODES
: // Episodes
214 strLabel
= g_localizeStrings
.Get(20360); break;
215 case NODE_TYPE_INPROGRESS_TVSHOWS
: // InProgress TvShows
216 strLabel
= g_localizeStrings
.Get(626); break;
225 std::string
CVideoDatabaseDirectory::GetIcon(const std::string
&strDirectory
)
227 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strDirectory
);
228 switch (GetDirectoryChildType(path
))
230 case NODE_TYPE_TITLE_MOVIES
:
231 if (URIUtils::PathEquals(path
, "videodb://movies/titles/"))
233 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYVIDEOS_FLATTEN
))
234 return "DefaultMovies.png";
235 return "DefaultMovieTitle.png";
238 case NODE_TYPE_TITLE_TVSHOWS
:
239 if (URIUtils::PathEquals(path
, "videodb://tvshows/titles/"))
241 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYVIDEOS_FLATTEN
))
242 return "DefaultTVShows.png";
243 return "DefaultTVShowTitle.png";
246 case NODE_TYPE_TITLE_MUSICVIDEOS
:
247 if (URIUtils::PathEquals(path
, "videodb://musicvideos/titles/"))
249 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYVIDEOS_FLATTEN
))
250 return "DefaultMusicVideos.png";
251 return "DefaultMusicVideoTitle.png";
254 case NODE_TYPE_ACTOR
: // Actor
255 return "DefaultActor.png";
256 case NODE_TYPE_GENRE
: // Genres
257 return "DefaultGenre.png";
258 case NODE_TYPE_COUNTRY
: // Countries
259 return "DefaultCountry.png";
260 case NODE_TYPE_SETS
: // Sets
261 return "DefaultSets.png";
262 case NODE_TYPE_TAGS
: // Tags
263 return "DefaultTags.png";
264 case NODE_TYPE_YEAR
: // Year
265 return "DefaultYear.png";
266 case NODE_TYPE_DIRECTOR
: // Director
267 return "DefaultDirector.png";
268 case NODE_TYPE_MOVIES_OVERVIEW
: // Movies
269 return "DefaultMovies.png";
270 case NODE_TYPE_TVSHOWS_OVERVIEW
: // TV Shows
271 return "DefaultTVShows.png";
272 case NODE_TYPE_RECENTLY_ADDED_MOVIES
: // Recently Added Movies
273 return "DefaultRecentlyAddedMovies.png";
274 case NODE_TYPE_RECENTLY_ADDED_EPISODES
: // Recently Added Episodes
275 return "DefaultRecentlyAddedEpisodes.png";
276 case NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS
: // Recently Added Episodes
277 return "DefaultRecentlyAddedMusicVideos.png";
278 case NODE_TYPE_INPROGRESS_TVSHOWS
: // InProgress TvShows
279 return "DefaultInProgressShows.png";
280 case NODE_TYPE_STUDIO
: // Studios
281 return "DefaultStudios.png";
282 case NODE_TYPE_MUSICVIDEOS_OVERVIEW
: // Music Videos
283 return "DefaultMusicVideos.png";
284 case NODE_TYPE_MUSICVIDEOS_ALBUM
: // Music Videos - Albums
285 return "DefaultMusicAlbums.png";
293 bool CVideoDatabaseDirectory::ContainsMovies(const std::string
&path
)
295 VIDEODATABASEDIRECTORY::NODE_TYPE type
= GetDirectoryChildType(path
);
296 if (type
== VIDEODATABASEDIRECTORY::NODE_TYPE_TITLE_MOVIES
|| type
== VIDEODATABASEDIRECTORY::NODE_TYPE_EPISODES
|| type
== VIDEODATABASEDIRECTORY::NODE_TYPE_TITLE_MUSICVIDEOS
) return true;
300 bool CVideoDatabaseDirectory::Exists(const CURL
& url
)
302 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(url
);
303 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
308 if (pNode
->GetChildType() == VIDEODATABASEDIRECTORY::NODE_TYPE_NONE
)
314 bool CVideoDatabaseDirectory::CanCache(const std::string
& strPath
)
316 std::string path
= CLegacyPathTranslation::TranslateVideoDbPath(strPath
);
317 std::unique_ptr
<CDirectoryNode
> pNode(CDirectoryNode::ParseURL(path
));
320 return pNode
->CanCache();