Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class SearchDefinitionFixture : CoreTest<MovieSearchCriteria>
[TestCase("Betty White\u00b4s Off Their Rockers", "Betty+Whites+Off+Their+Rockers")]
[TestCase("Betty White‘s Off Their Rockers", "Betty+Whites+Off+Their+Rockers")]
[TestCase("Betty White’s Off Their Rockers", "Betty+Whites+Off+Their+Rockers")]
[TestCase("Movie \"With Quotes\" Title", "Movie+With+Quotes+Title")]
[TestCase("Movie \u201CWith Quotes\u201D Title", "Movie+With+Quotes+Title")]
[TestCase("Movie \u201AWith Quotes\u201E Title", "Movie+With+Quotes+Title")]
[TestCase("Movie \u2039With Quotes\u203A Title", "Movie+With+Quotes+Title")]
[TestCase("Movie \u00ABWith Quotes\u00BB Title", "Movie+With+Quotes+Title")]
public void should_replace_some_special_characters(string input, string expected)
{
Subject.SceneTitles = new List<string> { input };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void should_delete_movie_file_from_database()
}

[Test]
public void should_delete_existing_file_fromdb_if_file_doesnt_exist()
public void should_delete_existing_file_fromdb_with_missing_reason_if_file_doesnt_exist()
{
GivenSingleMovieWithSingleMovieFile();

Expand All @@ -86,7 +86,7 @@ public void should_delete_existing_file_fromdb_if_file_doesnt_exist()

Subject.UpgradeMovieFile(_movieFile, _localMovie);

Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localMovie.Movie.MovieFile, DeleteMediaFileReason.Upgrade), Times.Once());
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localMovie.Movie.MovieFile, DeleteMediaFileReason.MissingFromDisk), Times.Once());
}

[Test]
Expand All @@ -111,6 +111,18 @@ public void should_return_old_movie_file_in_oldFiles()
Subject.UpgradeMovieFile(_movieFile, _localMovie).OldFiles.Count.Should().Be(1);
}

[Test]
public void should_not_return_old_movie_file_in_oldFiles_if_file_doesnt_exist()
{
GivenSingleMovieWithSingleMovieFile();

Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(false);

Subject.UpgradeMovieFile(_movieFile, _localMovie).OldFiles.Should().BeEmpty();
}

[Test]
public void should_throw_if_there_are_existing_movie_files_and_the_root_folder_is_missing()
{
Expand Down
6 changes: 6 additions & 0 deletions src/NzbDrone.Core/History/HistoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ public void Handle(MovieFileDeletedEvent message)
return;
}

if (message.Reason == DeleteMediaFileReason.MissingFromDisk)
{
_logger.Debug("Movie file already missing from disk, not creating history event.");
return;
}

var history = new MovieHistory
{
EventType = MovieHistoryEventType.MovieFileDeleted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
{
public abstract class SearchCriteriaBase
{
private static readonly Regex SpecialCharacter = new Regex(@"['.\u0060\u00B4\u2018\u2019]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex SpecialCharacter = new Regex(@"['"".`\u00B4\u2018\u2019\u201A\u201C\u201D\u201E\u2039\u203A\u00AB\u00BB]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex NonWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Expand Down
63 changes: 62 additions & 1 deletion src/NzbDrone.Core/MediaFiles/MediaInfo/VideoFileInfoReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public MediaInfoModel GetMediaInfo(string filename)
mediaInfoModel.VideoBitDepth = GetPixelFormat(primaryVideoStream?.PixelFormat)?.Components.Min(x => x.BitDepth) ?? 8;
mediaInfoModel.VideoColourPrimaries = primaryVideoStream?.ColorPrimaries;
mediaInfoModel.VideoTransferCharacteristics = primaryVideoStream?.ColorTransfer;
mediaInfoModel.DoviConfigurationRecord = primaryVideoStream?.SideDataList?.Find(x => x.GetType().Name == nameof(DoviConfigurationRecordSideData)) as DoviConfigurationRecordSideData;
mediaInfoModel.DoviConfigurationRecord = GetDoviConfigurationRecord(analysis, primaryVideoStream);
mediaInfoModel.Height = primaryVideoStream?.Height ?? 0;
mediaInfoModel.Width = primaryVideoStream?.Width ?? 0;
mediaInfoModel.AudioFormat = analysis.PrimaryAudioStream?.CodecName;
Expand Down Expand Up @@ -127,6 +127,16 @@ public MediaInfoModel GetMediaInfo(string filename)
var framesSideData = frames?.Frames?.Count > 0 ? frames?.Frames[0]?.SideDataList ?? new () : new ();

var sideData = streamSideData.Concat(framesSideData).ToList();

// If no Dolby Vision side data found on primary stream, check all other video streams
if (!sideData.Any(x => x.GetType().Name == nameof(DoviConfigurationRecordSideData)))
{
var dvSideData = GetDoviSideDataFromAllStreams(analysis, primaryVideoStream);
if (dvSideData.Count > 0)
{
sideData = sideData.Concat(dvSideData).ToList();
}
}
mediaInfoModel.VideoHdrFormat = GetHdrFormat(mediaInfoModel.VideoBitDepth, mediaInfoModel.VideoColourPrimaries, mediaInfoModel.VideoTransferCharacteristics, sideData);

return mediaInfoModel;
Expand Down Expand Up @@ -189,6 +199,57 @@ private VideoStream GetPrimaryVideoStream(IMediaAnalysis mediaAnalysis)
return mediaAnalysis.VideoStreams.FirstOrDefault(s => !codecFilter.Contains(s.CodecName)) ?? mediaAnalysis.PrimaryVideoStream;
}

private static DoviConfigurationRecordSideData GetDoviConfigurationRecord(IMediaAnalysis analysis, VideoStream primaryVideoStream)
{
// Check primary video stream first
var dovi = primaryVideoStream?.SideDataList?.Find(x => x.GetType().Name == nameof(DoviConfigurationRecordSideData)) as DoviConfigurationRecordSideData;

if (dovi != null)
{
return dovi;
}

// Check all other video streams for DV metadata (some releases have DV as a secondary stream)
foreach (var stream in analysis.VideoStreams)
{
if (stream == primaryVideoStream)
{
continue;
}

dovi = stream.SideDataList?.Find(x => x.GetType().Name == nameof(DoviConfigurationRecordSideData)) as DoviConfigurationRecordSideData;

if (dovi != null)
{
return dovi;
}
}

return null;
}

private static List<SideData> GetDoviSideDataFromAllStreams(IMediaAnalysis analysis, VideoStream primaryVideoStream)
{
var result = new List<SideData>();

foreach (var stream in analysis.VideoStreams)
{
if (stream == primaryVideoStream)
{
continue;
}

var dvSideData = stream.SideDataList?.Where(x => x.GetType().Name == nameof(DoviConfigurationRecordSideData)).ToList();

if (dvSideData?.Count > 0)
{
result.AddRange(dvSideData);
}
}

return result;
}

private FFProbePixelFormat GetPixelFormat(string format)
{
return _pixelFormats.Find(x => x.Name == format);
Expand Down
12 changes: 6 additions & 6 deletions src/NzbDrone.Core/MediaFiles/UpgradeMediaFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ public MovieFileMoveResult UpgradeMovieFile(MovieFile movieFile, LocalMovie loca
{
var movieFilePath = Path.Combine(localMovie.Movie.Path, existingFile.RelativePath);
var subfolder = rootFolder.GetRelativePath(_diskProvider.GetParentFolder(movieFilePath));
string recycleBinPath = null;

if (_diskProvider.FileExists(movieFilePath))
{
_logger.Debug("Removing existing movie file: {0}", existingFile);
recycleBinPath = _recycleBinProvider.DeleteFile(movieFilePath, subfolder);
var recycleBinPath = _recycleBinProvider.DeleteFile(movieFilePath, subfolder);

moveFileResult.OldFiles.Add(new DeletedMovieFile(existingFile, recycleBinPath));
_mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade);
}
else
{
_logger.Warn("Existing movie file missing from disk: {0}", movieFilePath);
_logger.Debug("Existing movie file missing from disk, removing from database without creating history event: {0}", movieFilePath);
_mediaFileService.Delete(existingFile, DeleteMediaFileReason.MissingFromDisk);
}

moveFileResult.OldFiles.Add(new DeletedMovieFile(existingFile, recycleBinPath));
_mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade);
}

localMovie.OldFiles = moveFileResult.OldFiles;
Expand Down