Repository: xbmc/xbmc
File: xbmc/video/VideoDatabase.cpp (C++)

Code before:
    CLog::LogF(LOGERROR, "({}) failed", idSet);
  }
  RollbackTransaction();
  return -1;
}

int CVideoDatabase::AddMovieVersion(CFileItem& item, int idMovie, const ART::Artwork& art)
{
  CVideoInfoTag* tag{item.GetVideoInfoTag()};

  const int idFile{
      AddFile(item.GetDynPath(), "", tag->m_dateAdded, tag->GetPlayCount(), tag->m_lastPlayed)};
  if (idFile < 0)
    return -1;
  item.GetVideoInfoTag()->m_iFileId = idFile;

  if (tag->HasStreamDetails() && !SetStreamDetailsForFileId(tag->m_streamDetails, idFile))
    return -1;

  if (!AddVideoVersion(item.GetVideoContentType(), idMovie, idFile, tag->GetAssetInfo().GetId(),
                       VideoAssetType::VERSION))
    return -1;

  for (const auto& [type, url] : art)
    if (!SetArtForItem(idFile, MediaTypeVideoVersion, type, url))
      return -1;

  return idFile;
}

int CVideoDatabase::GetMatchingTvShow(const CVideoInfoTag& details) const
{
  // first try matching on uniqueid, then on title + year
  int id = -1;
  if (details.HasUniqueID())
  {
    //! @todo better handling when no default uniqueid is defined ("unknown" - legacy nfo)
    //! @todo loop through the non-default uniqueid when no match is found

    id = GetDbId(PrepareSQL("SELECT uniqueid.media_id FROM uniqueid "
                            "JOIN tvshow ON uniqueid.media_id=tvshow.idShow "
                            "WHERE uniqueid.media_type='%s' "
                            "AND uniqueid.value='%s' "
                            "AND uniqueid.type='%s' ",
                            MediaTypeTvShow, details.GetUniqueID().c_str(),
                            details.GetDefaultUniqueID().c_str()));
  }
  if (id < 0)
    id = GetDbId(PrepareSQL("SELECT idShow FROM tvshow WHERE c%02d='%s' AND c%02d='%s'",
                            VIDEODB_ID_TV_TITLE, details.m_strTitle.c_str(),
                            VIDEODB_ID_TV_PREMIERED, details.GetPremiered().GetAsDBDate().c_str()));

Review comment (suggestion):
suggestion, use the other version of SetArtForItem, no loop needed in the caller:
```
if (!SetArtForItem(idFile, MediaTypeVideoVersion, art))
      return -1;
```

Code after:
    CLog::LogF(LOGERROR, "({}) failed", idSet);
  }
  RollbackTransaction();
  return -1;
}

int CVideoDatabase::AddMovieVersion(CFileItem& item, int idMovie, const ART::Artwork& art)
{
  CVideoInfoTag* tag{item.GetVideoInfoTag()};

  const int idFile{
      AddFile(item.GetDynPath(), "", tag->m_dateAdded, tag->GetPlayCount(), tag->m_lastPlayed)};
  if (idFile < 0)
    return -1;
  item.GetVideoInfoTag()->m_iFileId = idFile;

  if (tag->HasStreamDetails() && !SetStreamDetailsForFileId(tag->m_streamDetails, idFile))
    return -1;

  if (!AddOrUpdateVideoVersion(item.GetVideoContentType(), idMovie, idFile,
                               tag->GetAssetInfo().GetId(), VideoAssetType::VERSION))
    return -1;

  if (!SetArtForItem(idFile, MediaTypeVideoVersion, art))
    return -1;

  return idFile;
}

int CVideoDatabase::GetMatchingTvShow(const CVideoInfoTag& details) const
{
  // first try matching on uniqueid, then on title + year
  int id = -1;
  if (details.HasUniqueID())
  {
    //! @todo better handling when no default uniqueid is defined ("unknown" - legacy nfo)
    //! @todo loop through the non-default uniqueid when no match is found

    id = GetDbId(PrepareSQL("SELECT uniqueid.media_id FROM uniqueid "
                            "JOIN tvshow ON uniqueid.media_id=tvshow.idShow "
                            "WHERE uniqueid.media_type='%s' "
                            "AND uniqueid.value='%s' "
                            "AND uniqueid.type='%s' ",
                            MediaTypeTvShow, details.GetUniqueID().c_str(),
                            details.GetDefaultUniqueID().c_str()));
  }
  if (id < 0)
    id = GetDbId(PrepareSQL("SELECT idShow FROM tvshow WHERE c%02d='%s' AND c%02d='%s'",
                            VIDEODB_ID_TV_TITLE, details.m_strTitle.c_str(),
                            VIDEODB_ID_TV_PREMIERED, details.GetPremiered().GetAsDBDate().c_str()));
  return id;