From 52ff554d0991394772ed77f8b92ad1703efa1fc9 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 02:00:16 -0500 Subject: [PATCH 1/8] [video] Refactor GetVideoVersionInfo parameters and return type --- xbmc/video/VideoDatabase.cpp | 44 +++++++------------ xbmc/video/VideoDatabase.h | 14 ++---- xbmc/video/VideoManagerTypes.h | 10 +++++ .../dialogs/GUIDialogVideoManagerExtras.cpp | 35 +++++++-------- .../dialogs/GUIDialogVideoManagerVersions.cpp | 44 +++++++++---------- 5 files changed, 63 insertions(+), 84 deletions(-) diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 2dc02a179ea04..9b14bddc9e2af 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -12420,30 +12420,16 @@ void CVideoDatabase::AddVideoVersion(VideoDbContentType itemType, } } -int CVideoDatabase::GetVideoVersionInfo(const std::string& fileNameAndPath, - int& idFile, - std::string& typeVideoVersion, - int& idMedia, - MediaType& mediaType, - VideoAssetType& videoAssetType) -{ - idFile = GetFileId(fileNameAndPath); - if (idFile < 0) - return -1; +VideoAssetInfo CVideoDatabase::GetVideoVersionInfo(const std::string& filenameAndPath) +{ + 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 { @@ -12456,25 +12442,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(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(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, diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 2a74ccadbafa2..84b6e415d37d8 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -26,6 +26,8 @@ class CVideoSettings; class CGUIDialogProgress; class CGUIDialogProgressBarHandle; +struct VideoAssetInfo; + enum class VideoAssetTypeOwner; enum class VideoAssetType; @@ -1047,17 +1049,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, diff --git a/xbmc/video/VideoManagerTypes.h b/xbmc/video/VideoManagerTypes.h index 264a6b493e1df..46ef4d1d9efe8 100644 --- a/xbmc/video/VideoManagerTypes.h +++ b/xbmc/video/VideoManagerTypes.h @@ -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}; +}; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index a9c0090bd517b..6447b2bcd191d 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -100,47 +100,42 @@ void CGUIDialogVideoManagerExtras::AddVideoExtra() sources, CServiceBroker::GetFileExtensionProvider().GetVideoExtensions(), g_localizeStrings.Get(40015), path)) { - std::string typeVideoVersion; - std::string videoTitle; - int idFile{-1}; - int idMedia{-1}; - MediaType itemMediaType; - VideoAssetType videoAssetType{VideoAssetType::UNKNOWN}; - - const int idVideoVersion{m_database.GetVideoVersionInfo(path, idFile, typeVideoVersion, idMedia, - itemMediaType, videoAssetType)}; - const int dbId{m_videoAsset->GetVideoInfoTag()->m_iDbId}; const VideoDbContentType itemType = m_videoAsset->GetVideoContentType(); - if (idVideoVersion != -1) + const VideoAssetInfo newAsset{m_database.GetVideoVersionInfo(path)}; + + if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { CFileItemList versions; - m_database.GetVideoVersions(itemType, dbId, versions, videoAssetType); + m_database.GetVideoVersions(itemType, dbId, versions, newAsset.m_assetType); if (std::any_of(versions.begin(), versions.end(), - [idFile](const std::shared_ptr& version) - { return version->GetVideoInfoTag()->m_iDbId == idFile; })) + [newAsset](const std::shared_ptr& version) + { return version->GetVideoInfoTag()->m_iDbId == newAsset.m_idFile; })) { CGUIDialogOK::ShowAndGetInput( - CVariant{40015}, StringUtils::Format(g_localizeStrings.Get(40026), typeVideoVersion)); + CVariant{40015}, + StringUtils::Format(g_localizeStrings.Get(40026), newAsset.m_assetTypeName)); return; } - if (itemMediaType == MediaTypeMovie) + std::string videoTitle; + + if (newAsset.m_mediaType == MediaTypeMovie) { - videoTitle = m_database.GetMovieTitle(idMedia); + videoTitle = m_database.GetMovieTitle(newAsset.m_idMedia); } else return; if (!CGUIDialogYesNo::ShowAndGetInput( - CVariant{40014}, - StringUtils::Format(g_localizeStrings.Get(40027), typeVideoVersion, videoTitle))) + CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40027), + newAsset.m_assetTypeName, videoTitle))) { return; } - m_database.RemoveVideoVersion(idFile); + m_database.RemoveVideoVersion(newAsset.m_idFile); } CFileItem item{path, false}; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 778a06ca74f7c..3a5832f4a8e4c 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -452,9 +452,7 @@ bool CGUIDialogVideoManagerVersions::ProcessVideoVersion(VideoDbContentType item bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() { - const int dbId{m_videoAsset->GetVideoInfoTag()->m_iDbId}; const MediaType mediaType{m_videoAsset->GetVideoInfoTag()->m_type}; - const VideoDbContentType itemType{m_videoAsset->GetVideoContentType()}; // prompt to choose a video file VECSOURCES sources{*CMediaSourceSettings::GetInstance().GetSources("files")}; @@ -468,48 +466,46 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() sources, CServiceBroker::GetFileExtensionProvider().GetVideoExtensions(), g_localizeStrings.Get(40014), path)) { - std::string typeVideoVersion; - std::string videoTitle; - int idFile{-1}; - int idMedia{-1}; - MediaType itemMediaType; - VideoAssetType videoAssetType{VideoAssetType::UNKNOWN}; + const int dbId{m_videoAsset->GetVideoInfoTag()->m_iDbId}; + const VideoDbContentType itemType{m_videoAsset->GetVideoContentType()}; - const int idVideoVersion{m_database.GetVideoVersionInfo(path, idFile, typeVideoVersion, idMedia, - itemMediaType, videoAssetType)}; + const VideoAssetInfo newAsset{m_database.GetVideoVersionInfo(path)}; // @todo look only for a version identified by idFile instead of retrieving all versions - if (idVideoVersion != -1) + if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { CFileItemList versions; - m_database.GetVideoVersions(itemType, dbId, versions, videoAssetType); + m_database.GetVideoVersions(itemType, dbId, versions, newAsset.m_assetType); if (std::any_of(versions.begin(), versions.end(), - [idFile](const std::shared_ptr& version) - { return version->GetVideoInfoTag()->m_iDbId == idFile; })) + [newAsset](const std::shared_ptr& version) + { return version->GetVideoInfoTag()->m_iDbId == newAsset.m_idFile; })) { CGUIDialogOK::ShowAndGetInput( - CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40016), typeVideoVersion)); + CVariant{40014}, + StringUtils::Format(g_localizeStrings.Get(40016), newAsset.m_assetTypeName)); return false; } - if (itemMediaType == MediaTypeMovie) + std::string videoTitle; + + if (newAsset.m_mediaType == MediaTypeMovie) { - videoTitle = m_database.GetMovieTitle(idMedia); + videoTitle = m_database.GetMovieTitle(newAsset.m_idMedia); } else return false; if (!CGUIDialogYesNo::ShowAndGetInput( - CVariant{40014}, - StringUtils::Format(g_localizeStrings.Get(40017), typeVideoVersion, videoTitle))) + CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40017), + newAsset.m_assetTypeName, videoTitle))) { return false; } - if (m_database.IsDefaultVideoVersion(idFile)) + if (m_database.IsDefaultVideoVersion(newAsset.m_idFile)) { CFileItemList list; - m_database.GetVideoVersions(itemType, idMedia, list, videoAssetType); + m_database.GetVideoVersions(itemType, newAsset.m_idMedia, list, newAsset.m_assetType); if (list.Size() > 1) { @@ -518,16 +514,16 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() } else { - if (itemMediaType == MediaTypeMovie) + if (newAsset.m_mediaType == MediaTypeMovie) { - m_database.DeleteMovie(idMedia); + m_database.DeleteMovie(newAsset.m_idMedia); } else return false; } } else - m_database.RemoveVideoVersion(idFile); + m_database.RemoveVideoVersion(newAsset.m_idFile); } CFileItem item{path, false}; From 8456711411f117ec1b9a56b981f85d72b032512a Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 02:24:02 -0500 Subject: [PATCH 2/8] [video] Add success return code to AddVideoExtra --- xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp | 14 ++++++++++---- xbmc/video/dialogs/GUIDialogVideoManagerExtras.h | 6 +++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index 6447b2bcd191d..f3c25e605c820 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -84,7 +84,7 @@ void CGUIDialogVideoManagerExtras::SetVideoAsset(const std::shared_ptrGet(0)); } -void CGUIDialogVideoManagerExtras::AddVideoExtra() +bool CGUIDialogVideoManagerExtras::AddVideoExtra() { const MediaType mediaType{m_videoAsset->GetVideoInfoTag()->m_type}; @@ -116,7 +116,7 @@ void CGUIDialogVideoManagerExtras::AddVideoExtra() CGUIDialogOK::ShowAndGetInput( CVariant{40015}, StringUtils::Format(g_localizeStrings.Get(40026), newAsset.m_assetTypeName)); - return; + return false; } std::string videoTitle; @@ -126,13 +126,13 @@ void CGUIDialogVideoManagerExtras::AddVideoExtra() videoTitle = m_database.GetMovieTitle(newAsset.m_idMedia); } else - return; + return false; if (!CGUIDialogYesNo::ShowAndGetInput( CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40027), newAsset.m_assetTypeName, videoTitle))) { - return; + return false; } m_database.RemoveVideoVersion(newAsset.m_idFile); @@ -154,12 +154,18 @@ void CGUIDialogVideoManagerExtras::AddVideoExtra() const int idNewVideoVersion{m_database.AddVideoVersionType( typeNewVideoVersion, VideoAssetTypeOwner::AUTO, VideoAssetType::EXTRA)}; + if (idNewVideoVersion == -1) + return false; + m_database.AddExtrasVideoVersion(itemType, dbId, idNewVideoVersion, item); // refresh data and controls Refresh(); UpdateControls(); + + return true; } + return false; } void CGUIDialogVideoManagerExtras::ManageVideoExtras(const std::shared_ptr& item) diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.h b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.h index cbb6d48474f8f..8874775cd6fb1 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.h +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.h @@ -38,6 +38,10 @@ class CGUIDialogVideoManagerExtras : public CGUIDialogVideoManager void UpdateButtons() override; private: - void AddVideoExtra(); + /*! + * \brief Add an extra to the video, using GUI user-provided information. + * \return true if an extra was added, false otherwise. + */ + bool AddVideoExtra(); static std::string GenerateVideoExtra(const std::string& extrasPath); }; From 1e40641726cfe1fc89f554aca8d30bab5e9f2798 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 02:54:59 -0500 Subject: [PATCH 3/8] [video] Add error handling to video version removal --- xbmc/video/VideoDatabase.cpp | 9 ++++++--- xbmc/video/VideoDatabase.h | 2 +- xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp | 4 +++- xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 9b14bddc9e2af..0990a8d28c4ef 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -12319,13 +12319,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 { @@ -12336,11 +12336,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) diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 84b6e415d37d8..45cfda3402059 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -1037,7 +1037,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, diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index f3c25e605c820..d1562ef729b34 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -135,7 +135,9 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() return false; } - m_database.RemoveVideoVersion(newAsset.m_idFile); + // @todo: should be in a database transaction with the addition as a new version below + if (!m_database.RemoveVideoVersion(newAsset.m_idFile)) + return false; } CFileItem item{path, false}; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 3a5832f4a8e4c..951c3540262d0 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -516,6 +516,7 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() { if (newAsset.m_mediaType == MediaTypeMovie) { + // @todo: should be in a database transaction with the addition as a new version below m_database.DeleteMovie(newAsset.m_idMedia); } else @@ -523,7 +524,11 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() } } else - m_database.RemoveVideoVersion(newAsset.m_idFile); + { + // @todo: should be in a database transaction with the addition as a new version below + if (!m_database.RemoveVideoVersion(newAsset.m_idFile)) + return false; + } } CFileItem item{path, false}; From 28789fd1ceaedd145d11f607936f1f71e34585c5 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 02:59:55 -0500 Subject: [PATCH 4/8] [video] Fix incorrect message in version addition --- addons/resource.language.en_gb/resources/strings.po | 10 ++++++++-- xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index 878ad0b897e67..e1e1fc86b000f 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -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." @@ -23938,7 +23938,13 @@ 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 "" + +#empty strings with id 40034 to 40199 #. Select default video version setting #: system/settings/settings.xml diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 951c3540262d0..48658d9a39965 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -509,7 +509,8 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() if (list.Size() > 1) { - CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40019}); + // cannot add the default version of a movie with multiple versions as version of another movie + CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40033}); return false; } else From 10a1907cb86260b3c1c9762cd86399528265aa46 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 04:40:27 -0500 Subject: [PATCH 5/8] [video] Revise/align Add version/extra validations and clarify messages --- .../resources/strings.po | 8 +- .../dialogs/GUIDialogVideoManagerExtras.cpp | 82 +++++++++++++++---- .../dialogs/GUIDialogVideoManagerVersions.cpp | 65 +++++++++++---- 3 files changed, 123 insertions(+), 32 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index e1e1fc86b000f..f603773118cb2 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -23944,7 +23944,13 @@ 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 "" -#empty strings with id 40034 to 40199 +#. 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 "" + +#empty strings with id 40035 to 40199 #. Select default video version setting #: system/settings/settings.xml diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index d1562ef729b34..6ee1374615d1c 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -86,6 +86,8 @@ void CGUIDialogVideoManagerExtras::SetVideoAsset(const std::shared_ptrGetVideoInfoTag()->m_type}; // prompt to choose a video file @@ -107,20 +109,31 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { - CFileItemList versions; - m_database.GetVideoVersions(itemType, dbId, versions, newAsset.m_assetType); - if (std::any_of(versions.begin(), versions.end(), - [newAsset](const std::shared_ptr& version) - { return version->GetVideoInfoTag()->m_iDbId == newAsset.m_idFile; })) + // The video already is an asset of the movie + if (newAsset.m_idMedia == dbId && + newAsset.m_mediaType == m_videoAsset->GetVideoInfoTag()->m_type) { + unsigned int msgid{}; + + if (newAsset.m_assetType == VideoAssetType::VERSION) + msgid = 40016; // video is a version of the movie + else if (newAsset.m_assetType == VideoAssetType::EXTRA) + msgid = 40026; // video is an extra of the movie + else + { + CLog::LogF(LOGERROR, "unexpected asset type {}", static_cast(newAsset.m_assetType)); + return false; + } + CGUIDialogOK::ShowAndGetInput( CVariant{40015}, - StringUtils::Format(g_localizeStrings.Get(40026), newAsset.m_assetTypeName)); + StringUtils::Format(g_localizeStrings.Get(msgid), newAsset.m_assetTypeName)); return false; } - std::string videoTitle; + // The video is an asset of another movie + std::string videoTitle; if (newAsset.m_mediaType == MediaTypeMovie) { videoTitle = m_database.GetMovieTitle(newAsset.m_idMedia); @@ -128,16 +141,57 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() else return false; - if (!CGUIDialogYesNo::ShowAndGetInput( - CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40027), - newAsset.m_assetTypeName, videoTitle))) { - return false; + unsigned int msgid{}; + + if (newAsset.m_assetType == VideoAssetType::VERSION) + msgid = 40017; // video is a version of another movie + else if (newAsset.m_assetType == VideoAssetType::EXTRA) + msgid = 40027; // video is an extra of another movie + else + { + CLog::LogF(LOGERROR, "unexpected asset type {}", static_cast(newAsset.m_assetType)); + return false; + } + + if (!CGUIDialogYesNo::ShowAndGetInput( + CVariant{40015}, StringUtils::Format(g_localizeStrings.Get(msgid), + newAsset.m_assetTypeName, videoTitle))) + { + return false; + } } - // @todo: should be in a database transaction with the addition as a new version below - if (!m_database.RemoveVideoVersion(newAsset.m_idFile)) - return false; + // Additional constraints for the converion of a movie version + if (newAsset.m_assetType == VideoAssetType::VERSION && + m_database.IsDefaultVideoVersion(newAsset.m_idFile)) + { + CFileItemList list; + m_database.GetVideoVersions(itemType, newAsset.m_idMedia, list, newAsset.m_assetType); + + if (list.Size() > 1) + { + // cannot add the default version of a movie with multiple versions to another movie + CGUIDialogOK::ShowAndGetInput(CVariant{40015}, CVariant{40034}); + return false; + } + else + { + if (newAsset.m_mediaType == MediaTypeMovie) + { + // @todo: should be in a database transaction with the addition as a new asset below + m_database.DeleteMovie(newAsset.m_idMedia); + } + else + return false; + } + } + else + { + // @todo: should be in a database transaction with the addition as a new asset below + if (!m_database.RemoveVideoVersion(newAsset.m_idFile)) + return false; + } } CFileItem item{path, false}; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 48658d9a39965..7fbe389aa94b0 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -452,6 +452,8 @@ bool CGUIDialogVideoManagerVersions::ProcessVideoVersion(VideoDbContentType item bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() { + // @todo: combine with extras add file logic, structured similarly and sharing most logic. + const MediaType mediaType{m_videoAsset->GetVideoInfoTag()->m_type}; // prompt to choose a video file @@ -474,20 +476,31 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() // @todo look only for a version identified by idFile instead of retrieving all versions if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { - CFileItemList versions; - m_database.GetVideoVersions(itemType, dbId, versions, newAsset.m_assetType); - if (std::any_of(versions.begin(), versions.end(), - [newAsset](const std::shared_ptr& version) - { return version->GetVideoInfoTag()->m_iDbId == newAsset.m_idFile; })) + // The video already is an asset of the movie + if (newAsset.m_idMedia == dbId && + newAsset.m_mediaType == m_videoAsset->GetVideoInfoTag()->m_type) { + unsigned int msgid{}; + + if (newAsset.m_assetType == VideoAssetType::VERSION) + msgid = 40016; // video is a version of the movie + else if (newAsset.m_assetType == VideoAssetType::EXTRA) + msgid = 40026; // video is an extra of the movie + else + { + CLog::LogF(LOGERROR, "unexpected asset type {}", static_cast(newAsset.m_assetType)); + return false; + } + CGUIDialogOK::ShowAndGetInput( CVariant{40014}, - StringUtils::Format(g_localizeStrings.Get(40016), newAsset.m_assetTypeName)); + StringUtils::Format(g_localizeStrings.Get(msgid), newAsset.m_assetTypeName)); return false; } - std::string videoTitle; + // The video is an asset of another movie + std::string videoTitle; if (newAsset.m_mediaType == MediaTypeMovie) { videoTitle = m_database.GetMovieTitle(newAsset.m_idMedia); @@ -495,21 +508,37 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() else return false; - if (!CGUIDialogYesNo::ShowAndGetInput( - CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(40017), - newAsset.m_assetTypeName, videoTitle))) { - return false; + unsigned int msgid{}; + + if (newAsset.m_assetType == VideoAssetType::VERSION) + msgid = 40017; // video is a version of another movie + else if (newAsset.m_assetType == VideoAssetType::EXTRA) + msgid = 40027; // video is an extra of another movie + else + { + CLog::LogF(LOGERROR, "unexpected asset type {}", static_cast(newAsset.m_assetType)); + return false; + } + + if (!CGUIDialogYesNo::ShowAndGetInput( + CVariant{40014}, StringUtils::Format(g_localizeStrings.Get(msgid), + newAsset.m_assetTypeName, videoTitle))) + { + return false; + } } - if (m_database.IsDefaultVideoVersion(newAsset.m_idFile)) + // Additional constraints for the conversion of a movie version + if (newAsset.m_assetType == VideoAssetType::VERSION && + m_database.IsDefaultVideoVersion(newAsset.m_idFile)) { CFileItemList list; m_database.GetVideoVersions(itemType, newAsset.m_idMedia, list, newAsset.m_assetType); if (list.Size() > 1) { - // cannot add the default version of a movie with multiple versions as version of another movie + // cannot add the default version of a movie with multiple versions to another movie CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40033}); return false; } @@ -517,7 +546,7 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() { if (newAsset.m_mediaType == MediaTypeMovie) { - // @todo: should be in a database transaction with the addition as a new version below + // @todo: should be in a database transaction with the addition as a new asset below m_database.DeleteMovie(newAsset.m_idMedia); } else @@ -526,7 +555,7 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() } else { - // @todo: should be in a database transaction with the addition as a new version below + // @todo: should be in a database transaction with the addition as a new asset below if (!m_database.RemoveVideoVersion(newAsset.m_idFile)) return false; } @@ -543,8 +572,10 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() } const int idNewVideoVersion{ChooseVideoAsset(m_videoAsset, VideoAssetType::VERSION)}; - if (idNewVideoVersion != -1) - m_database.AddPrimaryVideoVersion(itemType, dbId, idNewVideoVersion, item); + if (idNewVideoVersion == -1) + return false; + + m_database.AddPrimaryVideoVersion(itemType, dbId, idNewVideoVersion, item); return true; } From 92dd629dc337e98b482491161ec01a6b8b38be4a Mon Sep 17 00:00:00 2001 From: CrystalP Date: Tue, 9 Jan 2024 04:49:52 -0500 Subject: [PATCH 6/8] [video] Ask the user for confirmation when turning a version into an extra or vice-versa --- .../resource.language.en_gb/resources/strings.po | 14 +++++++++++++- xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp | 8 ++++++++ .../dialogs/GUIDialogVideoManagerVersions.cpp | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index f603773118cb2..57c44ea9760ad 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -23950,7 +23950,19 @@ 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 "" -#empty strings with id 40035 to 40199 +#. 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 "" + +#empty strings with id 40037 to 40199 #. Select default video version setting #: system/settings/settings.xml diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index 6ee1374615d1c..027f9d3f1b9f7 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -133,6 +133,14 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() // The video is an asset of another movie + // The video is a version, ask for confirmation + if (newAsset.m_assetType == VideoAssetType::VERSION && + !CGUIDialogYesNo::ShowAndGetInput(CVariant{40015}, + StringUtils::Format(g_localizeStrings.Get(40036)))) + { + return false; + } + std::string videoTitle; if (newAsset.m_mediaType == MediaTypeMovie) { diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 7fbe389aa94b0..1b8290be94649 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -500,6 +500,14 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() // The video is an asset of another movie + // The video is an extra, ask for confirmation + if (newAsset.m_assetType == VideoAssetType::EXTRA && + !CGUIDialogYesNo::ShowAndGetInput(CVariant{40014}, + StringUtils::Format(g_localizeStrings.Get(40035)))) + { + return false; + } + std::string videoTitle; if (newAsset.m_mediaType == MediaTypeMovie) { From d4f5ff486a7f12ca07cad85e5c26662c339061d9 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Wed, 10 Jan 2024 05:22:23 -0500 Subject: [PATCH 7/8] [video] Fix conversion of movies with multiple versions (with user confirmation) --- .../resources/strings.po | 8 +++++- xbmc/video/VideoDatabase.cpp | 26 +++++++++---------- .../dialogs/GUIDialogVideoManagerVersions.cpp | 10 +++++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index 57c44ea9760ad..d8d9453f1865b 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -23962,7 +23962,13 @@ msgctxt "#40036" msgid "You are about to convert a movie version into a movie extra. Are you sure?" msgstr "" -#empty strings with id 40037 to 40199 +#. 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 "" + +#empty strings with id 40038 to 40199 #. Select default video version setting #: system/settings/settings.xml diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 0990a8d28c4ef..b97252ae750d0 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -12226,6 +12226,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, int idVideoVersion) { int idFile = -1; + MediaType mediaType; + VideoContentTypeToString(itemType, mediaType); if (itemType == VideoDbContentType::MOVIES) { @@ -12241,24 +12243,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 WHERE idFile = %i", idVideoVersion, idFile)); CommitTransaction(); diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 1b8290be94649..48cee292e9106 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -353,6 +353,16 @@ bool CGUIDialogVideoManagerVersions::ChooseVideoAndConvertToVideoVersion( if (!selectedItem) return false; + CFileItemList list; + videoDb.GetVideoVersions(itemType, selectedItem->GetVideoInfoTag()->m_iDbId, list, + VideoAssetType::VERSION); + + // ask confirmation for the addition of a movie with multiple versions to another movie + if (list.Size() > 1 && !CGUIDialogYesNo::ShowAndGetInput(CVariant{40014}, CVariant{40037})) + { + return false; + } + // choose a video version for the video const int idVideoVersion{ChooseVideoAsset(selectedItem, VideoAssetType::VERSION)}; if (idVideoVersion < 0) From 48257fc6521cc89c2934f9ceea46a07697afc6d8 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Thu, 11 Jan 2024 02:52:55 -0500 Subject: [PATCH 8/8] [video] Do not lose extras of the movie added to another via Browse files --- .../resources/strings.po | 8 ++++- xbmc/video/VideoDatabase.cpp | 7 ++-- xbmc/video/VideoDatabase.h | 14 +++++++- .../dialogs/GUIDialogVideoManagerExtras.cpp | 36 +++++++++---------- .../dialogs/GUIDialogVideoManagerVersions.cpp | 22 ++++++------ 5 files changed, 54 insertions(+), 33 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index d8d9453f1865b..625c113f7a4f2 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -23968,7 +23968,13 @@ 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 "" -#empty strings with id 40038 to 40199 +#. 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 diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index b97252ae750d0..a422b7ff5c7e5 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -12223,7 +12223,8 @@ 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; @@ -12257,8 +12258,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, } // Rename the default version - ExecuteQuery( - PrepareSQL("UPDATE videoversion SET idType = %i WHERE idFile = %i", idVideoVersion, idFile)); + ExecuteQuery(PrepareSQL("UPDATE videoversion SET idType = %i, itemType = %i WHERE idFile = %i", + idVideoVersion, assetType, idFile)); CommitTransaction(); diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 45cfda3402059..e7762feaf6a6d 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -1015,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, diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index 027f9d3f1b9f7..e35da64f90be8 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -53,7 +53,12 @@ bool CGUIDialogVideoManagerExtras::OnMessage(CGUIMessage& message) const int control{message.GetSenderId()}; if (control == CONTROL_BUTTON_ADD_EXTRAS) { - AddVideoExtra(); + if (AddVideoExtra()) + { + // refresh data and controls + Refresh(); + UpdateControls(); + } } break; } @@ -107,6 +112,9 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() const VideoAssetInfo newAsset{m_database.GetVideoVersionInfo(path)}; + std::string typeNewVideoVersion{ + CGUIDialogVideoManagerExtras::GenerateVideoExtra(URIUtils::GetFileName(path))}; + if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { // The video already is an asset of the movie @@ -183,16 +191,15 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() CGUIDialogOK::ShowAndGetInput(CVariant{40015}, CVariant{40034}); return false; } - else - { - if (newAsset.m_mediaType == MediaTypeMovie) - { - // @todo: should be in a database transaction with the addition as a new asset below - m_database.DeleteMovie(newAsset.m_idMedia); - } - else - return false; - } + + const int idNewVideoVersion{m_database.AddVideoVersionType( + typeNewVideoVersion, VideoAssetTypeOwner::AUTO, VideoAssetType::EXTRA)}; + + if (idNewVideoVersion == -1) + return false; + + return m_database.ConvertVideoToVersion(itemType, newAsset.m_idMedia, dbId, + idNewVideoVersion, VideoAssetType::EXTRA); } else { @@ -212,9 +219,6 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() CURL::GetRedacted(item.GetPath())); } - const std::string typeNewVideoVersion{ - CGUIDialogVideoManagerExtras::GenerateVideoExtra(URIUtils::GetFileName(path))}; - const int idNewVideoVersion{m_database.AddVideoVersionType( typeNewVideoVersion, VideoAssetTypeOwner::AUTO, VideoAssetType::EXTRA)}; @@ -223,10 +227,6 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() m_database.AddExtrasVideoVersion(itemType, dbId, idNewVideoVersion, item); - // refresh data and controls - Refresh(); - UpdateControls(); - return true; } return false; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 48cee292e9106..46bb3f159765e 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -383,7 +383,8 @@ bool CGUIDialogVideoManagerVersions::ChooseVideoAndConvertToVideoVersion( return false; } - return videoDb.ConvertVideoToVersion(itemType, sourceDbId, targetDbId, idVideoVersion); + return videoDb.ConvertVideoToVersion(itemType, sourceDbId, targetDbId, idVideoVersion, + VideoAssetType::VERSION); } bool CGUIDialogVideoManagerVersions::GetAllOtherMovies(const std::shared_ptr& item, @@ -557,18 +558,19 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() if (list.Size() > 1) { // cannot add the default version of a movie with multiple versions to another movie - CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40033}); + CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40038}); return false; } + + const int idNewVideoVersion{ChooseVideoAsset(m_videoAsset, VideoAssetType::VERSION)}; + if (idNewVideoVersion != -1) + { + return m_database.ConvertVideoToVersion(itemType, newAsset.m_idMedia, dbId, + idNewVideoVersion, VideoAssetType::VERSION); + } else { - if (newAsset.m_mediaType == MediaTypeMovie) - { - // @todo: should be in a database transaction with the addition as a new asset below - m_database.DeleteMovie(newAsset.m_idMedia); - } - else - return false; + return false; } } else @@ -645,7 +647,7 @@ bool CGUIDialogVideoManagerVersions::AddSimilarMovieAsVersion( const int sourceDbId{itemMovie->GetVideoInfoTag()->m_iDbId}; const int targetDbId{m_videoAsset->GetVideoInfoTag()->m_iDbId}; return videoDb.ConvertVideoToVersion(VideoDbContentType::MOVIES, sourceDbId, targetDbId, - idVideoVersion); + idVideoVersion, VideoAssetType::VERSION); } bool CGUIDialogVideoManagerVersions::PostProcessList(CFileItemList& list, int dbId)