Skip to content

Commit

Permalink
feat(plex): ✨ Added the ability to configure the watchlist to request…
Browse files Browse the repository at this point in the history
… the whole TV show rather than latest season (#4774)
  • Loading branch information
tidusjar authored Oct 7, 2022
1 parent dc98613 commit fa65712
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
52 changes: 51 additions & 1 deletion src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ public async Task MovieRequestFromWatchList_AlreadyRequested()
[Test]
public async Task TvRequestFromWatchList_AlreadyRequested()
{

_mocker.Setup<ISettingsService<PlexSettings>, Task<PlexSettings>>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
_mocker.Setup<IPlexApi, Task<PlexWatchlistContainer>>(x => x.GetWatchlist(It.IsAny<string>(), It.IsAny<CancellationToken>())).ReturnsAsync(new PlexWatchlistContainer
{
Expand Down Expand Up @@ -540,5 +539,56 @@ public async Task MovieRequestFromWatchList_AlreadyImported()
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Never);
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
}


[Test]
public async Task TvRequestFromWatchList_RequestAllSeasons()
{

_mocker.Setup<ISettingsService<PlexSettings>, Task<PlexSettings>>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true, MonitorAll = true });
_mocker.Setup<IPlexApi, Task<PlexWatchlistContainer>>(x => x.GetWatchlist(It.IsAny<string>(), It.IsAny<CancellationToken>())).ReturnsAsync(new PlexWatchlistContainer
{
MediaContainer = new PlexWatchlist
{
Metadata = new List<Metadata>
{
new Metadata
{
type = "show",
ratingKey = "abc"
}
}
}
});
_mocker.Setup<IPlexApi, Task<PlexWatchlistMetadataContainer>>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new PlexWatchlistMetadataContainer
{
MediaContainer = new PlexWatchlistMetadata
{
Metadata = new WatchlistMetadata[]
{
new WatchlistMetadata
{
Guid = new List<PlexGuids>
{
new PlexGuids
{
Id = "tmdb://123"
}
}
}
}

}
});
_mocker.Setup<ITvRequestEngine, Task<RequestEngineResult>>(x => x.RequestTvShow(It.IsAny<TvRequestViewModelV2>()))
.ReturnsAsync(new RequestEngineResult { RequestId = 1 });
await _subject.Execute(_context.Object);
_mocker.Verify<ITvRequestEngine>(x => x.RequestTvShow(It.Is<TvRequestViewModelV2>(x => x.TheMovieDbId == 123 && x.LatestSeason == false && x.RequestAll == true)), Times.Once);
_mocker.Verify<IPlexApi>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
_mocker.Verify<ITvRequestEngine>(x => x.SetUser(It.Is<OmbiUser>(x => x.Id == "abc")), Times.Once);
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Once);
}
}
}
12 changes: 9 additions & 3 deletions src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ await _userError.Add(new PlexWatchlistUserError
switch (item.type)
{
case "show":
await ProcessShow(int.Parse(providerIds.TheMovieDb), user);
await ProcessShow(int.Parse(providerIds.TheMovieDb), user, settings.MonitorAll);
break;
case "movie":
await ProcessMovie(int.Parse(providerIds.TheMovieDb), user);
Expand Down Expand Up @@ -165,10 +165,16 @@ private async Task ProcessMovie(int theMovieDbId, OmbiUser user)
}
}

private async Task ProcessShow(int theMovieDbId, OmbiUser user)
private async Task ProcessShow(int theMovieDbId, OmbiUser user, bool requestAll)
{
_tvRequestEngine.SetUser(user);
var response = await _tvRequestEngine.RequestTvShow(new TvRequestViewModelV2 { LatestSeason = true, TheMovieDbId = theMovieDbId, Source = RequestSource.PlexWatchlist });
var requestModel = new TvRequestViewModelV2 { LatestSeason = true, TheMovieDbId = theMovieDbId, Source = RequestSource.PlexWatchlist };
if (requestAll)
{
requestModel.RequestAll = true;
requestModel.LatestSeason = false;
}
var response = await _tvRequestEngine.RequestTvShow(requestModel);
if (response.IsError)
{
if (response.ErrorCode == ErrorCode.AlreadyRequested)
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Settings/Settings/Models/External/PlexSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public sealed class PlexSettings : Ombi.Settings.Settings.Models.Settings
{
public bool Enable { get; set; }
public bool EnableWatchlistImport { get; set; }
public bool MonitorAll { get; set; }
/// <summary>
/// This is the ClientId for OAuth
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"availability-rules",
"details",
"requests",
"sonarr"
"sonarr",
"plex"
],
"rpc.enabled": true
}
1 change: 1 addition & 0 deletions src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface IPublicInfo {
export interface IPlexSettings extends ISettings {
enable: boolean;
enableWatchlistImport: boolean;
monitorAll: boolean;
servers: IPlexServer[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Component, EventEmitter, Input, Output } from "@angular/core";

@Component({
selector: "settings-plex-form-field",
styles: [`
.margin {
margin: 10px;
}
`],
template: `
<div class="row">
<div class="col-2 align-self-center">
Expand All @@ -16,7 +21,7 @@ import { Component, EventEmitter, Input, Output } from "@angular/core";
<input matInput placeholder={{placeholder}} [attr.type]="type" id="{{id}}" name="{{id}}" [ngModel]="value" (ngModelChange)="change($event)" value="{{value}}">
</mat-form-field>
<mat-slide-toggle *ngIf="type === 'checkbox'" id="{{id}}" [ngModel]="value" (ngModelChange)="change($event)" [checked]="value"></mat-slide-toggle>
<mat-slide-toggle class="margin" *ngIf="type === 'checkbox'" id="{{id}}" [ngModel]="value" (ngModelChange)="change($event)" [checked]="value"></mat-slide-toggle>
<ng-content select="[below]"></ng-content>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/Ombi/ClientApp/src/app/settings/plex/plex.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
</small>
</settings-plex-form-field>

<settings-plex-form-field [label]="'Request All'" disabled [type]="'checkbox'" [id]="'monitorAll'" [(value)]="settings.monitorAll">
<small bottom>If true then watchlist requests for TV Shows, it will request the <strong><em>whole</em></strong> season. Otherwise it will only request the latest season.
</small>
</settings-plex-form-field>


<settings-plex-form-field [label]="'Advanced Options'" [type]="'checkbox'" [id]="'advanced'" [(value)]="advanced"></settings-plex-form-field>

<hr>
Expand Down

0 comments on commit fa65712

Please sign in to comment.