fix subtitle syncing
This commit is contained in:
@@ -233,57 +233,45 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
|
||||
await semaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
// Check again in case of lock contention
|
||||
try
|
||||
{
|
||||
if (File.Exists(cacheFilePath))
|
||||
{
|
||||
semaphore.Release();
|
||||
return cacheFilePath;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
semaphore.Release();
|
||||
throw;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var newWidth = Convert.ToInt32(newSize.Width);
|
||||
var newHeight = Convert.ToInt32(newSize.Height);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(options.BackgroundColor))
|
||||
if (!File.Exists(cacheFilePath))
|
||||
{
|
||||
using (var originalImage = new MagickWand(originalImagePath))
|
||||
{
|
||||
originalImage.CurrentImage.ResizeImage(newWidth, newHeight);
|
||||
var newWidth = Convert.ToInt32(newSize.Width);
|
||||
var newHeight = Convert.ToInt32(newSize.Height);
|
||||
|
||||
DrawIndicator(originalImage, newWidth, newHeight, options);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
||||
|
||||
originalImage.CurrentImage.CompressionQuality = quality;
|
||||
|
||||
originalImage.SaveImage(cacheFilePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var wand = new MagickWand(newWidth, newHeight, options.BackgroundColor))
|
||||
if (string.IsNullOrWhiteSpace(options.BackgroundColor))
|
||||
{
|
||||
using (var originalImage = new MagickWand(originalImagePath))
|
||||
{
|
||||
originalImage.CurrentImage.ResizeImage(newWidth, newHeight);
|
||||
|
||||
wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0);
|
||||
DrawIndicator(wand, newWidth, newHeight, options);
|
||||
DrawIndicator(originalImage, newWidth, newHeight, options);
|
||||
|
||||
wand.CurrentImage.CompressionQuality = quality;
|
||||
originalImage.CurrentImage.CompressionQuality = quality;
|
||||
|
||||
wand.SaveImage(cacheFilePath);
|
||||
originalImage.SaveImage(cacheFilePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var wand = new MagickWand(newWidth, newHeight, options.BackgroundColor))
|
||||
{
|
||||
using (var originalImage = new MagickWand(originalImagePath))
|
||||
{
|
||||
originalImage.CurrentImage.ResizeImage(newWidth, newHeight);
|
||||
|
||||
wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0);
|
||||
DrawIndicator(wand, newWidth, newHeight, options);
|
||||
|
||||
wand.CurrentImage.CompressionQuality = quality;
|
||||
|
||||
wand.SaveImage(cacheFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Sync;
|
||||
@@ -9,7 +10,6 @@ using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Sync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -152,7 +152,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
|
||||
try
|
||||
{
|
||||
var sendFileResult = await SendFile(provider, internalSyncJobItem.OutputPath, localItem, target, cancellationToken).ConfigureAwait(false);
|
||||
var sendFileResult = await SendFile(provider, internalSyncJobItem.OutputPath, localItem.LocalPath, target, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (localItem.Item.MediaSources != null)
|
||||
{
|
||||
@@ -173,10 +173,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
var mediaSource = localItem.Item.MediaSources.FirstOrDefault();
|
||||
if (mediaSource != null)
|
||||
{
|
||||
mediaSource.Path = sendFileResult.Path;
|
||||
mediaSource.Protocol = sendFileResult.Protocol;
|
||||
mediaSource.SupportsTranscoding = false;
|
||||
|
||||
await SendSubtitles(localItem, mediaSource, provider, dataProvider, target, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +212,8 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
try
|
||||
{
|
||||
var sendFileResult = await SendFile(provider, mediaStream.Path, localItem, target, cancellationToken).ConfigureAwait(false);
|
||||
var remotePath = GetRemoteSubtitlePath(localItem, mediaStream, provider, target);
|
||||
var sendFileResult = await SendFile(provider, mediaStream.Path, remotePath, target, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
mediaStream.Path = sendFileResult.Path;
|
||||
requiresSave = true;
|
||||
@@ -240,6 +237,38 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRemoteSubtitlePath(LocalItem item, MediaStream stream, IServerSyncProvider provider, SyncTarget target)
|
||||
{
|
||||
var path = item.LocalPath;
|
||||
|
||||
var filename = GetSubtitleSaveFileName(item, stream.Language, stream.IsForced) + "." + stream.Codec.ToLower();
|
||||
|
||||
var parentPath = provider.GetParentDirectoryPath(path, target);
|
||||
|
||||
path = Path.Combine(parentPath, filename);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private string GetSubtitleSaveFileName(LocalItem item, string language, bool isForced)
|
||||
{
|
||||
var path = item.LocalPath;
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(language))
|
||||
{
|
||||
name += "." + language.ToLower();
|
||||
}
|
||||
|
||||
if (isForced)
|
||||
{
|
||||
name += ".foreign";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private async Task RemoveItem(IServerSyncProvider provider,
|
||||
ISyncDataProvider dataProvider,
|
||||
string serverId,
|
||||
@@ -264,12 +293,12 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<SendFileResult> SendFile(IServerSyncProvider provider, string inputPath, LocalItem item, SyncTarget target, CancellationToken cancellationToken)
|
||||
private async Task<SendFileResult> SendFile(IServerSyncProvider provider, string inputPath, string remotePath, SyncTarget target, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Debug("Sending {0} to {1}. Remote path: {2}", inputPath, provider.Name, item.LocalPath);
|
||||
_logger.Debug("Sending {0} to {1}. Remote path: {2}", inputPath, provider.Name, remotePath);
|
||||
using (var stream = _fileSystem.GetFileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
|
||||
{
|
||||
return await provider.SendFile(stream, item.LocalPath, target, new Progress<double>(), cancellationToken).ConfigureAwait(false);
|
||||
return await provider.SendFile(stream, remotePath, target, new Progress<double>(), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -632,7 +632,8 @@ namespace MediaBrowser.Server.Implementations.Sync
|
||||
IsExternal = true,
|
||||
Language = subtitle.Language,
|
||||
Path = fileInfo.Path,
|
||||
SupportsExternalStream = true
|
||||
SupportsExternalStream = true,
|
||||
Type = MediaStreamType.Subtitle
|
||||
});
|
||||
|
||||
startingIndex++;
|
||||
|
||||
Reference in New Issue
Block a user