Compare commits

..

92 Commits

Author SHA1 Message Date
max
3d20c116da [CHANGE] Adding playlist functionality 2025-11-02 21:43:06 +01:00
max
a849b7524d [CHANGE] Added video info page 2025-11-02 21:22:56 +01:00
max
bf957436f0 [CHANGE] Disabled signature challenge. Need to run js. 2025-11-02 19:45:41 +01:00
max
16343c9a56 [CHANGE] Testing js runtime script 2025-11-02 00:02:09 +01:00
max
4c04378080 [CHANGE] Added jint. Reworking decipher functionality 2025-10-28 19:08:59 +01:00
max
b5c701b971 [CHANGE] Reworked cipher stuff 2025-10-24 21:16:08 +02:00
max
a84195aefa [CHANGE] Reworked parsers/converters. Decipher operation from script do not work! 2025-10-24 00:23:09 +02:00
max
de28591d24 [REFACTOR] 2025-10-23 21:51:31 +02:00
max
264be8d529 [REFACTOR] Rename response 2025-10-23 21:36:16 +02:00
max
25589d18d8 [CHANGE] Update client. Reworked small things 2025-10-23 21:28:08 +02:00
max
972af513f0 [CHANGE] Linked decipher to video implementation 2025-10-23 20:08:02 +02:00
max
e87e1c57f9 [CHANGE] Updated cipher implementation and added decipher function 2025-10-23 19:45:36 +02:00
max
41f880cfef [CHANGE] Added old cipher implementation 2025-10-23 19:27:07 +02:00
max
9fdde5e756 [CHANGE] Added logger to client 2025-10-23 18:15:05 +02:00
max
ed9cb7eff1 [CHANGE] Check for video id else throw exception. 2025-10-23 18:06:26 +02:00
max
97f7f5dcf6 [CHANGE] Implementation video data 2025-10-21 20:46:31 +02:00
max
ed1b7406a6 [CHANGE] Json video parser && video model 2025-10-21 16:47:24 +02:00
max
2b5e93ff8a [CHANGE] Implementing video fetching and deciphering 2025-10-20 13:57:55 +02:00
max
1555ae9f3d [CHANGE] No need to reload client from db if already loaded && can be loaded without checking library service 2025-10-19 23:32:05 +02:00
max
34e029ec79 [CHANGE] Client handling 2025-10-19 23:21:07 +02:00
max
e4596df392 [CHANGE] ApplicationContext removed and related classes. Added Drive info to library info page. 2025-10-19 22:47:48 +02:00
max
2f19d60be0 [CHANGE] Reworked ExtendedBackgroundService.cs with State logic and actions 2025-10-08 18:22:16 +02:00
max
b8d2573d78 [CHANGE] Fixes library db 2025-09-28 18:59:39 +02:00
max
a2a420d596 [CHANGE] Small optimizations 2025-09-28 18:34:45 +02:00
max
c170b8db1f [CHANGE] Added cookie rotation with state. Updated cookie table 2025-09-28 18:05:52 +02:00
max
abc1505b6e [CHANGE] Cookie import by netscape cookie txt format 2025-09-28 17:47:34 +02:00
max
2c125c24ae [CHANGE] Channel & Account list to view models 2025-09-22 17:12:42 +02:00
max
646e0a814a [ADD] Added endpoint for providing files 2025-09-22 16:15:18 +02:00
max
a478943792 [ADD] Simple views for accounts and channels 2025-09-22 15:50:30 +02:00
max
a7baeb0d73 [CHANGE] Fixed storing account/channel 2025-09-22 14:53:41 +02:00
max
1903cb2938 [CHANGE] Client cookie init 2025-09-22 13:41:02 +02:00
max
9e81e221c6 [CHANGE] Improved hash auth token gen. Added new cookie rotate 2025-09-22 13:37:55 +02:00
max
88e724099c [CHANGE] Simple cookie rotation post 2025-09-22 00:51:42 +02:00
max
79ea2badf1 [FIX] EventConsole batch fix 2025-09-18 02:10:13 +02:00
max
5250b9f3f9 [REWORK] Changes saving client and channel info 2025-09-18 02:01:45 +02:00
max
9e173258ed [CHANGES] 2025-09-18 00:42:17 +02:00
max
ab532ac6dc [CHANGE] Fixed cache service && Download channel images from cache 2025-09-18 00:30:35 +02:00
max
8a64d6fc64 [CHANGE] Remove anon accounts && added simple caching for urls 2025-09-17 23:44:02 +02:00
max
0056a14f79 [CHANGE] Fixed auditing, storing images from account import 2025-09-15 00:23:57 +02:00
max
e82736a45f [CHANGE] History -> Audit 2025-09-14 03:30:39 +02:00
max
0f83cf1ddc [CHANGE] Reworked db with interceptors 2025-09-10 23:49:41 +02:00
max
b1e5b0dc68 [CHANGE] event console own component 2025-09-10 20:09:58 +02:00
max
9be6f5be89 [CHANGE] Reworked event console 2025-09-10 18:19:36 +02:00
max
ef6ca0ee07 [OPTIMIZING] 2025-09-10 02:55:06 +02:00
max
03631cd0c8 [CHANGE] Service extended and events 2025-09-10 01:46:07 +02:00
max
9ff4fcded2 [CHANGE] Services view 2025-09-09 19:51:07 +02:00
max
2593d02a73 [CHANGE] BackgroundServices 2025-09-09 19:11:02 +02:00
max
d183803390 [CHANGE] DI fixes 2025-09-09 00:58:12 +02:00
max
a5e55e563e [CHANGE] Small fixes 2025-09-08 21:56:42 +02:00
max
b3861b7cd9 [CHANGE] Get username from other json property 2025-09-08 21:40:54 +02:00
max
680b6d2cc9 [CHANGE] Reworked client creation 2025-09-08 21:28:33 +02:00
max
b2c9fc2c52 [CHANGE] Finished impl required data for client 2025-09-08 01:40:43 +02:00
max
b2c6003203 [CHANGE] Split up json parsing, added getting account info 2025-09-07 22:18:56 +02:00
max
3db61b599d [CHANGE] GetChannel impl 2025-09-07 01:24:46 +02:00
max
c528ad9bb3 [CHANGE] Rework && adding channel fetching 2025-09-06 20:40:46 +02:00
max
d0eca248bb [CHANGE] Cleanup cookie import 2025-09-06 03:10:20 +02:00
max
fa0c617c9a [CHANGE] Get all account info 2025-09-06 01:07:12 +02:00
max
f334c87fbb [CHANGE] Cookie login fixed 2025-09-05 23:36:51 +02:00
max
55322f8792 [CHANGE] Added dev page 2025-09-05 16:23:32 +02:00
max
92e5bb7f1f [CHANGE] Working on auth hash 2025-09-04 20:32:39 +02:00
max
431a103fac [CHANGE] Add account dialog 2025-09-04 18:05:56 +02:00
max
a8cfbbe0db [CHANGE] Adding accounts 2025-09-04 10:37:38 +02:00
max
f7bfee5de2 [CHANGE] Accounts to Channels, update navmenu 2025-09-04 08:48:06 +02:00
max
dd19fc27d9 [CHANGE] 2025-09-03 23:04:02 +02:00
max
4bee6e6d35 [CHANGE] Remove service 2025-09-02 20:55:25 +02:00
max
a8b0291ebf [DB] Update migrations for datetime update 2025-09-02 16:17:47 +02:00
max
d98a99d145 [DB] Auto update datetimes on entities 2025-09-02 16:01:07 +02:00
max
c30e503642 [DB] Update initial db 2025-09-02 15:37:28 +02:00
max
dbf6938a7e [CHANGE] Preparing client init 2025-09-02 15:17:14 +02:00
max
0ab0a029c4 [CHANGE] Working on client manager 2025-08-31 21:36:53 +02:00
max
2f018d131e [CHANGE] Small changes, renamed app title 2025-08-31 21:08:14 +02:00
max
d501015b82 [GIT] Ignore library dir 2025-08-31 20:12:12 +02:00
max
98fe4b9391 [CHANGE] Library service, db migrations, ui blazor 2025-08-31 20:11:03 +02:00
max
aeb9adf930 [CHANGE] Updated settings and added warning messages 2025-08-31 15:52:30 +02:00
max
d4d5ef1846 [CHANGE] Added readme && added service 2025-08-31 15:45:42 +02:00
max
a2489fea8d [CHANGE] WIP YouTubeClient & HTML parsing 2025-08-25 15:27:16 +02:00
max
9789c5f535 [CHANGE] Preparing YouTubeClient 2025-08-18 15:53:01 +02:00
max
4df0064978 [CHANGE] Preparing library service 2025-08-18 01:56:41 +02:00
max
4dc3ffda36 [CHANGE] Moved to appsettings settings 2025-08-18 01:08:11 +02:00
max
f784000393 [CHANGE] Reworked entities and contexts 2025-08-18 00:46:40 +02:00
max
a62eeb727a [CHANGE] Remove build warning 2025-08-17 19:04:07 +02:00
max
b6453d8bf6 [CHANGE] Updated string maxsize on entities. Setup lib dbcontext 2025-08-17 18:54:20 +02:00
max
7f7e137a92 [CHANGE] Updated entity 2025-08-17 02:50:56 +02:00
max
f9aaf4267e [ADD] New entities for library db 2025-08-16 16:46:56 +02:00
max
3c3f2db4e7 [CHANGE] Preparing database 2025-08-11 00:44:52 +02:00
max
9edd0690cf [REFACTOR] Name change projects and solution 2025-08-10 22:41:36 +02:00
max
3649d4fad4 [CHANGE] Update logging config 2025-08-04 20:15:03 +02:00
max
18077ca58c [CHANGE] Added logging 2025-08-04 19:36:12 +02:00
max
0f8530b9c0 [CHANGE] Updated layouts && configured rendermode 2025-08-04 17:53:02 +02:00
max
9489742a95 [ADD] Added DotBased to solution & added nuget config 2025-08-04 17:04:57 +02:00
max
3748dd7d58 [ADD] Miner library 2025-08-02 14:16:28 +02:00
max
c7402d8bc4 [ADD] MudBlazer package added 2025-08-02 13:47:35 +02:00
147 changed files with 5658 additions and 485 deletions

21
.gitignore vendored
View File

@@ -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,15 +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
[Ll]ibrary/
[Cc]ache/

View File

@@ -1,20 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"/>
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="ImportUI.styles.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<HeadOutlet/>
</head>
<body>
<Routes/>
<script src="_framework/blazor.web.js"></script>
</body>
</html>

View File

@@ -1,23 +0,0 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu/>
</div>
<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

View File

@@ -1,96 +0,0 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}

View File

@@ -1,29 +0,0 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">ImportUI</a>
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler"/>
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>
</nav>
</div>

View File

@@ -1,105 +0,0 @@
.navbar-toggler {
appearance: none;
cursor: pointer;
width: 3.5rem;
height: 2.5rem;
color: white;
position: absolute;
top: 0.5rem;
right: 1rem;
border: 1px solid rgba(255, 255, 255, 0.1);
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, 0.5);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.bi {
display: inline-block;
position: relative;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
top: -1px;
background-size: cover;
}
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep .nav-link {
color: #d7d7d7;
background: none;
border: none;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
width: 100%;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}
.nav-item ::deep .nav-link:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-scrollable {
display: none;
}
.navbar-toggler:checked ~ .nav-scrollable {
display: block;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
}
}

View File

@@ -1,20 +0,0 @@
@page "/counter"
@rendermode InteractiveServer
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}

View File

@@ -1,7 +0,0 @@
@page "/"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.

View File

@@ -1,67 +0,0 @@
@page "/weather"
@attribute [StreamRendering]
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</p>
@if (forecasts == null)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@@ -1,51 +0,0 @@
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
a, .btn-link {
color: #006bb7;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
.content {
padding-top: 1.1rem;
}
h1:focus {
outline: none;
}
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
.invalid {
outline: 1px solid #e50000;
}
.validation-message {
color: #e50000;
}
.blazor-error-boundary {
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}
.blazor-error-boundary::after {
content: "An error has occurred."
}
.darker-border-checkbox.form-check-input {
border-color: #929292;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>YouTube Manager server</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<link rel="stylesheet" href="app.css"/>
<link href="Manager.App.styles.css" rel="stylesheet" />
<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="_content/MudBlazor/MudBlazor.min.css?v=@Metadata.Version" rel="stylesheet"/>
</head>
<body>
<Routes @rendermode="InteractiveServer"/>
<script src="_framework/blazor.web.js"></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>
</html>

View File

@@ -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>

View File

@@ -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);
}
}

View 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>

View 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;
}
}

View File

@@ -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>

View File

@@ -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}");
}
}

View File

@@ -0,0 +1,23 @@
<MudOverlay Absolute="Absolute" DarkBackground LockScroll @bind-Visible="Visible" ZIndex="ZIndex">
<MudStack AlignItems="AlignItems.Center">
<MudProgressCircular Indeterminate/>
<MudText>@Message</MudText>
@if (CancellationTokenSource != null)
{
<MudButton OnClick="() => CancellationTokenSource.Cancel()" Disabled="CancellationTokenSource.IsCancellationRequested">Cancel operation</MudButton>
}
</MudStack>
</MudOverlay>
@code {
[Parameter]
public bool Visible { get; set; }
[Parameter]
public string Message { get; set; } = "Loading...";
[Parameter]
public bool Absolute { get; set; }
[Parameter]
public int ZIndex { get; set; } = 9999;
[Parameter]
public CancellationTokenSource? CancellationTokenSource { get; set; }
}

View 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)&nbsp;
<span class="log-severity @GetLogClass(serviceEvent)">@serviceEvent.Severity</span>&nbsp;[<span style="color: #1565c0">@serviceEvent.Source</span>]&nbsp;
<span style="color: snow">@serviceEvent.Message</span>
</div>
</Virtualize>
</div>
</MudPaper>

View 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; }
}
}

View File

@@ -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;
}

View File

@@ -0,0 +1,219 @@
@using Manager.App.Services.System
@inject ISnackbar SnackbarService
@inject CacheService Cache
<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>
<TitleContent>
<MudText Typo="Typo.h6">Add new account</MudText>
</TitleContent>
<DialogContent>
@switch (_steps)
{
case AccountImportSteps.Authenticate:
<MudStack Spacing="2">
<MudPaper Elevation="0" Outlined Class="pa-2">
<MudTextField @bind-Value="@DefaultUserAgent" Required Label="User agent"
HelperText="Use an WEB user agent."/>
</MudPaper>
<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>
<MudDataGrid Items="ImportCookies" Dense Elevation="0" Outlined Style="width: 50%;">
<ToolBarContent>
<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>
break;
case AccountImportSteps.Validate:
<MudStack Spacing="3">
<MudPaper Elevation="0">
@if (banner != null)
{
<MudImage Src="@Cache.CreateCacheUrl(banner.Url)" Height="250" Style="width: 100%;"/>
}
else
{
<div Class="account-banner" Style="height: 250px; width: 100%;"></div>
}
<MudStack Row Spacing="3" Class="px-4">
@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>
<td>User agent:</td>
<td>@client?.UserAgent</td>
</tr>
<tr>
<td>InnerTube client:</td>
<td>@clientState?.InnerTubeClient</td>
</tr>
<tr>
<td>InnerTube client version:</td>
<td>@clientState?.InnerTubeClientVersion</td>
</tr>
<tr>
<td>InnerTube API key:</td>
<td>@clientState?.InnertubeApiKey</td>
</tr>
<tr>
<td>Language:</td>
<td>@clientState?.InnerTubeContext?.InnerTubeClient?.HLanguage</td>
</tr>
</tbody>
</MudSimpleTable>
</MudStack>
break;
}
</DialogContent>
<DialogActions>
<MudStack Spacing="2" Row>
<MudButton Color="Color.Error" OnClick="() => MudDialog?.Cancel()" Variant="Variant.Outlined">Cancel
</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>
</DialogActions>
</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>

View File

@@ -0,0 +1,161 @@
using System.Net;
using System.Net.Mime;
using System.Text;
using Manager.App.Models.Library;
using Manager.YouTube;
using Manager.YouTube.Constants;
using Manager.YouTube.Parsers;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using MudBlazor;
namespace Manager.App.Components.Dialogs
{
public partial class AccountDialog : ComponentBase
{
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
[Parameter] public string DefaultUserAgent { get; set; } = "";
private ClientChannel? ClientChannel { get; set; }
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 AccountImportSteps _steps = AccountImportSteps.Authenticate;
private string _cookieText = "";
private bool CanSave()
{
return ClientChannel?.YouTubeClient?.State?.LoggedIn == true;
}
private bool CanContinue()
{
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 UploadFiles(IBrowserFile? file)
{
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;
}
try
{
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 ClearPreparedClient()
{
ClientChannel?.YouTubeClient?.Dispose();
ClientChannel = null;
ImportCookies.Clear();
_steps = AccountImportSteps.Authenticate;
StateHasChanged();
}
private async Task BuildClient()
{
_isLoading = true;
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;
await InvokeAsync(StateHasChanged);
}
}
public enum AccountImportSteps
{
Authenticate,
Validate
}
}

View File

@@ -0,0 +1,22 @@
@inherits LayoutComponentBase
@layout BaseLayout
<CascadingValue Value="this">
<MudAppBar Color="Color.Primary">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@(_ => ToggleDrawerOpen())" />
<MudText Typo="Typo.h6">@AppText</MudText>
<MudSpacer/>
<MudTooltip Text="Gitea source">
<MudIconButton Icon="@Icons.Material.Filled.Code" Color="Color.Info" Href="https://git.netzbyte.com/max/Yt-Import" Target="_blank"/>
</MudTooltip>
@if (BaseLayout != null)
{
<MudTooltip Text="@(BaseLayout.DarkTheme ? "Toggle to light mode" : "Toggle to dark mode")">
<MudToggleIconButton @bind-Toggled="@BaseLayout.DarkTheme" Color="Color.Dark" ToggledColor="Color.Warning" Icon="@Icons.Material.Filled.DarkMode" ToggledIcon="@Icons.Material.Filled.LightMode"/>
</MudTooltip>
}
</MudAppBar>
<div style="display: flex; flex-direction: column; flex: 1; padding: 20px; min-height: 0;">
@Body
</div>
</CascadingValue>

View File

@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Components;
namespace Manager.App.Components.Layout;
public partial class ApplicationLayout
{
[CascadingParameter]
public BaseLayout? BaseLayout { get; set; }
public bool DrawerOpen { get; set; } = true;
public string AppText { get; set; } = "YouTube Manager";
private void ToggleDrawerOpen()
{
DrawerOpen = !DrawerOpen;
}
}

View File

@@ -0,0 +1,20 @@
@inherits LayoutComponentBase
<MudThemeProvider @ref="@_themeProvider" IsDarkModeChanged="@OnDarkThemeChanged" Theme="@_mudTheme" IsDarkMode="@DarkTheme"/>
<MudPopoverProvider @rendermode="InteractiveServer"/>
<MudDialogProvider @rendermode="InteractiveServer"/>
<MudSnackbarProvider @rendermode="InteractiveServer"/>
<CascadingValue Value="this">
<MudLayout>
<MudMainContent Style="display: flex; flex-direction: column; height: 100vh;">
@Body
</MudMainContent>
</MudLayout>
</CascadingValue>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

View File

@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace Manager.App.Components.Layout;
public partial class BaseLayout
{
private readonly MudTheme _mudTheme = new();
private MudThemeProvider? _themeProvider;
private bool _isDarkTheme = true;
public EventCallback<bool> OnDarkThemeChanged;
public bool DarkTheme
{
get => _isDarkTheme;
set
{
_isDarkTheme = value;
ThemeChanged();
}
}
private void ThemeChanged()
{
StateHasChanged();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _themeProvider != null)
{
DarkTheme = await _themeProvider.GetSystemDarkModeAsync();
}
}
}

View File

@@ -0,0 +1,18 @@
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}

View File

@@ -0,0 +1,16 @@
@inherits LayoutComponentBase
@layout ApplicationLayout
@if (ApplicationLayout != null)
{
<MudDrawer @bind-Open="@ApplicationLayout.DrawerOpen" ClipMode="DrawerClipMode.Always">
<NavMenu/>
<MudSpacer/>
</MudDrawer>
}
else
{
<MudAlert Severity="Severity.Error" Variant="Variant.Outlined">Error getting cascading parameter 'ApplicationLayout'!</MudAlert>
}
@Body

View File

@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Components;
namespace Manager.App.Components.Layout;
public partial class MainLayout
{
[CascadingParameter]
public ApplicationLayout? ApplicationLayout { get; set; }
}

View File

@@ -0,0 +1,10 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}

View File

@@ -0,0 +1,15 @@

<MudNavMenu>
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home" Match="NavLinkMatch.All">Home</MudNavLink>
<MudNavGroup Title="Library" Expanded Icon="@Icons.Custom.Brands.YouTube" IconColor="Color.Error">
<MudNavLink Href="/Search" Icon="@Icons.Material.Filled.Search" Match="NavLinkMatch.All" Disabled>Search</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>

View 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>

View 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);
}
}
}
}

View File

@@ -0,0 +1,38 @@
@page "/Channels"
@using Manager.App.Controllers
@inject ILibraryService LibraryService
<PageTitle>Channels</PageTitle>
<MudStack Spacing="2">
<MudTable @ref="@_table" ServerData="ServerReload">
<ToolBarContent>
<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>
<HeaderContent>
<MudTh></MudTh>
<MudTh>Name</MudTh>
<MudTh>Handle</MudTh>
<MudTh>Channel id</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>
</RowTemplate>
<NoRecordsContent>
<MudText>No channels found</MudText>
</NoRecordsContent>
<LoadingContent>
<MudText>Loading...</MudText>
</LoadingContent>
<PagerContent>
<MudTablePager/>
</PagerContent>
</MudTable>
</MudStack>

View File

@@ -0,0 +1,23 @@
using Manager.App.Models.Library;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace Manager.App.Components.Pages;
public partial class Channels : ComponentBase
{
private MudTable<ChannelListView>? _table;
private string _search = "";
private async Task<TableData<ChannelListView>> ServerReload(TableState state, CancellationToken token)
{
var results = await LibraryService.GetChannelsAsync(_search, state.Page * state.PageSize, state.PageSize, token);
return !results.IsSuccess ? new TableData<ChannelListView>() : new TableData<ChannelListView> { Items = results.Value, TotalItems = results.Total };
}
private void OnSearch(string text)
{
_search = text;
_table?.ReloadServerData();
}
}

View 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>

View File

@@ -0,0 +1,8 @@
using Microsoft.AspNetCore.Components;
namespace Manager.App.Components.Pages;
public partial class Development : ComponentBase
{
}

View File

@@ -0,0 +1,3 @@
@page "/"
<PageTitle>Home</PageTitle>

View File

@@ -0,0 +1,52 @@
@page "/Library"
@inject ISnackbar Snackbar
@inject ILibraryService LibraryService
<PageTitle>Library information</PageTitle>
<ForcedLoadingOverlay Visible="_loading" CancellationTokenSource="@_cancellationTokenSource"/>
@if (_libraryInformation != null)
{
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
<tbody>
<tr>
<td>Library path:</td>
<td>@_libraryInformation.LibraryPath</td>
</tr>
<tr>
<td>Created at (UTC):</td>
<td>@_libraryInformation.CreatedAtUtc</td>
</tr>
<tr>
<td>Last modified (UTC):</td>
<td>@_libraryInformation.LastModifiedUtc</td>
</tr>
<tr>
<td>Library size:</td>
<td>@($"{Suffix.BytesToSizeSuffix(_libraryInformation.TotalSizeBytes)} ({_libraryInformation.TotalSizeBytes} bytes)")</td>
</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>
<td>Total media:</td>
<td>@_libraryInformation.TotalMedia</td>
</tr>
<tr>
<td>Total channels:</td>
<td>@_libraryInformation.TotalChannels</td>
</tr>
</tbody>
</MudSimpleTable>
}

View File

@@ -0,0 +1,37 @@
using Manager.App.Models.Library;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace Manager.App.Components.Pages;
public partial class Library : ComponentBase
{
private LibraryInformation? _libraryInformation;
private bool _loading;
private CancellationTokenSource _cancellationTokenSource = new();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource = new CancellationTokenSource();
}
_loading = true;
await InvokeAsync(StateHasChanged);
var result = await LibraryService.GetLibraryInfoAsync(_cancellationTokenSource.Token);
if (result is { IsSuccess: true, Value: not null })
{
_libraryInformation = result.Value;
}
else
{
Snackbar.Add($"Failed to get library info. Error: {result.Error?.Description}", Severity.Error);
}
_loading = false;
await InvokeAsync(StateHasChanged);
}
}
}

View 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;"/>

View 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();
}
}

View 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>
}

View 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;
}
}

View File

@@ -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 />

View File

@@ -1,10 +1,14 @@
@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
@using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop @using Microsoft.JSInterop
@using ImportUI @using DotBased.Utilities
@using ImportUI.Components @using Manager.App
@using Manager.App.Components
@using Manager.App.Components.Application
@using Manager.App.Services
@* MudBlazor *@
@using MudBlazor

View 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";
}
}

View 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);
}
}

View 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);
}
}

View File

@@ -0,0 +1,105 @@
using DotBased.Logging;
using DotBased.Logging.MEL;
using DotBased.Logging.Serilog;
using Manager.App.Models.Settings;
using Manager.App.Services;
using Manager.App.Services.System;
using Manager.Data.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Serilog;
namespace Manager.App;
public static class DependencyInjection
{
public static void ManagerSetup(this WebApplicationBuilder builder)
{
builder.Services.AddDbContextFactory<LibraryDbContext>((serviceProvider, options) =>
{
var libSettings = serviceProvider.GetRequiredService<IOptions<LibrarySettings>>().Value;
var logger = serviceProvider.GetRequiredService<ILogger<LibraryDbContext>>();
var dbPath = Path.Combine(libSettings.Path, "Library.db");
logger.LogInformation("Setting library database to: {DbPath}", dbPath);
options.UseSqlite($"Data Source={dbPath}");
});
builder.RegisterExtendedBackgroundServices();
builder.Services.AddScoped<ILibraryService, LibraryService>();
}
public static void SetupSettings(this WebApplicationBuilder builder)
{
builder.Services.AddOptions<LibrarySettings>()
.Bind(builder.Configuration.GetSection("Library"))
.ValidateDataAnnotations()
.PostConfigure(settings =>
{
settings.Path = settings.Path.Replace("{workdir}", Environment.CurrentDirectory, StringComparison.InvariantCultureIgnoreCase);
})
.ValidateOnStart();
builder.Services.AddOptions<DownloadSettings>()
.Bind(builder.Configuration.GetSection("Downloads"))
.ValidateDataAnnotations()
.ValidateOnStart();
}
public static void SetupLogging(this WebApplicationBuilder builder)
{
var isDevelopment = builder.Environment.IsDevelopment();
var logSeverity = isDevelopment ? LogSeverity.Debug : LogSeverity.Info;
var severityFilters = new Dictionary<string, LogSeverity>();
var dotBasedLogSection = builder.Configuration.GetSection("DotBased:Logging");
if (dotBasedLogSection.Exists())
{
logSeverity = dotBasedLogSection.GetValue<LogSeverity>("Severity");
severityFilters = dotBasedLogSection.GetSection("SeverityFilters").GetChildren()
.ToDictionary(
x => x.Key,
x => x.Get<LogSeverity>()
);
}
LogService.Initialize(options =>
{
options.Severity = logSeverity;
foreach (var filter in severityFilters)
{
options.AddSeverityFilter(filter.Key, filter.Value);
}
});
Log.Logger = new LoggerConfiguration().UseBasedExtension()
.MinimumLevel.Verbose()
.Enrich.WithProperty("Application", "ImportUI")
.WriteTo.Console(outputTemplate: BasedSerilog.OutputTemplate)
.WriteTo.File(path: Path.Combine("Logs", $"{(isDevelopment ? "Debug" : "Release")}", "log_.log"), rollingInterval: RollingInterval.Day, outputTemplate: BasedSerilog.OutputTemplate)
.Destructure.ToMaximumDepth(4)
.Destructure.ToMaximumStringLength(100)
.Destructure.ToMaximumCollectionCount(10).CreateLogger();
LogService.AddLogAdapter(new BasedSerilogAdapter(Log.Logger));
builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(isDevelopment ? LogLevel.Trace : LogLevel.Information);
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>();
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotBased" Version="1.0.0" />
<PackageReference Include="DotBased.Logging.MEL" Version="1.0.0" />
<PackageReference Include="DotBased.Logging.Serilog" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MudBlazor" Version="8.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css" />
<_ContentIncludedByDefault Remove="wwwroot\bootstrap\bootstrap.min.css.map" />
<_ContentIncludedByDefault Remove="wwwroot\js\console.js" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Manager.Data\Manager.Data.csproj" />
<ProjectReference Include="..\Manager.Shared\Manager.Shared.csproj" />
<ProjectReference Include="..\Manager.YouTube\Manager.YouTube.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="cache\" />
<Folder Include="Library\" />
<Folder Include="Logs\Debug\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,14 @@
namespace Manager.App.Models.Library;
public record LibraryInformation
{
public DateTime CreatedAtUtc { get; set; }
public DateTime LastModifiedUtc { get; set; }
public string LibraryPath { get; set; } = "";
public long TotalMedia { get; set; }
public long TotalChannels { get; set; }
public long TotalSizeBytes { get; set; }
public long DriveTotalSpaceBytes { get; set; }
public long DriveFreeSpaceBytes { get; set; }
public long DriveUsedSpaceBytes { get; set; }
}

View File

@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.App.Models.Settings;
public class DownloadSettings
{
[ConfigurationKeyName("MaxConcurrentDownloads")]
[Range(-1, 20, ErrorMessage = "Max concurrent downloads must be between 0 and 20. (0 for unlimited concurrent downloads)")]
public int MaxConcurrentDownloads { get; set; } = 5;
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.App.Models.Settings;
public class LibrarySettings
{
[ConfigurationKeyName("Path")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Library path is required!")]
public required string Path { get; set; }
[ConfigurationKeyName("DefaultUserAgent")]
[Required(AllowEmptyStrings = false, ErrorMessage = "An default user agent is required.")]
public required string DefaultUserAgent { get; set; }
}

View File

@@ -0,0 +1,30 @@
using DotBased.Monads;
namespace Manager.App.Models.System;
public class ListResult<TResult> : Result<List<TResult>>
{
protected ListResult(List<TResult> result, int total) : base(result)
{
Total = total;
}
protected ListResult(Exception exception) : base(exception)
{
Total = 0;
}
protected ListResult(ResultError error) : base(error)
{
Total = 0;
}
public int Total { get; set; }
public static implicit operator ListResult<TResult>(ResultError error) => new(error);
public static implicit operator ListResult<TResult>(Exception exception) => new(exception);
public static implicit operator ListResult<TResult>(List<TResult> result) => new(result, 0);
public static implicit operator ListResult<TResult>(ListResultReturn<TResult> result) => new(result.List, result.Total);
}
public record ListResultReturn<TResult>(List<TResult> List, int Total);

View 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; }
}

View File

@@ -1,4 +1,6 @@
using ImportUI.Components; using Manager.App;
using Manager.App.Components;
using MudBlazor.Services;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -6,6 +8,18 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents() builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); .AddInteractiveServerComponents();
AppContext.SetSwitch("System.Net.Http.EnableActivityPropagation", false);
builder.Services.AddControllers();
/* Manager */
builder.SetupLogging();
builder.SetupSettings();
builder.ManagerSetup();
/* MudBlazor */
builder.Services.AddMudServices();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
@@ -20,6 +34,7 @@ app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseAntiforgery(); app.UseAntiforgery();
app.MapControllers();
app.MapRazorComponents<App>() app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode(); .AddInteractiveServerRenderMode();

View 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();
}

View 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);

View File

@@ -0,0 +1,18 @@
using DotBased.Monads;
using Manager.App.Models.Library;
using Manager.App.Models.System;
using Manager.Data.Entities.LibraryContext;
using Manager.YouTube.Models.Innertube;
namespace Manager.App.Services;
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<ListResult<AccountListView>> GetAccountsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
public Task<ListResult<ChannelListView>> GetChannelsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,383 @@
using System.Net.Mime;
using DotBased.Monads;
using Manager.App.Constants;
using Manager.App.Models.Library;
using Manager.App.Models.Settings;
using Manager.App.Models.System;
using Manager.App.Services.System;
using Manager.Data.Contexts;
using Manager.Data.Entities.LibraryContext;
using Manager.YouTube.Models.Innertube;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Manager.App.Services;
public class LibraryService : ILibraryService
{
private readonly ILogger<LibraryService> _logger;
private readonly IDbContextFactory<LibraryDbContext> _dbContextFactory;
private readonly DirectoryInfo _libraryDirectory;
private readonly CacheService _cacheService;
public LibraryService(ILogger<LibraryService> logger, IOptions<LibrarySettings> librarySettings, IDbContextFactory<LibraryDbContext> contextFactory, CacheService cacheService)
{
_logger = logger;
var librarySettings1 = librarySettings.Value;
_dbContextFactory = contextFactory;
_cacheService = cacheService;
_libraryDirectory = Directory.CreateDirectory(librarySettings1.Path);
logger.LogDebug("Library directory: {LibraryWorkingDir}", _libraryDirectory.FullName);
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)
{
try
{
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
var libraryDriveInfo = GetLibraryDriveInfo(_libraryDirectory);
var libInfo = new LibraryInformation
{
LibraryPath = _libraryDirectory.FullName,
CreatedAtUtc = _libraryDirectory.CreationTimeUtc,
LastModifiedUtc = _libraryDirectory.LastWriteTimeUtc,
TotalChannels = await context.Channels.CountAsync(cancellationToken: cancellationToken),
TotalMedia = await context.Media.CountAsync(cancellationToken: cancellationToken),
TotalSizeBytes = GetDirectorySize(_libraryDirectory),
DriveTotalSpaceBytes = libraryDriveInfo.totalSpace,
DriveFreeSpaceBytes = libraryDriveInfo.freeSpace,
DriveUsedSpaceBytes = libraryDriveInfo.usedSpace
};
return libInfo;
}
catch (Exception e)
{
return HandleException(e);
}
}
public async Task<ListResult<AccountListView>> GetAccountsAsync(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 accountsQuery = context.ClientAccounts
.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)
{
return HandleException(e);
}
}
private long GetDirectorySize(DirectoryInfo dir)
{
try
{
var size = dir.EnumerateFiles("*", SearchOption.AllDirectories).Select(f => f.Length).Sum();
return size;
}
catch (Exception e)
{
_logger.LogError(e, "Error while getting directory size.");
throw;
}
}
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)
{
if (exception is OperationCanceledException)
{
return ResultError.Fail("Library service operation cancelled");
}
_logger.LogError(exception, "Service error");
return ResultError.Error(exception);
}
}

View File

@@ -0,0 +1,9 @@
namespace Manager.App.Services.System;
public class BackgroundServiceRegistry(IEnumerable<ExtendedBackgroundService> backgroundServices)
{
public List<ExtendedBackgroundService> GetServices()
{
return backgroundServices.ToList();
}
}

View 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);

View 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;
}
}

View File

@@ -0,0 +1,27 @@
{
"DotBased": {
"Logging": {
"Severity": "Debug",
"SeverityFilters":{
"Microsoft": "Info",
"Microsoft.Hosting.Lifetime": "Debug",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.Authentication": "Debug",
"MudBlazor": "Info"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft.AspNetCore": "Debug"
}
},
"Library": {
"Path": "{workdir}/Library",
"DefaultUserAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0"
},
"Downloads": {
"MaxConcurrentDownloads": 5
}
}

View File

@@ -0,0 +1,28 @@
{
"DotBased": {
"Logging": {
"Severity": "Info",
"SeverityFilters":{
"Microsoft": "Info",
"Microsoft.Hosting.Lifetime": "Info",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.Authentication": "Info",
"MudBlazor": "Info"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Library": {
"Path": "{workdir}/Library",
"DefaultUserAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0"
},
"Downloads": {
"MaxConcurrentDownloads": 5
}
}

View File

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View 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
};
};

View File

@@ -0,0 +1,3 @@
function getUserTimeZone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}

View 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);
}
}

View 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);
}
}

View 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;
}
}
}
}

View File

@@ -0,0 +1,135 @@
using Manager.Data.Entities.Audit;
using Manager.Data.Entities.LibraryContext;
using Manager.Data.Entities.LibraryContext.Join;
using Microsoft.EntityFrameworkCore;
namespace Manager.Data.Contexts;
public sealed class LibraryDbContext : DbContext
{
public LibraryDbContext(DbContextOptions<LibraryDbContext> options) : base(options)
{
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
ChangeTracker.LazyLoadingEnabled = false;
Database.EnsureCreated();
}
public DbSet<EntityAudit> Histories { get; set; }
public DbSet<CaptionEntity> Captions { get; set; }
public DbSet<ChannelEntity> Channels { get; set; }
public DbSet<ClientAccountEntity> ClientAccounts { get; set; }
public DbSet<HttpCookieEntity> HttpCookies { get; set; }
public DbSet<MediaEntity> Media { get; set; }
public DbSet<MediaFormatEntity> MediaFormats { 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)
{
modelBuilder.Entity<EntityAudit>(ea =>
{
ea.HasKey(a => a.Id);
ea.ToTable("audits");
});
modelBuilder.Entity<CaptionEntity>(ce =>
{
ce.ToTable("captions");
ce.HasKey(x => new { x.MediaId, x.LanguageCode });
});
modelBuilder.Entity<ChannelEntity>(channel =>
{
channel.ToTable("channels");
channel.HasKey(x => x.Id);
channel.HasMany(x => x.Media)
.WithOne()
.HasForeignKey(x => x.ChannelId);
channel.HasMany(x => x.Playlists)
.WithOne()
.HasForeignKey(x => x.ChannelId);
channel.HasOne(x => x.ClientAccount)
.WithOne(x => x.Channel)
.HasForeignKey<ClientAccountEntity>(e => e.Id)
.IsRequired(false);
channel.HasMany(x => x.Files)
.WithOne()
.HasForeignKey(f => f.ForeignKey);
});
modelBuilder.Entity<ClientAccountEntity>(cae =>
{
cae.ToTable("client_accounts");
cae.HasKey(x => x.Id);
cae.HasMany(x => x.HttpCookies)
.WithOne()
.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 =>
{
httpce.ToTable("http_cookies");
httpce.HasKey(x => x.Name);
});
modelBuilder.Entity<MediaEntity>(me =>
{
me.ToTable("media");
me.HasKey(x => x.Id);
me.HasMany(x => x.Formats)
.WithOne()
.HasForeignKey(mf => mf.MediaId);
me.HasMany(x => x.Captions)
.WithOne()
.HasForeignKey(ce => ce.MediaId);
});
modelBuilder.Entity<MediaFormatEntity>(mfe =>
{
mfe.ToTable("media_formats");
mfe.HasKey(x => new { x.MediaId, x.Itag });
});
modelBuilder.Entity<PlaylistEntity>(ple =>
{
ple.ToTable("playlists");
ple.HasKey(x => x.Id);
});
modelBuilder.Entity<FileEntity>(file =>
{
file.ToTable("files");
file.HasKey(x => x.Id);
});
/* Join tables */
modelBuilder.Entity<PlaylistMedia>(pmj =>
{
pmj.ToTable("join_playlist_media");
pmj.HasKey(x => new { x.PlaylistId, x.MediaId });
pmj.HasOne<PlaylistEntity>()
.WithMany(pe => pe.PlaylistMedias)
.HasForeignKey(fk => fk.PlaylistId);
pmj.HasOne<MediaEntity>()
.WithMany(me => me.PlaylistMedias)
.HasForeignKey(fk => fk.MediaId);
});
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -0,0 +1,11 @@
namespace Manager.Data;
public static class DataConstants
{
public static class DbContext
{
public const int DefaultDbStringSize = 500;
public const int DefaultDbDescriptionStringSize = 5500;
public const int DefaultDbUrlSize = 10000;
}
}

View 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
{
}

View 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; }
}

View 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
{
}

View File

@@ -0,0 +1,10 @@
using Manager.Data.Entities.Audit;
namespace Manager.Data.Entities;
[NoAudit]
public abstract class DateTimeBase
{
public DateTime CreatedAtUtc { get; set; }
public DateTime LastModifiedUtc { get; set; }
}

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
namespace Manager.Data.Entities.LibraryContext;
[Auditable]
public class CaptionEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? LanguageCode { get; set; }
}

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
namespace Manager.Data.Entities.LibraryContext;
[Auditable]
public class ChannelEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Handle { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
public List<MediaEntity> Media { get; set; } = [];
public List<PlaylistEntity> Playlists { get; set; } = [];
public ClientAccountEntity? ClientAccount { get; set; }
public List<FileEntity>? Files { get; set; }
}

View File

@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
namespace Manager.Data.Entities.LibraryContext;
[Auditable]
public class ClientAccountEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? UserAgent { get; set; }
public ChannelEntity? Channel { get; set; }
public List<FileEntity>? Files { get; set; }
}

View 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; }
}

View File

@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
namespace Manager.Data.Entities.LibraryContext;
[NoAudit]
public class HttpCookieEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ClientId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Value { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Domain { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Path { get; set; }
public DateTime? ExpiresUtc { get; set; }
public bool Secure { get; set; }
public bool HttpOnly { get; set; }
}

View File

@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Entities.LibraryContext.Join;
public class PlaylistMedia : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string PlaylistId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
}

View File

@@ -0,0 +1,44 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
using Manager.Data.Entities.LibraryContext.Join;
namespace Manager.Data.Entities.LibraryContext;
[Auditable]
public class MediaEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Title { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
public DateTime UploadDateUtc { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ChannelId { get; set; }
public List<MediaFormatEntity> Formats { get; set; } = [];
public List<CaptionEntity> Captions { get; set; } = [];
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
public MediaExternalState ExternalState { get; set; } = MediaExternalState.Online;
public bool IsDownloaded { get; set; }
public MediaState State { get; set; } = MediaState.Indexed;
}
public enum MediaExternalState
{
Online,
Offline,
Limited,
Removed
}
[Flags]
public enum MediaState
{
None = 0,
Indexed = 1 << 0,
Downloading = 1 << 1,
Downloaded = 1 << 2,
Remove = 1 << 3,
Failed = 1 << 4,
}

View File

@@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Entities.LibraryContext;
public class MediaFormatEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
public required int Itag { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Quality { get; set; }
public bool IsAdaptive { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? MimeType { get; set; }
public long Bitrate { get; set; }
public long AverageBitrate { get; set; }
public long LastModifiedUnixEpoch { get; set; }
public long ContentLengthBytes { get; set; }
public long ApproxDurationMs { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public double? Framerate { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? QualityLabel { get; set; }
public int? AudioChannels { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? AudioSampleRate { get; set; }
public double? LoudnessDb { get; set; }
}

View File

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Entities.Audit;
using Manager.Data.Entities.LibraryContext.Join;
namespace Manager.Data.Entities.LibraryContext;
[Auditable]
public class PlaylistEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ChannelId { get; set; }
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
}

View File

@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Manager.Shared\Manager.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.19" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
<Folder Include="Models\" />
<Folder Include="Services\" />
</ItemGroup>
</Project>

View File

@@ -1,9 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="DotBased" Version="1.0.0" />
</ItemGroup>
</Project> </Project>

View 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"
};
}

Some files were not shown because too many files have changed in this diff Show More