Skip to content

Commit

Permalink
merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Jul 2, 2023
2 parents 8a3256b + e124a64 commit 2fe6b68
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 68 deletions.
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Currently exists two versions:
Etherna Video Importer requires at least [.NET 7 Runtime](https://dotnet.microsoft.com/download/dotnet/7.0) and [ASP.NET Core 7 Runtime](https://dotnet.microsoft.com/download/dotnet/7.0) installed on local machine to run, or it needs the `selfcontained` version of package, that already contains framework dependencies.

### Setup FFmpeg
To run the importer it is necessary to download [FFmpeg](https://ffmpeg.org/download.html) locally, and copy the binary file into the default folder "\FFmpeg", or specify its location with arguments.
To run the importer you need to download [FFmpeg](https://ffmpeg.org/download.html) locally, and copy the binary file into the default folder "\FFmpeg", or specify its location with arguments.

### How to use

**EthernaVideoImporter's help**
```
Usage: evi COMMAND [OPTIONS] SOURCE_URI
Usage: evi COMMAND SOURCE_URI [OPTIONS]
Commands:
json Import from json video list (requires metadata descriptor, see below)
youtube-channel Import from a YouTube channel
youtube-video Import from a YouTube video
local Import from local videos (requires metadata descriptor, see below)
General Options:
-k, --api-key Api Key (optional)
Expand All @@ -47,33 +47,37 @@ Bee Node Options:
--bee-api-port Port used by API (default: 1633)
--bee-debug-port Port used by Debug (default: 1635)
Local video metadata format:
To import from local videos you will need a metadata descriptor file. Metadata is a JSON file with the following structure:
Json videos metadata format:
To import from a video list you need a metadata descriptor file. Metadata is a JSON file with the following structure:
[
{
"Id": "myId1",
"Title": "My video1 title",
"Description": "My video description",
"Title": "First video title",
"Description": "My first video description",
"VideoFilePath": "path/to/your/video1.mp4",
"ThumbnailFilePath": "path/to/your/optional/thumbnail1.jpg"
},
{
"Id": "myId2",
"Title": "My video2 title",
...
"Title": "Second video title",
"Description": "My second video description",
"VideoFilePath": "http://example.com/stream.m3u8",
"ThumbnailFilePath": "path/to/your/optional/thumbnail2.jpg"
},
...
]
Paths can be either relative or absolute. ThumbnailFilePath is optional.
Id field is mandatory, and is needed to trace same video through different executions. Each Id needs to be unique.
Video paths can be local or online uris. Thumbnail paths are optional, and can only be local.
Local paths can be relative or absolute, online urls can only be absolute.
Run 'evi -h' or 'evi --help' to print help.
```

**EthernaVideoImporter.Devcon's help**
```
Usage: evid [OPTIONS] MD_FOLDER
Usage: evid MD_FOLDER [OPTIONS]
General Options:
-k, --api-key Api Key (optional)
Expand All @@ -99,14 +103,6 @@ Bee Node Options:
Run 'evid -h' or 'evid --help' to print help.
```

#### Local videos
To import from local videos you will need a JSON metadata descriptor file.

The `Id` field is mandatory, and is needed to trace same video through different executions. Each Id needs to be unique in the file.
The `ThumbnailFilePath` field is optional.

The Json file path needs to be passed as source uri with the source type `local`.

# Issue reports
If you've discovered a bug, or have an idea for a new feature, please report it to our issue manager based on Jira https://etherna.atlassian.net/projects/EVI.

Expand Down
2 changes: 1 addition & 1 deletion src/EthernaVideoImporter.Core/EthernaVideoImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task RunAsync(
var sourceVideosMetadata = await videoProvider.GetVideosMetadataAsync();
var totalSourceVideo = sourceVideosMetadata.Count();

Console.WriteLine($"Found {sourceVideosMetadata.Count()} valid videos from source");
Console.WriteLine($"Found {totalSourceVideo} valid videos from source");

// Get information from etherna index.
Console.WriteLine("Get user's videos on etherna index");
Expand Down
31 changes: 31 additions & 0 deletions src/EthernaVideoImporter.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,44 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Etherna.VideoImporter.Core.Models.Domain;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Etherna.VideoImporter.Core.Extensions
{
public static class StringExtensions
{
public static PathType GetPathType(this string path)
{
if (string.IsNullOrEmpty(path))
throw new ArgumentException("Path cannot be null or empty", nameof(path));
if (path.Intersect(Path.GetInvalidPathChars()).Any())
throw new ArgumentException("Path contains invalid chars", nameof(path));

// Check if it's a URL.
if (Uri.TryCreate(path, UriKind.Absolute, out var _))
return PathType.Url;

// Check if it's an absolute path.
if (Path.IsPathRooted(path))
return PathType.Absolute;

// If it's not a URL or an absolute path, it's a relative path.
return PathType.Relative;
}

public static string ToAbsolutePath(this string path, string currentDirectory) =>
path.GetPathType() switch
{
PathType.Relative => Path.Combine(currentDirectory, path),
PathType.Absolute => path,
PathType.Url => path,
_ => throw new InvalidOperationException()
};

public static string ToSafeFileName(this string value)
{
var strBuilder = new StringBuilder(value);
Expand Down
9 changes: 9 additions & 0 deletions src/EthernaVideoImporter.Core/Models/Domain/PathType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Etherna.VideoImporter.Core.Models.Domain
{
public enum PathType
{
Relative,
Absolute,
Url
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task UploadVideoAsync(
var amount = (long)(options.TtlPostageStamp.TotalSeconds * currentPrice / CommonConsts.GnosisBlockTime.TotalSeconds);
var bzzPrice = amount * Math.Pow(2, batchDepth) / BzzDecimalPlacesToUnit;

Console.WriteLine($"Creating postage batch... Depth: {batchDepth} Amount: {amount} BZZ price: {bzzPrice}");
Console.WriteLine($"Creating postage batch... Depth: {batchDepth}, Amount: {amount}, BZZ price: {bzzPrice}");

if (!options.AcceptPurchaseOfAllBatches)
{
Expand Down
20 changes: 10 additions & 10 deletions src/EthernaVideoImporter.Devcon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static class Program
{
// Consts.
private static readonly string HelpText = $$"""
Usage: evid [OPTIONS] MD_FOLDER
Usage: evid MD_FOLDER [OPTIONS]
General Options:
-k, --api-key Api Key (optional)
Expand Down Expand Up @@ -102,8 +102,16 @@ static async Task Main(string[] args)
}
}

//md source folder
mdSourceFolderPath = args[0];
if (!Directory.Exists(mdSourceFolderPath))
{
Console.WriteLine($"Not found MD directory path {mdSourceFolderPath}");
throw new ArgumentException("Not found MD directory path");
}

//options
var optArgs = args[..^1];
var optArgs = args[1..];
for (int i = 0; i < optArgs.Length; i++)
{
switch (optArgs[i])
Expand Down Expand Up @@ -202,14 +210,6 @@ static async Task Main(string[] args)
}
}

//md source folder
mdSourceFolderPath = args[^1];
if (!Directory.Exists(mdSourceFolderPath))
{
Console.WriteLine($"Not found MD directory path {mdSourceFolderPath}");
throw new ArgumentException("Not found MD directory path");
}

// Input validation.
//offer video
if (offerVideos && useBeeNativeNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ internal sealed class FFProbeResultDto
// Classes.
public sealed class FormatResult
{
// Properties.
public TimeSpan Duration { get; set; }
public string Size { get; set; } = default!;
public long SizeLong => Convert.ToInt64(Size);
}

public sealed class StreamResult
{
// Properties.
public int Height { get; set; }
public int Width { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Etherna.VideoImporter.Options
{
internal sealed class LocalVideoProviderOptions
internal sealed class JsonListVideoProviderOptions
{
public string FFProbeFolderPath { get; set; } = CommonConsts.DefaultFFmpegFolder;
public string FFProbeBinaryPath => Path.Combine(FFProbeFolderPath, CommonConsts.FFProbeBinaryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Etherna.VideoImporter.Options
{
internal sealed class LocalVideoProviderOptionsValidation : IValidateOptions<LocalVideoProviderOptions>
internal sealed class JsonListVideoProviderOptionsValidation : IValidateOptions<JsonListVideoProviderOptions>
{
public ValidateOptionsResult Validate(string? name, LocalVideoProviderOptions options)
public ValidateOptionsResult Validate(string? name, JsonListVideoProviderOptions options)
{
if (!File.Exists(options.FFProbeBinaryPath))
return ValidateOptionsResult.Fail($"FFProbe not found at ({options.FFProbeBinaryPath})");
Expand Down
46 changes: 25 additions & 21 deletions src/EthernaVideoImporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ internal static class Program
{
// Consts.
private static readonly string HelpText = $$"""
Usage: evi COMMAND [OPTIONS] SOURCE_URI
Usage: evi COMMAND SOURCE_URI [OPTIONS]
Commands:
json Import from json video list (requires metadata descriptor, see below)
youtube-channel Import from a YouTube channel
youtube-video Import from a YouTube video
local Import from local videos (requires metadata descriptor, see below)
General Options:
-k, --api-key Api Key (optional)
Expand All @@ -60,26 +60,30 @@ local Import from local videos (requires metadata descriptor, see be
--bee-api-port Port used by API (default: {{CommonConsts.BeeApiPort}})
--bee-debug-port Port used by Debug (default: {{CommonConsts.BeeDebugPort}})
Local video metadata format:
To import from local videos you will need a metadata descriptor file. Metadata is a JSON file with the following structure:
Json videos metadata format:
To import from a video list you need a metadata descriptor file. Metadata is a JSON file with the following structure:
[
{
"Id": "myId1",
"Title": "My video1 title",
"Description": "My video description",
"Title": "First video title",
"Description": "My first video description",
"VideoFilePath": "path/to/your/video1.mp4",
"ThumbnailFilePath": "path/to/your/optional/thumbnail1.jpg"
},
{
"Id": "myId2",
"Title": "My video2 title",
...
"Title": "Second video title",
"Description": "My second video description",
"VideoFilePath": "http://example.com/stream.m3u8",
"ThumbnailFilePath": "path/to/your/optional/thumbnail2.jpg"
},
...
]
Paths can be either relative or absolute. ThumbnailFilePath is optional.
Id field is mandatory, and is needed to trace same video through different executions. Each Id needs to be unique.
Video paths can be local or online uris. Thumbnail paths are optional, and can only be local.
Local paths can be relative or absolute, online urls can only be absolute.
Run 'evi -h' or 'evi --help' to print help.
""";
Expand Down Expand Up @@ -134,6 +138,10 @@ static async Task Main(string[] args)
//command
switch (args[0])
{
case "json":
sourceType = SourceType.JsonList;
break;

case "youtube-channel":
sourceType = SourceType.YouTubeChannel;
break;
Expand All @@ -142,17 +150,16 @@ static async Task Main(string[] args)
sourceType = SourceType.YouTubeVideo;
break;

case "local":
sourceType = SourceType.LocalVideos;
break;

default:
Console.WriteLine($"Invalid command: {args[0]}");
throw new ArgumentException($"Invalid command: {args[0]}");
}

//source uri
sourceUri = args[1];

//options
var optArgs = args[1..^1];
var optArgs = args[2..];
for (int i = 0; i < optArgs.Length; i++)
{
switch (optArgs[i])
Expand Down Expand Up @@ -251,9 +258,6 @@ static async Task Main(string[] args)
}
}

//source uri
sourceUri = args[^1];

// Input validation.
//offer video
if (offerVideos && useBeeNativeNode)
Expand Down Expand Up @@ -349,18 +353,18 @@ static async Task Main(string[] args)

switch (sourceType)
{
case SourceType.LocalVideos:
case SourceType.JsonList:
//options
services.Configure<LocalVideoProviderOptions>(options =>
services.Configure<JsonListVideoProviderOptions>(options =>
{
if (customFFMpegFolderPath is not null)
options.FFProbeFolderPath = customFFMpegFolderPath;
options.JsonMetadataFilePath = sourceUri;
});
services.AddSingleton<IValidateOptions<LocalVideoProviderOptions>, LocalVideoProviderOptionsValidation>();
services.AddSingleton<IValidateOptions<JsonListVideoProviderOptions>, JsonListVideoProviderOptionsValidation>();

//services
services.AddTransient<IVideoProvider, LocalVideoProvider>();
services.AddTransient<IVideoProvider, JsonListVideoProvider>();
break;
case SourceType.YouTubeChannel:
//options
Expand Down
Loading

0 comments on commit 2fe6b68

Please sign in to comment.