Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions ImmichFrame.Core/Logic/PooledImmichFrameLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,60 @@ public Task<IEnumerable<AssetResponseDto>> GetAssets()

private async Task<(string fileName, string ContentType, Stream fileStream)> GetVideoAsset(Guid id)
{
var videoResponse = await _immichApi.PlayAssetVideoAsync(id, string.Empty);

if (videoResponse == null)
throw new AssetNotFoundException($"Video asset {id} was not found!");
var fileName = $"{id}.mp4";

var contentType = "";
if (videoResponse.Headers.ContainsKey("Content-Type"))
if (_generalSettings.DownloadImages)
{
contentType = videoResponse.Headers["Content-Type"].FirstOrDefault() ?? "";
}
if (!Directory.Exists(_downloadLocation))
{
Directory.CreateDirectory(_downloadLocation);
}

if (string.IsNullOrWhiteSpace(contentType))
{
contentType = "video/mp4";
var filePath = Path.Combine(_downloadLocation, fileName);

if (File.Exists(filePath))
{
if (_generalSettings.RenewImagesDuration > (DateTime.UtcNow - File.GetCreationTimeUtc(filePath)).Days)
{
return (fileName, "video/mp4", File.OpenRead(filePath));
}
File.Delete(filePath);
}

using var videoResponse = await _immichApi.PlayAssetVideoAsync(id, string.Empty);

if (videoResponse == null)
throw new AssetNotFoundException($"Video asset {id} was not found!");

var contentType = videoResponse.Headers.ContainsKey("Content-Type")
? videoResponse.Headers["Content-Type"].FirstOrDefault() ?? "video/mp4"
: "video/mp4";

using (var fileStream = File.Create(filePath))
{
await videoResponse.Stream.CopyToAsync(fileStream);
}

return (fileName, contentType, File.OpenRead(filePath));
}
else
{
using var videoResponse = await _immichApi.PlayAssetVideoAsync(id, string.Empty);

var fileName = $"{id}.mp4";
if (videoResponse == null)
throw new AssetNotFoundException($"Video asset {id} was not found!");

return (fileName, contentType, videoResponse.Stream);
}
var contentType = videoResponse.Headers.ContainsKey("Content-Type")
? videoResponse.Headers["Content-Type"].FirstOrDefault() ?? "video/mp4"
: "video/mp4";

var memoryStream = new MemoryStream();
await videoResponse.Stream.CopyToAsync(memoryStream);
memoryStream.Position = 0;

return (fileName, contentType, memoryStream);
}
}
public Task SendWebhookNotification(IWebhookNotification notification) =>
WebhookHelper.SendWebhookNotification(notification, _generalSettings.Webhook);

Expand Down
Loading