Skip to content

Commit

Permalink
Merge pull request xbmc#24477 from CrystalP/add-extra-validations
Browse files Browse the repository at this point in the history
[video] Adjust the validations and messages in add version/extra
  • Loading branch information
CrystalP authored Jan 11, 2024
2 parents d5e1c87 + 48257fc commit 39d7860
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 132 deletions.
40 changes: 38 additions & 2 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -23858,7 +23858,7 @@ msgctxt "#40018"
msgid "Remove video version"
msgstr ""

#. Add new video version dialog text
#. Manage versions, remove: removing the default version of a movie is not allowed.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40019"
msgid "The default version of a movie cannot be removed. Set a different default version and try again."
Expand Down Expand Up @@ -23938,7 +23938,43 @@ msgctxt "#40032"
msgid "No similar movies were found in the library."
msgstr ""

#empty strings with id 40033 to 40199
#. Addition of new version: a movie with multiple versions cannot be turned into a version of another movie.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40033"
msgid "The default version of a movie with multiple versions cannot be added as a version to another movie. Please add its additional versions first."
msgstr ""

#. Addition of new extra: a movie with multiple versions cannot be turned into an extra of another movie.
#: xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp
msgctxt "#40034"
msgid "The default version of a movie with multiple versions cannot be added as an extra to another movie. Please move or remove the other versions first."
msgstr ""

#. Addition of new version: the user picked an extra of another movie. Ask for confirmation.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40035"
msgid "You are about to convert a movie extra into a movie version. Are you sure?"
msgstr ""

#. Addition of new version: the user picked an extra of another movie. Ask for confirmation.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40036"
msgid "You are about to convert a movie version into a movie extra. Are you sure?"
msgstr ""

#. Addition of new version to a movie: the user chose a movie that has multiple versions. Ask for confirmation.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40037"
msgid "The movie to be added has multiple versions.[CR]The type of the default version will be selected in the next dialog. The other versions will keep their current type.[CR]Do you want to continue?"
msgstr ""

#. Addition of new version: the default version of a movie with multiple versions cannot be turned into a version of another movie.
#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
msgctxt "#40038"
msgid "The default version of a movie with multiple versions cannot be added to another movie. Please move or remove the other versions first."
msgstr ""

#empty strings with id 40039 to 40199

#. Select default video version setting
#: system/settings/settings.xml
Expand Down
80 changes: 35 additions & 45 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12223,9 +12223,12 @@ bool CVideoDatabase::GetDefaultVersionForVideo(VideoDbContentType itemType,
bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType,
int dbIdSource,
int dbIdTarget,
int idVideoVersion)
int idVideoVersion,
VideoAssetType assetType)
{
int idFile = -1;
MediaType mediaType;
VideoContentTypeToString(itemType, mediaType);

if (itemType == VideoDbContentType::MOVIES)
{
Expand All @@ -12241,24 +12244,22 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType,

if (dbIdSource != dbIdTarget)
{
// First transfer the extras to the new movie.
// A movie with versions cannot be transformed into a version of another movie so there is no
// problem with moving all extras to the new movie. With the the current data model it's not
// possible to tell which extras initially belonged to which version.
// Transfer all assets (versions, extras,...) to the new movie.
ExecuteQuery(
PrepareSQL("UPDATE videoversion SET idMedia = %i WHERE idMedia = %i AND itemType = %i",
dbIdTarget, dbIdSource, VideoAssetType::EXTRA));

ExecuteQuery(PrepareSQL("UPDATE videoversion SET idMedia = %i, idType = %i WHERE idFile = %i",
dbIdTarget, idVideoVersion, idFile));
PrepareSQL("UPDATE videoversion SET idMedia = %i WHERE idMedia = %i AND media_type = '%s'",
dbIdTarget, dbIdSource, mediaType.c_str()));

// version-level art doesn't need any change.
// 'movie' art is converted to 'videoversion' art.
SetVideoVersionDefaultArt(idFile, dbIdSource, itemType);

DeleteMovie(dbIdSource);
if (itemType == VideoDbContentType::MOVIES)
DeleteMovie(dbIdSource);
}
else
ExecuteQuery(PrepareSQL("UPDATE videoversion SET idType = %i WHERE idFile = %i", idVideoVersion,
idFile));

// Rename the default version
ExecuteQuery(PrepareSQL("UPDATE videoversion SET idType = %i, itemType = %i WHERE idFile = %i",
idVideoVersion, assetType, idFile));

CommitTransaction();

Expand Down Expand Up @@ -12319,13 +12320,13 @@ bool CVideoDatabase::IsDefaultVideoVersion(int idFile)
return false;
}

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

if (IsDefaultVideoVersion(dbId))
return;
return false;

try
{
Expand All @@ -12336,11 +12337,14 @@ void CVideoDatabase::RemoveVideoVersion(int dbId)
InvalidatePathHash(path);

m_pDS->exec(PrepareSQL("DELETE FROM videoversion WHERE idFile = %i", dbId));

return true;
}
catch (...)
{
CLog::Log(LOGERROR, "{} failed for {}", __FUNCTION__, dbId);
}
return false;
}

void CVideoDatabase::SetVideoVersion(int idFile, int idVideoVersion)
Expand Down Expand Up @@ -12420,30 +12424,16 @@ void CVideoDatabase::AddVideoVersion(VideoDbContentType itemType,
}
}

int CVideoDatabase::GetVideoVersionInfo(const std::string& fileNameAndPath,
int& idFile,
std::string& typeVideoVersion,
int& idMedia,
MediaType& mediaType,
VideoAssetType& videoAssetType)
VideoAssetInfo CVideoDatabase::GetVideoVersionInfo(const std::string& filenameAndPath)
{
idFile = GetFileId(fileNameAndPath);
if (idFile < 0)
return -1;
VideoAssetInfo info;

return GetVideoVersionInfo(idFile, typeVideoVersion, idMedia, mediaType, videoAssetType);
}
info.m_idFile = GetFileId(filenameAndPath);
if (info.m_idFile < 0)
return info;

int CVideoDatabase::GetVideoVersionInfo(int idFile,
std::string& typeVideoVersion,
int& idMedia,
MediaType& mediaType,
VideoAssetType& videoAssetType)
{
if (!m_pDB || !m_pDS)
return -1;

int idVideoVersion = -1;
return info;

try
{
Expand All @@ -12456,25 +12446,25 @@ int CVideoDatabase::GetVideoVersionInfo(int idFile,
" JOIN videoversiontype ON "
" videoversiontype.id = videoversion.idType "
"WHERE videoversion.idFile = %i",
idFile));
info.m_idFile));

if (m_pDS->num_rows() > 0)
{
idVideoVersion = m_pDS->fv("id").get_asInt();
typeVideoVersion = m_pDS->fv("name").get_asString();
idMedia = m_pDS->fv("idMedia").get_asInt();
mediaType = m_pDS->fv("media_type").get_asString();
videoAssetType = static_cast<VideoAssetType>(m_pDS->fv("itemType").get_asInt());
info.m_assetTypeId = m_pDS->fv("id").get_asInt();
info.m_assetTypeName = m_pDS->fv("name").get_asString();
info.m_idMedia = m_pDS->fv("idMedia").get_asInt();
info.m_mediaType = m_pDS->fv("media_type").get_asString();
info.m_assetType = static_cast<VideoAssetType>(m_pDS->fv("itemType").get_asInt());
}

m_pDS->close();
}
catch (...)
{
CLog::Log(LOGERROR, "{} failed for {}", __FUNCTION__, idFile);
CLog::LogF(LOGERROR, "failed for {}", filenameAndPath);
}

return idVideoVersion;
return info;
}

bool CVideoDatabase::GetVideoVersionsNav(const std::string& strBaseDir,
Expand Down
30 changes: 17 additions & 13 deletions xbmc/video/VideoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CVideoSettings;
class CGUIDialogProgress;
class CGUIDialogProgressBarHandle;

struct VideoAssetInfo;

enum class VideoAssetTypeOwner;
enum class VideoAssetType;

Expand Down Expand Up @@ -1013,10 +1015,22 @@ class CVideoDatabase : public CDatabase
CFileItemList& items,
VideoAssetType videoAssetType);
void GetDefaultVideoVersion(VideoDbContentType itemType, int dbId, CFileItem& item);

/*!
* \brief Remove a video from the library and transfer all of its assets to another video of the
* same type.
* \param itemType Type of the video being converted
* \param dbIdSource id of the video being converted
* \param dbIdTarget id that the video will be attached to
* \param idVideoVersion new versiontype of the default version of the video
* \param assetType new asset type of the default version of the video
* \return true for success, false otherwise
*/
bool ConvertVideoToVersion(VideoDbContentType itemType,
int dbIdSource,
int dbIdTarget,
int idVideoVersion);
int idVideoVersion,
VideoAssetType assetType);
void SetDefaultVideoVersion(VideoDbContentType itemType, int dbId, int idFile);
void SetVideoVersion(int idFile, int idVideoVersion);
int AddVideoVersionType(const std::string& typeVideoVersion,
Expand All @@ -1035,7 +1049,7 @@ class CVideoDatabase : public CDatabase
int dbId,
int idVideoVersion,
CFileItem& item);
void RemoveVideoVersion(int dbId);
bool RemoveVideoVersion(int dbId);
bool IsDefaultVideoVersion(int idFile);
bool GetVideoVersionTypes(VideoDbContentType idContent,
VideoAssetType asset,
Expand All @@ -1047,17 +1061,7 @@ class CVideoDatabase : public CDatabase
CFileItemList& items,
VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
const Filter& filter = Filter());
int GetVideoVersionInfo(const std::string& strFilenameAndPath,
int& idFile,
std::string& typeVideoVersion,
int& idMedia,
MediaType& mediaType,
VideoAssetType& videoAssetType);
int GetVideoVersionInfo(int idFile,
std::string& typeVideoVersion,
int& idMedia,
MediaType& mediaType,
VideoAssetType& videoAssetType);
VideoAssetInfo GetVideoVersionInfo(const std::string& filenameAndPath);
bool GetAssetsForVideo(VideoDbContentType itemType,
int mediaId,
VideoAssetType assetType,
Expand Down
10 changes: 10 additions & 0 deletions xbmc/video/VideoManagerTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ 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;

struct VideoAssetInfo
{
int m_idFile{-1};
int m_assetTypeId{-1};
std::string m_assetTypeName;
int m_idMedia{-1};
MediaType m_mediaType{MediaTypeNone};
VideoAssetType m_assetType{VideoAssetType::UNKNOWN};
};
Loading

0 comments on commit 39d7860

Please sign in to comment.