Skip to content

Commit

Permalink
[video] Do not lose extras of the movie added to another via Browse f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
CrystalP committed Jan 11, 2024
1 parent d4f5ff4 commit 48257fc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
8 changes: 7 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
14 changes: 13 additions & 1 deletion xbmc/video/VideoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 18 additions & 18 deletions xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand All @@ -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)};

Expand All @@ -223,10 +227,6 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra()

m_database.AddExtrasVideoVersion(itemType, dbId, idNewVideoVersion, item);

// refresh data and controls
Refresh();
UpdateControls();

return true;
}
return false;
Expand Down
22 changes: 12 additions & 10 deletions xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CFileItem>& item,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 48257fc

Please sign in to comment.