mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
feat: ✨ Added the ability to provide your own custom plex url
This commit is contained in:
parent
d24c390fe4
commit
6c6b7bb498
7 changed files with 95 additions and 3 deletions
|
@ -3,6 +3,8 @@ using System.Threading.Tasks;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Core.Settings.Models.External;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
|
@ -11,10 +13,13 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
{
|
||||
public class PlexAvailabilityRule : BaseSearchRule, IRules<SearchViewModel>
|
||||
{
|
||||
public PlexAvailabilityRule(IPlexContentRepository repo, ILogger<PlexAvailabilityRule> log)
|
||||
private readonly ISettingsService<PlexSettings> _plexSettings;
|
||||
|
||||
public PlexAvailabilityRule(IPlexContentRepository repo, ILogger<PlexAvailabilityRule> log, ISettingsService<PlexSettings> plexSettings)
|
||||
{
|
||||
PlexContentRepository = repo;
|
||||
Log = log;
|
||||
_plexSettings = plexSettings;
|
||||
}
|
||||
|
||||
private IPlexContentRepository PlexContentRepository { get; }
|
||||
|
@ -72,13 +77,20 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
|
||||
if (item != null)
|
||||
{
|
||||
var settings = await _plexSettings.GetSettingsAsync();
|
||||
var firstServer = settings.Servers.FirstOrDefault();
|
||||
var host = string.Empty;
|
||||
if (firstServer != null)
|
||||
{
|
||||
host = firstServer.ServerHostname;
|
||||
}
|
||||
if (useId)
|
||||
{
|
||||
obj.TheMovieDbId = obj.Id.ToString();
|
||||
useTheMovieDb = true;
|
||||
}
|
||||
obj.Available = true;
|
||||
obj.PlexUrl = item.Url;
|
||||
obj.PlexUrl = PlexHelper.BuildPlexMediaUrl(item.Url, host);
|
||||
obj.Quality = item.Quality;
|
||||
|
||||
if (obj.Type == RequestType.TvShow)
|
||||
|
|
|
@ -76,6 +76,29 @@ namespace Ombi.Helpers.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(PlexBuildUrlData))]
|
||||
public string BuildPlexMediaUrlTest(string saved, string hostname)
|
||||
{
|
||||
return PlexHelper.BuildPlexMediaUrl(saved, hostname);
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> PlexBuildUrlData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData("web/app#!/server/df5", "https://myhost.com/").Returns("https://myhost.com/web/app#!/server/df5");
|
||||
yield return new TestCaseData("web/app#!/server/df5", "").Returns("https://app.plex.tv/web/app#!/server/df5");
|
||||
yield return new TestCaseData("web/app#!/server/df5", "https://myhost.com").Returns("https://myhost.com/web/app#!/server/df5");
|
||||
yield return new TestCaseData("web/app#!/server/df5", "http://myhost.com").Returns("http://myhost.com/web/app#!/server/df5");
|
||||
yield return new TestCaseData("web/app#!/server/df5", "http://www.myhost.com").Returns("http://www.myhost.com/web/app#!/server/df5");
|
||||
yield return new TestCaseData("web/app#!/server/df5", "http://www.myhost.com:3456").Returns("http://www.myhost.com:3456/web/app#!/server/df5").SetName("PortTest");
|
||||
yield return new TestCaseData("https://app.plex.tv/web/app#!/server/df5", "http://www.myhost.com:3456").Returns("http://www.myhost.com:3456/web/app#!/server/df5");
|
||||
yield return new TestCaseData("https://app.plex.tv/web/app#!/server/df5", "https://tidusjar.com:3456").Returns("https://tidusjar.com:3456/web/app#!/server/df5");
|
||||
yield return new TestCaseData("https://app.plex.tv/web/app#!/server/df5", "").Returns("https://app.plex.tv/web/app#!/server/df5").SetName("OldUrl_BlankHost");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum ProviderIdType
|
||||
{
|
||||
Imdb,
|
||||
|
|
|
@ -107,10 +107,40 @@ namespace Ombi.Helpers
|
|||
public static string GetPlexMediaUrl(string machineId, int mediaId)
|
||||
{
|
||||
var url =
|
||||
$"https://app.plex.tv/web/app#!/server/{machineId}/details?key=%2flibrary%2Fmetadata%2F{mediaId}";
|
||||
$"web/app#!/server/{machineId}/details?key=%2flibrary%2Fmetadata%2F{mediaId}";
|
||||
return url;
|
||||
}
|
||||
|
||||
public static string BuildPlexMediaUrl(string savedUrl, string plexHost)
|
||||
{
|
||||
if (savedUrl.Contains("app.plex.tv"))
|
||||
{
|
||||
var split = savedUrl.Split("https://app.plex.tv/", StringSplitOptions.RemoveEmptyEntries);
|
||||
if (split.Length == 1)
|
||||
{
|
||||
savedUrl = split[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Attempt to parse url {savedUrl} and could not");
|
||||
}
|
||||
}
|
||||
if (!plexHost.HasValue())
|
||||
{
|
||||
plexHost = "https://app.plex.tv/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plexHost[plexHost.Length - 1] != '/')
|
||||
{
|
||||
plexHost += '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $"{plexHost}{savedUrl}";
|
||||
}
|
||||
|
||||
public static ProviderId GetProviderIdsFromMetadata(params string[] guids)
|
||||
{
|
||||
var providerIds = new ProviderId();
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Ombi.Core.Settings.Models.External
|
|||
public string MachineIdentifier { get; set; }
|
||||
|
||||
public int EpisodeBatchSize { get; set; }
|
||||
public string ServerHostname { get; set; } = "https://app.plex.tv";
|
||||
|
||||
public List<PlexSelectedLibraries> PlexSelectedLibraries { get; set; } = new List<PlexSelectedLibraries>();
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ export interface IPlexServer extends IExternalSettings {
|
|||
machineIdentifier: string;
|
||||
episodeBatchSize: number;
|
||||
plexSelectedLibraries: IPlexLibrariesSettings[];
|
||||
serverHostname: string;
|
||||
}
|
||||
|
||||
export interface IPlexLibrariesSettings {
|
||||
|
|
|
@ -68,6 +68,16 @@
|
|||
[(ngModel)]="server.machineIdentifier" value="{{server.machineIdentifier}}">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="md-form-field">
|
||||
<mat-form-field appearance="outline" floatLabel=auto>
|
||||
<mat-label>Externally Facing Hostname</mat-label>
|
||||
<input matInput placeholder="e.g. https://app.plex.tv" [(ngModel)]="server.serverHostname" value="{{server.serverHostname}}" matTooltip="This will be the external address that users will navigate to when they press the 'View On Plex' button">
|
||||
</mat-form-field>
|
||||
<small>
|
||||
<span *ngIf="server.serverHostname">Current URL: "{{server.serverHostname}}/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334"</span>
|
||||
<span *ngIf="!server.serverHostname">Current URL: "https://app.plex.tv/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334"</span>
|
||||
</small>
|
||||
</div>
|
||||
<div class="md-form-field">
|
||||
<div class="md-form-field" *ngIf="advanced">
|
||||
<mat-form-field appearance="outline" floatLabel=auto>
|
||||
|
|
|
@ -55,6 +55,8 @@ export class PlexComponent implements OnInit, OnDestroy {
|
|||
var splitServers = selectedServer.localAddresses.split(",");
|
||||
if (splitServers.length > 1) {
|
||||
server.ip = splitServers[splitServers.length - 1];
|
||||
} else {
|
||||
server.ip = selectedServer.localAddresses;
|
||||
}
|
||||
server.name = selectedServer.name;
|
||||
server.machineIdentifier = selectedServer.machineIdentifier;
|
||||
|
@ -123,6 +125,19 @@ export class PlexComponent implements OnInit, OnDestroy {
|
|||
public save() {
|
||||
const filtered = this.settings.servers.filter(x => x.name !== "");
|
||||
this.settings.servers = filtered;
|
||||
let invalid = false;
|
||||
|
||||
this.settings.servers.forEach(server => {
|
||||
if (server.serverHostname.length > 0 && !server.serverHostname.startsWith("http")) {
|
||||
invalid = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (invalid) {
|
||||
this.notificationService.error("Please ensure that your External Hostname is a full URL including the Scheme (http/https)")
|
||||
return;
|
||||
}
|
||||
|
||||
this.settingsService.savePlex(this.settings).subscribe(x => {
|
||||
if (x) {
|
||||
this.notificationService.success("Successfully saved Plex settings");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue