From 31a02776a1cf695350ea60cd391332ab72129a8a Mon Sep 17 00:00:00 2001 From: Federico Cicciarella Date: Fri, 7 Apr 2023 09:58:28 +0200 Subject: [PATCH 01/22] local video provider EVI-43 --- .../Models/Domain/LocalVideoMetadata.cs | 27 ++++ .../LocalVideoDtos/ArchiveLocalVideoDto.cs | 11 ++ src/EthernaVideoImporter/Program.cs | 24 +++ .../Services/LocalVideoProvider.cs | 151 ++++++++++++++++++ src/EthernaVideoImporter/SourceType.cs | 3 +- 5 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 src/EthernaVideoImporter/Models/Domain/LocalVideoMetadata.cs create mode 100644 src/EthernaVideoImporter/Models/LocalVideoDtos/ArchiveLocalVideoDto.cs create mode 100644 src/EthernaVideoImporter/Services/LocalVideoProvider.cs diff --git a/src/EthernaVideoImporter/Models/Domain/LocalVideoMetadata.cs b/src/EthernaVideoImporter/Models/Domain/LocalVideoMetadata.cs new file mode 100644 index 0000000..243fcd4 --- /dev/null +++ b/src/EthernaVideoImporter/Models/Domain/LocalVideoMetadata.cs @@ -0,0 +1,27 @@ +using Etherna.VideoImporter.Core.Models.Domain; +using System; + +namespace Etherna.VideoImporter.Models.Domain +{ + internal sealed class LocalVideoMetadata : VideoMetadataBase + { + // Constructors. + internal LocalVideoMetadata( + string description, + TimeSpan duration, + string originVideoQualityLabel, + ThumbnailLocalFile? thumbnail, + string title, + string filePathVideo) + : base(description, duration, originVideoQualityLabel, title) + { + FilePath = filePathVideo; + Thumbnail = thumbnail; + } + + // Properties. + public override string Id => FilePath; + public string FilePath { get; } + public ThumbnailLocalFile? Thumbnail { get; } + } +} diff --git a/src/EthernaVideoImporter/Models/LocalVideoDtos/ArchiveLocalVideoDto.cs b/src/EthernaVideoImporter/Models/LocalVideoDtos/ArchiveLocalVideoDto.cs new file mode 100644 index 0000000..7910311 --- /dev/null +++ b/src/EthernaVideoImporter/Models/LocalVideoDtos/ArchiveLocalVideoDto.cs @@ -0,0 +1,11 @@ +namespace Etherna.VideoImporter.Models.LocalVideoDto +{ + internal sealed class ArchiveLocalVideoDto + { + // Properties. + public string Description { get; set; } = default!; + public string Title { get; set; } = default!; + public string? Thumbnail { get; set; } + public string Video { get; set; } = default!; + } +} diff --git a/src/EthernaVideoImporter/Program.cs b/src/EthernaVideoImporter/Program.cs index bf81878..1738989 100644 --- a/src/EthernaVideoImporter/Program.cs +++ b/src/EthernaVideoImporter/Program.cs @@ -41,6 +41,7 @@ internal static class Program "Source types:\n" + " ytchannel\tYouTube channel\n" + " ytvideo\tYouTube video\n" + + " localvideo\tLocal video\n" + "\n" + "Options:\n" + $" -ff\tPath FFmpeg (default dir: {DefaultFFmpegFolder})\n" + @@ -127,6 +128,16 @@ static async Task Main(string[] args) sourceUri = args[1]; break; + case "localvideo": + if (args.Length < 2) + { + Console.WriteLine("Local Video path is missing"); + throw new ArgumentException("Invalid argument"); + } + sourceType = SourceType.LocalVideo; + sourceUri = args[1]; + break; + default: Console.WriteLine($"Invalid argument"); Console.WriteLine(HelpText); @@ -213,6 +224,14 @@ static async Task Main(string[] args) return; } + //check local video input + if (sourceType == SourceType.LocalVideo && + !File.Exists(sourceUri)) + { + Console.WriteLine($"Local video not found at ({sourceUri})"); + return; + } + //bee node api port if (!string.IsNullOrEmpty(beeNodeApiPortStr) && !int.TryParse(beeNodeApiPortStr, CultureInfo.InvariantCulture, out beeNodeApiPort)) @@ -301,6 +320,11 @@ static async Task Main(string[] args) encoderService, includeAudioTrack, GetSupportedHeightResolutions(skip1440, skip1080, skip720, skip480, skip360)), + SourceType.LocalVideo => new LocalVideoProvider( + sourceUri, + encoderService, + includeAudioTrack, + GetSupportedHeightResolutions(skip1440, skip1080, skip720, skip480, skip360)), _ => throw new InvalidOperationException() }; diff --git a/src/EthernaVideoImporter/Services/LocalVideoProvider.cs b/src/EthernaVideoImporter/Services/LocalVideoProvider.cs new file mode 100644 index 0000000..d942e34 --- /dev/null +++ b/src/EthernaVideoImporter/Services/LocalVideoProvider.cs @@ -0,0 +1,151 @@ +using Etherna.VideoImporter.Core.Models.Domain; +using Etherna.VideoImporter.Core.Services; +using Etherna.VideoImporter.Models.Domain; +using Etherna.VideoImporter.Models.LocalVideoDto; +using SkiaSharp; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Etherna.VideoImporter.Services +{ + public sealed class LocalVideoProvider : IVideoProvider + { + // Fields. + private readonly string localFile; + private readonly IEncoderService encoderService; + private readonly bool includeAudioTrack; + private readonly IEnumerable supportedHeightResolutions; + + // Constructor. + public LocalVideoProvider( + string localFile, + IEncoderService encoderService, + bool includeAudioTrack, + IEnumerable supportedHeightResolutions) + { + this.localFile = localFile; + this.encoderService = encoderService; + this.includeAudioTrack = includeAudioTrack; + this.supportedHeightResolutions = supportedHeightResolutions; + } + + // Properties. + public string SourceName => localFile; + + // Methods. + public async Task