[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / filesystem / VideoDatabaseFile.cpp
blob036eeba77d9387ae9c7ef8be7968cd0ac7686020
1 /*
2 * Copyright (C) 2005-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.
7 */
9 #include "VideoDatabaseFile.h"
11 #include "URL.h"
12 #include "utils/StringUtils.h"
13 #include "utils/URIUtils.h"
14 #include "video/VideoDatabase.h"
15 #include "video/VideoInfoTag.h"
17 using namespace XFILE;
19 CVideoDatabaseFile::CVideoDatabaseFile(void)
20 : COverrideFile(true)
21 { }
23 CVideoDatabaseFile::~CVideoDatabaseFile(void) = default;
25 CVideoInfoTag CVideoDatabaseFile::GetVideoTag(const CURL& url)
27 CVideoInfoTag tag;
29 std::string strFileName = URIUtils::GetFileName(url.Get());
30 if (strFileName.empty())
31 return tag;
33 URIUtils::RemoveExtension(strFileName);
34 if (!StringUtils::IsNaturalNumber(strFileName))
35 return tag;
36 long idDb = atol(strFileName.c_str());
38 VideoDbContentType type = GetType(url);
39 if (type == VideoDbContentType::UNKNOWN)
40 return tag;
42 CVideoDatabase videoDatabase;
43 if (!videoDatabase.Open())
44 return tag;
46 tag = videoDatabase.GetDetailsByTypeAndId(type, idDb);
48 return tag;
51 VideoDbContentType CVideoDatabaseFile::GetType(const CURL& url)
53 std::string strPath = URIUtils::GetDirectory(url.Get());
54 if (strPath.empty())
55 return VideoDbContentType::UNKNOWN;
57 std::vector<std::string> pathElem = StringUtils::Split(strPath, "/");
58 if (pathElem.size() == 0)
59 return VideoDbContentType::UNKNOWN;
61 std::string itemType = pathElem.at(2);
62 VideoDbContentType type;
63 if (itemType == "movies" || itemType == "recentlyaddedmovies")
64 type = VideoDbContentType::MOVIES;
65 else if (itemType == "episodes" || itemType == "recentlyaddedepisodes" || itemType == "inprogresstvshows" || itemType == "tvshows")
66 type = VideoDbContentType::EPISODES;
67 else if (itemType == "musicvideos" || itemType == "recentlyaddedmusicvideos")
68 type = VideoDbContentType::MUSICVIDEOS;
69 else
70 type = VideoDbContentType::UNKNOWN;
72 return type;
76 std::string CVideoDatabaseFile::TranslatePath(const CURL& url)
78 std::string strFileName = URIUtils::GetFileName(url.Get());
79 if (strFileName.empty())
80 return "";
82 URIUtils::RemoveExtension(strFileName);
83 if (!StringUtils::IsNaturalNumber(strFileName))
84 return "";
85 long idDb = atol(strFileName.c_str());
87 VideoDbContentType type = GetType(url);
88 if (type == VideoDbContentType::UNKNOWN)
89 return "";
91 CVideoDatabase videoDatabase;
92 if (!videoDatabase.Open())
93 return "";
95 std::string realFilename;
96 videoDatabase.GetFilePathById(idDb, realFilename, type);
98 return realFilename;