Skip to content

Commit

Permalink
[video] Fix conversion of movies with multiple versions (with user co…
Browse files Browse the repository at this point in the history
…nfirmation)
  • Loading branch information
CrystalP committed Jan 11, 2024
1 parent 92dd629 commit d4f5ff4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 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 @@ -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
Expand Down
26 changes: 13 additions & 13 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12226,6 +12226,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType,
int idVideoVersion)
{
int idFile = -1;
MediaType mediaType;
VideoContentTypeToString(itemType, mediaType);

if (itemType == VideoDbContentType::MOVIES)
{
Expand All @@ -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();

Expand Down
10 changes: 10 additions & 0 deletions xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4f5ff4

Please sign in to comment.