enable plex for movies (#72)
* re-enable plex, temp force secure connections * add plex fanart * synchronize genre from plex * fix plex library sync * improve stream error handling * synchronize plex artwork * use switch instead of button * prioritize local connections for insecure plex sources * sign out of plex * better plex sign in/out * code cleanup * fix plex movie aspect ratio and scan type
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
@using ErsatzTV.Application.Plex
|
||||
@using ErsatzTV.Application.Plex.Commands
|
||||
@using ErsatzTV.Application.Plex.Queries
|
||||
@implements IDisposable
|
||||
@inject IDialogService Dialog
|
||||
@inject IMediator Mediator
|
||||
@inject IEntityLocker Locker
|
||||
@inject ISnackbar Snackbar
|
||||
@inject ILogger<PlexMediaSources> Logger
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraLarge">
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
||||
<MudTable Hover="true" Dense="true" Items="_mediaSources">
|
||||
<ToolBarContent>
|
||||
<MudText Typo="Typo.h6">Plex Media Sources</MudText>
|
||||
@@ -42,9 +44,26 @@
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
@* <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(_ => AddPlexMediaSource())" Class="mt-4"> *@
|
||||
@* Add Plex Media Source *@
|
||||
@* </MudButton> *@
|
||||
@if (_mediaSources.Any())
|
||||
{
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Error"
|
||||
OnClick="@(_ => SignOutOfPlex())"
|
||||
Disabled="@Locker.IsPlexLocked()"
|
||||
Class="mt-4">
|
||||
Sign out of plex
|
||||
</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
OnClick="@(_ => AddPlexMediaSource())"
|
||||
Disabled="@Locker.IsPlexLocked()"
|
||||
Class="mt-4">
|
||||
Sign in to plex
|
||||
</MudButton>
|
||||
}
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
@@ -52,46 +71,50 @@
|
||||
|
||||
protected override async Task OnParametersSetAsync() => await LoadMediaSources();
|
||||
|
||||
protected override void OnInitialized() =>
|
||||
Locker.OnPlexChanged += PlexChanged;
|
||||
|
||||
private async Task LoadMediaSources() =>
|
||||
_mediaSources = await Mediator.Send(new GetAllPlexMediaSources());
|
||||
|
||||
// private async Task DeleteMediaSource(PlexMediaSourceViewModel mediaSource)
|
||||
// {
|
||||
// int count = await Mediator.Send(new CountMediaItemsById(mediaSource.Id));
|
||||
//
|
||||
// var parameters = new DialogParameters
|
||||
// {
|
||||
// { "EntityType", "media source" },
|
||||
// { "EntityName", mediaSource.Name },
|
||||
// { "DetailText", $"This media source contains {count} media items." },
|
||||
// { "DetailHighlight", count.ToString() }
|
||||
// };
|
||||
// var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
|
||||
//
|
||||
// IDialogReference dialog = Dialog.Show<DeleteDialog>("Delete Media Source", parameters, options);
|
||||
// DialogResult result = await dialog.Result;
|
||||
// if (!result.Cancelled)
|
||||
// {
|
||||
// await Mediator.Send(new DeleteLocalMediaSource(mediaSource.Id));
|
||||
// await LoadMediaSources();
|
||||
// }
|
||||
// }
|
||||
|
||||
// edit media source
|
||||
// - manage libraries to include in smart collections
|
||||
// - manage list of path replacements
|
||||
private async Task SignOutOfPlex()
|
||||
{
|
||||
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small };
|
||||
IDialogReference dialog = Dialog.Show<SignOutOfPlexDialog>("Sign out of Plex", options);
|
||||
DialogResult result = await dialog.Result;
|
||||
if (!result.Cancelled)
|
||||
{
|
||||
if (Locker.LockPlex())
|
||||
{
|
||||
await Mediator.Send(new SignOutOfPlex());
|
||||
await LoadMediaSources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddPlexMediaSource()
|
||||
{
|
||||
Either<BaseError, string> maybeUrl = await Mediator.Send(new StartPlexPinFlow());
|
||||
await maybeUrl.Match(
|
||||
async url => await JsRuntime.InvokeAsync<object>("open", new object[] { url, "_blank" }),
|
||||
error =>
|
||||
{
|
||||
Snackbar.Add(error.Value, Severity.Error);
|
||||
Logger.LogError("Unexpected error generating plex auth app url: {Error}", error.Value);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
if (Locker.LockPlex())
|
||||
{
|
||||
Either<BaseError, string> maybeUrl = await Mediator.Send(new StartPlexPinFlow());
|
||||
await maybeUrl.Match(
|
||||
async url => await JsRuntime.InvokeAsync<object>("open", new object[] { url, "_blank" }),
|
||||
error =>
|
||||
{
|
||||
Locker.UnlockPlex();
|
||||
Snackbar.Add(error.Value, Severity.Error);
|
||||
Logger.LogError("Unexpected error generating plex auth app url: {Error}", error.Value);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void PlexChanged(object sender, EventArgs e)
|
||||
{
|
||||
InvokeAsync(LoadMediaSources);
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose() => Locker.OnPlexChanged -= PlexChanged;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user