Repository: xbmc/xbmc
File: xbmc/application/ApplicationPlayerCallback.cpp (C++)

Code before:
    return;

  // Adjust paths of new fileItem for physical/removable blurays
  // If first play then DynPath contains the mpls played
  // If resume then DynPath is empty and VideoInfoTag()->m_strFileNameAndPath contains the mpls played
  if (fileItem.HasVideoInfoTag() &&
      fileItem.GetVideoInfoTag()->m_strFileNameAndPath.starts_with("bluray://removable"))
  {
    std::string newPath;
    const std::string dynPath{fileItem.GetDynPath()};
    const std::string tagPath{fileItem.GetVideoInfoTag()->m_strFileNameAndPath};
    if (URIUtils::IsBlurayPath(dynPath))
    {
      // First play
      CURL url{tagPath};
      const CURL fileUrl{dynPath};
      url.SetFileName(fileUrl.GetFileName());
      newPath = url.Get();
      fileItem.GetVideoInfoTag()->SetFileNameAndPath(newPath);
    }
    else
    {
      // Resume
      newPath = tagPath;
    }
    fileItem.SetDynPath(newPath);
    fileItem.SetPath(newPath);
  }

  if (stackHelper->GetRegisteredStack(fileItem) != nullptr)
  {
    if (stackHelper->GetRegisteredStackTotalTimeMs(fileItem) > 0)
    {
      // Regular (not disc image) stack case: We have to save the bookmark on the stack.
      fileItem = *stackHelper->GetRegisteredStack(file);

      // The bookmark coming from the player is only relative to the current part, thus needs
      // to be corrected with these attributes (start time will be 0 for non-stackparts).
      bookmark.timeInSeconds += stackHelper->GetRegisteredStackPartStartTimeMs(file) / 1000.0;

      const uint64_t registeredStackTotalTimeMs{stackHelper->GetRegisteredStackTotalTimeMs(file)};
      if (registeredStackTotalTimeMs > 0)
        bookmark.totalTimeInSeconds = registeredStackTotalTimeMs / 1000.0;
    }
    // Any stack case: We need to save the part number.
    bookmark.partNumber =
        stackHelper->GetRegisteredStackPartNumber(file) + 1; // CBookmark part numbers are 1-based
  }

  percent = bookmark.timeInSeconds / bookmark.totalTimeInSeconds * 100;


Review comment (suggestion):
DynPath falls back to Path if path is set and dynpath isn't. Storing state in two places could introduce inconsistencies. DynPath is made to be dynamic, but path isn't. If we're updating the non-dynamic component, I feel like we should clear the dynpath (or leave it empty) to convey the intention that it's the non-dynamic path being set and not the dynamic one.

Code after:
    return;

  // Adjust paths of new fileItem for physical/removable blurays
  // DynPath contains the mpls (playlist) played
  // VideoInfoTag()->m_strFileNameAndPath contains the removable:// path
  // We need to update DynPath with the removable:// path (for the database), keeping the playlist
  if (fileItem.HasVideoInfoTag() &&
      fileItem.GetVideoInfoTag()->m_strFileNameAndPath.starts_with("bluray://removable"))
  {
    const std::string dynPath{fileItem.GetDynPath()};
    if (URIUtils::IsBlurayPath(dynPath))
    {
      CURL url{fileItem.GetVideoInfoTag()->m_strFileNameAndPath};
      const CURL fileUrl{dynPath};
      url.SetFileName(fileUrl.GetFileName());
      fileItem.SetPath(url.Get());
      fileItem.SetDynPath("");
    }
  }

  if (stackHelper->GetRegisteredStack(fileItem) != nullptr)
  {
    if (stackHelper->GetRegisteredStackTotalTimeMs(fileItem) > 0)
    {
      // Regular (not disc image) stack case: We have to save the bookmark on the stack.
      fileItem = *stackHelper->GetRegisteredStack(file);

      // The bookmark coming from the player is only relative to the current part, thus needs
      // to be corrected with these attributes (start time will be 0 for non-stackparts).
      bookmark.timeInSeconds += stackHelper->GetRegisteredStackPartStartTimeMs(file) / 1000.0;

      const uint64_t registeredStackTotalTimeMs{stackHelper->GetRegisteredStackTotalTimeMs(file)};
      if (registeredStackTotalTimeMs > 0)
        bookmark.totalTimeInSeconds = registeredStackTotalTimeMs / 1000.0;
    }
    // Any stack case: We need to save the part number.
    bookmark.partNumber =
        stackHelper->GetRegisteredStackPartNumber(file) + 1; // CBookmark part numbers are 1-based
  }

  percent = bookmark.timeInSeconds / bookmark.totalTimeInSeconds * 100;

  const std::shared_ptr<CAdvancedSettings> advancedSettings =
      CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();

  if ((MUSIC::IsAudio(fileItem) && advancedSettings->m_audioPlayCountMinimumPercent > 0 &&
       percent >= advancedSettings->m_audioPlayCountMinimumPercent) ||
      (VIDEO::IsVideo(fileItem) && advancedSettings->m_videoPlayCountMinimumPercent > 0 &&
       percent >= advancedSettings->m_videoPlayCountMinimumPercent))
  {
    playCountUpdate = true;