mirror of https://github.com/ErsatzTV/ErsatzTV.git
20 changed files with 4577 additions and 57 deletions
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
namespace ErsatzTV.Core.Domain; |
||||
|
||||
public enum ChannelMusicVideoCreditsMode |
||||
{ |
||||
None = 0, |
||||
GenerateSubtitles = 1 |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
using System.Text; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Interfaces.FFmpeg; |
||||
|
||||
namespace ErsatzTV.Core.FFmpeg; |
||||
|
||||
public class MusicVideoCreditsGenerator : IMusicVideoCreditsGenerator |
||||
{ |
||||
private readonly ITempFilePool _tempFilePool; |
||||
|
||||
public MusicVideoCreditsGenerator(ITempFilePool tempFilePool) => _tempFilePool = tempFilePool; |
||||
|
||||
public async Task<Option<Subtitle>> GenerateCreditsSubtitle(MusicVideo musicVideo, FFmpegProfile ffmpegProfile) |
||||
{ |
||||
const int HORIZONTAL_MARGIN_PERCENT = 3; |
||||
const int VERTICAL_MARGIN_PERCENT = 5; |
||||
|
||||
var fontSize = (int)Math.Round(ffmpegProfile.Resolution.Height / 20.0); |
||||
|
||||
int leftMarginPercent = HORIZONTAL_MARGIN_PERCENT; |
||||
int rightMarginPercent = HORIZONTAL_MARGIN_PERCENT; |
||||
|
||||
var leftMargin = (int)Math.Round(leftMarginPercent / 100.0 * ffmpegProfile.Resolution.Width); |
||||
var rightMargin = (int)Math.Round(rightMarginPercent / 100.0 * ffmpegProfile.Resolution.Width); |
||||
var verticalMargin = |
||||
(int)Math.Round(VERTICAL_MARGIN_PERCENT / 100.0 * ffmpegProfile.Resolution.Height); |
||||
|
||||
foreach (MusicVideoMetadata metadata in musicVideo.MusicVideoMetadata) |
||||
{ |
||||
var sb = new StringBuilder(); |
||||
|
||||
string artist = string.Empty; |
||||
foreach (ArtistMetadata artistMetadata in Optional(metadata.MusicVideo?.Artist?.ArtistMetadata).Flatten()) |
||||
{ |
||||
artist = artistMetadata.Title; |
||||
} |
||||
|
||||
if (!string.IsNullOrWhiteSpace(artist)) |
||||
{ |
||||
sb.Append(artist); |
||||
} |
||||
|
||||
if (!string.IsNullOrWhiteSpace(metadata.Title)) |
||||
{ |
||||
sb.Append($"\\N\"{metadata.Title}\""); |
||||
} |
||||
|
||||
if (!string.IsNullOrWhiteSpace(metadata.Album)) |
||||
{ |
||||
sb.Append($"\\N{metadata.Album}"); |
||||
} |
||||
|
||||
string subtitles = await new SubtitleBuilder(_tempFilePool) |
||||
.WithResolution(ffmpegProfile.Resolution) |
||||
.WithFontName("OPTIKabel-Heavy") |
||||
.WithFontSize(fontSize) |
||||
.WithPrimaryColor("&HFFFFFF") |
||||
.WithOutlineColor("&H444444") |
||||
.WithAlignment(0) |
||||
.WithMarginRight(rightMargin) |
||||
.WithMarginLeft(leftMargin) |
||||
.WithMarginV(verticalMargin) |
||||
.WithBorderStyle(1) |
||||
.WithShadow(3) |
||||
.WithFormattedContent(sb.ToString()) |
||||
.WithStartEnd(TimeSpan.FromSeconds(9), TimeSpan.FromSeconds(16)) |
||||
.BuildFile(); |
||||
|
||||
return new Subtitle |
||||
{ |
||||
Codec = "ass", Default = true, Forced = true, IsExtracted = false, SubtitleKind = SubtitleKind.Sidecar, |
||||
Path = subtitles, SDH = false |
||||
}; |
||||
} |
||||
|
||||
return None; |
||||
} |
||||
} |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
using ErsatzTV.Core.Domain; |
||||
|
||||
namespace ErsatzTV.Core.Interfaces.FFmpeg; |
||||
|
||||
public interface IMusicVideoCreditsGenerator |
||||
{ |
||||
Task<Option<Subtitle>> GenerateCreditsSubtitle(MusicVideo musicVideo, FFmpegProfile ffmpegProfile); |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
||||
#nullable disable |
||||
|
||||
namespace ErsatzTV.Infrastructure.Migrations |
||||
{ |
||||
public partial class Add_ChannelMusicVideoCreditsMode : Migration |
||||
{ |
||||
protected override void Up(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.AddColumn<int>( |
||||
name: "MusicVideoCreditsMode", |
||||
table: "Channel", |
||||
type: "INTEGER", |
||||
nullable: false, |
||||
defaultValue: 0); |
||||
} |
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.DropColumn( |
||||
name: "MusicVideoCreditsMode", |
||||
table: "Channel"); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue