Compare commits
59 Commits
92e5bb7f1f
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d20c116da | ||
|
|
a849b7524d | ||
|
|
bf957436f0 | ||
|
|
16343c9a56 | ||
|
|
4c04378080 | ||
|
|
b5c701b971 | ||
|
|
a84195aefa | ||
|
|
de28591d24 | ||
|
|
264be8d529 | ||
|
|
25589d18d8 | ||
|
|
972af513f0 | ||
|
|
e87e1c57f9 | ||
|
|
41f880cfef | ||
|
|
9fdde5e756 | ||
|
|
ed9cb7eff1 | ||
|
|
97f7f5dcf6 | ||
|
|
ed1b7406a6 | ||
|
|
2b5e93ff8a | ||
|
|
1555ae9f3d | ||
|
|
34e029ec79 | ||
|
|
e4596df392 | ||
|
|
2f19d60be0 | ||
|
|
b8d2573d78 | ||
|
|
a2a420d596 | ||
|
|
c170b8db1f | ||
|
|
abc1505b6e | ||
|
|
2c125c24ae | ||
|
|
646e0a814a | ||
|
|
a478943792 | ||
|
|
a7baeb0d73 | ||
|
|
1903cb2938 | ||
|
|
9e81e221c6 | ||
|
|
88e724099c | ||
|
|
79ea2badf1 | ||
|
|
5250b9f3f9 | ||
|
|
9e173258ed | ||
|
|
ab532ac6dc | ||
|
|
8a64d6fc64 | ||
|
|
0056a14f79 | ||
|
|
e82736a45f | ||
|
|
0f83cf1ddc | ||
|
|
b1e5b0dc68 | ||
|
|
9be6f5be89 | ||
|
|
ef6ca0ee07 | ||
|
|
03631cd0c8 | ||
|
|
9ff4fcded2 | ||
|
|
2593d02a73 | ||
|
|
d183803390 | ||
|
|
a5e55e563e | ||
|
|
b3861b7cd9 | ||
|
|
680b6d2cc9 | ||
|
|
b2c9fc2c52 | ||
|
|
b2c6003203 | ||
|
|
3db61b599d | ||
|
|
c528ad9bb3 | ||
|
|
d0eca248bb | ||
|
|
fa0c617c9a | ||
|
|
f334c87fbb | ||
|
|
55322f8792 |
22
.gitignore
vendored
22
.gitignore
vendored
@@ -307,10 +307,6 @@ node_modules/
|
|||||||
*.dsw
|
*.dsw
|
||||||
*.dsp
|
*.dsp
|
||||||
|
|
||||||
# Visual Studio 6 technical files
|
|
||||||
*.ncb
|
|
||||||
*.aps
|
|
||||||
|
|
||||||
# Visual Studio LightSwitch build output
|
# Visual Studio LightSwitch build output
|
||||||
**/*.HTMLClient/GeneratedArtifacts
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
**/*.DesktopClient/GeneratedArtifacts
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
@@ -404,14 +400,8 @@ FodyWeavers.xsd
|
|||||||
*.sln.iml
|
*.sln.iml
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
##
|
|
||||||
## Visual studio for Mac
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
# globs
|
# globs
|
||||||
Makefile.in
|
Makefile.in
|
||||||
*.userprefs
|
|
||||||
*.usertasks
|
*.usertasks
|
||||||
config.make
|
config.make
|
||||||
config.status
|
config.status
|
||||||
@@ -470,16 +460,12 @@ ehthumbs_vista.db
|
|||||||
# Recycle Bin used on file shares
|
# Recycle Bin used on file shares
|
||||||
$RECYCLE.BIN/
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
# Windows Installer files
|
|
||||||
*.cab
|
|
||||||
*.msi
|
|
||||||
*.msix
|
|
||||||
*.msm
|
|
||||||
*.msp
|
|
||||||
|
|
||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
# Vim temporary swap files
|
# Vim temporary swap files
|
||||||
*.swp
|
*.swp
|
||||||
/Manager.App/Library/
|
|
||||||
|
# Manager.App
|
||||||
|
[Ll]ibrary/
|
||||||
|
[Cc]ache/
|
||||||
|
|||||||
@@ -2,21 +2,23 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Application</title>
|
<title>YouTube Manager server</title>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<base href="/"/>
|
<base href="/"/>
|
||||||
<link rel="stylesheet" href="app.css"/>
|
<link rel="stylesheet" href="app.css"/>
|
||||||
|
<link href="Manager.App.styles.css" rel="stylesheet" />
|
||||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet"/>
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet"/>
|
||||||
<link href="_content/MudBlazor/MudBlazor.min.css?v=@Metadata.Version" rel="stylesheet"/>
|
<link href="_content/MudBlazor/MudBlazor.min.css?v=@Metadata.Version" rel="stylesheet"/>
|
||||||
<HeadOutlet/>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<Routes @rendermode="InteractiveServer"/>
|
<Routes @rendermode="InteractiveServer"/>
|
||||||
<script src="_framework/blazor.web.js"></script>
|
<script src="_framework/blazor.web.js"></script>
|
||||||
<script src="_content/MudBlazor/MudBlazor.min.js?v=@Metadata.Version"></script>
|
<script src="_content/MudBlazor/MudBlazor.min.js?v=@Metadata.Version"></script>
|
||||||
|
<script src="js/tz.js"></script>
|
||||||
|
<script src="js/eventConsole.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
<MudText>SAPISID Hash generator</MudText>
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudTextField HelperText="Datasync id" @bind-Value="@DatasyncId"/>
|
||||||
|
<MudTextField HelperText="Time" Mask="@(new PatternMask("0000000000"))" @bind-Value="@Time"/>
|
||||||
|
<MudTextField HelperText="SAPISID" @bind-Value="@SecureCookie"/>
|
||||||
|
<MudTextField HelperText="Origin" @bind-Value="@Origin"/>
|
||||||
|
</MudStack>
|
||||||
|
<MudTextField HelperText="Hash" ReadOnly @bind-Value="@OutputHash"/>
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudButton OnClick="Hash">Generate</MudButton>
|
||||||
|
<MudButton OnClick="Clear">Clear</MudButton>
|
||||||
|
</MudStack>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Manager.YouTube.Util;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Application.Dev;
|
||||||
|
|
||||||
|
public partial class AuthenticationHasher : ComponentBase
|
||||||
|
{
|
||||||
|
private const string DefaultOrigin = "https://www.youtube.com";
|
||||||
|
public string DatasyncId { get; set; } = "";
|
||||||
|
public string Time { get; set; } = "";
|
||||||
|
public string SecureCookie { get; set; } = "";
|
||||||
|
public string Origin { get; set; } = DefaultOrigin;
|
||||||
|
|
||||||
|
public string OutputHash { get; set; } = "";
|
||||||
|
|
||||||
|
private void Clear()
|
||||||
|
{
|
||||||
|
DatasyncId = "";
|
||||||
|
Time = "";
|
||||||
|
SecureCookie = "";
|
||||||
|
Origin = DefaultOrigin;
|
||||||
|
OutputHash = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Hash()
|
||||||
|
{
|
||||||
|
OutputHash = AuthenticationUtilities.GetSapisidHash(DatasyncId, SecureCookie, Origin, Time);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Manager.App/Components/Application/Dev/CipherDev.razor
Normal file
13
Manager.App/Components/Application/Dev/CipherDev.razor
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
@using Manager.App.Models.System
|
||||||
|
@using Manager.App.Services.System
|
||||||
|
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject ClientService ClientService
|
||||||
|
|
||||||
|
<MudText>Cipher manager</MudText>
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudAutocomplete T="YouTubeClientItem" Label="Client" @bind-Value="@_selectedClient" SearchFunc="SearchClientsAsync" ToStringFunc="@(i => i == null ? "null?" : $"{i.Name} ({i.Handle})")"
|
||||||
|
Variant="Variant.Outlined" ShowProgressIndicator ProgressIndicatorColor="Color.Primary">
|
||||||
|
</MudAutocomplete>
|
||||||
|
<MudButton OnClick="ExecCipher">Exec</MudButton>
|
||||||
|
</MudStack>
|
||||||
43
Manager.App/Components/Application/Dev/CipherDev.razor.cs
Normal file
43
Manager.App/Components/Application/Dev/CipherDev.razor.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using Manager.App.Models.System;
|
||||||
|
using Manager.YouTube.Util.Cipher;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Application.Dev;
|
||||||
|
|
||||||
|
public partial class CipherDev : ComponentBase
|
||||||
|
{
|
||||||
|
private YouTubeClientItem? _selectedClient;
|
||||||
|
|
||||||
|
private async Task ExecCipher(MouseEventArgs obj)
|
||||||
|
{
|
||||||
|
if (_selectedClient == null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("No client selected", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ytClientResult = await ClientService.LoadClientByIdAsync(_selectedClient.Id);
|
||||||
|
if (!ytClientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
Snackbar.Add(ytClientResult.Error?.Description ?? "Failed to get the client!", Severity.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ytClient = ytClientResult.Value;
|
||||||
|
if (ytClient.State == null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Client state is null!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decoder = await CipherManager.GetDecoderAsync(ytClient.State, ytClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IEnumerable<YouTubeClientItem>> SearchClientsAsync(string? search, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var searchResults = await ClientService.GetClientsAsync(search, cancellationToken: cancellationToken);
|
||||||
|
return !searchResults.IsSuccess ? [] : searchResults.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
@using Manager.App.Models.System
|
||||||
|
@using Manager.App.Services.System
|
||||||
|
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject ClientService ClientService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
|
<MudText>Video data</MudText>
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudAutocomplete T="YouTubeClientItem" Label="Client" @bind-Value="@_selectedClient" SearchFunc="SearchClientsAsync" ToStringFunc="@(i => i == null ? "null?" : $"{i.Name} ({i.Handle})")"
|
||||||
|
Variant="Variant.Outlined" ShowProgressIndicator ProgressIndicatorColor="Color.Primary">
|
||||||
|
</MudAutocomplete>
|
||||||
|
<MudTextField Label="Video id" @bind-Value="@_videoId"/>
|
||||||
|
</MudStack>
|
||||||
|
<MudStack>
|
||||||
|
<MudButton OnClick="NavigateToVideo">Get data</MudButton>
|
||||||
|
</MudStack>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Manager.App.Models.System;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Application.Dev;
|
||||||
|
|
||||||
|
public partial class DevelopmentVideo : ComponentBase
|
||||||
|
{
|
||||||
|
private YouTubeClientItem? _selectedClient;
|
||||||
|
private string _videoId = "";
|
||||||
|
|
||||||
|
private async Task<IEnumerable<YouTubeClientItem>> SearchClientsAsync(string? search, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var searchResults = await ClientService.GetClientsAsync(search, cancellationToken: cancellationToken);
|
||||||
|
return !searchResults.IsSuccess ? [] : searchResults.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NavigateToVideo(MouseEventArgs obj)
|
||||||
|
{
|
||||||
|
if (_selectedClient == null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("No client selected!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(_videoId))
|
||||||
|
{
|
||||||
|
Snackbar.Add("No video ID set!", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_videoId.Length != 11)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Video ID needs to have an length of 11 chars!", Severity.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationManager.NavigateTo($"/video/{_videoId}?clientId={_selectedClient.Id}");
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Manager.App/Components/Application/System/EventConsole.razor
Normal file
21
Manager.App/Components/Application/System/EventConsole.razor
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
@inject IJSRuntime JsRuntime
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
|
<MudPaper Elevation="Elevation" Class="@Class" Style="@Style">
|
||||||
|
<MudStack Class="ml-2 mb-2" Spacing="2" Row>
|
||||||
|
<MudStack Spacing="1">
|
||||||
|
<MudText Typo="Typo.h5">Live service events</MudText>
|
||||||
|
<MudText Typo="Typo.caption">@($"{_serviceEvents.Count} events")</MudText>
|
||||||
|
</MudStack>
|
||||||
|
<MudSwitch @bind-Value="@_autoScroll">Auto-scroll</MudSwitch>
|
||||||
|
</MudStack>
|
||||||
|
<div @ref="@_consoleContainer" class="console-container" @onwheel="OnUserScroll">
|
||||||
|
<Virtualize @ref="_virtualize" TItem="ServiceEvent" ItemsProvider="VirtualizedItemsProvider" Context="serviceEvent">
|
||||||
|
<div class="log-line">
|
||||||
|
@TimeZoneInfo.ConvertTime(serviceEvent.DateUtc, _timeZone)
|
||||||
|
<span class="log-severity @GetLogClass(serviceEvent)">@serviceEvent.Severity</span> [<span style="color: #1565c0">@serviceEvent.Source</span>]
|
||||||
|
<span style="color: snow">@serviceEvent.Message</span>
|
||||||
|
</div>
|
||||||
|
</Virtualize>
|
||||||
|
</div>
|
||||||
|
</MudPaper>
|
||||||
165
Manager.App/Components/Application/System/EventConsole.razor.cs
Normal file
165
Manager.App/Components/Application/System/EventConsole.razor.cs
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
using DotBased.Logging;
|
||||||
|
using Manager.App.Services;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Application.System;
|
||||||
|
|
||||||
|
public partial class EventConsole : ComponentBase
|
||||||
|
{
|
||||||
|
private const int BatchDelayMs = 2000;
|
||||||
|
private List<ServiceEvent> _serviceEvents = [];
|
||||||
|
private readonly List<ServiceEvent> _batchBuffer = [];
|
||||||
|
private readonly SemaphoreSlim _batchLock = new(1, 1);
|
||||||
|
private ElementReference _consoleContainer;
|
||||||
|
private bool _autoScroll = true;
|
||||||
|
private CancellationTokenSource _cts = new();
|
||||||
|
private TimeZoneInfo _timeZone = TimeZoneInfo.Local;
|
||||||
|
private Virtualize<ServiceEvent>? _virtualize;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public List<ServiceEvent> InitialEvents { get; set; } = [];
|
||||||
|
[Parameter]
|
||||||
|
public IAsyncEnumerable<ServiceEvent>? AsyncEnumerable { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public int Elevation { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public string? Class { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public string? Style { get; set; }
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
_serviceEvents.AddRange(InitialEvents);
|
||||||
|
var jsTimeZone = await JsRuntime.InvokeAsync<string>("getUserTimeZone");
|
||||||
|
if (!string.IsNullOrEmpty(jsTimeZone))
|
||||||
|
{
|
||||||
|
_timeZone = TimeZoneInfo.FindSystemTimeZoneById(jsTimeZone);
|
||||||
|
}
|
||||||
|
_ = Task.Run(() => ReadEventStreamsAsync(_cts.Token));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReadEventStreamsAsync(CancellationToken token)
|
||||||
|
{
|
||||||
|
if (AsyncEnumerable == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await foreach (var serviceEvent in AsyncEnumerable.WithCancellation(token))
|
||||||
|
{
|
||||||
|
await _batchLock.WaitAsync(token);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_batchBuffer.Add(serviceEvent);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_batchLock.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = BatchUpdateUi();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetLogClass(ServiceEvent serviceEvent) =>
|
||||||
|
serviceEvent.Severity switch
|
||||||
|
{
|
||||||
|
LogSeverity.Info => "log-info",
|
||||||
|
LogSeverity.Warning => "log-warning",
|
||||||
|
LogSeverity.Error => "log-error",
|
||||||
|
LogSeverity.Debug => "log-debug",
|
||||||
|
LogSeverity.Trace => "log-trace",
|
||||||
|
LogSeverity.Fatal => "log-fatal",
|
||||||
|
LogSeverity.Verbose => "log-error",
|
||||||
|
_ => "log-info"
|
||||||
|
};
|
||||||
|
|
||||||
|
private DateTime _lastBatchUpdate = DateTime.MinValue;
|
||||||
|
private bool _updateScheduled;
|
||||||
|
|
||||||
|
private async Task BatchUpdateUi()
|
||||||
|
{
|
||||||
|
if (_updateScheduled) return;
|
||||||
|
_updateScheduled = true;
|
||||||
|
|
||||||
|
while (!_cts.Token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
var elapsed = (DateTime.UtcNow - _lastBatchUpdate).TotalMilliseconds;
|
||||||
|
if (elapsed < BatchDelayMs)
|
||||||
|
{
|
||||||
|
await Task.Delay(BatchDelayMs - (int)elapsed, _cts.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ServiceEvent> batch;
|
||||||
|
await _batchLock.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_batchBuffer.Count == 0) continue;
|
||||||
|
batch = new List<ServiceEvent>(_batchBuffer);
|
||||||
|
_batchBuffer.Clear();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_batchLock.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var serviceEvent in batch.Where(serviceEvent => !_serviceEvents.Contains(serviceEvent)))
|
||||||
|
{
|
||||||
|
_serviceEvents.Add(serviceEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastBatchUpdate = DateTime.UtcNow;
|
||||||
|
|
||||||
|
if (_virtualize != null)
|
||||||
|
{
|
||||||
|
await _virtualize.RefreshDataAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_autoScroll)
|
||||||
|
{
|
||||||
|
await JsRuntime.InvokeVoidAsync("scrollToBottom", _consoleContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
_updateScheduled = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUserScroll(WheelEventArgs e)
|
||||||
|
{
|
||||||
|
_ = UpdateAutoScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateAutoScroll()
|
||||||
|
{
|
||||||
|
if (_consoleContainer.Context != null)
|
||||||
|
{
|
||||||
|
var scrollInfo = await JsRuntime.InvokeAsync<ScrollInfo>("getScrollInfo", _consoleContainer);
|
||||||
|
_autoScroll = scrollInfo.ScrollTop + scrollInfo.ClientHeight >= scrollInfo.ScrollHeight - 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValueTask<ItemsProviderResult<ServiceEvent>> VirtualizedItemsProvider(ItemsProviderRequest request)
|
||||||
|
{
|
||||||
|
var items = _serviceEvents.Skip(request.StartIndex).Take(request.Count);
|
||||||
|
return ValueTask.FromResult(new ItemsProviderResult<ServiceEvent>(items, _serviceEvents.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_batchLock.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ScrollInfo
|
||||||
|
{
|
||||||
|
public double ScrollTop { get; set; }
|
||||||
|
public double ScrollHeight { get; set; }
|
||||||
|
public double ClientHeight { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
.console-container {
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
color: #9c9898;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-severity{
|
||||||
|
display: inline-block;
|
||||||
|
width: 8ch;
|
||||||
|
text-align: left;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-line {
|
||||||
|
display: flex;
|
||||||
|
justify-content: start;
|
||||||
|
align-items: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-info {
|
||||||
|
color: #3f6b81;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-warning {
|
||||||
|
color: #f8f802;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-error {
|
||||||
|
color: #f44747;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-debug {
|
||||||
|
color: #e110ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-trace {
|
||||||
|
color: #535353;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-fatal {
|
||||||
|
color: #af1e1e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-verbose {
|
||||||
|
color: #8085ff;
|
||||||
|
}
|
||||||
@@ -1,106 +1,219 @@
|
|||||||
|
@using Manager.App.Services.System
|
||||||
|
@inject ISnackbar SnackbarService
|
||||||
|
@inject CacheService Cache
|
||||||
|
|
||||||
<ForcedLoadingOverlay Visible="_isLoading"/>
|
<ForcedLoadingOverlay Visible="_isLoading"/>
|
||||||
|
|
||||||
|
@{
|
||||||
|
var client = ClientChannel?.YouTubeClient;
|
||||||
|
var clientState = client?.State;
|
||||||
|
var channel = ClientChannel?.Channel;
|
||||||
|
var avatar = channel?.AvatarImages.FirstOrDefault();
|
||||||
|
var banner = channel?.BannerImages.FirstOrDefault();
|
||||||
|
}
|
||||||
<MudDialog>
|
<MudDialog>
|
||||||
<TitleContent>
|
<TitleContent>
|
||||||
<MudText Typo="Typo.h6">Add new account</MudText>
|
<MudText Typo="Typo.h6">Add new account</MudText>
|
||||||
</TitleContent>
|
</TitleContent>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<MudStack Spacing="2">
|
@switch (_steps)
|
||||||
@if (_showCookieTextImport)
|
{
|
||||||
{
|
case AccountImportSteps.Authenticate:
|
||||||
<MudTextField @bind-Value="@_cookieDomain" Required HelperText="Domain"/>
|
<MudStack Spacing="2">
|
||||||
<MudTextField AutoGrow @bind-Value="@_cookieText" HelperText="Cookie text" Placeholder="EXAMPLE: Cookie1=Value1; Cookie2=Value2;"/>
|
<MudPaper Elevation="0" Outlined Class="pa-2">
|
||||||
|
<MudTextField @bind-Value="@DefaultUserAgent" Required Label="User agent"
|
||||||
|
HelperText="Use an WEB user agent."/>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
<MudButton Variant="Variant.Outlined" Disabled="@(string.IsNullOrWhiteSpace(_cookieDomain) || string.IsNullOrWhiteSpace(_cookieText))" OnClick="ApplyTextCookies">Apply</MudButton>
|
<MudStack Row Spacing="2" Style="height: 100%">
|
||||||
}
|
<MudPaper Elevation="0" Outlined Class="pa-2" Style="width: 50%;">
|
||||||
|
<MudText>Import cookies (Netscape Cookie format)</MudText>
|
||||||
|
<MudStack Spacing="2">
|
||||||
|
<MudStack Row Spacing="2">
|
||||||
|
<MudFileUpload T="IBrowserFile" Accept=".txt" FilesChanged="UploadFiles">
|
||||||
|
<ActivatorContent>
|
||||||
|
<MudButton Variant="Variant.Filled"
|
||||||
|
Color="Color.Primary"
|
||||||
|
StartIcon="@Icons.Material.Filled.CloudUpload">
|
||||||
|
Upload cookie txt
|
||||||
|
</MudButton>
|
||||||
|
</ActivatorContent>
|
||||||
|
</MudFileUpload>
|
||||||
|
<MudButton Variant="Variant.Outlined"
|
||||||
|
OnClick="ParseCookies" Disabled="@(string.IsNullOrWhiteSpace(_cookieText))">Import
|
||||||
|
</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
@if (MissingCookies.Any())
|
||||||
|
{
|
||||||
|
<MudPaper Class="pa-2" Elevation="0" Outlined>
|
||||||
|
<MudAlert Severity="Severity.Warning" Square Class="mb-2 mt-3">Some required cookies are not found, add the following cookie(s) to continue.</MudAlert>
|
||||||
|
<MudChipSet T="string" ReadOnly>
|
||||||
|
@foreach (var missingCookieName in MissingCookies)
|
||||||
|
{
|
||||||
|
<MudChip Variant="Variant.Text" Color="Color.Info">@missingCookieName</MudChip>
|
||||||
|
}
|
||||||
|
</MudChipSet>
|
||||||
|
</MudPaper>
|
||||||
|
}
|
||||||
|
<MudTextField Class="my-2" Lines="4" AutoGrow @bind-Value="@_cookieText" Immediate
|
||||||
|
Required Label="Cookies" Variant="Variant.Outlined"/>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
<MudStack Row Spacing="2" AlignItems="AlignItems.Stretch" Justify="Justify.SpaceEvenly" StretchItems="StretchItems.All">
|
<MudDataGrid Items="ImportCookies" Dense Elevation="0" Outlined Style="width: 50%;">
|
||||||
<MudStack Spacing="2" Style="width: 100%">
|
<ToolBarContent>
|
||||||
<MudTextField Label="UserAgent" Required @bind-Value="@Client.UserAgent"/>
|
<MudText>Cookies</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudText Typo="Typo.caption">@($"{ImportCookies.Count} cookie(s)")</MudText>
|
||||||
|
</ToolBarContent>
|
||||||
|
<Columns>
|
||||||
|
<TemplateColumn Title="Name">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudText>@context.Item.Name</MudText>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
<TemplateColumn Title="Domain">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudText>@context.Item.Domain</MudText>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
<TemplateColumn Title="Expires">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudText>@context.Item.Expires</MudText>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
<TemplateColumn Title="Value">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudTooltip Text="@context.Item.Value">
|
||||||
|
<MudText Style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px;">@context.Item.Value</MudText>
|
||||||
|
</MudTooltip>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
</Columns>
|
||||||
|
</MudDataGrid>
|
||||||
|
</MudStack>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
<MudSimpleTable Style="width: 100%" Bordered Dense Elevation="0" Outlined Square Hover>
|
break;
|
||||||
<tbody>
|
case AccountImportSteps.Validate:
|
||||||
<tr>
|
<MudStack Spacing="3">
|
||||||
<td>Account id:</td>
|
<MudPaper Elevation="0">
|
||||||
<td>@Client.Id</td>
|
@if (banner != null)
|
||||||
</tr>
|
{
|
||||||
<tr>
|
<MudImage Src="@Cache.CreateCacheUrl(banner.Url)" Height="250" Style="width: 100%;"/>
|
||||||
<td>Account name:</td>
|
}
|
||||||
<td>@Client.AccountName</td>
|
else
|
||||||
</tr>
|
{
|
||||||
<tr>
|
<div Class="account-banner" Style="height: 250px; width: 100%;"></div>
|
||||||
<td>User agent:</td>
|
}
|
||||||
<td>@Client.UserAgent</td>
|
<MudStack Row Spacing="3" Class="px-4">
|
||||||
</tr>
|
@if (avatar != null)
|
||||||
|
{
|
||||||
|
<MudImage Src="@Cache.CreateCacheUrl(avatar.Url)" Class="mt-n5" Height="100" Width="100"/>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div Class="avatar-pattern mt-n6" Style="height: 100px; width: 100px;"></div>
|
||||||
|
}
|
||||||
|
<MudStack Spacing="0">
|
||||||
|
<MudText Typo="Typo.h5">@(channel?.ChannelName ?? client?.Id)</MudText>
|
||||||
|
<MudText Typo="Typo.caption">@(string.IsNullOrWhiteSpace(channel?.Description) ? "No description!" : channel.Description)</MudText>
|
||||||
|
</MudStack>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Account id:</td>
|
||||||
|
<td>@client?.Id</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Account name:</td>
|
||||||
|
<td>@channel?.ChannelName</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Account handle:</td>
|
||||||
|
<td>@channel?.Handle</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Logged in:</td>
|
||||||
|
<td style="@($"color: {(clientState?.LoggedIn ?? false ? "green" : "red")}")">@clientState?.LoggedIn</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>YouTube Premium:</td>
|
||||||
|
<td style="@($"color: {(clientState?.IsPremiumUser ?? false ? "green" : "red")}")">@clientState?.IsPremiumUser</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Logged in:</td>
|
<td>User agent:</td>
|
||||||
<td style="@($"color: {(Client.ClientState?.LoggedIn ?? false ? "green" : "red")}")">@Client.ClientState?.LoggedIn</td>
|
<td>@client?.UserAgent</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>InnerTube API key:</td>
|
<td>InnerTube client:</td>
|
||||||
<td>@Client.ClientState?.InnertubeApiKey</td>
|
<td>@clientState?.InnerTubeClient</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>InnerTube client version:</td>
|
<td>InnerTube client version:</td>
|
||||||
<td>@Client.ClientState?.InnerTubeClientVersion</td>
|
<td>@clientState?.InnerTubeClientVersion</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Language:</td>
|
<td>InnerTube API key:</td>
|
||||||
<td>@Client.ClientState?.InnerTubeContext?.InnerTubeClient?.HLanguage</td>
|
<td>@clientState?.InnertubeApiKey</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
<tr>
|
||||||
</MudSimpleTable>
|
<td>Language:</td>
|
||||||
</MudStack>
|
<td>@clientState?.InnerTubeContext?.InnerTubeClient?.HLanguage</td>
|
||||||
|
</tr>
|
||||||
<MudDataGrid Items="Client.CookieContainer.GetAllCookies()" Dense Elevation="0" Outlined>
|
</tbody>
|
||||||
<Header>
|
</MudSimpleTable>
|
||||||
<MudStack Class="ma-2">
|
</MudStack>
|
||||||
<MudText>Cookies</MudText>
|
break;
|
||||||
</MudStack>
|
}
|
||||||
<MudStack Row Spacing="2" Class="ma-1">
|
|
||||||
<MudTooltip Text="Add cookie">
|
|
||||||
<MudIconButton Icon="@Icons.Material.Filled.Add" Size="Size.Small" Color="Color.Success" Disabled="_showCookieTextImport" OnClick="AddCookie"/>
|
|
||||||
</MudTooltip>
|
|
||||||
<MudTooltip Text="Add from text">
|
|
||||||
<MudIconButton Icon="@Icons.Material.Filled.InsertDriveFile" Size="Size.Small" Color="Color.Primary" OnClick="ToggleCookieTextImport"/>
|
|
||||||
</MudTooltip>
|
|
||||||
</MudStack>
|
|
||||||
</Header>
|
|
||||||
<Columns>
|
|
||||||
<TemplateColumn Title="Name">
|
|
||||||
<CellTemplate>
|
|
||||||
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Name" Immediate/>
|
|
||||||
</CellTemplate>
|
|
||||||
</TemplateColumn>
|
|
||||||
<TemplateColumn Title="Domain">
|
|
||||||
<CellTemplate>
|
|
||||||
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Domain" Immediate/>
|
|
||||||
</CellTemplate>
|
|
||||||
</TemplateColumn>
|
|
||||||
<TemplateColumn Title="Value">
|
|
||||||
<CellTemplate>
|
|
||||||
<MudTextField Variant="Variant.Text" @bind-Value="@context.Item.Value" Immediate/>
|
|
||||||
</CellTemplate>
|
|
||||||
</TemplateColumn>
|
|
||||||
<PropertyColumn Title="Expires" Property="x => x.Expires"/>
|
|
||||||
|
|
||||||
<TemplateColumn>
|
|
||||||
<CellTemplate>
|
|
||||||
<MudTooltip Text="Remove">
|
|
||||||
<MudIconButton Size="Size.Small" Icon="@Icons.Material.Filled.Remove" Color="Color.Error" OnClick="@(() => RemoveCookie(context.Item))"/>
|
|
||||||
</MudTooltip>
|
|
||||||
</CellTemplate>
|
|
||||||
</TemplateColumn>
|
|
||||||
</Columns>
|
|
||||||
</MudDataGrid>
|
|
||||||
</MudStack>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<MudStack Spacing="2" Row>
|
<MudStack Spacing="2" Row>
|
||||||
<MudButton Color="Color.Error" OnClick="() => MudDialog?.Cancel()" Variant="Variant.Outlined">Cancel</MudButton>
|
<MudButton Color="Color.Error" OnClick="() => MudDialog?.Cancel()" Variant="Variant.Outlined">Cancel
|
||||||
<MudButton Color="Color.Info" Variant="Variant.Outlined" OnClick="ValidateAccount" Disabled="@(!CanValidate())">Validate</MudButton>
|
</MudButton>
|
||||||
<MudButton Color="Color.Primary" Variant="Variant.Outlined" Disabled="@(!CanSave())" OnClick="OnSave">Save</MudButton>
|
<MudButton Color="Color.Info" OnClick="ClearPreparedClient" Variant="Variant.Outlined">Reset</MudButton>
|
||||||
|
<MudButton Color="Color.Primary" OnClick="OnNextStep" Disabled="@(!CanContinue())" Variant="Variant.Outlined">@(_steps == AccountImportSteps.Validate ? "Save" : "Next")</MudButton>
|
||||||
</MudStack>
|
</MudStack>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</MudDialog>
|
</MudDialog>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.account-banner {
|
||||||
|
width: 100%;
|
||||||
|
height: 180px;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
|
||||||
|
/* Pattern background */
|
||||||
|
background: repeating-linear-gradient(
|
||||||
|
135deg,
|
||||||
|
#1976d2, /* MudBlazor Primary */
|
||||||
|
#1976d2 20px,
|
||||||
|
#1565c0 20px,
|
||||||
|
#1565c0 40px
|
||||||
|
);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-pattern {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
/* Patterned background */
|
||||||
|
background: repeating-linear-gradient(
|
||||||
|
45deg,
|
||||||
|
#1976d2,
|
||||||
|
#1976d2 10px,
|
||||||
|
#1565c0 10px,
|
||||||
|
#1565c0 20px
|
||||||
|
);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Text;
|
||||||
|
using Manager.App.Models.Library;
|
||||||
using Manager.YouTube;
|
using Manager.YouTube;
|
||||||
|
using Manager.YouTube.Constants;
|
||||||
|
using Manager.YouTube.Parsers;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
|
||||||
namespace Manager.App.Components.Dialogs
|
namespace Manager.App.Components.Dialogs
|
||||||
@@ -9,109 +15,147 @@ namespace Manager.App.Components.Dialogs
|
|||||||
{
|
{
|
||||||
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
|
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
|
||||||
[Parameter] public string DefaultUserAgent { get; set; } = "";
|
[Parameter] public string DefaultUserAgent { get; set; } = "";
|
||||||
|
private ClientChannel? ClientChannel { get; set; }
|
||||||
public YouTubeClient Client { get; set; } = new();
|
private CookieCollection ImportCookies { get; set; } = [];
|
||||||
|
private IEnumerable<string> MissingCookies => CookieConstants.RequiredCookiesNames.Where(req => !ImportCookies.Select(c => c.Name).ToHashSet().Contains(req)).ToList();
|
||||||
private bool _isLoading;
|
private bool _isLoading;
|
||||||
|
private AccountImportSteps _steps = AccountImportSteps.Authenticate;
|
||||||
|
|
||||||
private bool _showCookieTextImport;
|
|
||||||
private string _cookieText = "";
|
private string _cookieText = "";
|
||||||
private string _cookieDomain = ".youtube.com";
|
|
||||||
|
private bool CanSave()
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
{
|
||||||
Client.UserAgent = DefaultUserAgent;
|
return ClientChannel?.YouTubeClient?.State?.LoggedIn == true;
|
||||||
base.OnInitialized();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCookie()
|
private bool CanContinue()
|
||||||
{
|
{
|
||||||
Client.CookieContainer.Add(new Cookie { Name = "SET_NAME", Domain = ".youtube.com" });
|
switch (_steps)
|
||||||
|
{
|
||||||
|
case AccountImportSteps.Authenticate:
|
||||||
|
if (ImportCookies.Count != 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AccountImportSteps.Validate:
|
||||||
|
if (ClientChannel?.YouTubeClient?.State?.LoggedIn == true)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnNextStep()
|
||||||
|
{
|
||||||
|
switch (_steps)
|
||||||
|
{
|
||||||
|
case AccountImportSteps.Authenticate:
|
||||||
|
if (CanContinue())
|
||||||
|
{
|
||||||
|
_steps = AccountImportSteps.Validate;
|
||||||
|
await BuildClient();
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SnackbarService.Add("Cannot continue!", Severity.Warning);
|
||||||
|
break;
|
||||||
|
case AccountImportSteps.Validate:
|
||||||
|
if (CanSave())
|
||||||
|
{
|
||||||
|
MudDialog?.Close(DialogResult.Ok(ClientChannel));
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SnackbarService.Add("Cannot save!", Severity.Warning);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RemoveCookie(Cookie? cookie)
|
private async Task UploadFiles(IBrowserFile? file)
|
||||||
{
|
{
|
||||||
if (cookie == null)
|
if (file == null)
|
||||||
|
{
|
||||||
|
SnackbarService.Add("File is null!", Severity.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.ContentType != MediaTypeNames.Text.Plain)
|
||||||
|
{
|
||||||
|
SnackbarService.Add($"File uploaded with unsupported content type: {file.ContentType}", Severity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isLoading = true;
|
||||||
|
var streamReader = new StreamReader(file.OpenReadStream(), Encoding.UTF8);
|
||||||
|
_cookieText = await streamReader.ReadToEndAsync();
|
||||||
|
_isLoading = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ParseCookies()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_cookieText))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cookie.Expired = true;
|
try
|
||||||
await InvokeAsync(StateHasChanged);
|
{
|
||||||
|
ImportCookies.Clear();
|
||||||
|
var parsedCookies = await CookieTxtParser.ParseAsync(new MemoryStream(Encoding.UTF8.GetBytes(_cookieText)), CookieConstants.RequiredCookiesNames.ToHashSet());
|
||||||
|
ImportCookies.Add(parsedCookies);
|
||||||
|
_cookieText = string.Empty;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
SnackbarService.Add($"Parsing cookies failed: {e.Message}", Severity.Error);
|
||||||
|
}
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleCookieTextImport()
|
private void ClearPreparedClient()
|
||||||
{
|
{
|
||||||
_showCookieTextImport =! _showCookieTextImport;
|
ClientChannel?.YouTubeClient?.Dispose();
|
||||||
}
|
ClientChannel = null;
|
||||||
|
ImportCookies.Clear();
|
||||||
private void ApplyTextCookies()
|
_steps = AccountImportSteps.Authenticate;
|
||||||
{
|
|
||||||
_showCookieTextImport = false;
|
|
||||||
var cookies = ParseCookieHeader(_cookieText, _cookieDomain);
|
|
||||||
Client.CookieContainer.Add(cookies);
|
|
||||||
_cookieText = string.Empty;
|
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CookieCollection ParseCookieHeader(string cookieHeader, string domain = "")
|
private async Task BuildClient()
|
||||||
{
|
|
||||||
var collection = new CookieCollection();
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(cookieHeader))
|
|
||||||
return collection;
|
|
||||||
|
|
||||||
var cookies = cookieHeader.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
foreach (var cookieStr in cookies)
|
|
||||||
{
|
|
||||||
var parts = cookieStr.Split('=', 2);
|
|
||||||
if (parts.Length == 2)
|
|
||||||
{
|
|
||||||
var name = parts[0].Trim();
|
|
||||||
var value = parts[1].Trim();
|
|
||||||
|
|
||||||
// Escape invalid characters
|
|
||||||
var safeName = Uri.EscapeDataString(name);
|
|
||||||
var safeValue = Uri.EscapeDataString(value);
|
|
||||||
|
|
||||||
var cookie = new Cookie(safeName, safeValue);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(domain))
|
|
||||||
cookie.Domain = domain;
|
|
||||||
|
|
||||||
collection.Add(cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CanValidate()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(Client.UserAgent) || Client.CookieContainer.Count <= 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CanSave()
|
|
||||||
{
|
|
||||||
return Client.ClientState is { LoggedIn: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ValidateAccount()
|
|
||||||
{
|
{
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
await Client.GetStateAsync();
|
ClientChannel = new ClientChannel();
|
||||||
|
var clientResult = await YouTubeClient.CreateAsync(ImportCookies, DefaultUserAgent);
|
||||||
|
if (clientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
ClientChannel.YouTubeClient = clientResult.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ClientChannel.YouTubeClient == null)
|
||||||
|
{
|
||||||
|
SnackbarService.Add("Failed to get client!", Severity.Error);
|
||||||
|
_isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountResult = await ClientChannel.YouTubeClient.GetChannelByIdAsync(ClientChannel.YouTubeClient.Id);
|
||||||
|
if (accountResult.IsSuccess)
|
||||||
|
{
|
||||||
|
ClientChannel.Channel = accountResult.Value;
|
||||||
|
}
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
}
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
private void OnSave()
|
|
||||||
{
|
|
||||||
MudDialog?.Close(DialogResult.Ok(Client));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AccountImportSteps
|
||||||
|
{
|
||||||
|
Authenticate,
|
||||||
|
Validate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</MudTooltip>
|
</MudTooltip>
|
||||||
}
|
}
|
||||||
</MudAppBar>
|
</MudAppBar>
|
||||||
<div style="margin: 20px">
|
<div style="display: flex; flex-direction: column; flex: 1; padding: 20px; min-height: 0;">
|
||||||
@Body
|
@Body
|
||||||
</div>
|
</div>
|
||||||
</CascadingValue>
|
</CascadingValue>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<CascadingValue Value="this">
|
<CascadingValue Value="this">
|
||||||
<MudLayout>
|
<MudLayout>
|
||||||
<MudMainContent>
|
<MudMainContent Style="display: flex; flex-direction: column; height: 100vh;">
|
||||||
@Body
|
@Body
|
||||||
</MudMainContent>
|
</MudMainContent>
|
||||||
</MudLayout>
|
</MudLayout>
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
|
|
||||||
<MudNavMenu>
|
<MudNavMenu>
|
||||||
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home" Match="NavLinkMatch.All">Home</MudNavLink>
|
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home" Match="NavLinkMatch.All">Home</MudNavLink>
|
||||||
<MudNavLink Href="/Channels" Icon="@Icons.Material.Filled.SupervisorAccount" Match="NavLinkMatch.All">Channels</MudNavLink>
|
<MudNavGroup Title="Library" Expanded Icon="@Icons.Custom.Brands.YouTube" IconColor="Color.Error">
|
||||||
<MudNavLink Href="/Library" Icon="@Icons.Material.Filled.LocalLibrary" Match="NavLinkMatch.All">Library</MudNavLink>
|
<MudNavLink Href="/Search" Icon="@Icons.Material.Filled.Search" Match="NavLinkMatch.All" Disabled>Search</MudNavLink>
|
||||||
<MudNavLink Href="/Playlists" Icon="@Icons.Material.Filled.ViewList" Match="NavLinkMatch.All">Playlists</MudNavLink>
|
<MudNavLink Href="/Accounts" Icon="@Icons.Material.Filled.AccountBox" Match="NavLinkMatch.All">Accounts</MudNavLink>
|
||||||
|
<MudNavLink Href="/Channels" Icon="@Icons.Material.Filled.AccountCircle" Match="NavLinkMatch.All">Channels</MudNavLink>
|
||||||
|
<MudNavLink Href="/Playlists" Icon="@Icons.Material.Filled.ViewList" Match="NavLinkMatch.All" Disabled>Playlists</MudNavLink>
|
||||||
|
<MudNavLink Href="/Library" Icon="@Icons.Material.Filled.Info" Match="NavLinkMatch.All" IconColor="Color.Info">Info</MudNavLink>
|
||||||
|
</MudNavGroup>
|
||||||
|
<MudNavGroup Title="Application" Expanded Icon="@Icons.Material.Filled.SettingsSystemDaydream" IconColor="Color.Primary">
|
||||||
|
<MudNavLink Href="/Development" Icon="@Icons.Material.Filled.DeveloperMode" Match="NavLinkMatch.All">Development</MudNavLink>
|
||||||
|
<MudNavLink Href="/Services" Icon="@Icons.Material.Filled.MiscellaneousServices" Match="NavLinkMatch.All">Services</MudNavLink>
|
||||||
|
</MudNavGroup>
|
||||||
</MudNavMenu>
|
</MudNavMenu>
|
||||||
53
Manager.App/Components/Pages/Accounts.razor
Normal file
53
Manager.App/Components/Pages/Accounts.razor
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
@page "/Accounts"
|
||||||
|
@using Manager.App.Controllers
|
||||||
|
@using Manager.App.Models.Settings
|
||||||
|
@using Manager.App.Services.System
|
||||||
|
@using Microsoft.Extensions.Options
|
||||||
|
|
||||||
|
@inject ILibraryService LibraryService
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
@inject IOptions<LibrarySettings> LibraryOptions
|
||||||
|
@inject ClientService ClientService
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
|
||||||
|
<PageTitle>Accounts</PageTitle>
|
||||||
|
|
||||||
|
<MudStack Spacing="2">
|
||||||
|
<MudPaper Elevation="0" Outlined>
|
||||||
|
<MudStack Row Class="ma-2">
|
||||||
|
<MudButton IconSize="Size.Small" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" OnClick="OnAddAccountDialogAsync">Add account</MudButton>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudTable @ref="@_table" ServerData="ServerReload">
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.h6">Accounts</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudTextField T="string" ValueChanged="@(s=>OnSearch(s))" Placeholder="Search" Adornment="Adornment.Start" DebounceInterval="300"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
|
||||||
|
</ToolBarContent>
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh></MudTh>
|
||||||
|
<MudTh>Name</MudTh>
|
||||||
|
<MudTh>Handle</MudTh>
|
||||||
|
<MudTh>ID</MudTh>
|
||||||
|
<MudTh>Cookies</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd><MudImage Src="@(FileController.CreateProvideUrl(context.AvatarFileId))" Height="40"/></MudTd>
|
||||||
|
<MudTd>@context.Name</MudTd>
|
||||||
|
<MudTd>@context.Handle</MudTd>
|
||||||
|
<MudTd>@context.Id</MudTd>
|
||||||
|
<MudTd>@context.HasCookies</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
<NoRecordsContent>
|
||||||
|
<MudText>No channels found</MudText>
|
||||||
|
</NoRecordsContent>
|
||||||
|
<LoadingContent>
|
||||||
|
<MudText>Loading...</MudText>
|
||||||
|
</LoadingContent>
|
||||||
|
<PagerContent>
|
||||||
|
<MudTablePager/>
|
||||||
|
</PagerContent>
|
||||||
|
</MudTable>
|
||||||
|
</MudStack>
|
||||||
72
Manager.App/Components/Pages/Accounts.razor.cs
Normal file
72
Manager.App/Components/Pages/Accounts.razor.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using Manager.App.Components.Dialogs;
|
||||||
|
using Manager.App.Models.Library;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
|
public partial class Accounts : ComponentBase
|
||||||
|
{
|
||||||
|
private MudTable<AccountListView>? _table;
|
||||||
|
private readonly DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true, MaxWidth = MaxWidth.ExtraLarge };
|
||||||
|
private string _search = "";
|
||||||
|
|
||||||
|
private async Task<TableData<AccountListView>> ServerReload(TableState state, CancellationToken token)
|
||||||
|
{
|
||||||
|
var results = await LibraryService.GetAccountsAsync(_search, state.Page * state.PageSize, state.PageSize, token);
|
||||||
|
return !results.IsSuccess ? new TableData<AccountListView>() : new TableData<AccountListView> { Items = results.Value, TotalItems = results.Total };
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSearch(string text)
|
||||||
|
{
|
||||||
|
_search = text;
|
||||||
|
_table?.ReloadServerData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnAddAccountDialogAsync()
|
||||||
|
{
|
||||||
|
var libSettings = LibraryOptions.Value;
|
||||||
|
var parameters = new DialogParameters<AccountDialog> { { x => x.DefaultUserAgent, libSettings.DefaultUserAgent } };
|
||||||
|
var dialog = await DialogService.ShowAsync<AccountDialog>("Add account", parameters, _dialogOptions);
|
||||||
|
var result = await dialog.Result;
|
||||||
|
|
||||||
|
if (result == null || result.Canceled || result.Data == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientChannel = (ClientChannel)result.Data;
|
||||||
|
if (clientChannel?.YouTubeClient == null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("No YouTube client received.", Severity.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var savedClientResult = await ClientService.SaveClientAsync(clientChannel.YouTubeClient);
|
||||||
|
if (savedClientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
if (_table != null)
|
||||||
|
{
|
||||||
|
await _table.ReloadServerData();
|
||||||
|
}
|
||||||
|
Snackbar.Add($"Client {clientChannel.Channel?.Handle ?? clientChannel.YouTubeClient.Id} saved!", Severity.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Snackbar.Add($"Failed to store client: {savedClientResult.Error?.Description ?? "Unknown!"}", Severity.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientChannel.Channel == null)
|
||||||
|
{
|
||||||
|
Snackbar.Add("No channel information received!", Severity.Warning);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var saveChannelResult = await LibraryService.SaveChannelAsync(clientChannel.Channel);
|
||||||
|
if (!saveChannelResult.IsSuccess)
|
||||||
|
{
|
||||||
|
Snackbar.Add("Failed to save channel information", Severity.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,29 @@
|
|||||||
@page "/Channels"
|
@page "/Channels"
|
||||||
@using Manager.App.Models.Settings
|
@using Manager.App.Controllers
|
||||||
@using Microsoft.Extensions.Options
|
|
||||||
|
|
||||||
@inject ILibraryService LibraryService
|
@inject ILibraryService LibraryService
|
||||||
@inject IDialogService DialogService
|
|
||||||
@inject IOptions<LibrarySettings> LibraryOptions
|
|
||||||
|
|
||||||
<PageTitle>Channels</PageTitle>
|
<PageTitle>Channels</PageTitle>
|
||||||
|
|
||||||
|
|
||||||
<MudStack Spacing="2">
|
<MudStack Spacing="2">
|
||||||
<MudPaper Elevation="0" Outlined>
|
<MudTable @ref="@_table" ServerData="ServerReload">
|
||||||
<MudStack Row Class="ma-2">
|
|
||||||
<MudButton IconSize="Size.Small" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Outlined" OnClick="OnAddAccountDialogAsync">Add account</MudButton>
|
|
||||||
</MudStack>
|
|
||||||
</MudPaper>
|
|
||||||
|
|
||||||
<MudTable ServerData="ServerReload">
|
|
||||||
<ToolBarContent>
|
<ToolBarContent>
|
||||||
<MudText Typo="Typo.h6">Channels</MudText>
|
<MudText Typo="Typo.h6">Channels</MudText>
|
||||||
|
<MudSpacer />
|
||||||
|
<MudTextField T="string" ValueChanged="@(s=>OnSearch(s))" Placeholder="Search" Adornment="Adornment.Start" DebounceInterval="300"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
|
||||||
</ToolBarContent>
|
</ToolBarContent>
|
||||||
<HeaderContent>
|
<HeaderContent>
|
||||||
|
<MudTh></MudTh>
|
||||||
<MudTh>Name</MudTh>
|
<MudTh>Name</MudTh>
|
||||||
|
<MudTh>Handle</MudTh>
|
||||||
<MudTh>Channel id</MudTh>
|
<MudTh>Channel id</MudTh>
|
||||||
<MudTh>Has login</MudTh>
|
|
||||||
</HeaderContent>
|
</HeaderContent>
|
||||||
<RowTemplate>
|
<RowTemplate>
|
||||||
|
<MudTd><MudImage Src="@(FileController.CreateProvideUrl(context.AvatarFileId))" Height="40"/></MudTd>
|
||||||
<MudTd>@context.Name</MudTd>
|
<MudTd>@context.Name</MudTd>
|
||||||
|
<MudTd>@context.Handle</MudTd>
|
||||||
<MudTd>@context.Id</MudTd>
|
<MudTd>@context.Id</MudTd>
|
||||||
<MudTd>@(context.ClientAccount != null)</MudTd>
|
|
||||||
</RowTemplate>
|
</RowTemplate>
|
||||||
<NoRecordsContent>
|
<NoRecordsContent>
|
||||||
<MudText>No channels found</MudText>
|
<MudText>No channels found</MudText>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Manager.App.Components.Dialogs;
|
using Manager.App.Models.Library;
|
||||||
using Manager.Data.Entities.LibraryContext;
|
|
||||||
using Manager.YouTube;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using MudBlazor;
|
using MudBlazor;
|
||||||
|
|
||||||
@@ -8,26 +6,18 @@ namespace Manager.App.Components.Pages;
|
|||||||
|
|
||||||
public partial class Channels : ComponentBase
|
public partial class Channels : ComponentBase
|
||||||
{
|
{
|
||||||
private readonly DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true, MaxWidth = MaxWidth.ExtraLarge };
|
private MudTable<ChannelListView>? _table;
|
||||||
|
private string _search = "";
|
||||||
|
|
||||||
private async Task<TableData<ChannelEntity>> ServerReload(TableState state, CancellationToken token)
|
private async Task<TableData<ChannelListView>> ServerReload(TableState state, CancellationToken token)
|
||||||
{
|
{
|
||||||
var results = await LibraryService.GetChannelAccountsAsync(state.Page * state.PageSize, state.PageSize, token);
|
var results = await LibraryService.GetChannelsAsync(_search, state.Page * state.PageSize, state.PageSize, token);
|
||||||
return !results.IsSuccess ? new TableData<ChannelEntity>() : new TableData<ChannelEntity> { Items = results.Value, TotalItems = results.Total };
|
return !results.IsSuccess ? new TableData<ChannelListView>() : new TableData<ChannelListView> { Items = results.Value, TotalItems = results.Total };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnAddAccountDialogAsync()
|
private void OnSearch(string text)
|
||||||
{
|
{
|
||||||
var libSettings = LibraryOptions.Value;
|
_search = text;
|
||||||
var parameters = new DialogParameters<AccountDialog> { { x => x.DefaultUserAgent, libSettings.DefaultUserAgent } };
|
_table?.ReloadServerData();
|
||||||
var dialog = await DialogService.ShowAsync<AccountDialog>("Add account", parameters, _dialogOptions);
|
|
||||||
var result = await dialog.Result;
|
|
||||||
|
|
||||||
if (result == null || result.Canceled || result.Data == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var client = (YouTubeClient)result.Data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
15
Manager.App/Components/Pages/Development.razor
Normal file
15
Manager.App/Components/Pages/Development.razor
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
@page "/Development"
|
||||||
|
@using Manager.App.Components.Application.Dev
|
||||||
|
<PageTitle>Development page</PageTitle>
|
||||||
|
|
||||||
|
<MudTabs Outlined Position="Position.Left" PanelClass="pa-4" ApplyEffectsToContainer Style="height: 100%">
|
||||||
|
<MudTabPanel Text="Authentication">
|
||||||
|
<AuthenticationHasher />
|
||||||
|
</MudTabPanel>
|
||||||
|
<MudTabPanel Text="Video">
|
||||||
|
<DevelopmentVideo />
|
||||||
|
</MudTabPanel>
|
||||||
|
<MudTabPanel Text="Cipher">
|
||||||
|
<CipherDev />
|
||||||
|
</MudTabPanel>
|
||||||
|
</MudTabs>
|
||||||
8
Manager.App/Components/Pages/Development.razor.cs
Normal file
8
Manager.App/Components/Pages/Development.razor.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
|
public partial class Development : ComponentBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,6 +26,18 @@
|
|||||||
<td>Library size:</td>
|
<td>Library size:</td>
|
||||||
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)")</td>
|
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)")</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Drive total size:</td>
|
||||||
|
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveTotalSpaceBytes)} ({_libraryInformation.DriveTotalSpaceBytes} bytes)")</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Drive used space:</td>
|
||||||
|
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveUsedSpaceBytes)} ({_libraryInformation.DriveUsedSpaceBytes} bytes)")</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Drive free space available:</td>
|
||||||
|
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.DriveFreeSpaceBytes)} ({_libraryInformation.DriveFreeSpaceBytes} bytes)")</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total media:</td>
|
<td>Total media:</td>
|
||||||
|
|||||||
45
Manager.App/Components/Pages/Services.razor
Normal file
45
Manager.App/Components/Pages/Services.razor
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
@page "/Services"
|
||||||
|
@using Manager.App.Services.System
|
||||||
|
@using Manager.App.Components.Application.System
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
|
@inject BackgroundServiceRegistry ServiceRegistry
|
||||||
|
|
||||||
|
<PageTitle>Services</PageTitle>
|
||||||
|
|
||||||
|
<MudDataGrid T="ExtendedBackgroundService" Items="@_backgroundServices" Filterable QuickFilter="@QuickFilter" Dense>
|
||||||
|
<ToolBarContent>
|
||||||
|
<MudText Typo="Typo.h6">Services</MudText>
|
||||||
|
<MudSpacer/>
|
||||||
|
<MudTextField T="string" @bind-Value="@_searchText" Immediate
|
||||||
|
Placeholder="Search" Adornment="Adornment.Start"
|
||||||
|
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium"/>
|
||||||
|
</ToolBarContent>
|
||||||
|
<Columns>
|
||||||
|
<PropertyColumn Property="x => x.Name" Title="Service"/>
|
||||||
|
<PropertyColumn Property="x => x.Description" Title="Description"/>
|
||||||
|
<PropertyColumn Property="x => x.State" Title="Status"/>
|
||||||
|
<PropertyColumn Property="x => x.ExecuteInterval" Title="Execute interval"/>
|
||||||
|
<TemplateColumn Title="Actions">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudMenu Icon="@Icons.Material.Filled.MoreVert"
|
||||||
|
AriaLabel="Actions">
|
||||||
|
@foreach (var action in context.Item?.Actions ?? [])
|
||||||
|
{
|
||||||
|
<MudMenuItem OnClick="@action.Action" Disabled="@(!action.IsEnabled())">
|
||||||
|
<MudTooltip Text="@action.Description">
|
||||||
|
<span>@action.Id</span>
|
||||||
|
</MudTooltip>
|
||||||
|
</MudMenuItem>
|
||||||
|
}
|
||||||
|
</MudMenu>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
</Columns>
|
||||||
|
<PagerContent>
|
||||||
|
<MudDataGridPager T="ExtendedBackgroundService"/>
|
||||||
|
</PagerContent>
|
||||||
|
</MudDataGrid>
|
||||||
|
|
||||||
|
<EventConsole AsyncEnumerable="@GetEventAsyncEnumerable()" InitialEvents="@GetInitialEvents()"
|
||||||
|
Elevation="0" Class="mt-3" Style="flex: 1; display: flex; flex-direction: column; min-height: 350px;"/>
|
||||||
41
Manager.App/Components/Pages/Services.razor.cs
Normal file
41
Manager.App/Components/Pages/Services.razor.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Manager.App.Extensions;
|
||||||
|
using Manager.App.Services;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
|
public partial class Services : ComponentBase
|
||||||
|
{
|
||||||
|
private string _searchText = "";
|
||||||
|
private List<ExtendedBackgroundService> _backgroundServices = [];
|
||||||
|
private readonly CancellationTokenSource _cts = new();
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
_backgroundServices = ServiceRegistry.GetServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Func<ExtendedBackgroundService, bool> QuickFilter
|
||||||
|
=> x => string.IsNullOrWhiteSpace(_searchText) || $"{x.Name} {x.Description} {x.State} {x.ExecuteInterval}".Contains(_searchText);
|
||||||
|
|
||||||
|
private IAsyncEnumerable<ServiceEvent> GetEventAsyncEnumerable()
|
||||||
|
{
|
||||||
|
var asyncEnumerators = _backgroundServices.Select(x => x.ProgressEvents.GetStreamAsync());
|
||||||
|
return AsyncEnumerableExtensions.Merge(asyncEnumerators, CancellationToken.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ServiceEvent> GetInitialEvents()
|
||||||
|
{
|
||||||
|
var totalToGet = 1000 / _backgroundServices.Count;
|
||||||
|
var initial = _backgroundServices
|
||||||
|
.SelectMany(x => x.ProgressEvents.Items.TakeLast(totalToGet))
|
||||||
|
.OrderBy(x => x.DateUtc);
|
||||||
|
return initial.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_cts.Cancel();
|
||||||
|
_cts.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
244
Manager.App/Components/Pages/Video.razor
Normal file
244
Manager.App/Components/Pages/Video.razor
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
@page "/Video/{VideoId}"
|
||||||
|
@using Manager.App.Services.System
|
||||||
|
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject ClientService ClientService
|
||||||
|
@inject CacheService Cache
|
||||||
|
|
||||||
|
<ForcedLoadingOverlay Visible="_loading"/>
|
||||||
|
@if (!_loading && _video != null)
|
||||||
|
{
|
||||||
|
<MudStack Spacing="2">
|
||||||
|
<MudCard>
|
||||||
|
@{
|
||||||
|
var thumbnailUrl = _video.Thumbnails.OrderByDescending(t => t.Width).FirstOrDefault()?.Url;
|
||||||
|
}
|
||||||
|
@if (!string.IsNullOrWhiteSpace(thumbnailUrl))
|
||||||
|
{
|
||||||
|
<MudCardMedia Image="@Cache.CreateCacheUrl(thumbnailUrl)" Height="500"/>
|
||||||
|
}
|
||||||
|
<MudCardContent>
|
||||||
|
<MudText Typo="Typo.h5">@_video.Title</MudText>
|
||||||
|
<MudText Typo="Typo.body2">@_video.Description</MudText>
|
||||||
|
</MudCardContent>
|
||||||
|
</MudCard>
|
||||||
|
<MudExpansionPanels MultiExpansion>
|
||||||
|
<MudExpansionPanel Text="Info" Expanded>
|
||||||
|
<MudStack Spacing="2" Row Wrap="Wrap.Wrap">
|
||||||
|
@* Info *@
|
||||||
|
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Video ID:</td>
|
||||||
|
<td>@_video.VideoId</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Title:</td>
|
||||||
|
<td>@_video.Title</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Description:</td>
|
||||||
|
<td>@_video.Description</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>HashTags:</td>
|
||||||
|
<td>@foreach (var hashtag in _video.HashTags)
|
||||||
|
{
|
||||||
|
<MudChip T="string" Variant="Variant.Text" Color="Color.Info">@hashtag</MudChip>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>View count:</td>
|
||||||
|
<td>@_video.ViewCount</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Like count:</td>
|
||||||
|
<td>@_video.LikeCount</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Channel ID:</td>
|
||||||
|
<td>@_video.ChannelId</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Author:</td>
|
||||||
|
<td>@_video.Author</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Playability status:</td>
|
||||||
|
<td>@_video.PlayabilityStatus</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Length seconds:</td>
|
||||||
|
<td>@_video.LengthSeconds</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Keywords:</td>
|
||||||
|
<td>@foreach (var keyword in _video.Keywords)
|
||||||
|
{
|
||||||
|
<MudChip T="string" Variant="Variant.Text">@keyword</MudChip>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Publish date:</td>
|
||||||
|
<td>@_video.PublishDate</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Upload date:</td>
|
||||||
|
<td>@_video.UploadDate</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Category:</td>
|
||||||
|
<td>@_video.Category</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</MudSimpleTable>
|
||||||
|
@* Boolean values *@
|
||||||
|
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Is owner viewing:</td>
|
||||||
|
<td>@_video.IsOwnerViewing</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Allow rating:</td>
|
||||||
|
<td>@_video.AllowRating</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is crawlable:</td>
|
||||||
|
<td>@_video.IsCrawlable</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is private:</td>
|
||||||
|
<td>@_video.IsPrivate</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is unplugged corpus:</td>
|
||||||
|
<td>@_video.IsUnpluggedCorpus</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is live:</td>
|
||||||
|
<td>@_video.IsLive</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is family save:</td>
|
||||||
|
<td>@_video.IsFamilySave</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is unlisted:</td>
|
||||||
|
<td>@_video.IsUnlisted</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Has Ypc metadata:</td>
|
||||||
|
<td>@_video.HasYpcMetadata</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Is shorts eligible:</td>
|
||||||
|
<td>@_video.IsShortsEligible</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</MudSimpleTable>
|
||||||
|
</MudStack>
|
||||||
|
</MudExpansionPanel>
|
||||||
|
<MudExpansionPanel Text="Streaming data">
|
||||||
|
@if (_video.StreamingData == null)
|
||||||
|
{
|
||||||
|
<MudAlert Severity="Severity.Info">No streaming data available!</MudAlert>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudStack Spacing="2" Row Wrap="Wrap.Wrap">
|
||||||
|
<MudStack>
|
||||||
|
<MudText Typo="Typo.h5">Adaptive Formats</MudText>
|
||||||
|
<MudTable Items="@_video.StreamingData.AdaptiveFormats">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Id</MudTh>
|
||||||
|
<MudTh>Mime type</MudTh>
|
||||||
|
<MudTh>Bitrate</MudTh>
|
||||||
|
<MudTh>Resolution</MudTh>
|
||||||
|
<MudTh>Last modified (UNIX epoch)</MudTh>
|
||||||
|
<MudTh>Quality</MudTh>
|
||||||
|
<MudTh>FPS</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Itag</MudTd>
|
||||||
|
<MudTd>@context.MimeType</MudTd>
|
||||||
|
<MudTd>@context.Bitrate</MudTd>
|
||||||
|
<MudTd>@($"{context.Width}x{context.Height}")</MudTd>
|
||||||
|
<MudTd>@context.LastModified</MudTd>
|
||||||
|
<MudTd>@context.Quality</MudTd>
|
||||||
|
<MudTd>@context.Fps</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
</MudStack>
|
||||||
|
<MudStack>
|
||||||
|
<MudText Typo="Typo.h5">Formats</MudText>
|
||||||
|
<MudTable Items="@_video.StreamingData.Formats">
|
||||||
|
<HeaderContent>
|
||||||
|
<MudTh>Id</MudTh>
|
||||||
|
<MudTh>Mime type</MudTh>
|
||||||
|
<MudTh>Bitrate</MudTh>
|
||||||
|
<MudTh>Resolution</MudTh>
|
||||||
|
<MudTh>Last modified (UNIX epoch)</MudTh>
|
||||||
|
<MudTh>Quality</MudTh>
|
||||||
|
<MudTh>FPS</MudTh>
|
||||||
|
</HeaderContent>
|
||||||
|
<RowTemplate>
|
||||||
|
<MudTd>@context.Itag</MudTd>
|
||||||
|
<MudTd>@context.MimeType</MudTd>
|
||||||
|
<MudTd>@context.Bitrate</MudTd>
|
||||||
|
<MudTd>@($"{context.Width}x{context.Height}")</MudTd>
|
||||||
|
<MudTd>@context.LastModified</MudTd>
|
||||||
|
<MudTd>@context.Quality</MudTd>
|
||||||
|
<MudTd>@context.Fps</MudTd>
|
||||||
|
</RowTemplate>
|
||||||
|
</MudTable>
|
||||||
|
</MudStack>
|
||||||
|
</MudStack>
|
||||||
|
}
|
||||||
|
</MudExpansionPanel>
|
||||||
|
<MudExpansionPanel Text="Player config">
|
||||||
|
@if (_video.PlayerConfig == null)
|
||||||
|
{
|
||||||
|
<MudAlert Severity="Severity.Info">No player config available!</MudAlert>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Audio loudness DB:</td>
|
||||||
|
<td>@_video.PlayerConfig.AudioLoudnessDb</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Audio perceptual loudness DB:</td>
|
||||||
|
<td>@_video.PlayerConfig.AudioPerceptualLoudnessDb</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Audio enable per format loudness:</td>
|
||||||
|
<td>@_video.PlayerConfig.AudioLoudnessDb</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Max bitrate:</td>
|
||||||
|
<td>@_video.PlayerConfig.MaxBitrate</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Max read ahead time MS:</td>
|
||||||
|
<td>@_video.PlayerConfig.MaxReadAheadMediaTimeMs</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Min read ahead time MS:</td>
|
||||||
|
<td>@_video.PlayerConfig.MinReadAheadMediaTimeMs</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Read ahead growth rate MS:</td>
|
||||||
|
<td>@_video.PlayerConfig.ReadAheadGrowthRateMs</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</MudSimpleTable>
|
||||||
|
}
|
||||||
|
</MudExpansionPanel>
|
||||||
|
</MudExpansionPanels>
|
||||||
|
</MudStack>
|
||||||
|
}
|
||||||
48
Manager.App/Components/Pages/Video.razor.cs
Normal file
48
Manager.App/Components/Pages/Video.razor.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using Manager.YouTube.Models;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using MudBlazor;
|
||||||
|
|
||||||
|
namespace Manager.App.Components.Pages;
|
||||||
|
|
||||||
|
public partial class Video : ComponentBase
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public required string VideoId { get; set; }
|
||||||
|
|
||||||
|
[SupplyParameterFromQuery(Name = "clientId")]
|
||||||
|
public string ClientId { get; set; } = "";
|
||||||
|
|
||||||
|
private bool _loading = true;
|
||||||
|
private YouTubeVideo? _video;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(VideoId))
|
||||||
|
{
|
||||||
|
Snackbar.Add("Video id is null or empty!", Severity.Error);
|
||||||
|
_loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientResult = await ClientService.LoadClientByIdAsync(ClientId);
|
||||||
|
if (!clientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
Snackbar.Add(clientResult.Error?.Description ?? "Failed to load client!", Severity.Error);
|
||||||
|
_loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var client = clientResult.Value;
|
||||||
|
|
||||||
|
var videoResult = await client.GetVideoByIdAsync(VideoId);
|
||||||
|
if (!videoResult.IsSuccess)
|
||||||
|
{
|
||||||
|
Snackbar.Add(videoResult.Error?.Description ?? "Failed to get video.", Severity.Error);
|
||||||
|
_loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_video = videoResult.Value;
|
||||||
|
_loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,4 +3,5 @@
|
|||||||
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)"/>
|
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)"/>
|
||||||
<FocusOnNavigate RouteData="routeData" Selector="h1"/>
|
<FocusOnNavigate RouteData="routeData" Selector="h1"/>
|
||||||
</Found>
|
</Found>
|
||||||
</Router>
|
</Router>
|
||||||
|
<HeadOutlet />
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
@using System.Net.Http
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using System.Net.Http.Json
|
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||||
|
|||||||
18
Manager.App/Constants/LibraryConstants.cs
Normal file
18
Manager.App/Constants/LibraryConstants.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Manager.App.Constants;
|
||||||
|
|
||||||
|
public static class LibraryConstants
|
||||||
|
{
|
||||||
|
public static class Directories
|
||||||
|
{
|
||||||
|
public const string SubDirMedia = "Media";
|
||||||
|
public const string SubDirChannels = "Channels";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FileTypes
|
||||||
|
{
|
||||||
|
public const string ChannelAvatar = "channel/avatar";
|
||||||
|
public const string ChannelBanner = "channel/banner";
|
||||||
|
public const string VideoThumbnail = "video/thumbnail";
|
||||||
|
public const string VideoCaption = "video/caption";
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Manager.App/Controllers/CacheController.cs
Normal file
27
Manager.App/Controllers/CacheController.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Manager.App.Services.System;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Manager.App.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/v1/[controller]")]
|
||||||
|
public class CacheController(ILogger<CacheController> logger, CacheService cacheService) : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> Cache([FromQuery(Name = "url")] string url, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(url))
|
||||||
|
{
|
||||||
|
return BadRequest("No url given.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var cacheResult = await cacheService.CacheFromUrl(url, cancellationToken);
|
||||||
|
if (!cacheResult.IsSuccess)
|
||||||
|
{
|
||||||
|
logger.LogError("Cache request failed. {ErrorMessage}", cacheResult.Error?.Description);
|
||||||
|
return StatusCode(500, cacheResult.Error?.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File(cacheResult.Value.Data, cacheResult.Value.ContentType ?? string.Empty, cacheResult.Value.OriginalFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Manager.App/Controllers/FileController.cs
Normal file
24
Manager.App/Controllers/FileController.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Manager.App.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Manager.App.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/v1/[controller]")]
|
||||||
|
public class FileController(ILibraryService libraryService) : ControllerBase
|
||||||
|
{
|
||||||
|
public static string CreateProvideUrl(Guid? id) => id == null ? "" : $"/api/v1/file/provide?id={id}";
|
||||||
|
|
||||||
|
[HttpGet("provide")]
|
||||||
|
public async Task<IActionResult> ProvideFile([FromQuery(Name = "id")] Guid id, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var fileResult = await libraryService.GetFileByIdAsync(id, cancellationToken);
|
||||||
|
if (!fileResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return BadRequest(fileResult.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
var libFile = fileResult.Value;
|
||||||
|
return File(libFile.DataStream, libFile.MimeType, libFile.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using DotBased.Logging.MEL;
|
|||||||
using DotBased.Logging.Serilog;
|
using DotBased.Logging.Serilog;
|
||||||
using Manager.App.Models.Settings;
|
using Manager.App.Models.Settings;
|
||||||
using Manager.App.Services;
|
using Manager.App.Services;
|
||||||
|
using Manager.App.Services.System;
|
||||||
using Manager.Data.Contexts;
|
using Manager.Data.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -23,7 +24,9 @@ public static class DependencyInjection
|
|||||||
logger.LogInformation("Setting library database to: {DbPath}", dbPath);
|
logger.LogInformation("Setting library database to: {DbPath}", dbPath);
|
||||||
options.UseSqlite($"Data Source={dbPath}");
|
options.UseSqlite($"Data Source={dbPath}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.RegisterExtendedBackgroundServices();
|
||||||
|
|
||||||
builder.Services.AddScoped<ILibraryService, LibraryService>();
|
builder.Services.AddScoped<ILibraryService, LibraryService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,4 +86,20 @@ public static class DependencyInjection
|
|||||||
builder.Logging.SetMinimumLevel(isDevelopment ? LogLevel.Trace : LogLevel.Information);
|
builder.Logging.SetMinimumLevel(isDevelopment ? LogLevel.Trace : LogLevel.Information);
|
||||||
builder.Logging.AddDotBasedLoggerProvider(LogService.Options);
|
builder.Logging.AddDotBasedLoggerProvider(LogService.Options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RegisterExtendedBackgroundServices(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var assembly = typeof(Program).Assembly;
|
||||||
|
|
||||||
|
foreach (var exBgService in assembly.GetTypes()
|
||||||
|
.Where(t => typeof(ExtendedBackgroundService).IsAssignableFrom(t)
|
||||||
|
&& t is { IsClass: true, IsAbstract: false }))
|
||||||
|
{
|
||||||
|
builder.Services.AddSingleton(exBgService);
|
||||||
|
builder.Services.AddSingleton(typeof(ExtendedBackgroundService), sp => (ExtendedBackgroundService)sp.GetRequiredService(exBgService));
|
||||||
|
builder.Services.AddSingleton<IHostedService>(sp => (IHostedService)sp.GetRequiredService(exBgService));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<BackgroundServiceRegistry>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
48
Manager.App/Extensions/AsyncEnumerableExtensions.cs
Normal file
48
Manager.App/Extensions/AsyncEnumerableExtensions.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System.Threading.Channels;
|
||||||
|
|
||||||
|
namespace Manager.App.Extensions;
|
||||||
|
|
||||||
|
public static class AsyncEnumerableExtensions
|
||||||
|
{
|
||||||
|
public static async IAsyncEnumerable<T> Merge<T>(IEnumerable<IAsyncEnumerable<T>> sources, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var channel = Channel.CreateUnbounded<T>( new UnboundedChannelOptions { SingleReader = true, SingleWriter = false });
|
||||||
|
|
||||||
|
var writerTasks = sources.Select(source => Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await foreach (var item in source.WithCancellation(cancellationToken))
|
||||||
|
{
|
||||||
|
await channel.Writer.WriteAsync(item, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
channel.Writer.TryComplete(ex);
|
||||||
|
}
|
||||||
|
}, cancellationToken)).ToArray();
|
||||||
|
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.WhenAll(writerTasks);
|
||||||
|
channel.Writer.TryComplete();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
channel.Writer.TryComplete();
|
||||||
|
}
|
||||||
|
}, cancellationToken);
|
||||||
|
|
||||||
|
await foreach (var item in channel.Reader.ReadAllAsync(cancellationToken))
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css" />
|
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css" />
|
||||||
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css.map" />
|
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css.map" />
|
||||||
|
<_ContentIncludedByDefault Remove="wwwroot\js\console.js" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="cache\" />
|
||||||
<Folder Include="Library\" />
|
<Folder Include="Library\" />
|
||||||
<Folder Include="Logs\Debug\" />
|
<Folder Include="Logs\Debug\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ public record LibraryInformation
|
|||||||
public long TotalMedia { get; set; }
|
public long TotalMedia { get; set; }
|
||||||
public long TotalChannels { get; set; }
|
public long TotalChannels { get; set; }
|
||||||
public long TotalSizeBytes { get; set; }
|
public long TotalSizeBytes { get; set; }
|
||||||
|
public long DriveTotalSpaceBytes { get; set; }
|
||||||
|
public long DriveFreeSpaceBytes { get; set; }
|
||||||
|
public long DriveUsedSpaceBytes { get; set; }
|
||||||
}
|
}
|
||||||
16
Manager.App/Models/System/YouTubeClientItem.cs
Normal file
16
Manager.App/Models/System/YouTubeClientItem.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Manager.App.Models.Library;
|
||||||
|
|
||||||
|
namespace Manager.App.Models.System;
|
||||||
|
|
||||||
|
public class YouTubeClientItem : AccountListView
|
||||||
|
{
|
||||||
|
public YouTubeClientItem(AccountListView accountListView)
|
||||||
|
{
|
||||||
|
Id = accountListView.Id;
|
||||||
|
Name = accountListView.Name;
|
||||||
|
Handle = accountListView.Handle;
|
||||||
|
HasCookies = accountListView.HasCookies;
|
||||||
|
AvatarFileId = accountListView.AvatarFileId;
|
||||||
|
}
|
||||||
|
public bool IsLoaded { get; set; }
|
||||||
|
}
|
||||||
@@ -8,6 +8,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
|
|
||||||
|
AppContext.SetSwitch("System.Net.Http.EnableActivityPropagation", false);
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
/* Manager */
|
/* Manager */
|
||||||
builder.SetupLogging();
|
builder.SetupLogging();
|
||||||
@@ -31,6 +34,7 @@ app.UseHttpsRedirection();
|
|||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseAntiforgery();
|
app.UseAntiforgery();
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
app.MapRazorComponents<App>()
|
app.MapRazorComponents<App>()
|
||||||
.AddInteractiveServerRenderMode();
|
.AddInteractiveServerRenderMode();
|
||||||
|
|||||||
64
Manager.App/Services/CircularBuffer.cs
Normal file
64
Manager.App/Services/CircularBuffer.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System.Threading.Channels;
|
||||||
|
|
||||||
|
namespace Manager.App.Services;
|
||||||
|
|
||||||
|
public class CircularBuffer <T>
|
||||||
|
{
|
||||||
|
private readonly T[] _buffer;
|
||||||
|
private readonly Channel<T> _channel;
|
||||||
|
private readonly object _lock = new();
|
||||||
|
|
||||||
|
public int Capacity { get; }
|
||||||
|
public int Head { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public CircularBuffer(int capacity)
|
||||||
|
{
|
||||||
|
if (capacity <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(capacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
Capacity = capacity;
|
||||||
|
_buffer = new T[Capacity];
|
||||||
|
_channel = Channel.CreateBounded<T>(new BoundedChannelOptions(Capacity)
|
||||||
|
{
|
||||||
|
SingleReader = false,
|
||||||
|
SingleWriter = false,
|
||||||
|
FullMode = BoundedChannelFullMode.DropOldest
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(T item)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
_buffer[Head] = item;
|
||||||
|
Head = (Head + 1) % _buffer.Length;
|
||||||
|
|
||||||
|
if (Count < _buffer.Length)
|
||||||
|
{
|
||||||
|
Count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_channel.Writer.TryWrite(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T> Items
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
for (var i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
yield return _buffer[(Head - Count + i + _buffer.Length) % _buffer.Length];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAsyncEnumerable<T> GetStreamAsync() => _channel.Reader.ReadAllAsync();
|
||||||
|
}
|
||||||
138
Manager.App/Services/ExtendedBackgroundService.cs
Normal file
138
Manager.App/Services/ExtendedBackgroundService.cs
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
using DotBased.Logging;
|
||||||
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||||
|
|
||||||
|
namespace Manager.App.Services;
|
||||||
|
|
||||||
|
public abstract class ExtendedBackgroundService(string name, string description, ILogger logger, TimeSpan? executeInterval = null)
|
||||||
|
: BackgroundService
|
||||||
|
{
|
||||||
|
private TaskCompletionSource _resumeSignal = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
private readonly List<ServiceAction> _actions = [];
|
||||||
|
private TaskCompletionSource? _manualContinue;
|
||||||
|
|
||||||
|
public ServiceState State { get; private set; } = ServiceState.Stopped;
|
||||||
|
public CircularBuffer<ServiceEvent> ProgressEvents { get; } = new(500);
|
||||||
|
public string Name { get; } = name;
|
||||||
|
public string Description { get; } = description;
|
||||||
|
public TimeSpan ExecuteInterval { get; } = executeInterval ?? TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
|
public IReadOnlyList<ServiceAction> Actions => _actions;
|
||||||
|
|
||||||
|
protected void AddActions(IEnumerable<ServiceAction> actions)
|
||||||
|
{
|
||||||
|
_actions.AddRange(actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected sealed override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
State = ServiceState.Running;
|
||||||
|
logger.LogInformation("Initializing background service: {ServiceName}", Name);
|
||||||
|
|
||||||
|
_actions.AddRange(
|
||||||
|
[
|
||||||
|
new ServiceAction("Start", "Start the service (after the service is stopped of faulted.)", Start, () => State is ServiceState.Stopped or ServiceState.Faulted),
|
||||||
|
new ServiceAction("Pause", "Pause the service", Pause, () => State != ServiceState.Paused),
|
||||||
|
new ServiceAction("Resume", "Resume the service", Resume, () => State != ServiceState.Running)
|
||||||
|
]);
|
||||||
|
|
||||||
|
await InitializeAsync(stoppingToken);
|
||||||
|
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
if (State == ServiceState.Running)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation("Started running background service: {ServiceName}", Name);
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
if (State == ServiceState.Paused)
|
||||||
|
{
|
||||||
|
_resumeSignal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
await _resumeSignal.Task.WaitAsync(stoppingToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
await ExecuteServiceAsync(stoppingToken);
|
||||||
|
|
||||||
|
await Task.Delay(ExecuteInterval, stoppingToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException e)
|
||||||
|
{
|
||||||
|
logger.LogInformation(e, "Service {ServiceName} received cancellation", Name);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
State = ServiceState.Faulted;
|
||||||
|
logger.LogError(e, "Background service {ServiceName} faulted!", Name);
|
||||||
|
LogEvent("Error executing background service.", LogSeverity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
State = ServiceState.Stopped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_manualContinue = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
var delayTask = Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
||||||
|
await Task.WhenAny(delayTask, _manualContinue.Task);
|
||||||
|
_manualContinue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void LogEvent(string message, LogSeverity severity = LogSeverity.Info) => ProgressEvents.Add(new ServiceEvent(string.Intern(Name), message, DateTime.UtcNow, severity));
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
if (State is ServiceState.Stopped or ServiceState.Faulted)
|
||||||
|
{
|
||||||
|
State = ServiceState.Running;
|
||||||
|
_manualContinue?.TrySetResult();
|
||||||
|
LogEvent("Started service.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Pause()
|
||||||
|
{
|
||||||
|
if (State == ServiceState.Running)
|
||||||
|
{
|
||||||
|
State = ServiceState.Paused;
|
||||||
|
LogEvent("Service paused.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Resume()
|
||||||
|
{
|
||||||
|
if (State == ServiceState.Paused)
|
||||||
|
{
|
||||||
|
State = ServiceState.Running;
|
||||||
|
_resumeSignal.TrySetResult();
|
||||||
|
LogEvent("Service resumed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task InitializeAsync(CancellationToken stoppingToken);
|
||||||
|
protected abstract Task ExecuteServiceAsync(CancellationToken stoppingToken);
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
return obj is ExtendedBackgroundService bgService && bgService.Name.Equals(Name, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ServiceState
|
||||||
|
{
|
||||||
|
Stopped,
|
||||||
|
Faulted,
|
||||||
|
Running,
|
||||||
|
Paused
|
||||||
|
}
|
||||||
|
|
||||||
|
public record struct ServiceEvent(string Source, string Message, DateTime DateUtc, LogSeverity Severity);
|
||||||
|
|
||||||
|
public record ServiceAction(string Id, string Description, Action Action, Func<bool> IsEnabled);
|
||||||
@@ -2,12 +2,17 @@ using DotBased.Monads;
|
|||||||
using Manager.App.Models.Library;
|
using Manager.App.Models.Library;
|
||||||
using Manager.App.Models.System;
|
using Manager.App.Models.System;
|
||||||
using Manager.Data.Entities.LibraryContext;
|
using Manager.Data.Entities.LibraryContext;
|
||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
namespace Manager.App.Services;
|
namespace Manager.App.Services;
|
||||||
|
|
||||||
public interface ILibraryService
|
public interface ILibraryService
|
||||||
{
|
{
|
||||||
|
public Task<Result> SaveClientAsync(ClientAccountEntity client, CancellationToken cancellationToken = default);
|
||||||
|
public Task<Result<LibraryFile>> GetFileByIdAsync(Guid id, CancellationToken cancellationToken = default);
|
||||||
|
public Task<Result<ChannelEntity>> GetChannelByIdAsync(string id, CancellationToken cancellationToken = default);
|
||||||
|
public Task<Result> SaveChannelAsync(InnertubeChannel innertubeChannel, CancellationToken cancellationToken = default);
|
||||||
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
|
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
|
||||||
|
public Task<ListResult<AccountListView>> GetAccountsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
|
||||||
public Task<ListResult<ChannelEntity>> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default);
|
public Task<ListResult<ChannelListView>> GetChannelsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
|
using System.Net.Mime;
|
||||||
using DotBased.Monads;
|
using DotBased.Monads;
|
||||||
|
using Manager.App.Constants;
|
||||||
using Manager.App.Models.Library;
|
using Manager.App.Models.Library;
|
||||||
using Manager.App.Models.Settings;
|
using Manager.App.Models.Settings;
|
||||||
using Manager.App.Models.System;
|
using Manager.App.Models.System;
|
||||||
|
using Manager.App.Services.System;
|
||||||
using Manager.Data.Contexts;
|
using Manager.Data.Contexts;
|
||||||
using Manager.Data.Entities.LibraryContext;
|
using Manager.Data.Entities.LibraryContext;
|
||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -12,21 +16,206 @@ namespace Manager.App.Services;
|
|||||||
public class LibraryService : ILibraryService
|
public class LibraryService : ILibraryService
|
||||||
{
|
{
|
||||||
private readonly ILogger<LibraryService> _logger;
|
private readonly ILogger<LibraryService> _logger;
|
||||||
private readonly LibrarySettings _librarySettings;
|
|
||||||
private readonly IDbContextFactory<LibraryDbContext> _dbContextFactory;
|
private readonly IDbContextFactory<LibraryDbContext> _dbContextFactory;
|
||||||
private readonly DirectoryInfo _libraryDirectory;
|
private readonly DirectoryInfo _libraryDirectory;
|
||||||
private const string SubDirMedia = "Media";
|
private readonly CacheService _cacheService;
|
||||||
private const string SubDirChannels = "Channels";
|
|
||||||
|
public LibraryService(ILogger<LibraryService> logger, IOptions<LibrarySettings> librarySettings, IDbContextFactory<LibraryDbContext> contextFactory, CacheService cacheService)
|
||||||
public LibraryService(ILogger<LibraryService> logger, IOptions<LibrarySettings> librarySettings, IDbContextFactory<LibraryDbContext> contextFactory)
|
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_librarySettings = librarySettings.Value;
|
var librarySettings1 = librarySettings.Value;
|
||||||
_dbContextFactory = contextFactory;
|
_dbContextFactory = contextFactory;
|
||||||
_libraryDirectory = Directory.CreateDirectory(_librarySettings.Path);
|
_cacheService = cacheService;
|
||||||
logger.LogDebug("Working dir for library: {LibraryWorkingDir}", _libraryDirectory.FullName);
|
_libraryDirectory = Directory.CreateDirectory(librarySettings1.Path);
|
||||||
Directory.CreateDirectory(Path.Combine(_librarySettings.Path, SubDirMedia));
|
logger.LogDebug("Library directory: {LibraryWorkingDir}", _libraryDirectory.FullName);
|
||||||
Directory.CreateDirectory(Path.Combine(_librarySettings.Path, SubDirChannels));
|
Directory.CreateDirectory(Path.Combine(librarySettings1.Path, LibraryConstants.Directories.SubDirMedia));
|
||||||
|
Directory.CreateDirectory(Path.Combine(librarySettings1.Path, LibraryConstants.Directories.SubDirChannels));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddWebImagesAsync(LibraryDbContext context, List<WebImage> images, string foreignKey, string libSubDir, string fileType, string subDir)
|
||||||
|
{
|
||||||
|
foreach (var image in images)
|
||||||
|
{
|
||||||
|
if (context.Files.Any(f => image.Url.Equals(f.OriginalUrl)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cacheResult = await _cacheService.CacheFromUrl(image.Url);
|
||||||
|
if (!cacheResult.IsSuccess)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to get image {ImageUrl}", image.Url);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cachedFile = cacheResult.Value;
|
||||||
|
|
||||||
|
var fileId = Guid.NewGuid();
|
||||||
|
var fileName = cachedFile.OriginalFileName ?? $"{fileId}.{cachedFile.ContentType?.Split('/').Last() ?? "unknown"}";
|
||||||
|
var relativePath = Path.Combine(foreignKey, libSubDir, $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}_{fileName}");
|
||||||
|
var savePath = Path.Combine(_libraryDirectory.FullName, subDir, relativePath);
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(savePath) ?? savePath);
|
||||||
|
await using var fileStream = File.Create(savePath);
|
||||||
|
await fileStream.WriteAsync(cachedFile.Data.AsMemory(0, cachedFile.Data.Length));
|
||||||
|
|
||||||
|
var file = new FileEntity
|
||||||
|
{
|
||||||
|
Id = fileId,
|
||||||
|
OriginalUrl = image.Url,
|
||||||
|
OriginalFileName = cachedFile.OriginalFileName,
|
||||||
|
ForeignKey = foreignKey,
|
||||||
|
FileType = fileType,
|
||||||
|
RelativePath = relativePath.Replace('\\', '/'),
|
||||||
|
MimeType = cachedFile.ContentType,
|
||||||
|
SizeBytes = cachedFile.Data.Length,
|
||||||
|
Height = image.Height,
|
||||||
|
Width = image.Width
|
||||||
|
};
|
||||||
|
|
||||||
|
await context.Files.AddAsync(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result> SaveClientAsync(ClientAccountEntity client, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var updateEntity = false;
|
||||||
|
var dbClient = context.ClientAccounts.Include(ca => ca.HttpCookies).FirstOrDefault(c => c.Id == client.Id);
|
||||||
|
if (dbClient == null)
|
||||||
|
{
|
||||||
|
dbClient = client;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateEntity = true;
|
||||||
|
dbClient.HttpCookies = client.HttpCookies;
|
||||||
|
dbClient.UserAgent = client.UserAgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateEntity)
|
||||||
|
{
|
||||||
|
context.ClientAccounts.Update(dbClient);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.HttpCookies.RemoveRange(context.HttpCookies.Where(x => x.ClientId == client.Id));
|
||||||
|
context.ClientAccounts.Add(dbClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
var savedResult= await context.SaveChangesAsync(cancellationToken);
|
||||||
|
return savedResult <= 0 ? ResultError.Fail("Could not save changes!") : Result.Success();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HandleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result<LibraryFile>> GetFileByIdAsync(Guid id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
var file = context.Files.FirstOrDefault(f => f.Id == id);
|
||||||
|
if (file == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail($"File with id {id} not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var fs = new FileStream(Path.Combine(_libraryDirectory.FullName, LibraryConstants.Directories.SubDirChannels, file.RelativePath), FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
|
return new LibraryFile { DataStream = fs, SizeBytes = file.SizeBytes, FileName = file.OriginalFileName ?? file.Id.ToString(), MimeType = file.MimeType ?? MediaTypeNames.Application.Octet };
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HandleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result<ChannelEntity>> GetChannelByIdAsync(string id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(id))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Channel id cannot be null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
var channel = await context.Channels.AsSplitQuery()
|
||||||
|
.Include(c => c.ClientAccount)
|
||||||
|
.ThenInclude(p => p!.HttpCookies)
|
||||||
|
.Include(f => f.Files)
|
||||||
|
.FirstOrDefaultAsync(c => c.Id == id, cancellationToken);
|
||||||
|
|
||||||
|
if (channel == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Channel not found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HandleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result> SaveChannelAsync(InnertubeChannel innertubeChannel, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var channelResult = await GetChannelByIdAsync(innertubeChannel.Id, cancellationToken);
|
||||||
|
|
||||||
|
ChannelEntity? channelEntity;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (channelResult.IsSuccess)
|
||||||
|
{
|
||||||
|
channelEntity = channelResult.Value;
|
||||||
|
channelEntity.Name = innertubeChannel.ChannelName;
|
||||||
|
channelEntity.Handle = innertubeChannel.Handle;
|
||||||
|
channelEntity.Description = innertubeChannel.Description;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
channelEntity = new ChannelEntity
|
||||||
|
{
|
||||||
|
Id = innertubeChannel.Id,
|
||||||
|
Name = innertubeChannel.ChannelName,
|
||||||
|
Handle = innertubeChannel.Handle,
|
||||||
|
Description = innertubeChannel.Description
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return ResultError.Error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channelResult.IsSuccess)
|
||||||
|
{
|
||||||
|
context.Channels.Update(channelEntity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Channels.Add(channelEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
await AddWebImagesAsync(context, innertubeChannel.AvatarImages, innertubeChannel.Id, "avatars", LibraryConstants.FileTypes.ChannelAvatar, LibraryConstants.Directories.SubDirChannels);
|
||||||
|
await AddWebImagesAsync(context, innertubeChannel.BannerImages, innertubeChannel.Id, "banners", LibraryConstants.FileTypes.ChannelBanner, LibraryConstants.Directories.SubDirChannels);
|
||||||
|
|
||||||
|
var changed = await context.SaveChangesAsync(cancellationToken);
|
||||||
|
return changed <= 0 ? ResultError.Fail("Failed to save channel!") : Result.Success();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HandleException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default)
|
public async Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default)
|
||||||
@@ -34,6 +223,7 @@ public class LibraryService : ILibraryService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
var libraryDriveInfo = GetLibraryDriveInfo(_libraryDirectory);
|
||||||
var libInfo = new LibraryInformation
|
var libInfo = new LibraryInformation
|
||||||
{
|
{
|
||||||
LibraryPath = _libraryDirectory.FullName,
|
LibraryPath = _libraryDirectory.FullName,
|
||||||
@@ -41,7 +231,10 @@ public class LibraryService : ILibraryService
|
|||||||
LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc,
|
LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc,
|
||||||
TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken),
|
TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken),
|
||||||
TotalMedia = await context.Media.CountAsync(cancellationToken: cancellationToken),
|
TotalMedia = await context.Media.CountAsync(cancellationToken: cancellationToken),
|
||||||
TotalSizeBytes = GetDirectorySize(_libraryDirectory)
|
TotalSizeBytes = GetDirectorySize(_libraryDirectory),
|
||||||
|
DriveTotalSpaceBytes = libraryDriveInfo.totalSpace,
|
||||||
|
DriveFreeSpaceBytes = libraryDriveInfo.freeSpace,
|
||||||
|
DriveUsedSpaceBytes = libraryDriveInfo.usedSpace
|
||||||
};
|
};
|
||||||
return libInfo;
|
return libInfo;
|
||||||
}
|
}
|
||||||
@@ -50,14 +243,98 @@ public class LibraryService : ILibraryService
|
|||||||
return HandleException(e);
|
return HandleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ListResult<ChannelEntity>> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default)
|
public async Task<ListResult<AccountListView>> GetAccountsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
if (total == 0)
|
||||||
|
{
|
||||||
|
total = 20;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
var orderedAccounts = context.Channels.Include(x => x.ClientAccount).Where(x => x.ClientAccount != null).OrderBy(x => x.Id);
|
var accountsQuery = context.ClientAccounts
|
||||||
return new ListResultReturn<ChannelEntity>(orderedAccounts.Skip(offset).Take(total).ToList(), orderedAccounts.Count());
|
.Include(ca => ca.Channel)
|
||||||
|
.Include(ca => ca.HttpCookies)
|
||||||
|
.OrderByDescending(ca => ca.Id).AsQueryable();
|
||||||
|
var totalAccounts = accountsQuery.Count();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(search) && totalAccounts != 0)
|
||||||
|
{
|
||||||
|
var normalizedSearch = $"%{search.ToLower()}%";
|
||||||
|
accountsQuery = accountsQuery
|
||||||
|
.Where(ca =>
|
||||||
|
EF.Functions.Like(
|
||||||
|
(
|
||||||
|
ca.Id.ToString() + " " +
|
||||||
|
(ca.Channel != null ? ca.Channel.Name : "") + " " +
|
||||||
|
(ca.Channel != null ? ca.Channel.Handle : "")
|
||||||
|
).ToLower(),
|
||||||
|
normalizedSearch
|
||||||
|
)
|
||||||
|
);
|
||||||
|
totalAccounts = accountsQuery.Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountViews = accountsQuery.Skip(offset).Take(total).Select(account => new AccountListView
|
||||||
|
{
|
||||||
|
Id = account.Id,
|
||||||
|
Name = account.Channel != null ? account.Channel.Name : "",
|
||||||
|
Handle = account.Channel != null ? account.Channel.Handle : "",
|
||||||
|
HasCookies = account.HttpCookies.Count != 0,
|
||||||
|
AvatarFileId = account.Files == null ? null
|
||||||
|
: account.Files.Where(f => f.FileType == LibraryConstants.FileTypes.ChannelAvatar).OrderBy(x => x.Id).Select(f => f.Id).FirstOrDefault()
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ListResultReturn<AccountListView>(totalAccounts == 0 ? [] : accountViews.ToList(), totalAccounts);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HandleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ListResult<ChannelListView>> GetChannelsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (total == 0)
|
||||||
|
{
|
||||||
|
total = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var channelQuery = context.Channels.OrderByDescending(c => c.Id).AsQueryable();
|
||||||
|
|
||||||
|
var totalChannels = channelQuery.Count();
|
||||||
|
if (!string.IsNullOrWhiteSpace(search) && totalChannels != 0)
|
||||||
|
{
|
||||||
|
var normalizedSearch = $"%{search.ToLower()}%";
|
||||||
|
channelQuery = channelQuery
|
||||||
|
.Where(ca =>
|
||||||
|
EF.Functions.Like((
|
||||||
|
ca.Id.ToString() + " " +
|
||||||
|
ca.Name + " " +
|
||||||
|
ca.Handle
|
||||||
|
).ToLower(),
|
||||||
|
normalizedSearch
|
||||||
|
)
|
||||||
|
);
|
||||||
|
totalChannels = channelQuery.Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
var channelViews = channelQuery.Skip(offset).Take(total).Select(channel => new ChannelListView
|
||||||
|
{
|
||||||
|
Id = channel.Id,
|
||||||
|
Name = channel.Name,
|
||||||
|
Handle = channel.Handle,
|
||||||
|
AvatarFileId = channel.Files == null ? null
|
||||||
|
: channel.Files.Where(f => f.FileType == LibraryConstants.FileTypes.ChannelAvatar).OrderBy(x => x.Id).Select(f => f.Id).FirstOrDefault()
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ListResultReturn<ChannelListView>(totalChannels == 0 ? [] : channelViews.ToList(), totalChannels);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -79,6 +356,20 @@ public class LibraryService : ILibraryService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private (long totalSpace, long freeSpace, long usedSpace) GetLibraryDriveInfo(DirectoryInfo dir)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var drive = new DriveInfo(dir.FullName);
|
||||||
|
return (drive.TotalSize, drive.AvailableFreeSpace, drive.TotalSize - drive.AvailableFreeSpace);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Error while getting directory free space.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ResultError HandleException(Exception exception)
|
private ResultError HandleException(Exception exception)
|
||||||
{
|
{
|
||||||
if (exception is OperationCanceledException)
|
if (exception is OperationCanceledException)
|
||||||
@@ -86,7 +377,7 @@ public class LibraryService : ILibraryService
|
|||||||
return ResultError.Fail("Library service operation cancelled");
|
return ResultError.Fail("Library service operation cancelled");
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogError(exception, "Failed to get library information");
|
_logger.LogError(exception, "Service error");
|
||||||
return ResultError.Fail("Failed to get library information");
|
return ResultError.Error(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
9
Manager.App/Services/System/BackgroundServiceRegistry.cs
Normal file
9
Manager.App/Services/System/BackgroundServiceRegistry.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Manager.App.Services.System;
|
||||||
|
|
||||||
|
public class BackgroundServiceRegistry(IEnumerable<ExtendedBackgroundService> backgroundServices)
|
||||||
|
{
|
||||||
|
public List<ExtendedBackgroundService> GetServices()
|
||||||
|
{
|
||||||
|
return backgroundServices.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
224
Manager.App/Services/System/CacheService.cs
Normal file
224
Manager.App/Services/System/CacheService.cs
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using DotBased.Logging;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using DotBased.Utilities;
|
||||||
|
using Manager.Data.Contexts;
|
||||||
|
using Manager.Data.Entities.Cache;
|
||||||
|
using Manager.YouTube;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
|
||||||
|
namespace Manager.App.Services.System;
|
||||||
|
|
||||||
|
public class CacheService(ILogger<CacheService> logger, IHostEnvironment environment)
|
||||||
|
: ExtendedBackgroundService(nameof(CacheService), "Manages caching.", logger, TimeSpan.FromHours(5))
|
||||||
|
{
|
||||||
|
private DirectoryInfo? _cacheDirectory;
|
||||||
|
private PooledDbContextFactory<CacheDbContext>? _dbContextFactory;
|
||||||
|
private const string DataSubDir = "data";
|
||||||
|
private const int CacheMaxAgeDays = 1;
|
||||||
|
private readonly SemaphoreSlim _cacheSemaphoreSlim = new(1, 1);
|
||||||
|
|
||||||
|
protected override Task InitializeAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
_cacheDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "cache"));
|
||||||
|
_cacheDirectory.Create();
|
||||||
|
Directory.CreateDirectory(Path.Combine(_cacheDirectory.FullName, DataSubDir));
|
||||||
|
LogEvent($"Cache directory: {_cacheDirectory.FullName}");
|
||||||
|
|
||||||
|
AddActions([
|
||||||
|
new ServiceAction("Clear cache", "Manually clear cache", () =>
|
||||||
|
{
|
||||||
|
LogEvent("Manual cache clear requested.");
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ClearCacheAsync(stoppingToken);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "Error clearing cache manually!");
|
||||||
|
LogEvent("Error manually clearing cache.", LogSeverity.Error);
|
||||||
|
}
|
||||||
|
}, stoppingToken);
|
||||||
|
}, () => true)
|
||||||
|
]);
|
||||||
|
|
||||||
|
var dbContextOptionsBuilder = new DbContextOptionsBuilder<CacheDbContext>();
|
||||||
|
dbContextOptionsBuilder.UseSqlite($"Data Source={Path.Combine(_cacheDirectory.FullName, "cache_index.db")}");
|
||||||
|
_dbContextFactory = new PooledDbContextFactory<CacheDbContext>(dbContextOptionsBuilder.Options);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteServiceAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
if (environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
LogEvent("Development mode detected, skipping cache cleaning...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ClearCacheAsync(stoppingToken);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "Error in execution of service.");
|
||||||
|
LogEvent($"Service execution failed. {e.Message}", LogSeverity.Error);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CreateCacheUrl(string originalUrl) => $"/api/v1/cache?url={originalUrl}";
|
||||||
|
|
||||||
|
public async Task<Result<CacheFile>> CacheFromUrl(string url, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(url))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Url is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cacheDirectory == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Cache directory is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_dbContextFactory == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Context factory is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var urlKeyBytes = SHA1.HashData(Encoding.UTF8.GetBytes(url));
|
||||||
|
var urlKey = Convert.ToHexString(urlKeyBytes);
|
||||||
|
var cacheEntity =
|
||||||
|
await context.Cache.FirstOrDefaultAsync(c => c.Id == urlKey, cancellationToken: cancellationToken);
|
||||||
|
if (cacheEntity == null)
|
||||||
|
{
|
||||||
|
var downloadResult =
|
||||||
|
await NetworkService.DownloadBytesAsync(new HttpRequestMessage(HttpMethod.Get, url));
|
||||||
|
if (!downloadResult.IsSuccess)
|
||||||
|
{
|
||||||
|
LogEvent($"Failed to download from url: {url}");
|
||||||
|
return ResultError.Fail("Download failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var download = downloadResult.Value;
|
||||||
|
await using var downloadFile =
|
||||||
|
File.Create(Path.Combine(_cacheDirectory.FullName, DataSubDir, $"{urlKey}.cache"));
|
||||||
|
await downloadFile.WriteAsync(download.Data.AsMemory(0, download.Data.Length), cancellationToken);
|
||||||
|
|
||||||
|
cacheEntity = new CacheEntity
|
||||||
|
{
|
||||||
|
Id = urlKey,
|
||||||
|
CachedAtUtc = DateTime.UtcNow,
|
||||||
|
ContentLength = download.ContentLength,
|
||||||
|
ContentType = download.ContentType,
|
||||||
|
OriginalFileName = download.FileName,
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Cache.Add(cacheEntity);
|
||||||
|
var saved = await context.SaveChangesAsync(cancellationToken);
|
||||||
|
if (saved <= 0)
|
||||||
|
{
|
||||||
|
LogEvent($"Cache entity {cacheEntity.Id} could not be saved.", LogSeverity.Error);
|
||||||
|
return ResultError.Fail("Failed to save to cache db.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CacheFile(download.Data, download.ContentType, download.FileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var filePath = Path.Combine(_cacheDirectory.FullName, DataSubDir, $"{urlKey}.cache");
|
||||||
|
var buffer = await File.ReadAllBytesAsync(filePath, cancellationToken);
|
||||||
|
if (buffer.Length == 0)
|
||||||
|
{
|
||||||
|
LogEvent($"Failed to read data from disk. File: {filePath}", LogSeverity.Error);
|
||||||
|
return ResultError.Fail($"Error reading data from disk. File: {filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CacheFile(buffer.ToArray(), cacheEntity.ContentType, cacheEntity.OriginalFileName);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return ResultError.Error(e, "Cache error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ClearCacheAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (!await _cacheSemaphoreSlim.WaitAsync(0, cancellationToken))
|
||||||
|
{
|
||||||
|
LogEvent("The cache cleaning task is already running. Skipping this call.", LogSeverity.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_dbContextFactory == null)
|
||||||
|
throw new InvalidOperationException("No DbContext factory configured.");
|
||||||
|
|
||||||
|
if (_cacheDirectory == null)
|
||||||
|
throw new InvalidOperationException("No cache directory configured.");
|
||||||
|
|
||||||
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var toRemove = dbContext.Cache.Where(c => c.CachedAtUtc < DateTime.UtcNow.AddDays(-CacheMaxAgeDays));
|
||||||
|
if (!toRemove.Any())
|
||||||
|
{
|
||||||
|
LogEvent($"No items older than {CacheMaxAgeDays} day(s) found to clear from cache.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalToRemove = toRemove.Count();
|
||||||
|
LogEvent($"Found {totalToRemove} cache items that are older than 1 day(s)");
|
||||||
|
|
||||||
|
var deleted = new List<CacheEntity>();
|
||||||
|
long totalBytesRemoved = 0;
|
||||||
|
foreach (var entity in toRemove)
|
||||||
|
{
|
||||||
|
var pathToFile = Path.Combine(_cacheDirectory.FullName, DataSubDir, $"{entity.Id}.cache");
|
||||||
|
if (!File.Exists(pathToFile))
|
||||||
|
{
|
||||||
|
deleted.Add(entity);
|
||||||
|
totalBytesRemoved += entity.ContentLength;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(pathToFile);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, "Failed to delete cache entity with id: {EntityId}. Skipping cache entity...",
|
||||||
|
entity.Id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalBytesRemoved += entity.ContentLength;
|
||||||
|
deleted.Add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.RemoveRange(deleted);
|
||||||
|
var dbDeleted = await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
if (dbDeleted < deleted.Count)
|
||||||
|
LogEvent("Could not delete all files from cache.", LogSeverity.Warning);
|
||||||
|
|
||||||
|
LogEvent($"Removed {dbDeleted}/{totalToRemove} items from cache. Total of {Suffix.BytesToSizeSuffix(totalBytesRemoved)} removed from disk.");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_cacheSemaphoreSlim.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CacheFile(byte[] Data, string? ContentType, string? OriginalFileName);
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using DotBased.Monads;
|
|
||||||
using Manager.Data.Entities.LibraryContext;
|
|
||||||
using Manager.YouTube;
|
|
||||||
|
|
||||||
namespace Manager.App.Services.System;
|
|
||||||
|
|
||||||
public class ClientManager : BackgroundService
|
|
||||||
{
|
|
||||||
private readonly List<YouTubeClient> _clients = [];
|
|
||||||
private CancellationToken _cancellationToken;
|
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
||||||
{
|
|
||||||
_cancellationToken = stoppingToken;
|
|
||||||
stoppingToken.Register(CancellationRequested);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CancellationRequested()
|
|
||||||
{
|
|
||||||
// Clear up
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Result<YouTubeClient>> LoadClient(ClientAccountEntity accountEntity)
|
|
||||||
{
|
|
||||||
if (_cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
return ResultError.Fail("Service is shutting down.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = new CookieContainer();
|
|
||||||
|
|
||||||
if (accountEntity.HttpCookies.Count != 0)
|
|
||||||
{
|
|
||||||
var cookieColl = new CookieCollection();
|
|
||||||
foreach (var cookieEntity in accountEntity.HttpCookies)
|
|
||||||
{
|
|
||||||
cookieColl.Add(new Cookie(cookieEntity.Name, cookieEntity.Value, cookieEntity.Domain));
|
|
||||||
}
|
|
||||||
|
|
||||||
container.Add(cookieColl);
|
|
||||||
}
|
|
||||||
|
|
||||||
var ytClient = new YouTubeClient();
|
|
||||||
//ytClient.CookieContainer = container;
|
|
||||||
ytClient.UserAgent = accountEntity.UserAgent;
|
|
||||||
await ytClient.GetStateAsync();
|
|
||||||
|
|
||||||
return ytClient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
142
Manager.App/Services/System/ClientService.cs
Normal file
142
Manager.App/Services/System/ClientService.cs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
using System.Net;
|
||||||
|
using DotBased.Logging;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using Manager.App.Models.System;
|
||||||
|
using Manager.Data.Entities.LibraryContext;
|
||||||
|
using Manager.YouTube;
|
||||||
|
|
||||||
|
namespace Manager.App.Services.System;
|
||||||
|
|
||||||
|
public class ClientService(IServiceScopeFactory scopeFactory, ILogger<ClientService> logger)
|
||||||
|
: ExtendedBackgroundService(nameof(ClientService), "Managing YouTube clients", logger, TimeSpan.FromMinutes(10))
|
||||||
|
{
|
||||||
|
private readonly YouTubeClientCollection _loadedClients = [];
|
||||||
|
private ILibraryService? _libraryService;
|
||||||
|
|
||||||
|
protected override Task InitializeAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
stoppingToken.Register(CancellationRequested);
|
||||||
|
using var scope = scopeFactory.CreateScope();
|
||||||
|
_libraryService = scope.ServiceProvider.GetRequiredService<ILibraryService>();
|
||||||
|
LogEvent("Initializing service...");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteServiceAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
LogEvent($"Saving {_loadedClients.Count} loaded client(s)");
|
||||||
|
foreach (var client in _loadedClients)
|
||||||
|
{
|
||||||
|
await SaveClientAsync(client, cancellationToken: stoppingToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancellationRequested()
|
||||||
|
{
|
||||||
|
foreach (var client in _loadedClients)
|
||||||
|
{
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ListResult<YouTubeClientItem>> GetClientsAsync(string? search, int offset = 0, int limit = 10, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (_libraryService == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Library service is not initialized!.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountsResult = await _libraryService.GetAccountsAsync(search, offset, limit, cancellationToken);
|
||||||
|
if (!accountsResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return accountsResult.Error ?? ResultError.Fail("Failed to get accounts!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var comparedClients = accountsResult.Value.Select(x => new YouTubeClientItem(x)
|
||||||
|
{ Id = x.Id, IsLoaded = _loadedClients.Contains(x.Id) }).ToList();
|
||||||
|
return new ListResultReturn<YouTubeClientItem>(comparedClients, accountsResult.Total);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result<YouTubeClient>> LoadClientByIdAsync(string id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (_loadedClients.TryGetValue(id, out var client))
|
||||||
|
{
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_libraryService == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Library service is not initialized!.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientResult = await _libraryService.GetChannelByIdAsync(id, cancellationToken);
|
||||||
|
if (!clientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return clientResult.Error ?? ResultError.Fail("Failed to load channel from database!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientAcc = clientResult.Value.ClientAccount;
|
||||||
|
if (clientAcc == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Client account is not initialized!.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var cookieCollection = new CookieCollection();
|
||||||
|
foreach (var httpCookie in clientAcc.HttpCookies)
|
||||||
|
{
|
||||||
|
var cookie = new Cookie
|
||||||
|
{
|
||||||
|
Name = httpCookie.Name,
|
||||||
|
Value = httpCookie.Value,
|
||||||
|
Domain = httpCookie.Domain,
|
||||||
|
Path = httpCookie.Path,
|
||||||
|
Secure = httpCookie.Secure,
|
||||||
|
HttpOnly = httpCookie.HttpOnly,
|
||||||
|
Expires = httpCookie.ExpiresUtc ?? DateTime.MinValue
|
||||||
|
};
|
||||||
|
cookieCollection.Add(cookie);
|
||||||
|
}
|
||||||
|
var ytClientResult = await YouTubeClient.CreateAsync(cookieCollection, clientAcc.UserAgent ?? "");
|
||||||
|
if (!ytClientResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return ytClientResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadedClients.Add(ytClientResult.Value);
|
||||||
|
return ytClientResult.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Result> SaveClientAsync(YouTubeClient client, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (_libraryService == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Library service is not initialized!.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(client.Id))
|
||||||
|
{
|
||||||
|
LogEvent("Failed to store client no ID!", LogSeverity.Warning);
|
||||||
|
return ResultError.Fail("Client does not have an ID, cannot save to library database!");
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadedClients.Add(client);
|
||||||
|
|
||||||
|
List<HttpCookieEntity> httpCookies = [];
|
||||||
|
httpCookies.AddRange(client.CookieContainer.GetAllCookies().Where(c => c.Expires != DateTime.MinValue)
|
||||||
|
.ToList()
|
||||||
|
.Select(cookie => new HttpCookieEntity
|
||||||
|
{
|
||||||
|
ClientId = client.Id,
|
||||||
|
Name = cookie.Name,
|
||||||
|
Value = cookie.Value,
|
||||||
|
Domain = cookie.Domain,
|
||||||
|
Path = cookie.Path,
|
||||||
|
Secure = cookie.Secure,
|
||||||
|
HttpOnly = cookie.HttpOnly,
|
||||||
|
ExpiresUtc = cookie.Expires
|
||||||
|
}));
|
||||||
|
|
||||||
|
var saveResult = await _libraryService.SaveClientAsync(new ClientAccountEntity { Id = client.Id, UserAgent = client.UserAgent, HttpCookies = httpCookies }, cancellationToken);
|
||||||
|
return saveResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
"Logging": {
|
"Logging": {
|
||||||
"Severity": "Debug",
|
"Severity": "Debug",
|
||||||
"SeverityFilters":{
|
"SeverityFilters":{
|
||||||
"Microsoft": "Debug",
|
"Microsoft": "Info",
|
||||||
"Microsoft.Hosting.Lifetime": "Debug",
|
"Microsoft.Hosting.Lifetime": "Debug",
|
||||||
"Microsoft.AspNetCore": "Warning",
|
"Microsoft.AspNetCore": "Warning",
|
||||||
"Microsoft.AspNetCore.Authentication": "Debug",
|
"Microsoft.AspNetCore.Authentication": "Debug",
|
||||||
"MudBlazor": "Debug"
|
"MudBlazor": "Info"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
16
Manager.App/wwwroot/js/eventConsole.js
Normal file
16
Manager.App/wwwroot/js/eventConsole.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
window.scrollToBottom = (element) => {
|
||||||
|
if (element) {
|
||||||
|
requestAnimationFrame(function () {
|
||||||
|
element.scroll({ top: element.scrollHeight, behavior: 'smooth' });
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.getScrollInfo = (element) => {
|
||||||
|
if (!element) return null;
|
||||||
|
return {
|
||||||
|
scrollTop: element.scrollTop,
|
||||||
|
scrollHeight: element.scrollHeight,
|
||||||
|
clientHeight: element.clientHeight
|
||||||
|
};
|
||||||
|
};
|
||||||
3
Manager.App/wwwroot/js/tz.js
Normal file
3
Manager.App/wwwroot/js/tz.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
function getUserTimeZone() {
|
||||||
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
}
|
||||||
112
Manager.Data/Contexts/AuditInterceptor.cs
Normal file
112
Manager.Data/Contexts/AuditInterceptor.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
|
||||||
|
namespace Manager.Data.Contexts;
|
||||||
|
|
||||||
|
public class AuditInterceptor : SaveChangesInterceptor
|
||||||
|
{
|
||||||
|
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
|
||||||
|
{
|
||||||
|
AddAudit(eventData.Context);
|
||||||
|
return base.SavingChanges(eventData, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
|
||||||
|
DbContextEventData eventData,
|
||||||
|
InterceptionResult<int> result,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
AddAudit(eventData.Context);
|
||||||
|
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddAudit(DbContext? context)
|
||||||
|
{
|
||||||
|
if (context == null) return;
|
||||||
|
|
||||||
|
var entries = context.ChangeTracker.Entries()
|
||||||
|
.Where(e => e.State is EntityState.Modified or EntityState.Deleted or EntityState.Added && Attribute.IsDefined(e.Entity.GetType(),
|
||||||
|
typeof(AuditableAttribute)));
|
||||||
|
|
||||||
|
var audits = new List<EntityAudit>();
|
||||||
|
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
var primaryKey = entry.Properties.First(p => p.Metadata.IsPrimaryKey()).CurrentValue?.ToString();
|
||||||
|
|
||||||
|
var declaredProperties = entry.Entity.GetType()
|
||||||
|
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
|
||||||
|
.Where(p => !Attribute.IsDefined(p.DeclaringType!, typeof(NoAuditAttribute), false))
|
||||||
|
.Select(p => p.Name)
|
||||||
|
.ToHashSet();
|
||||||
|
|
||||||
|
var allowedProperties = entry.Properties.Where(p => declaredProperties.Contains(p.Metadata.Name));
|
||||||
|
|
||||||
|
switch (entry.State)
|
||||||
|
{
|
||||||
|
case EntityState.Added:
|
||||||
|
audits.AddRange(allowedProperties
|
||||||
|
.Where(p => p.CurrentValue != null)
|
||||||
|
.Select(p => CreateAudit(entry, p, entry.State, primaryKey))
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case EntityState.Modified:
|
||||||
|
audits.AddRange(allowedProperties
|
||||||
|
.Where(p => p.IsModified && !Equals(p.OriginalValue, p.CurrentValue))
|
||||||
|
.Select(p => CreateAudit(entry, p, entry.State, primaryKey))
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case EntityState.Deleted:
|
||||||
|
audits.AddRange(allowedProperties
|
||||||
|
.Select(p => CreateAudit(entry, p, entry.State, primaryKey))
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audits.Count != 0)
|
||||||
|
{
|
||||||
|
context.Set<EntityAudit>().AddRange(audits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityAudit CreateAudit(EntityEntry entry, PropertyEntry prop, EntityState changeType, string? primaryKey)
|
||||||
|
{
|
||||||
|
return new EntityAudit
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
EntityName = entry.Entity.GetType().Name,
|
||||||
|
EntityId = primaryKey ?? "Unknown",
|
||||||
|
PropertyName = prop.Metadata.Name,
|
||||||
|
OldValue = changeType == EntityState.Added ? null : SerializeValue(prop.OriginalValue),
|
||||||
|
NewValue = SerializeValue(prop.CurrentValue),
|
||||||
|
ModifiedUtc = DateTime.UtcNow,
|
||||||
|
ChangedBy = "SYSTEM",
|
||||||
|
ChangeType = changeType
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly JsonSerializerOptions _jsonSerializerOptions = new()
|
||||||
|
{
|
||||||
|
WriteIndented = false,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||||
|
};
|
||||||
|
|
||||||
|
private string? SerializeValue(object? value)
|
||||||
|
{
|
||||||
|
if (value == null) return null;
|
||||||
|
|
||||||
|
var type = value.GetType();
|
||||||
|
|
||||||
|
if (type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(decimal))
|
||||||
|
{
|
||||||
|
return value.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonSerializer.Serialize(value, _jsonSerializerOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Manager.Data/Contexts/CacheDbContext.cs
Normal file
25
Manager.Data/Contexts/CacheDbContext.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using Manager.Data.Entities.Cache;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Manager.Data.Contexts;
|
||||||
|
|
||||||
|
public sealed class CacheDbContext : DbContext
|
||||||
|
{
|
||||||
|
public CacheDbContext(DbContextOptions<CacheDbContext> options) : base(options)
|
||||||
|
{
|
||||||
|
Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<CacheEntity> Cache { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<CacheEntity>(ce =>
|
||||||
|
{
|
||||||
|
ce.ToTable("cache");
|
||||||
|
ce.HasKey(x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Manager.Data/Contexts/DateInterceptor.cs
Normal file
38
Manager.Data/Contexts/DateInterceptor.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using Manager.Data.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
|
||||||
|
namespace Manager.Data.Contexts;
|
||||||
|
|
||||||
|
public class DateInterceptor : SaveChangesInterceptor
|
||||||
|
{
|
||||||
|
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
|
||||||
|
{
|
||||||
|
UpdateEntryDates(eventData.Context);
|
||||||
|
return base.SavingChanges(eventData, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result,
|
||||||
|
CancellationToken cancellationToken = new())
|
||||||
|
{
|
||||||
|
UpdateEntryDates(eventData.Context);
|
||||||
|
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateEntryDates(DbContext? context)
|
||||||
|
{
|
||||||
|
if (context == null) return;
|
||||||
|
|
||||||
|
var entries = context.ChangeTracker.Entries().Where(x => x is { Entity: DateTimeBase, State: EntityState.Added or EntityState.Modified });
|
||||||
|
|
||||||
|
foreach (var entity in entries)
|
||||||
|
{
|
||||||
|
((DateTimeBase)entity.Entity).LastModifiedUtc = DateTime.UtcNow;
|
||||||
|
|
||||||
|
if (entity.State == EntityState.Added)
|
||||||
|
{
|
||||||
|
((DateTimeBase)entity.Entity).CreatedAtUtc = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using Manager.Data.Entities;
|
using Manager.Data.Entities.Audit;
|
||||||
using Manager.Data.Entities.LibraryContext;
|
using Manager.Data.Entities.LibraryContext;
|
||||||
using Manager.Data.Entities.LibraryContext.Join;
|
using Manager.Data.Entities.LibraryContext.Join;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -13,17 +13,31 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
ChangeTracker.LazyLoadingEnabled = false;
|
ChangeTracker.LazyLoadingEnabled = false;
|
||||||
Database.EnsureCreated();
|
Database.EnsureCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DbSet<EntityAudit> Histories { get; set; }
|
||||||
|
|
||||||
public DbSet<CaptionEntity> Captions { get; set; }
|
public DbSet<CaptionEntity> Captions { get; set; }
|
||||||
public DbSet<ChannelEntity> Channels { get; set; }
|
public DbSet<ChannelEntity> Channels { get; set; }
|
||||||
public DbSet<ClientAccountEntity> Accounts { get; set; }
|
public DbSet<ClientAccountEntity> ClientAccounts { get; set; }
|
||||||
public DbSet<HttpCookieEntity> HttpCookies { get; set; }
|
public DbSet<HttpCookieEntity> HttpCookies { get; set; }
|
||||||
public DbSet<MediaEntity> Media { get; set; }
|
public DbSet<MediaEntity> Media { get; set; }
|
||||||
public DbSet<MediaFormatEntity> MediaFormats { get; set; }
|
public DbSet<MediaFormatEntity> MediaFormats { get; set; }
|
||||||
public DbSet<PlaylistEntity> Playlists { get; set; }
|
public DbSet<PlaylistEntity> Playlists { get; set; }
|
||||||
|
public DbSet<FileEntity> Files { get; set; }
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
optionsBuilder.AddInterceptors(new DateInterceptor(), new AuditInterceptor());
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
modelBuilder.Entity<EntityAudit>(ea =>
|
||||||
|
{
|
||||||
|
ea.HasKey(a => a.Id);
|
||||||
|
ea.ToTable("audits");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<CaptionEntity>(ce =>
|
modelBuilder.Entity<CaptionEntity>(ce =>
|
||||||
{
|
{
|
||||||
ce.ToTable("captions");
|
ce.ToTable("captions");
|
||||||
@@ -41,8 +55,12 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey(x => x.ChannelId);
|
.HasForeignKey(x => x.ChannelId);
|
||||||
channel.HasOne(x => x.ClientAccount)
|
channel.HasOne(x => x.ClientAccount)
|
||||||
|
.WithOne(x => x.Channel)
|
||||||
|
.HasForeignKey<ClientAccountEntity>(e => e.Id)
|
||||||
|
.IsRequired(false);
|
||||||
|
channel.HasMany(x => x.Files)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey<ClientAccountEntity>(e => e.Id);
|
.HasForeignKey(f => f.ForeignKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<ClientAccountEntity>(cae =>
|
modelBuilder.Entity<ClientAccountEntity>(cae =>
|
||||||
@@ -52,6 +70,13 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
cae.HasMany(x => x.HttpCookies)
|
cae.HasMany(x => x.HttpCookies)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey(x => x.ClientId);
|
.HasForeignKey(x => x.ClientId);
|
||||||
|
cae.HasOne(x => x.Channel)
|
||||||
|
.WithOne(ca => ca.ClientAccount)
|
||||||
|
.HasForeignKey<ChannelEntity>(ce => ce.Id)
|
||||||
|
.IsRequired(false);
|
||||||
|
cae.HasMany(x => x.Files)
|
||||||
|
.WithOne()
|
||||||
|
.HasForeignKey(f => f.ForeignKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<HttpCookieEntity>(httpce =>
|
modelBuilder.Entity<HttpCookieEntity>(httpce =>
|
||||||
@@ -83,6 +108,12 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
ple.ToTable("playlists");
|
ple.ToTable("playlists");
|
||||||
ple.HasKey(x => x.Id);
|
ple.HasKey(x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<FileEntity>(file =>
|
||||||
|
{
|
||||||
|
file.ToTable("files");
|
||||||
|
file.HasKey(x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
/* Join tables */
|
/* Join tables */
|
||||||
|
|
||||||
@@ -101,31 +132,4 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int SaveChanges()
|
|
||||||
{
|
|
||||||
UpdateEntryDates();
|
|
||||||
return base.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = new())
|
|
||||||
{
|
|
||||||
UpdateEntryDates();
|
|
||||||
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateEntryDates()
|
|
||||||
{
|
|
||||||
var entries = ChangeTracker.Entries().Where(x => x is { Entity: DateTimeBase, State: EntityState.Added or EntityState.Modified });
|
|
||||||
|
|
||||||
foreach (var entity in entries)
|
|
||||||
{
|
|
||||||
((DateTimeBase)entity.Entity).LastModifiedUtc = DateTime.UtcNow;
|
|
||||||
|
|
||||||
if (entity.State == EntityState.Added)
|
|
||||||
{
|
|
||||||
((DateTimeBase)entity.Entity).CreatedAtUtc = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,8 @@ public static class DataConstants
|
|||||||
{
|
{
|
||||||
public static class DbContext
|
public static class DbContext
|
||||||
{
|
{
|
||||||
public const int DefaultDbStringSize = 100;
|
public const int DefaultDbStringSize = 500;
|
||||||
public const int DefaultDbDescriptionStringSize = 500;
|
public const int DefaultDbDescriptionStringSize = 5500;
|
||||||
|
public const int DefaultDbUrlSize = 10000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
9
Manager.Data/Entities/Audit/AuditableAttribute.cs
Normal file
9
Manager.Data/Entities/Audit/AuditableAttribute.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make all properties in the entity audible, if they are changed this will be stored as a history in the db.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class AuditableAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
23
Manager.Data/Entities/Audit/EntityAudit.cs
Normal file
23
Manager.Data/Entities/Audit/EntityAudit.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
|
public class EntityAudit
|
||||||
|
{
|
||||||
|
public required Guid Id { get; set; }
|
||||||
|
[MaxLength(200)]
|
||||||
|
public required string EntityName { get; set; }
|
||||||
|
[MaxLength(200)]
|
||||||
|
public required string EntityId { get; set; }
|
||||||
|
[MaxLength(200)]
|
||||||
|
public required string PropertyName { get; set; }
|
||||||
|
[MaxLength(1000)]
|
||||||
|
public string? OldValue { get; set; }
|
||||||
|
[MaxLength(1000)]
|
||||||
|
public string? NewValue { get; set; }
|
||||||
|
public DateTime ModifiedUtc { get; set; } = DateTime.UtcNow;
|
||||||
|
[MaxLength(200)]
|
||||||
|
public string? ChangedBy { get; set; }
|
||||||
|
public EntityState ChangeType { get; set; }
|
||||||
|
}
|
||||||
9
Manager.Data/Entities/Audit/NoAuditAttribute.cs
Normal file
9
Manager.Data/Entities/Audit/NoAuditAttribute.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies to ignore the properties in the entity to not audit.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class NoAuditAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
namespace Manager.Data.Entities;
|
namespace Manager.Data.Entities;
|
||||||
|
|
||||||
|
[NoAudit]
|
||||||
public abstract class DateTimeBase
|
public abstract class DateTimeBase
|
||||||
{
|
{
|
||||||
public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedAtUtc { get; set; }
|
||||||
public DateTime LastModifiedUtc { get; set; } = DateTime.UtcNow;
|
public DateTime LastModifiedUtc { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[Auditable]
|
||||||
public class CaptionEntity : DateTimeBase
|
public class CaptionEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[Auditable]
|
||||||
public class ChannelEntity : DateTimeBase
|
public class ChannelEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public required string Id { get; set; }
|
public required string Id { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public string? Handle { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
public DateTime JoinedDate { get; set; }
|
|
||||||
public long Subscribers { get; set; }
|
|
||||||
public long TotalVideos { get; set; }
|
|
||||||
public long TotalViews { get; set; }
|
|
||||||
public List<MediaEntity> Media { get; set; } = [];
|
public List<MediaEntity> Media { get; set; } = [];
|
||||||
public List<PlaylistEntity> Playlists { get; set; } = [];
|
public List<PlaylistEntity> Playlists { get; set; } = [];
|
||||||
public ClientAccountEntity? ClientAccount { get; set; }
|
public ClientAccountEntity? ClientAccount { get; set; }
|
||||||
|
public List<FileEntity>? Files { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[Auditable]
|
||||||
public class ClientAccountEntity : DateTimeBase
|
public class ClientAccountEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
@@ -9,4 +11,6 @@ public class ClientAccountEntity : DateTimeBase
|
|||||||
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
|
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public string? UserAgent { get; set; }
|
public string? UserAgent { get; set; }
|
||||||
|
public ChannelEntity? Channel { get; set; }
|
||||||
|
public List<FileEntity>? Files { get; set; }
|
||||||
}
|
}
|
||||||
25
Manager.Data/Entities/LibraryContext/FileEntity.cs
Normal file
25
Manager.Data/Entities/LibraryContext/FileEntity.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
public class FileEntity : DateTimeBase
|
||||||
|
{
|
||||||
|
public required Guid Id { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public required string ForeignKey { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public required string FileType { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public required string RelativePath { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public string? MimeType { get; set; }
|
||||||
|
public long SizeBytes { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbUrlSize)]
|
||||||
|
public string? OriginalUrl { get; set; }
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public string? OriginalFileName { get; set; }
|
||||||
|
|
||||||
|
public int? Width { get; set; }
|
||||||
|
public int? Height { get; set; }
|
||||||
|
public long? LenghtMilliseconds { get; set; }
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[NoAudit]
|
||||||
public class HttpCookieEntity : DateTimeBase
|
public class HttpCookieEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
public required string ClientId { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
@@ -12,11 +16,7 @@ public class HttpCookieEntity : DateTimeBase
|
|||||||
public string? Domain { get; set; }
|
public string? Domain { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public string? Path { get; set; }
|
public string? Path { get; set; }
|
||||||
public DateTimeOffset? ExpiresUtc { get; set; }
|
public DateTime? ExpiresUtc { get; set; }
|
||||||
public bool Secure { get; set; }
|
public bool Secure { get; set; }
|
||||||
public bool HttpOnly { get; set; }
|
public bool HttpOnly { get; set; }
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
|
||||||
public string? SameSite { get; set; }
|
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
|
||||||
public required string ClientId { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
using Manager.Data.Entities.LibraryContext.Join;
|
using Manager.Data.Entities.LibraryContext.Join;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[Auditable]
|
||||||
public class MediaEntity : DateTimeBase
|
public class MediaEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
@@ -17,7 +19,6 @@ public class MediaEntity : DateTimeBase
|
|||||||
public List<MediaFormatEntity> Formats { get; set; } = [];
|
public List<MediaFormatEntity> Formats { get; set; } = [];
|
||||||
public List<CaptionEntity> Captions { get; set; } = [];
|
public List<CaptionEntity> Captions { get; set; } = [];
|
||||||
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
|
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
|
||||||
|
|
||||||
public MediaExternalState ExternalState { get; set; } = MediaExternalState.Online;
|
public MediaExternalState ExternalState { get; set; } = MediaExternalState.Online;
|
||||||
public bool IsDownloaded { get; set; }
|
public bool IsDownloaded { get; set; }
|
||||||
public MediaState State { get; set; } = MediaState.Indexed;
|
public MediaState State { get; set; } = MediaState.Indexed;
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Manager.Data.Entities.Audit;
|
||||||
using Manager.Data.Entities.LibraryContext.Join;
|
using Manager.Data.Entities.LibraryContext.Join;
|
||||||
|
|
||||||
namespace Manager.Data.Entities.LibraryContext;
|
namespace Manager.Data.Entities.LibraryContext;
|
||||||
|
|
||||||
|
[Auditable]
|
||||||
public class PlaylistEntity : DateTimeBase
|
public class PlaylistEntity : DateTimeBase
|
||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
|
|||||||
@@ -1,424 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Manager.Data.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Manager.Data.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(LibraryDbContext))]
|
|
||||||
[Migration("20250902141251_InitialLibrary")]
|
|
||||||
partial class InitialLibrary
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.19");
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.CaptionEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("LanguageCode")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("MediaId", "LanguageCode");
|
|
||||||
|
|
||||||
b.ToTable("captions", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("JoinedDate")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<long>("Subscribers")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("TotalVideos")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("TotalViews")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("channels", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("UserAgent")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("client_accounts", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ClientId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Domain")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTimeOffset?>("ExpiresUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<bool>("HttpOnly")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Path")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("SameSite")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<bool>("Secure")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("Value")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Name");
|
|
||||||
|
|
||||||
b.HasIndex("ClientId");
|
|
||||||
|
|
||||||
b.ToTable("http_cookies", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.Join.PlaylistMedia", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("PlaylistId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("PlaylistId", "MediaId");
|
|
||||||
|
|
||||||
b.HasIndex("MediaId");
|
|
||||||
|
|
||||||
b.ToTable("join_playlist_media", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ChannelId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("ExternalState")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDownloaded")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("State")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("Title")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UploadDateUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ChannelId");
|
|
||||||
|
|
||||||
b.ToTable("media", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("Itag")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("ApproxDurationMs")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<int?>("AudioChannels")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("AudioSampleRate")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<long>("AverageBitrate")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("Bitrate")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("ContentLengthBytes")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<double?>("Framerate")
|
|
||||||
.HasColumnType("REAL");
|
|
||||||
|
|
||||||
b.Property<int?>("Height")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<bool>("IsAdaptive")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("LastModifiedUnixEpoch")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<double?>("LoudnessDb")
|
|
||||||
.HasColumnType("REAL");
|
|
||||||
|
|
||||||
b.Property<string>("MimeType")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Quality")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("QualityLabel")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int?>("Width")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.HasKey("MediaId", "Itag");
|
|
||||||
|
|
||||||
b.ToTable("media_formats", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ChannelId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ChannelId");
|
|
||||||
|
|
||||||
b.ToTable("playlists", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.CaptionEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("Captions")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithOne("ClientAccount")
|
|
||||||
.HasForeignKey("Manager.Data.Entities.LibraryContext.ClientAccountEntity", "Id")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
|
||||||
.WithMany("HttpCookies")
|
|
||||||
.HasForeignKey("ClientId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.Join.PlaylistMedia", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("PlaylistMedias")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.PlaylistEntity", null)
|
|
||||||
.WithMany("PlaylistMedias")
|
|
||||||
.HasForeignKey("PlaylistId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithMany("Media")
|
|
||||||
.HasForeignKey("ChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("Formats")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithMany("Playlists")
|
|
||||||
.HasForeignKey("ChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("ClientAccount");
|
|
||||||
|
|
||||||
b.Navigation("Media");
|
|
||||||
|
|
||||||
b.Navigation("Playlists");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("HttpCookies");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Captions");
|
|
||||||
|
|
||||||
b.Navigation("Formats");
|
|
||||||
|
|
||||||
b.Navigation("PlaylistMedias");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("PlaylistMedias");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,259 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Manager.Data.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class InitialLibrary : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "channels",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
||||||
JoinedDate = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
Subscribers = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
TotalVideos = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
TotalViews = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_channels", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "client_accounts",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
UserAgent = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_client_accounts", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_client_accounts_channels_Id",
|
|
||||||
column: x => x.Id,
|
|
||||||
principalTable: "channels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "media",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Title = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
||||||
UploadDateUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
ChannelId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
ExternalState = table.Column<int>(type: "INTEGER", nullable: false),
|
|
||||||
IsDownloaded = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
||||||
State = table.Column<int>(type: "INTEGER", nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_media", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_media_channels_ChannelId",
|
|
||||||
column: x => x.ChannelId,
|
|
||||||
principalTable: "channels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "playlists",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
||||||
ChannelId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_playlists", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_playlists_channels_ChannelId",
|
|
||||||
column: x => x.ChannelId,
|
|
||||||
principalTable: "channels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "http_cookies",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Value = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
Domain = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
Path = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
ExpiresUtc = table.Column<DateTimeOffset>(type: "TEXT", nullable: true),
|
|
||||||
Secure = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
||||||
HttpOnly = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
||||||
SameSite = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
ClientId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_http_cookies", x => x.Name);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_http_cookies_client_accounts_ClientId",
|
|
||||||
column: x => x.ClientId,
|
|
||||||
principalTable: "client_accounts",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "captions",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
MediaId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
LanguageCode = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_captions", x => new { x.MediaId, x.LanguageCode });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_captions_media_MediaId",
|
|
||||||
column: x => x.MediaId,
|
|
||||||
principalTable: "media",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "media_formats",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
MediaId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
Itag = table.Column<int>(type: "INTEGER", nullable: false),
|
|
||||||
Quality = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
IsAdaptive = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
||||||
MimeType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
Bitrate = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
AverageBitrate = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
LastModifiedUnixEpoch = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
ContentLengthBytes = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
ApproxDurationMs = table.Column<long>(type: "INTEGER", nullable: false),
|
|
||||||
Width = table.Column<int>(type: "INTEGER", nullable: true),
|
|
||||||
Height = table.Column<int>(type: "INTEGER", nullable: true),
|
|
||||||
Framerate = table.Column<double>(type: "REAL", nullable: true),
|
|
||||||
QualityLabel = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
AudioChannels = table.Column<int>(type: "INTEGER", nullable: true),
|
|
||||||
AudioSampleRate = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
||||||
LoudnessDb = table.Column<double>(type: "REAL", nullable: true),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_media_formats", x => new { x.MediaId, x.Itag });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_media_formats_media_MediaId",
|
|
||||||
column: x => x.MediaId,
|
|
||||||
principalTable: "media",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "join_playlist_media",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
PlaylistId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
MediaId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
||||||
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_join_playlist_media", x => new { x.PlaylistId, x.MediaId });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_join_playlist_media_media_MediaId",
|
|
||||||
column: x => x.MediaId,
|
|
||||||
principalTable: "media",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_join_playlist_media_playlists_PlaylistId",
|
|
||||||
column: x => x.PlaylistId,
|
|
||||||
principalTable: "playlists",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_http_cookies_ClientId",
|
|
||||||
table: "http_cookies",
|
|
||||||
column: "ClientId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_join_playlist_media_MediaId",
|
|
||||||
table: "join_playlist_media",
|
|
||||||
column: "MediaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_media_ChannelId",
|
|
||||||
table: "media",
|
|
||||||
column: "ChannelId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_playlists_ChannelId",
|
|
||||||
table: "playlists",
|
|
||||||
column: "ChannelId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "captions");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "http_cookies");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "join_playlist_media");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "media_formats");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "client_accounts");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "playlists");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "media");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "channels");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Manager.Data.Contexts;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Manager.Data.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(LibraryDbContext))]
|
|
||||||
partial class LibraryDbContextModelSnapshot : ModelSnapshot
|
|
||||||
{
|
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.19");
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.CaptionEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("LanguageCode")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("MediaId", "LanguageCode");
|
|
||||||
|
|
||||||
b.ToTable("captions", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("JoinedDate")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<long>("Subscribers")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("TotalVideos")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("TotalViews")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("channels", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("UserAgent")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("client_accounts", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ClientId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Domain")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTimeOffset?>("ExpiresUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<bool>("HttpOnly")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Path")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("SameSite")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<bool>("Secure")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("Value")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Name");
|
|
||||||
|
|
||||||
b.HasIndex("ClientId");
|
|
||||||
|
|
||||||
b.ToTable("http_cookies", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.Join.PlaylistMedia", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("PlaylistId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("PlaylistId", "MediaId");
|
|
||||||
|
|
||||||
b.HasIndex("MediaId");
|
|
||||||
|
|
||||||
b.ToTable("join_playlist_media", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ChannelId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("ExternalState")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDownloaded")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("State")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("Title")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UploadDateUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ChannelId");
|
|
||||||
|
|
||||||
b.ToTable("media", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("MediaId")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int>("Itag")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("ApproxDurationMs")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<int?>("AudioChannels")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("AudioSampleRate")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<long>("AverageBitrate")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("Bitrate")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("ContentLengthBytes")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<double?>("Framerate")
|
|
||||||
.HasColumnType("REAL");
|
|
||||||
|
|
||||||
b.Property<int?>("Height")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<bool>("IsAdaptive")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<long>("LastModifiedUnixEpoch")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<double?>("LoudnessDb")
|
|
||||||
.HasColumnType("REAL");
|
|
||||||
|
|
||||||
b.Property<string>("MimeType")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Quality")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("QualityLabel")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<int?>("Width")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.HasKey("MediaId", "Itag");
|
|
||||||
|
|
||||||
b.ToTable("media_formats", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("ChannelId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAtUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(500)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<DateTime>("LastModifiedUtc")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ChannelId");
|
|
||||||
|
|
||||||
b.ToTable("playlists", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.CaptionEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("Captions")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithOne("ClientAccount")
|
|
||||||
.HasForeignKey("Manager.Data.Entities.LibraryContext.ClientAccountEntity", "Id")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
|
||||||
.WithMany("HttpCookies")
|
|
||||||
.HasForeignKey("ClientId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.Join.PlaylistMedia", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("PlaylistMedias")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.PlaylistEntity", null)
|
|
||||||
.WithMany("PlaylistMedias")
|
|
||||||
.HasForeignKey("PlaylistId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithMany("Media")
|
|
||||||
.HasForeignKey("ChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
|
||||||
.WithMany("Formats")
|
|
||||||
.HasForeignKey("MediaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
|
|
||||||
.WithMany("Playlists")
|
|
||||||
.HasForeignKey("ChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("ClientAccount");
|
|
||||||
|
|
||||||
b.Navigation("Media");
|
|
||||||
|
|
||||||
b.Navigation("Playlists");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("HttpCookies");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Captions");
|
|
||||||
|
|
||||||
b.Navigation("Formats");
|
|
||||||
|
|
||||||
b.Navigation("PlaylistMedias");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("PlaylistMedias");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
22
Manager.YouTube/Constants/CookieConstants.cs
Normal file
22
Manager.YouTube/Constants/CookieConstants.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace Manager.YouTube.Constants;
|
||||||
|
|
||||||
|
public static class CookieConstants
|
||||||
|
{
|
||||||
|
public static readonly IReadOnlyCollection<string> RequiredCookiesNames = new HashSet<string>
|
||||||
|
{
|
||||||
|
"SID",
|
||||||
|
"SIDCC",
|
||||||
|
"HSID",
|
||||||
|
"SSID",
|
||||||
|
"APISID",
|
||||||
|
"SAPISID",
|
||||||
|
"__Secure-1PAPISID",
|
||||||
|
"__Secure-1PSID",
|
||||||
|
"__Secure-1PSIDCC",
|
||||||
|
"__Secure-1PSIDTS",
|
||||||
|
"__Secure-3PAPISID",
|
||||||
|
"__Secure-3PSID",
|
||||||
|
"__Secure-3PSIDCC",
|
||||||
|
"__Secure-3PSIDTS"
|
||||||
|
};
|
||||||
|
}
|
||||||
58
Manager.YouTube/Interpreter/JavaScriptEngineManager.cs
Normal file
58
Manager.YouTube/Interpreter/JavaScriptEngineManager.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Text;
|
||||||
|
using DotBased.Monads;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Interpreter;
|
||||||
|
|
||||||
|
public static class JavaScriptEngineManager
|
||||||
|
{
|
||||||
|
private static readonly PlayerEngineCollection Engines = [];
|
||||||
|
|
||||||
|
public static async Task<Result<PlayerEngine>> GetPlayerEngine(string playerUrl)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(playerUrl))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("player url is empty or null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var version = GetScriptVersion(playerUrl);
|
||||||
|
|
||||||
|
if (Engines.TryGetValue(version, out var engine))
|
||||||
|
{
|
||||||
|
return engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
var playerJsSourceResult = await DownloadPlayerScriptAsync(playerUrl);
|
||||||
|
if (!playerJsSourceResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return playerJsSourceResult.Error ?? ResultError.Fail("Download player script failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlayerEngine(version, playerJsSourceResult.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetScriptVersion(string relativePlayerUrl)
|
||||||
|
{
|
||||||
|
var split = relativePlayerUrl.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
var v = split[2];
|
||||||
|
var lang = split[4];
|
||||||
|
return $"{v}-{lang}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<Result<string>> DownloadPlayerScriptAsync(string relativeUrl, YouTubeClient? client = null)
|
||||||
|
{
|
||||||
|
var downloadRequest = new HttpRequestMessage(HttpMethod.Get, new Uri($"{NetworkService.Origin}/{relativeUrl}"));
|
||||||
|
var downloadResponse = await NetworkService.DownloadBytesAsync(downloadRequest, client);
|
||||||
|
if (!downloadResponse.IsSuccess)
|
||||||
|
{
|
||||||
|
return downloadResponse.Error ?? ResultError.Fail($"Failed to download script from url: {relativeUrl}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var playerJs = Encoding.UTF8.GetString(downloadResponse.Value.Data);
|
||||||
|
if (string.IsNullOrWhiteSpace(playerJs))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Script value is empty!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerJs;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Manager.YouTube/Interpreter/PlayerEngine.cs
Normal file
42
Manager.YouTube/Interpreter/PlayerEngine.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using DotBased.Logging;
|
||||||
|
using Jint;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Interpreter;
|
||||||
|
|
||||||
|
public class PlayerEngine
|
||||||
|
{
|
||||||
|
public string Version { get; set; }
|
||||||
|
public Engine JsEngine { get; set; }
|
||||||
|
private ILogger Logger { get; set; }
|
||||||
|
|
||||||
|
public PlayerEngine(string version, string script)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(version))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(version));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(script))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(script));
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger = LogService.RegisterLogger(typeof(PlayerEngine), version);
|
||||||
|
Version = version;
|
||||||
|
JsEngine = new Engine().Execute(script).SetValue("log", new Action<object>(obj =>
|
||||||
|
{
|
||||||
|
var logStr = obj.ToString();
|
||||||
|
if (string.IsNullOrEmpty(logStr))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Logger.Information(logStr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitializePlayer()
|
||||||
|
{
|
||||||
|
JsEngine.Execute("createPlayer");
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Manager.YouTube/Interpreter/PlayerEngineCollection.cs
Normal file
11
Manager.YouTube/Interpreter/PlayerEngineCollection.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Interpreter;
|
||||||
|
|
||||||
|
public class PlayerEngineCollection : KeyedCollection<string, PlayerEngine>
|
||||||
|
{
|
||||||
|
protected override string GetKeyForItem(PlayerEngine item)
|
||||||
|
{
|
||||||
|
return item.Version;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DotBased" Version="1.0.0" />
|
<PackageReference Include="DotBased" Version="1.0.0" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.2" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.2" />
|
||||||
|
<PackageReference Include="Jint" Version="4.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Manager.YouTube.Models.Innertube;
|
|||||||
|
|
||||||
public class ClientState : AdditionalJsonData
|
public class ClientState : AdditionalJsonData
|
||||||
{
|
{
|
||||||
|
public bool IsPremiumUser { get; set; }
|
||||||
[JsonPropertyName("INNERTUBE_API_KEY")]
|
[JsonPropertyName("INNERTUBE_API_KEY")]
|
||||||
public string? InnertubeApiKey { get; set; }
|
public string? InnertubeApiKey { get; set; }
|
||||||
|
|
||||||
@@ -15,6 +16,9 @@ public class ClientState : AdditionalJsonData
|
|||||||
|
|
||||||
[JsonPropertyName("SIGNIN_URL")]
|
[JsonPropertyName("SIGNIN_URL")]
|
||||||
public string? SigninUrl { get; set; }
|
public string? SigninUrl { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("INNERTUBE_CLIENT_NAME")]
|
||||||
|
public string? InnerTubeClient { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("INNERTUBE_CLIENT_VERSION")]
|
[JsonPropertyName("INNERTUBE_CLIENT_VERSION")]
|
||||||
public string? InnerTubeClientVersion { get; set; }
|
public string? InnerTubeClientVersion { get; set; }
|
||||||
@@ -31,6 +35,9 @@ public class ClientState : AdditionalJsonData
|
|||||||
[JsonPropertyName("SERVER_VERSION")]
|
[JsonPropertyName("SERVER_VERSION")]
|
||||||
public string? ServerVersion { get; set; }
|
public string? ServerVersion { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("PLAYER_JS_URL")]
|
||||||
|
public string? PlayerJsUrl { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("INNERTUBE_CONTEXT")]
|
[JsonPropertyName("INNERTUBE_CONTEXT")]
|
||||||
public InnerTubeContext? InnerTubeContext { get; set; }
|
public InnerTubeContext? InnerTubeContext { get; set; }
|
||||||
|
|
||||||
|
|||||||
13
Manager.YouTube/Models/Innertube/ColorInfo.cs
Normal file
13
Manager.YouTube/Models/Innertube/ColorInfo.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class ColorInfo
|
||||||
|
{
|
||||||
|
[JsonPropertyName("primaries")]
|
||||||
|
public string Primaries { get; set; } = "";
|
||||||
|
[JsonPropertyName("transferCharacteristics")]
|
||||||
|
public string TransferCharacteristics { get; set; } = "";
|
||||||
|
[JsonPropertyName("matrixCoefficients")]
|
||||||
|
public string MatrixCoefficients { get; set; } = "";
|
||||||
|
}
|
||||||
15
Manager.YouTube/Models/Innertube/InnertubeChannel.cs
Normal file
15
Manager.YouTube/Models/Innertube/InnertubeChannel.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class InnertubeChannel
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
public bool NoIndex { get; set; }
|
||||||
|
public bool Unlisted { get; set; }
|
||||||
|
public bool FamilySafe { get; set; }
|
||||||
|
public string? ChannelName { get; set; }
|
||||||
|
public string? Handle { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public List<string> AvailableCountries { get; set; } = [];
|
||||||
|
public List<WebImage> AvatarImages { get; set; } = [];
|
||||||
|
public List<WebImage> BannerImages { get; set; } = [];
|
||||||
|
}
|
||||||
11
Manager.YouTube/Models/Innertube/Range.cs
Normal file
11
Manager.YouTube/Models/Innertube/Range.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class Range
|
||||||
|
{
|
||||||
|
[JsonPropertyName("start")]
|
||||||
|
public uint Start { get; set; }
|
||||||
|
[JsonPropertyName("end")]
|
||||||
|
public uint End { get; set; }
|
||||||
|
}
|
||||||
8
Manager.YouTube/Models/Innertube/StoryBoard.cs
Normal file
8
Manager.YouTube/Models/Innertube/StoryBoard.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class StoryBoard
|
||||||
|
{
|
||||||
|
public string Spec { get; set; } = "";
|
||||||
|
public int RecommendedLevel { get; set; }
|
||||||
|
public int HighResolutionRecommendedLevel { get; set; }
|
||||||
|
}
|
||||||
18
Manager.YouTube/Models/Innertube/StreamingData.cs
Normal file
18
Manager.YouTube/Models/Innertube/StreamingData.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Manager.YouTube.Util.Converters;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class StreamingData
|
||||||
|
{
|
||||||
|
public DateTime FetchedUtc { get; set; } = DateTime.UtcNow;
|
||||||
|
[JsonPropertyName("expiresInSeconds")]
|
||||||
|
public int ExpiresInSeconds { get; set; }
|
||||||
|
[JsonPropertyName("serverAbrStreamingUrl")]
|
||||||
|
[JsonConverter(typeof(JsonUrlEscapeConverter))]
|
||||||
|
public string ServerAbrStreamingUrl { get; set; } = "";
|
||||||
|
[JsonPropertyName("formats")]
|
||||||
|
public List<StreamingFormat> Formats { get; set; } = [];
|
||||||
|
[JsonPropertyName("adaptiveFormats")]
|
||||||
|
public List<StreamingFormat> AdaptiveFormats { get; set; } = [];
|
||||||
|
}
|
||||||
59
Manager.YouTube/Models/Innertube/StreamingFormat.cs
Normal file
59
Manager.YouTube/Models/Innertube/StreamingFormat.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class StreamingFormat
|
||||||
|
{
|
||||||
|
[JsonPropertyName("itag")]
|
||||||
|
public int Itag { get; set; }
|
||||||
|
[JsonPropertyName("url")]
|
||||||
|
public string? Url { get; set; }
|
||||||
|
[JsonPropertyName("mimeType")]
|
||||||
|
public string MimeType { get; set; } = "";
|
||||||
|
[JsonPropertyName("bitrate")]
|
||||||
|
public uint Bitrate { get; set; }
|
||||||
|
[JsonPropertyName("width")]
|
||||||
|
public uint? Width { get; set; }
|
||||||
|
[JsonPropertyName("height")]
|
||||||
|
public uint? Height { get; set; }
|
||||||
|
[JsonPropertyName("initRange")]
|
||||||
|
public Range? InitRange { get; set; }
|
||||||
|
[JsonPropertyName("indexRange")]
|
||||||
|
public Range? IndexRange { get; set; }
|
||||||
|
[JsonPropertyName("lastModified")]
|
||||||
|
public long LastModified { get; set; }
|
||||||
|
[JsonPropertyName("contentLength")]
|
||||||
|
public long ContentLength { get; set; }
|
||||||
|
[JsonPropertyName("quality")]
|
||||||
|
public string Quality { get; set; } = "";
|
||||||
|
[JsonPropertyName("xtags")]
|
||||||
|
public string? Xtags { get; set; }
|
||||||
|
[JsonPropertyName("fps")]
|
||||||
|
public uint Fps { get; set; }
|
||||||
|
[JsonPropertyName("qualityLabel")]
|
||||||
|
public string QualityLabel { get; set; } = "";
|
||||||
|
[JsonPropertyName("projectionType")]
|
||||||
|
public string ProjectionType { get; set; } = "";
|
||||||
|
[JsonPropertyName("averagebitrate")]
|
||||||
|
public uint? AverageBitrate { get; set; }
|
||||||
|
[JsonPropertyName("highReplication")]
|
||||||
|
public bool? HighReplication { get; set; }
|
||||||
|
[JsonPropertyName("colorInfo")]
|
||||||
|
public ColorInfo? ColorInfo { get; set; }
|
||||||
|
[JsonPropertyName("audioQuality")]
|
||||||
|
public string? AudioQuality { get; set; } = "";
|
||||||
|
[JsonPropertyName("approxDurationMs")]
|
||||||
|
public long ApproxDurationMs { get; set; }
|
||||||
|
[JsonPropertyName("audioSampleRate")]
|
||||||
|
public int? AudioSampleRate { get; set; }
|
||||||
|
[JsonPropertyName("audioChannels")]
|
||||||
|
public int? AudioChannels { get; set; }
|
||||||
|
[JsonPropertyName("loudnessDb")]
|
||||||
|
public double? LoudnessDb { get; set; }
|
||||||
|
[JsonPropertyName("isDrc")]
|
||||||
|
public bool? IsDrc { get; set; }
|
||||||
|
[JsonPropertyName("signatureCipher")]
|
||||||
|
public string? SignatureCipher { get; set; }
|
||||||
|
[JsonPropertyName("qualityOrdinal")]
|
||||||
|
public string QualityOrdinal { get; set; } = "";
|
||||||
|
}
|
||||||
13
Manager.YouTube/Models/Innertube/WebImage.cs
Normal file
13
Manager.YouTube/Models/Innertube/WebImage.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
public class WebImage
|
||||||
|
{
|
||||||
|
[JsonPropertyName("width")]
|
||||||
|
public int Width { get; set; }
|
||||||
|
[JsonPropertyName("height")]
|
||||||
|
public int Height { get; set; }
|
||||||
|
[JsonPropertyName("url")]
|
||||||
|
public string Url { get; set; } = "";
|
||||||
|
}
|
||||||
9
Manager.YouTube/Models/Parser/YouTubeVideoData.cs
Normal file
9
Manager.YouTube/Models/Parser/YouTubeVideoData.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Parser;
|
||||||
|
|
||||||
|
public class YouTubeVideoData
|
||||||
|
{
|
||||||
|
public JsonNode? YouTubePlayerData { get; set; }
|
||||||
|
public JsonNode? YouTubeInitialData { get; set; }
|
||||||
|
}
|
||||||
12
Manager.YouTube/Models/PlayerConfig.cs
Normal file
12
Manager.YouTube/Models/PlayerConfig.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Manager.YouTube.Models;
|
||||||
|
|
||||||
|
public class PlayerConfig
|
||||||
|
{
|
||||||
|
public double AudioLoudnessDb { get; set; }
|
||||||
|
public double AudioPerceptualLoudnessDb { get; set; }
|
||||||
|
public bool AudioEnablePerFormatLoudness { get; set; }
|
||||||
|
public uint MaxBitrate { get; set; }
|
||||||
|
public uint MaxReadAheadMediaTimeMs { get; set; }
|
||||||
|
public uint MinReadAheadMediaTimeMs { get; set; }
|
||||||
|
public uint ReadAheadGrowthRateMs { get; set; }
|
||||||
|
}
|
||||||
13
Manager.YouTube/Models/Playlist/PlaylistVideo.cs
Normal file
13
Manager.YouTube/Models/Playlist/PlaylistVideo.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models.Playlist;
|
||||||
|
|
||||||
|
public class PlaylistVideo
|
||||||
|
{
|
||||||
|
public required string VideoId { get; set; }
|
||||||
|
public List<WebImage> Thumbnails { get; set; } = [];
|
||||||
|
public required string Title { get; set; }
|
||||||
|
public required string Author { get; set; }
|
||||||
|
public long LengthSeconds { get; set; }
|
||||||
|
public bool IsPlayable { get; set; }
|
||||||
|
}
|
||||||
19
Manager.YouTube/Models/YouTubePlaylist.cs
Normal file
19
Manager.YouTube/Models/YouTubePlaylist.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Manager.YouTube.Models.Playlist;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models;
|
||||||
|
|
||||||
|
public class YouTubePlaylist
|
||||||
|
{
|
||||||
|
public required string Id { get; set; }
|
||||||
|
public required string Title { get; set; }
|
||||||
|
public required string Description { get; set; }
|
||||||
|
public required string Owner { get; set; }
|
||||||
|
public required string OwnerId { get; set; }
|
||||||
|
public bool NoIndex { get; set; }
|
||||||
|
public bool Unlisted { get; set; }
|
||||||
|
public bool CanReorder { get; set; }
|
||||||
|
public bool IsEditable { get; set; }
|
||||||
|
public List<PlaylistVideo> Videos { get; set; } = [];
|
||||||
|
|
||||||
|
public string? ContinuationToken { get; set; }
|
||||||
|
}
|
||||||
38
Manager.YouTube/Models/YouTubeVideo.cs
Normal file
38
Manager.YouTube/Models/YouTubeVideo.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Models;
|
||||||
|
|
||||||
|
public class YouTubeVideo
|
||||||
|
{
|
||||||
|
public required string VideoId { get; set; }
|
||||||
|
public string Title { get; set; } = "";
|
||||||
|
public string Description { get; set; } = "";
|
||||||
|
public string[] HashTags { get; set; } = [];
|
||||||
|
public long ViewCount { get; set; }
|
||||||
|
public long LikeCount { get; set; }
|
||||||
|
public string ChannelId { get; set; } = "";
|
||||||
|
public string Author { get; set; } = "";
|
||||||
|
public string PlayabilityStatus { get; set; } = "";
|
||||||
|
public long LengthSeconds { get; set; }
|
||||||
|
public string[] Keywords { get; set; } = [];
|
||||||
|
public bool IsOwnerViewing { get; set; }
|
||||||
|
public bool AllowRating { get; set; }
|
||||||
|
public bool IsCrawlable { get; set; }
|
||||||
|
public bool IsPrivate { get; set; }
|
||||||
|
public bool IsUnpluggedCorpus { get; set; }
|
||||||
|
public bool IsLive { get; set; }
|
||||||
|
public bool IsFamilySave { get; set; }
|
||||||
|
public string[] AvailableCountries { get; set; } = [];
|
||||||
|
public bool IsUnlisted { get; set; }
|
||||||
|
public bool HasYpcMetadata { get; set; }
|
||||||
|
public DateTime PublishDate { get; set; }
|
||||||
|
public DateTime UploadDate { get; set; }
|
||||||
|
public bool IsShortsEligible { get; set; }
|
||||||
|
public string Category { get; set; } = "";
|
||||||
|
|
||||||
|
public StreamingData? StreamingData { get; set; }
|
||||||
|
public List<WebImage> Thumbnails { get; set; } = [];
|
||||||
|
|
||||||
|
public PlayerConfig? PlayerConfig { get; set; }
|
||||||
|
public StoryBoard? StoryBoard { get; set; }
|
||||||
|
}
|
||||||
@@ -1,104 +1,57 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using DotBased.Monads;
|
using DotBased.Monads;
|
||||||
using Manager.YouTube.Models.Innertube;
|
|
||||||
using Manager.YouTube.Parsers;
|
|
||||||
using Manager.YouTube.Util;
|
using Manager.YouTube.Util;
|
||||||
|
|
||||||
namespace Manager.YouTube;
|
namespace Manager.YouTube;
|
||||||
|
|
||||||
public static class NetworkService
|
public static class NetworkService
|
||||||
{
|
{
|
||||||
private const string Origin = "https://www.youtube.com";
|
public const string Origin = "https://www.youtube.com";
|
||||||
|
private static readonly HttpClient HttpClient = new();
|
||||||
public static async Task<Result<ClientState>> GetClientStateAsync(YouTubeClient client)
|
|
||||||
|
public static async Task<Result<string>> MakeRequestAsync(HttpRequestMessage request, YouTubeClient client, bool skipAuthenticationHeader = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var httpRequest = new HttpRequestMessage
|
request.Headers.Add("Origin", Origin);
|
||||||
|
request.Headers.UserAgent.ParseAdd(client.UserAgent);
|
||||||
|
if (client.SapisidCookie != null && !skipAuthenticationHeader)
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Get,
|
request.Headers.Authorization = AuthenticationUtilities.GetSapisidHashHeader(client.GetDatasyncId(), client.SapisidCookie.Value, Origin);
|
||||||
RequestUri = new Uri(Origin)
|
|
||||||
};
|
|
||||||
httpRequest.Headers.IfModifiedSince = new DateTimeOffset(DateTime.UtcNow);
|
|
||||||
httpRequest.Headers.UserAgent.ParseAdd(client.UserAgent);
|
|
||||||
httpRequest.Headers.Accept.ParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
|
||||||
httpRequest.Headers.Connection.Add("keep-alive");
|
|
||||||
httpRequest.Headers.Add("DNT", "1");
|
|
||||||
httpRequest.Headers.Add("Upgrade-Insecure-Requests", "1");
|
|
||||||
|
|
||||||
var http = client.GetHttpClient();
|
|
||||||
if (http == null)
|
|
||||||
{
|
|
||||||
return ResultError.Fail("Unable to get http client!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = await http.SendAsync(httpRequest);
|
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
var responseResult = await response.Content.ReadAsStringAsync();
|
|
||||||
return ResultError.Fail(responseResult);
|
|
||||||
}
|
|
||||||
var responseHtml = await response.Content.ReadAsStringAsync();
|
|
||||||
var clientStateResult = HtmlParser.GetStateJson(responseHtml);
|
|
||||||
if (clientStateResult is { IsSuccess: false, Error: not null })
|
|
||||||
{
|
|
||||||
return clientStateResult.Error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientState? clientState;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
clientState = JsonSerializer.Deserialize<ClientState>(clientStateResult.Value.Item1);
|
var response = await client.HttpClient.SendAsync(request, cancellationToken);
|
||||||
|
var contentString = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return ResultError.Fail(contentString);
|
||||||
|
}
|
||||||
|
return contentString;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return ResultError.Error(e, "Error while parsing JSON!");
|
return ResultError.Error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientState == null ? ResultError.Fail("Unable to parse client state!") : clientState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Result> GetCurrentAccountInfoAsync(YouTubeClient client)
|
public static async Task<Result<DownloadResult>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient? client = null)
|
||||||
{
|
{
|
||||||
if (client.ClientState is not { LoggedIn: true })
|
try
|
||||||
{
|
{
|
||||||
return ResultError.Fail("Client not logged in!");
|
var response = client != null ? await client.HttpClient.SendAsync(request) : await HttpClient.SendAsync(request);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return ResultError.Fail($"Failed to get file to download, response code: {response.StatusCode}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
|
||||||
|
return new DownloadResult(data, response.Content.Headers.ContentType?.MediaType, response.Content.Headers.ContentDisposition?.FileName?.Trim('"'), response.Content.Headers.ContentLength ?? 0);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
var httpRequest = new HttpRequestMessage
|
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Post,
|
return ResultError.Error(e);
|
||||||
RequestUri = new Uri($"{Origin}/youtubei/v1/account/account_menu")
|
|
||||||
};
|
|
||||||
httpRequest.Headers.UserAgent.ParseAdd(client.UserAgent);
|
|
||||||
httpRequest.Headers.Add("Origin", Origin);
|
|
||||||
|
|
||||||
if (client.SapisidCookie != null)
|
|
||||||
{
|
|
||||||
httpRequest.Headers.Authorization = AuthenticationUtilities.GetSapisidHashHeader(client.ClientState.WebPlayerContextConfig?.WebPlayerContext?.DatasyncId ?? "", client.SapisidCookie.Value, Origin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var serializedContext = JsonSerializer.SerializeToNode(client.ClientState.InnerTubeContext);
|
|
||||||
var contextJson = new JsonObject { { "context", serializedContext } };
|
|
||||||
httpRequest.Content = new StringContent(contextJson.ToJsonString(), Encoding.UTF8, MediaTypeNames.Application.Json);
|
|
||||||
|
|
||||||
var http = client.GetHttpClient();
|
|
||||||
if (http == null)
|
|
||||||
{
|
|
||||||
return ResultError.Fail("Unable to get http client!");
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = await http.SendAsync(httpRequest);
|
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
var responseResult = await response.Content.ReadAsStringAsync();
|
|
||||||
return ResultError.Fail(responseResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
|
||||||
var jsonObject = JsonNode.Parse(json);
|
|
||||||
|
|
||||||
return ResultError.Fail("Not implemented");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record DownloadResult(byte[] Data, string? ContentType, string? FileName, long ContentLength);
|
||||||
53
Manager.YouTube/Parsers/CookieTxtParser.cs
Normal file
53
Manager.YouTube/Parsers/CookieTxtParser.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers;
|
||||||
|
|
||||||
|
public static class CookieTxtParser
|
||||||
|
{
|
||||||
|
public static async Task<CookieCollection> ParseAsync(Stream stream, HashSet<string>? allowedCookies = null)
|
||||||
|
{
|
||||||
|
var cookieCollection = new CookieCollection();
|
||||||
|
|
||||||
|
using var reader = new StreamReader(stream);
|
||||||
|
while (await reader.ReadLineAsync() is { } line)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(line) || line.StartsWith('#'))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineParts = line.Split('\t');
|
||||||
|
if (lineParts.Length < 7)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var domain = lineParts[0];
|
||||||
|
//var includeSubdomains = lineParts[1].Equals("TRUE", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var path = lineParts[2];
|
||||||
|
var secure = lineParts[3].Equals("TRUE", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var unixExpiry = long.TryParse(lineParts[4], out var exp) ? exp : 0;
|
||||||
|
var name = lineParts[5];
|
||||||
|
var value = lineParts[6];
|
||||||
|
|
||||||
|
if (!allowedCookies?.Contains(name) ?? false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cookie = new Cookie(name, value, path, domain)
|
||||||
|
{
|
||||||
|
Secure = secure
|
||||||
|
};
|
||||||
|
|
||||||
|
if (unixExpiry is > 0 and < int.MaxValue)
|
||||||
|
{
|
||||||
|
cookie.Expires = DateTimeOffset.FromUnixTimeSeconds(unixExpiry).DateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
cookieCollection.Add(cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookieCollection;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
using DotBased.Monads;
|
using DotBased.Monads;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
using Manager.YouTube.Models.Parser;
|
||||||
|
|
||||||
namespace Manager.YouTube.Parsers;
|
namespace Manager.YouTube.Parsers;
|
||||||
|
|
||||||
public static class HtmlParser
|
public static class HtmlParser
|
||||||
{
|
{
|
||||||
public static Result<(string, string)> GetStateJson(string html)
|
public static Result<(string, bool)> GetStateJson(string html)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(html))
|
if (string.IsNullOrWhiteSpace(html))
|
||||||
{
|
{
|
||||||
@@ -21,16 +23,67 @@ public static class HtmlParser
|
|||||||
return ResultError.Fail($"Could not find {setFunction} in html script nodes!");
|
return ResultError.Fail($"Could not find {setFunction} in html script nodes!");
|
||||||
|
|
||||||
var json = ExtractJson(scriptNode.InnerText, "ytcfg.set(");
|
var json = ExtractJson(scriptNode.InnerText, "ytcfg.set(");
|
||||||
var jsonText = ExtractJson(scriptNode.InnerText, "setMessage(");
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(json) || string.IsNullOrWhiteSpace(jsonText))
|
if (string.IsNullOrWhiteSpace(json))
|
||||||
{
|
{
|
||||||
return ResultError.Fail($"Could not find {setFunction} in html script nodes!");
|
return ResultError.Fail($"Could not find {setFunction} in html script nodes!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (json, jsonText);
|
var isPremiumUser = html.Contains("logo-type=\"YOUTUBE_PREMIUM_LOGO\"", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
return (json, isPremiumUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Result<YouTubeVideoData> GetVideoDataFromHtml(string html)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(html))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("html cannot be empty!");
|
||||||
|
}
|
||||||
|
var htmlDocument = new HtmlDocument();
|
||||||
|
htmlDocument.LoadHtml(html);
|
||||||
|
|
||||||
|
const string initialYoutubeData = "var ytInitialPlayerResponse = {";
|
||||||
|
var initialPlayerDataNode = htmlDocument.DocumentNode.SelectSingleNode($"//script[contains(., '{initialYoutubeData}')]");
|
||||||
|
if (string.IsNullOrWhiteSpace(initialPlayerDataNode.InnerText))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Could not find {initialPlayerData} in html script nodes!");
|
||||||
|
}
|
||||||
|
var initialPlayerDataString = ExtractJson(initialPlayerDataNode.InnerText, "var ytInitialPlayerResponse = ");
|
||||||
|
if (string.IsNullOrWhiteSpace(initialPlayerDataString))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Failed to extract initial player date from JSON.");
|
||||||
|
}
|
||||||
|
var parsedPlayerInitialData = JsonNode.Parse(initialPlayerDataString);
|
||||||
|
|
||||||
|
const string initialData = "var ytInitialData = {";
|
||||||
|
var initialDataNode = htmlDocument.DocumentNode.SelectSingleNode($"//script[contains(., '{initialData}')]");
|
||||||
|
if (string.IsNullOrWhiteSpace(initialDataNode.InnerText))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Could not find {initialData} in html script nodes!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var initialDataJsonString = ExtractJson(initialDataNode.InnerText, "var ytInitialData = ");
|
||||||
|
if (string.IsNullOrWhiteSpace(initialDataJsonString))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Failed to extract initial player date from JSON.");
|
||||||
|
}
|
||||||
|
var parsedInitialData = JsonNode.Parse(initialDataJsonString);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new YouTubeVideoData
|
||||||
|
{
|
||||||
|
YouTubePlayerData = parsedPlayerInitialData,
|
||||||
|
YouTubeInitialData = parsedInitialData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return ResultError.Error(e, "Could not parse youtube player data.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static string? ExtractJson(string input, string marker)
|
static string? ExtractJson(string input, string marker)
|
||||||
{
|
{
|
||||||
var start = input.IndexOf(marker, StringComparison.Ordinal);
|
var start = input.IndexOf(marker, StringComparison.Ordinal);
|
||||||
|
|||||||
83
Manager.YouTube/Parsers/Json/ChannelJsonParser.cs
Normal file
83
Manager.YouTube/Parsers/Json/ChannelJsonParser.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers.Json;
|
||||||
|
|
||||||
|
public static class ChannelJsonParser
|
||||||
|
{
|
||||||
|
public static Result<InnertubeChannel> ParseJsonToChannelData(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var doc = JsonDocument.Parse(json);
|
||||||
|
var rootDoc = doc.RootElement;
|
||||||
|
|
||||||
|
var channelMetadata = rootDoc
|
||||||
|
.GetProperty("metadata")
|
||||||
|
.GetProperty("channelMetadataRenderer");
|
||||||
|
|
||||||
|
var channelId = channelMetadata.GetProperty("externalId").GetString();
|
||||||
|
if (channelId == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("No channel id found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var channel = new InnertubeChannel
|
||||||
|
{
|
||||||
|
Id = channelId,
|
||||||
|
ChannelName = channelMetadata.GetProperty("title").ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var microformat = rootDoc.GetProperty("microformat").GetProperty("microformatDataRenderer");
|
||||||
|
|
||||||
|
channel.AvailableCountries = microformat
|
||||||
|
.GetProperty("availableCountries")
|
||||||
|
.EnumerateArray()
|
||||||
|
.Select(e => e.GetString())
|
||||||
|
.OfType<string>().ToList();
|
||||||
|
channel.Description = microformat.GetProperty("description").GetString();
|
||||||
|
channel.NoIndex = microformat.GetProperty("noindex").GetBoolean();
|
||||||
|
channel.Unlisted = microformat.GetProperty("unlisted").GetBoolean();
|
||||||
|
channel.FamilySafe = microformat.GetProperty("familySafe").GetBoolean();
|
||||||
|
|
||||||
|
var avatarThumbnails = channelMetadata.GetProperty("avatar")
|
||||||
|
.GetProperty("thumbnails")
|
||||||
|
.EnumerateArray();
|
||||||
|
channel.AvatarImages = JsonParser.ParseImages(avatarThumbnails);
|
||||||
|
|
||||||
|
var headerContent = rootDoc
|
||||||
|
.GetProperty("header")
|
||||||
|
.GetProperty("pageHeaderRenderer")
|
||||||
|
.GetProperty("content");
|
||||||
|
|
||||||
|
channel.Handle = headerContent
|
||||||
|
.GetProperty("pageHeaderViewModel")
|
||||||
|
.GetProperty("metadata")
|
||||||
|
.GetProperty("contentMetadataViewModel")
|
||||||
|
.GetProperty("metadataRows")
|
||||||
|
.EnumerateArray()
|
||||||
|
.FirstOrDefault()
|
||||||
|
.GetProperty("metadataParts")
|
||||||
|
.EnumerateArray()
|
||||||
|
.FirstOrDefault()
|
||||||
|
.GetProperty("text")
|
||||||
|
.GetProperty("content").GetString();
|
||||||
|
|
||||||
|
var bannerImages = headerContent
|
||||||
|
.GetProperty("pageHeaderViewModel")
|
||||||
|
.GetProperty("banner")
|
||||||
|
.GetProperty("imageBannerViewModel")
|
||||||
|
.GetProperty("image")
|
||||||
|
.GetProperty("sources")
|
||||||
|
.EnumerateArray();
|
||||||
|
channel.BannerImages = JsonParser.ParseImages(bannerImages);
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return ResultError.Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Manager.YouTube/Parsers/Json/JsonAccountParser.cs
Normal file
43
Manager.YouTube/Parsers/Json/JsonAccountParser.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using DotBased.Monads;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers.Json;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parsing functionality for the response from endpoint: /youtubei/v1/account/account_menu
|
||||||
|
/// </summary>
|
||||||
|
public static class JsonAccountParser
|
||||||
|
{
|
||||||
|
public static Result<string> ParseAccountId(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jsonDocument = JsonDocument.Parse(json);
|
||||||
|
|
||||||
|
var id = jsonDocument.RootElement
|
||||||
|
.GetProperty("actions")[0]
|
||||||
|
.GetProperty("openPopupAction")
|
||||||
|
.GetProperty("popup")
|
||||||
|
.GetProperty("multiPageMenuRenderer")
|
||||||
|
.GetProperty("header")
|
||||||
|
.GetProperty("activeAccountHeaderRenderer")
|
||||||
|
.GetProperty("manageAccountTitle")
|
||||||
|
.GetProperty("runs")
|
||||||
|
.EnumerateArray()
|
||||||
|
.FirstOrDefault()
|
||||||
|
.GetProperty("navigationEndpoint")
|
||||||
|
.GetProperty("browseEndpoint")
|
||||||
|
.GetProperty("browseId").GetString();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(id))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Unable to get account id!");
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return ResultError.Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
Manager.YouTube/Parsers/Json/JsonParser.cs
Normal file
91
Manager.YouTube/Parsers/Json/JsonParser.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers.Json;
|
||||||
|
|
||||||
|
public static class JsonParser
|
||||||
|
{
|
||||||
|
public static List<WebImage> ParseImages(JsonElement.ArrayEnumerator array) =>
|
||||||
|
array
|
||||||
|
.Select(image => new WebImage { Width = image.GetProperty("width").GetInt32(), Height = image.GetProperty("height").GetInt32(), Url = image.GetProperty("url").GetString() ?? "" })
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
public static string ExtractTextOrHtml(JsonNode? node)
|
||||||
|
{
|
||||||
|
if (node is not JsonObject nodeObj)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 1: Simple text (no formatting)
|
||||||
|
if (nodeObj.TryGetPropertyValue("simpleText", out var simpleText))
|
||||||
|
return simpleText?.GetValue<string>() ?? string.Empty;
|
||||||
|
|
||||||
|
// Case 2: Runs (formatted text segments)
|
||||||
|
if (nodeObj.TryGetPropertyValue("runs", out var runs) && runs != null && runs.GetValueKind() == JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var runNode in runs.AsArray())
|
||||||
|
{
|
||||||
|
if (runNode is not JsonObject run)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = runNode["text"]?.GetValue<string>() ?? string.Empty;
|
||||||
|
var formatted = System.Net.WebUtility.HtmlEncode(text);
|
||||||
|
|
||||||
|
var bold = run.TryGetPropertyValue("bold", out var boldNode) && boldNode is JsonValue bv && bv.GetValue<bool>();
|
||||||
|
|
||||||
|
var italic = run.TryGetPropertyValue("italic", out var italicNode) && italicNode is JsonValue iv && iv.GetValue<bool>();
|
||||||
|
|
||||||
|
var underline = run.TryGetPropertyValue("underline", out var underlineNode) && underlineNode is JsonValue uv && uv.GetValue<bool>();
|
||||||
|
|
||||||
|
var strikethrough = run.TryGetPropertyValue("strikethrough", out var strikeNode) && strikeNode is JsonValue sv && sv.GetValue<bool>();
|
||||||
|
|
||||||
|
if (bold) formatted = $"<b>{formatted}</b>";
|
||||||
|
if (italic) formatted = $"<i>{formatted}</i>";
|
||||||
|
if (underline) formatted = $"<u>{formatted}</u>";
|
||||||
|
if (strikethrough) formatted = $"<s>{formatted}</s>";
|
||||||
|
|
||||||
|
if (run.TryGetPropertyValue("navigationEndpoint", out var nav) && nav is JsonObject navObj &&
|
||||||
|
navObj.TryGetPropertyValue("url", out var urlProp))
|
||||||
|
{
|
||||||
|
var url = urlProp?.GetValue<string>();
|
||||||
|
if (!string.IsNullOrEmpty(url))
|
||||||
|
formatted = $"<a href=\"{url}\">{formatted}</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (run.TryGetPropertyValue("emoji", out var emoji) && emoji is JsonObject emojiObj)
|
||||||
|
{
|
||||||
|
if (emojiObj.TryGetPropertyValue("url", out var emojiUrl))
|
||||||
|
{
|
||||||
|
var src = emojiUrl?.GetValue<string>();
|
||||||
|
if (!string.IsNullOrEmpty(src))
|
||||||
|
formatted = $"<img src=\"{src}\" alt=\"{text}\" class=\"emoji\" />";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(formatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<WebImage> ExtractWebImages(JsonNode? node)
|
||||||
|
{
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var thumbnailsArray = node["thumbnails"];
|
||||||
|
return thumbnailsArray?.Deserialize<List<WebImage>>() ?? [];
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Manager.YouTube/Parsers/Json/VideoJsonParser.cs
Normal file
35
Manager.YouTube/Parsers/Json/VideoJsonParser.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using DotBased.Logging;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using Manager.YouTube.Models;
|
||||||
|
using Manager.YouTube.Models.Parser;
|
||||||
|
using Manager.YouTube.Util.Converters;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers.Json;
|
||||||
|
|
||||||
|
public static class VideoJsonParser
|
||||||
|
{
|
||||||
|
private static readonly JsonSerializerOptions VideoParserOptions = new() { Converters = { new YouTubeVideoJsonConverter() } };
|
||||||
|
private static readonly ILogger Logger = LogService.RegisterLogger(typeof(VideoJsonParser), "Video JSON parser");
|
||||||
|
|
||||||
|
public static Result<YouTubeVideo> ParseVideoData(YouTubeVideoData videoData)
|
||||||
|
{
|
||||||
|
if (videoData.YouTubePlayerData == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("No initial video data found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
YouTubeVideo? video;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
video = videoData.YouTubePlayerData.Deserialize<YouTubeVideo>(VideoParserOptions);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "Failed to parse video data");
|
||||||
|
return ResultError.Fail("Failed to parse video data");
|
||||||
|
}
|
||||||
|
|
||||||
|
return video != null? video : ResultError.Fail("Failed to parse video data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,20 +9,44 @@ public static class AuthenticationUtilities
|
|||||||
{
|
{
|
||||||
private const string HeaderScheme = "SAPISIDHASH";
|
private const string HeaderScheme = "SAPISIDHASH";
|
||||||
|
|
||||||
// Dave Thomas @ https://stackoverflow.com/a/32065323/9948300
|
// Dave Thomas & windy for updated answer @ https://stackoverflow.com/a/32065323/9948300
|
||||||
public static AuthenticationHeaderValue? GetSapisidHashHeader(string datasyncId, string sapisid, string origin)
|
public static AuthenticationHeaderValue GetSapisidHashHeader(string datasyncId, string sapisid, string origin)
|
||||||
{
|
{
|
||||||
var strHash = GetSapisidHash(datasyncId, sapisid, origin);
|
var strHash = GetSapisidHash(datasyncId, sapisid, origin);
|
||||||
return new AuthenticationHeaderValue(HeaderScheme, strHash);
|
return new AuthenticationHeaderValue(HeaderScheme, strHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string? GetSapisidHash(string datasyncId, string sapisid, string origin)
|
public static string GetSapisidHash(string datasyncId, string sapisid, string origin, string? time = null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(datasyncId) || string.IsNullOrWhiteSpace(sapisid) || string.IsNullOrWhiteSpace(origin))
|
if (string.IsNullOrWhiteSpace(datasyncId))
|
||||||
return null;
|
{
|
||||||
datasyncId = datasyncId.Replace("||", "");
|
throw new ArgumentNullException(nameof(datasyncId));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(sapisid))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(sapisid));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(origin))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(origin));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (datasyncId.Contains("||", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var ids = datasyncId.Split("||", StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
datasyncId = ids.Length switch
|
||||||
|
{
|
||||||
|
1 => ids[0],
|
||||||
|
2 => ids[1],
|
||||||
|
_ => datasyncId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
sapisid = Uri.UnescapeDataString(sapisid);
|
sapisid = Uri.UnescapeDataString(sapisid);
|
||||||
var time = GetTime();
|
if (string.IsNullOrWhiteSpace(time))
|
||||||
|
{
|
||||||
|
time = GetTime();
|
||||||
|
}
|
||||||
var sha1 = HashString($"{datasyncId} {time} {sapisid} {origin}");
|
var sha1 = HashString($"{datasyncId} {time} {sapisid} {origin}");
|
||||||
var completeHash = $"{time}_{sha1}_u";
|
var completeHash = $"{time}_{sha1}_u";
|
||||||
return completeHash;
|
return completeHash;
|
||||||
@@ -38,7 +62,7 @@ public static class AuthenticationUtilities
|
|||||||
private static string GetTime()
|
private static string GetTime()
|
||||||
{
|
{
|
||||||
var st = new DateTime(1970, 1, 1);
|
var st = new DateTime(1970, 1, 1);
|
||||||
var t = DateTime.Now.ToUniversalTime() - st;
|
var t = DateTime.UtcNow - st;
|
||||||
var time = (t.TotalMilliseconds + 0.5).ToString(CultureInfo.InvariantCulture);
|
var time = (t.TotalMilliseconds + 0.5).ToString(CultureInfo.InvariantCulture);
|
||||||
return time[..10];
|
return time[..10];
|
||||||
}
|
}
|
||||||
|
|||||||
125
Manager.YouTube/Util/Cipher/CipherDecoder.cs
Normal file
125
Manager.YouTube/Util/Cipher/CipherDecoder.cs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
using System.Collections.Frozen;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Manager.YouTube.Util.Cipher.Operations;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Util.Cipher;
|
||||||
|
|
||||||
|
public partial class CipherDecoder
|
||||||
|
{
|
||||||
|
public required string Version { get; init; }
|
||||||
|
public readonly IReadOnlySet<ICipherOperation> Operations;
|
||||||
|
|
||||||
|
private CipherDecoder(IEnumerable<ICipherOperation> operations)
|
||||||
|
{
|
||||||
|
Operations = operations.ToFrozenSet();
|
||||||
|
if (Operations.Count == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(operations), "No decipher operations given.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<CipherDecoder> CreateAsync(string relativeUrl, string version, YouTubeClient? client = null)
|
||||||
|
{
|
||||||
|
var operations = await GetCipherOperations(relativeUrl, client);
|
||||||
|
var decoder = new CipherDecoder(operations)
|
||||||
|
{
|
||||||
|
Version = version
|
||||||
|
};
|
||||||
|
return decoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Decipher(string? signatureCipher)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(signatureCipher))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var urlBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
var indexStart = signatureCipher.IndexOf("s=", StringComparison.Ordinal);
|
||||||
|
var indexEnd = signatureCipher.IndexOf("&", StringComparison.Ordinal);
|
||||||
|
var signature = signatureCipher.Substring(indexStart, indexEnd);
|
||||||
|
|
||||||
|
indexStart = signatureCipher.IndexOf("&sp", StringComparison.Ordinal);
|
||||||
|
indexEnd = signatureCipher.IndexOf("&url", StringComparison.Ordinal);
|
||||||
|
var spParam = signatureCipher.Substring(indexStart, indexEnd - indexStart);
|
||||||
|
|
||||||
|
indexStart = signatureCipher.IndexOf("&url", StringComparison.Ordinal);
|
||||||
|
var videoUrl = signatureCipher[indexStart..];
|
||||||
|
|
||||||
|
|
||||||
|
signature = signature[(signature.IndexOf('=') + 1)..];
|
||||||
|
spParam = spParam[(spParam.IndexOf('=') + 1)..];
|
||||||
|
videoUrl = videoUrl[(videoUrl.IndexOf('=') + 1)..];
|
||||||
|
if (string.IsNullOrWhiteSpace(signature))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Invalid signature.");
|
||||||
|
}
|
||||||
|
var signatureDeciphered = Operations.Aggregate(signature, (acc, op) => op.Decipher(acc));
|
||||||
|
|
||||||
|
urlBuilder.Append(videoUrl);
|
||||||
|
urlBuilder.Append($"&{spParam}=");
|
||||||
|
urlBuilder.Append(signatureDeciphered);
|
||||||
|
return urlBuilder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<IEnumerable<ICipherOperation>> GetCipherOperations(string relativeUrl, YouTubeClient? client = null)
|
||||||
|
{
|
||||||
|
var downloadRequest = new HttpRequestMessage(HttpMethod.Get, new Uri($"{NetworkService.Origin}/{relativeUrl}"));
|
||||||
|
var downloadResponse = await NetworkService.DownloadBytesAsync(downloadRequest, client);
|
||||||
|
if (!downloadResponse.IsSuccess)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var playerJs = Encoding.UTF8.GetString(downloadResponse.Value.Data);
|
||||||
|
if (string.IsNullOrWhiteSpace(playerJs))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var functionBody = FunctionBodyRegex().Match(playerJs).Groups[0].ToString();
|
||||||
|
var definitionBody = DefinitionBodyRegex().Match(functionBody).Groups[1].Value;
|
||||||
|
var decipherDefinition = Regex.Match(playerJs, $@"var\s+{definitionBody}=\{{(\w+:function\(\w+(,\w+)?\)\{{(.*?)\}}),?\}};", RegexOptions.Singleline).Groups[0].ToString();
|
||||||
|
|
||||||
|
SortedSet<ICipherOperation> operations = [];
|
||||||
|
foreach (var statement in functionBody.Split(';'))
|
||||||
|
{
|
||||||
|
// Get the name of the function called in this statement
|
||||||
|
var calledFuncName = StatementFunctionNameRegex().Match(statement).Groups[1].Value;
|
||||||
|
if (string.IsNullOrWhiteSpace(calledFuncName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (Regex.IsMatch(decipherDefinition, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\."))
|
||||||
|
{
|
||||||
|
var index = int.Parse(OperationIndexRegex().Match(statement).Groups[1].Value);
|
||||||
|
operations.Add(new CipherSlice(index));
|
||||||
|
}
|
||||||
|
else if (Regex.IsMatch(decipherDefinition, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b"))
|
||||||
|
{
|
||||||
|
var index = int.Parse(OperationIndexRegex().Match(statement).Groups[1].Value);
|
||||||
|
operations.Add(new CipherSwap(index));
|
||||||
|
}
|
||||||
|
else if (Regex.IsMatch(decipherDefinition, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\(\w+\)"))
|
||||||
|
{
|
||||||
|
operations.Add(new CipherReverse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[GeneratedRegex(@"([A-Za-z_$][A-Za-z0-9_$]*)=function\([A-Za-z_$][A-Za-z0-9_$]*\)\{\s*([A-Za-z_$][A-Za-z0-9_$]*)=\2\.split\(\x22\x22\);[\s\S]*?return\s+\2\.join\(\x22\x22\)\s*\}")]
|
||||||
|
private static partial Regex FunctionBodyRegex();
|
||||||
|
[GeneratedRegex("([\\$_\\w]+).\\w+\\(\\w+,\\d+\\);")]
|
||||||
|
private static partial Regex DefinitionBodyRegex();
|
||||||
|
|
||||||
|
|
||||||
|
[GeneratedRegex(@"\(\w+,(\d+)\)")]
|
||||||
|
private static partial Regex OperationIndexRegex();
|
||||||
|
[GeneratedRegex(@"\w+(?:.|\[)(\""?\w+(?:\"")?)\]?\(")]
|
||||||
|
private static partial Regex StatementFunctionNameRegex();
|
||||||
|
}
|
||||||
11
Manager.YouTube/Util/Cipher/CipherDecoderCollection.cs
Normal file
11
Manager.YouTube/Util/Cipher/CipherDecoderCollection.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Util.Cipher;
|
||||||
|
|
||||||
|
public class CipherDecoderCollection : KeyedCollection<string, CipherDecoder>
|
||||||
|
{
|
||||||
|
protected override string GetKeyForItem(CipherDecoder item)
|
||||||
|
{
|
||||||
|
return item.Version;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Manager.YouTube/Util/Cipher/CipherManager.cs
Normal file
47
Manager.YouTube/Util/Cipher/CipherManager.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using DotBased.Logging;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Util.Cipher;
|
||||||
|
|
||||||
|
public static class CipherManager
|
||||||
|
{
|
||||||
|
private static readonly CipherDecoderCollection LoadedCiphers = [];
|
||||||
|
private static readonly ILogger Logger = LogService.RegisterLogger(typeof(CipherManager));
|
||||||
|
|
||||||
|
public static async Task<Result<CipherDecoder>> GetDecoderAsync(ClientState clientState, YouTubeClient? client = null)
|
||||||
|
{
|
||||||
|
var relativePlayerJsUrl = clientState.PlayerJsUrl;
|
||||||
|
if (string.IsNullOrEmpty(relativePlayerJsUrl))
|
||||||
|
{
|
||||||
|
return ResultError.Fail("Could not get player js url.");
|
||||||
|
}
|
||||||
|
var version = GetCipherVersion(relativePlayerJsUrl);
|
||||||
|
|
||||||
|
Logger.Debug($"Getting cipher decoder for version: {version}");
|
||||||
|
if (LoadedCiphers.TryGetValue(version, out var cipher))
|
||||||
|
{
|
||||||
|
return cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var decoder = await CipherDecoder.CreateAsync(relativePlayerJsUrl, version, client);
|
||||||
|
LoadedCiphers.Add(decoder);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "Could not create cipher decoder. Version: {DecoderVersion}", version);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultError.Fail($"Could not create cipher decoder for {relativePlayerJsUrl} (v: {version})");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetCipherVersion(string relativePlayerUrl)
|
||||||
|
{
|
||||||
|
var split = relativePlayerUrl.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
var v = split[2];
|
||||||
|
var lang = split[4];
|
||||||
|
return $"{v}_{lang}";
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Manager.YouTube/Util/Cipher/Operations/CipherReverse.cs
Normal file
18
Manager.YouTube/Util/Cipher/Operations/CipherReverse.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Util.Cipher.Operations;
|
||||||
|
|
||||||
|
public class CipherReverse : ICipherOperation
|
||||||
|
{
|
||||||
|
public string Decipher(string cipherSignature)
|
||||||
|
{
|
||||||
|
var buffer = new StringBuilder(cipherSignature.Length);
|
||||||
|
|
||||||
|
for (var i = cipherSignature.Length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
buffer.Append(cipherSignature[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Manager.YouTube/Util/Cipher/Operations/CipherSlice.cs
Normal file
6
Manager.YouTube/Util/Cipher/Operations/CipherSlice.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Manager.YouTube.Util.Cipher.Operations;
|
||||||
|
|
||||||
|
public class CipherSlice(int indexToSlice) : ICipherOperation
|
||||||
|
{
|
||||||
|
public string Decipher(string cipherSignature) => cipherSignature[indexToSlice..];
|
||||||
|
}
|
||||||
12
Manager.YouTube/Util/Cipher/Operations/CipherSwap.cs
Normal file
12
Manager.YouTube/Util/Cipher/Operations/CipherSwap.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Util.Cipher.Operations;
|
||||||
|
|
||||||
|
public class CipherSwap(int indexToSwap) : ICipherOperation
|
||||||
|
{
|
||||||
|
public string Decipher(string cipherSignature) => new StringBuilder(cipherSignature)
|
||||||
|
{
|
||||||
|
[0] = cipherSignature[indexToSwap],
|
||||||
|
[indexToSwap] = cipherSignature[0]
|
||||||
|
}.ToString();
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user