@@ -16,7 +16,8 @@ public class RemuxLibraryTask(IItemRepository _itemRepo,
1616 ITranscodeManager _transcodeManager ,
1717 IPluginManager _pluginManager ,
1818 ILogger < RemuxLibraryTask > _logger ,
19- IApplicationPaths _paths )
19+ IApplicationPaths _paths ,
20+ ILibraryManager _libraryManager )
2021 : IScheduledTask
2122{
2223 public string Name => "Remux Dolby Vision MKVs" ;
@@ -83,6 +84,9 @@ private bool ShouldProcessItem(Video item)
8384 var otherSources = item . GetMediaSources ( true ) ;
8485 if ( otherSources . Any ( s => s . Container == "mp4" ) ) return false ;
8586
87+ // or if there's an unmerged, standalone item at the expected path
88+ if ( _libraryManager . FindByPath ( item . Path + ".mp4" , false ) is not null ) return false ;
89+
8690 return true ;
8791 }
8892
@@ -102,6 +106,17 @@ private async Task ProcessOneItem(Video item, CancellationToken cancellationToke
102106 var finalPath = $ "{ inputPath } .mp4";
103107 var outputPath = Path . Combine ( _paths . TempDirectory , finalPath . GetHashCode ( ) + ".mp4" ) ;
104108
109+ if ( File . Exists ( finalPath ) )
110+ {
111+ throw new Exception ( $ "File already exists at { finalPath } ") ;
112+ }
113+
114+ if ( File . Exists ( outputPath ) )
115+ {
116+ _logger . LogWarning ( "Deleting temporary file at {OutputPath}" , outputPath ) ;
117+ File . Delete ( outputPath ) ;
118+ }
119+
105120 // truehd isn't supported by many consumer MP4 decoders even though ffmpeg can do it.
106121 // it's found on a lot of DoVi media (cough particularly hybrid remuxes cough),
107122 // but media like Bluray is required to have an AAC/AC3/whatever fallback stream for compatibility
0 commit comments