Skip to content

Commit

Permalink
Merge pull request xbmc#24253 from ksooo/video-infotag-remove-videodb…
Browse files Browse the repository at this point in the history
…-dep

[video] CVideoInfoTag: Remove CVideoDataBase dependency.
  • Loading branch information
ksooo authored Dec 17, 2023
2 parents 140dc86 + 770acd0 commit 9c5cba0
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 57 deletions.
1 change: 1 addition & 0 deletions xbmc/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(HEADERS Bookmark.h
VideoLibraryQueue.h
VideoThumbLoader.h
VideoUtils.h
VideoVersionTypes.h
ViewModeSettings.h)

core_add_library(video)
30 changes: 8 additions & 22 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
#include "video/VideoDbUrl.h"
#include "video/VideoInfoTag.h"
#include "video/VideoLibraryQueue.h"
#include "video/windows/GUIWindowVideoBase.h"
#include "video/VideoThumbLoader.h"
#include "video/VideoVersionTypes.h"

#include <algorithm>
#include <map>
Expand Down Expand Up @@ -11778,25 +11779,6 @@ int CVideoDatabase::AddVideoVersionType(const std::string& typeVideoVersion,
return id;
}

bool CVideoDatabase::IsVideoExtras(int dbId)
{
if (!m_pDB || !m_pDS)
return false;

try
{
return static_cast<VideoVersionItemType>(GetSingleValueInt(
PrepareSQL("SELECT itemType FROM videoversion WHERE idFile = %i", dbId))) ==
VideoVersionItemType::EXTRAS;
}
catch (...)
{
CLog::Log(LOGERROR, "{} failed for {} {}", __FUNCTION__, dbId);
}

return false;
}

void CVideoDatabase::GetVideoVersions(VideoDbContentType itemType, int dbId, CFileItemList& items)
{
// get main video versions
Expand Down Expand Up @@ -11865,6 +11847,7 @@ void CVideoDatabase::GetVideoVersions(VideoDbContentType itemType,
infoTag.m_idVideoVersion = id;
infoTag.m_typeVideoVersion = name;
infoTag.m_strTitle = name;
infoTag.m_videoVersionItemType = versionItemType;

infoTag.m_strPictureURL = videoItem.GetVideoInfoTag()->m_strPictureURL;
infoTag.m_fanart = videoItem.GetVideoInfoTag()->m_fanart;
Expand Down Expand Up @@ -11908,7 +11891,8 @@ void CVideoDatabase::GetDefaultVideoVersion(VideoDbContentType itemType, int dbI
mediaType = MediaTypeMovie;
strSQL = PrepareSQL("SELECT videoversiontype.name AS name,"
" videoversiontype.id AS id,"
" videoversion.idFile AS idFile "
" videoversion.idFile AS idFile,"
" videoversion.itemType AS itemType "
"FROM videoversiontype"
" JOIN videoversion ON"
" videoversion.idType = videoversiontype.id"
Expand All @@ -11929,7 +11913,8 @@ void CVideoDatabase::GetDefaultVideoVersion(VideoDbContentType itemType, int dbI
std::string name = m_pDS->fv("name").get_asString();
int id = m_pDS->fv("id").get_asInt();
int idFile = m_pDS->fv("idFile").get_asInt();

const auto versionItemType{
static_cast<VideoVersionItemType>(m_pDS->fv("itemType").get_asInt())};
CVideoInfoTag infoTag;
if (GetFileInfo("", infoTag, idFile))
{
Expand All @@ -11938,6 +11923,7 @@ void CVideoDatabase::GetDefaultVideoVersion(VideoDbContentType itemType, int dbI
infoTag.m_idVideoVersion = id;
infoTag.m_typeVideoVersion = name;
infoTag.m_strTitle = name;
infoTag.m_videoVersionItemType = versionItemType;

item.SetFromVideoInfoTag(infoTag);
item.m_strTitle = name;
Expand Down
25 changes: 3 additions & 22 deletions xbmc/video/VideoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CVideoSettings;
class CGUIDialogProgress;
class CGUIDialogProgressBarHandle;

enum class VideoVersionTypeOwner;
enum class VideoVersionItemType;

namespace dbiplus
{
class field_value;
Expand Down Expand Up @@ -393,27 +396,6 @@ const struct SDbTableOffsets DbMusicVideoOffsets[] =
#define COMPARE_PERCENTAGE 0.90f // 90%
#define COMPARE_PERCENTAGE_MIN 0.50f // 50%

// Video Versions
enum class VideoVersionTypeOwner
{
UNKNOWN = -1,
SYSTEM = 0,
AUTO = 1,
USER = 2
};

enum class VideoVersionItemType
{
UNKNOWN = -1,
PRIMARY = 0,
EXTRAS = 1
};

static constexpr int VIDEO_VERSION_ID_BEGIN = 40400;
static constexpr int VIDEO_VERSION_ID_END = 40800;
static constexpr int VIDEO_VERSION_ID_DEFAULT = VIDEO_VERSION_ID_BEGIN;
static constexpr int VIDEO_VERSION_ID_ALL = 0;

class CVideoDatabase : public CDatabase
{
public:
Expand Down Expand Up @@ -1014,7 +996,6 @@ class CVideoDatabase : public CDatabase
std::string GetVideoVersionById(int id);
bool GetVideoItemByVideoVersion(int dbId, CFileItem& item);
int GetVideoVersionFile(VideoDbContentType itemType, int dbId, int idVideoVersion);
bool IsVideoExtras(int dbId);
void GetVideoVersions(VideoDbContentType itemType, int dbId, CFileItemList& items);
void GetVideoVersions(VideoDbContentType itemType,
int dbId,
Expand Down
1 change: 1 addition & 0 deletions xbmc/video/VideoInfoScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "utils/Variant.h"
#include "utils/log.h"
#include "video/VideoThumbLoader.h"
#include "video/VideoVersionTypes.h"
#include "video/dialogs/GUIDialogVideoVersion.h"

#include <algorithm>
Expand Down
26 changes: 13 additions & 13 deletions xbmc/video/VideoInfoTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "utils/Variant.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"
#include "video/VideoDatabase.h"
#include "video/VideoVersionTypes.h"

#include <algorithm>
#include <sstream>
Expand All @@ -45,6 +45,9 @@ void CVideoInfoTag::Reset()
m_set.overview.clear();
m_tags.clear();
m_typeVideoVersion.clear();
m_idVideoVersion = -1;
m_hasVideoVersions = false;
m_videoVersionItemType = VideoVersionItemType::UNKNOWN;
m_strFile.clear();
m_strPath.clear();
m_strMPAARating.clear();
Expand Down Expand Up @@ -226,6 +229,8 @@ bool CVideoInfoTag::Save(TiXmlNode *node, const std::string &tag, bool savePathI
XMLUtils::SetStringArray(movie, "tag", m_tags);
XMLUtils::SetString(movie, "videoversion", m_typeVideoVersion);
XMLUtils::SetInt(movie, "videoversionid", m_idVideoVersion);
XMLUtils::SetBoolean(movie, "hasvideoversions", m_hasVideoVersions);
XMLUtils::SetInt(movie, "videoversionitemtype", static_cast<int>(m_videoVersionItemType));
XMLUtils::SetStringArray(movie, "credits", m_writingCredits);
XMLUtils::SetStringArray(movie, "director", m_director);
if (HasPremiered())
Expand Down Expand Up @@ -512,6 +517,7 @@ void CVideoInfoTag::Archive(CArchive& ar)
ar << m_typeVideoVersion;
ar << m_idVideoVersion;
ar << m_hasVideoVersions;
ar << static_cast<int>(m_videoVersionItemType);
ar << m_duration;
ar << m_strFile;
ar << m_strPath;
Expand Down Expand Up @@ -617,6 +623,9 @@ void CVideoInfoTag::Archive(CArchive& ar)
ar >> m_typeVideoVersion;
ar >> m_idVideoVersion;
ar >> m_hasVideoVersions;
int versionItemType{0};
ar >> versionItemType;
m_videoVersionItemType = static_cast<VideoVersionItemType>(versionItemType);
ar >> m_duration;
ar >> m_strFile;
ar >> m_strPath;
Expand Down Expand Up @@ -738,6 +747,8 @@ void CVideoInfoTag::Serialize(CVariant& value) const
value["tag"] = m_tags;
value["videoversion"] = m_typeVideoVersion;
value["videoversionid"] = m_idVideoVersion;
value["hasvideoversions"] = m_hasVideoVersions;
value["videoversionitemtype"] = static_cast<int>(m_videoVersionItemType);
value["runtime"] = GetDuration();
value["file"] = m_strFile;
value["path"] = m_strPath;
Expand Down Expand Up @@ -1822,16 +1833,5 @@ bool CVideoInfoTag::SetResumePoint(double timeInSeconds, double totalTimeInSecon

bool CVideoInfoTag::IsVideoExtras() const
{
if (m_type == MediaTypeVideoVersion)
{
CVideoDatabase videodb;
if (videodb.Open())
{
return videodb.IsVideoExtras(m_iDbId);
}
else
CLog::Log(LOGERROR, "{}: Failed to open database", __FUNCTION__);
}

return false;
return m_videoVersionItemType == VideoVersionItemType::EXTRAS;
}
3 changes: 3 additions & 0 deletions xbmc/video/VideoInfoTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TiXmlNode;
class TiXmlElement;
class CVariant;

enum class VideoVersionItemType;

struct SActorInfo
{
bool operator<(const SActorInfo &right) const
Expand Down Expand Up @@ -245,6 +247,7 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
std::string m_typeVideoVersion;
int m_idVideoVersion{-1};
bool m_hasVideoVersions{false};
VideoVersionItemType m_videoVersionItemType{-1};
std::string m_strFile;
std::string m_strPath;
std::string m_strMPAARating;
Expand Down
29 changes: 29 additions & 0 deletions xbmc/video/VideoVersionTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2023 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

enum class VideoVersionTypeOwner
{
UNKNOWN = -1,
SYSTEM = 0,
AUTO = 1,
USER = 2
};

enum class VideoVersionItemType
{
UNKNOWN = -1,
PRIMARY = 0,
EXTRAS = 1
};

static constexpr int VIDEO_VERSION_ID_BEGIN = 40400;
static constexpr int VIDEO_VERSION_ID_END = 40800;
static constexpr int VIDEO_VERSION_ID_DEFAULT = VIDEO_VERSION_ID_BEGIN;
static constexpr int VIDEO_VERSION_ID_ALL = 0;
1 change: 1 addition & 0 deletions xbmc/video/dialogs/GUIDialogVideoVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "video/VideoInfoTag.h"
#include "video/VideoThumbLoader.h"
#include "video/VideoUtils.h"
#include "video/VideoVersionTypes.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "video/guilib/VideoPlayActionProcessor.h"

Expand Down
1 change: 1 addition & 0 deletions xbmc/video/guilib/VideoVersionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "utils/log.h"
#include "video/VideoDatabase.h"
#include "video/VideoThumbLoader.h"
#include "video/VideoVersionTypes.h"

using namespace VIDEO::GUILIB;

Expand Down
1 change: 1 addition & 0 deletions xbmc/video/windows/GUIWindowVideoBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "video/VideoInfoScanner.h"
#include "video/VideoLibraryQueue.h"
#include "video/VideoUtils.h"
#include "video/VideoVersionTypes.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "video/guilib/VideoPlayActionProcessor.h"
#include "video/guilib/VideoSelectActionProcessor.h"
Expand Down

0 comments on commit 9c5cba0

Please sign in to comment.