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.
9 #include "VideoDatabaseFile.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)
23 CVideoDatabaseFile::~CVideoDatabaseFile(void) = default;
25 CVideoInfoTag
CVideoDatabaseFile::GetVideoTag(const CURL
& url
)
29 std::string strFileName
= URIUtils::GetFileName(url
.Get());
30 if (strFileName
.empty())
33 URIUtils::RemoveExtension(strFileName
);
34 if (!StringUtils::IsNaturalNumber(strFileName
))
36 long idDb
= atol(strFileName
.c_str());
38 VideoDbContentType type
= GetType(url
);
39 if (type
== VideoDbContentType::UNKNOWN
)
42 CVideoDatabase videoDatabase
;
43 if (!videoDatabase
.Open())
46 tag
= videoDatabase
.GetDetailsByTypeAndId(type
, idDb
);
51 VideoDbContentType
CVideoDatabaseFile::GetType(const CURL
& url
)
53 std::string strPath
= URIUtils::GetDirectory(url
.Get());
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
;
70 type
= VideoDbContentType::UNKNOWN
;
76 std::string
CVideoDatabaseFile::TranslatePath(const CURL
& url
)
78 std::string strFileName
= URIUtils::GetFileName(url
.Get());
79 if (strFileName
.empty())
82 URIUtils::RemoveExtension(strFileName
);
83 if (!StringUtils::IsNaturalNumber(strFileName
))
85 long idDb
= atol(strFileName
.c_str());
87 VideoDbContentType type
= GetType(url
);
88 if (type
== VideoDbContentType::UNKNOWN
)
91 CVideoDatabase videoDatabase
;
92 if (!videoDatabase
.Open())
95 std::string realFilename
;
96 videoDatabase
.GetFilePathById(idDb
, realFilename
, type
);