mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
merge
This commit is contained in:
commit
bea8551cd3
60 changed files with 12547 additions and 482 deletions
8
src/Ombi.Helpers/JobDataKeys.cs
Normal file
8
src/Ombi.Helpers/JobDataKeys.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ombi.Helpers
|
||||
{
|
||||
public class JobDataKeys
|
||||
{
|
||||
public const string RecentlyAddedSearch = "recentlyAddedSearch";
|
||||
public const string NotificationOptions = nameof(NotificationOptions);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
|
||||
<PackageReference Include="Quartz" Version="3.0.7" />
|
||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
91
src/Ombi.Helpers/OmbiQuartz.cs
Normal file
91
src/Ombi.Helpers/OmbiQuartz.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Spi;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
public class OmbiQuartz
|
||||
{
|
||||
protected IScheduler _scheduler { get; set; }
|
||||
|
||||
public static IScheduler Scheduler => Instance._scheduler;
|
||||
|
||||
// Singleton
|
||||
protected static OmbiQuartz _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton
|
||||
/// </summary>
|
||||
public static OmbiQuartz Instance => _instance ?? (_instance = new OmbiQuartz());
|
||||
|
||||
protected OmbiQuartz()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
private async void Init()
|
||||
{
|
||||
_scheduler = await new StdSchedulerFactory().GetScheduler();
|
||||
}
|
||||
|
||||
public IScheduler UseJobFactory(IJobFactory jobFactory)
|
||||
{
|
||||
Scheduler.JobFactory = jobFactory;
|
||||
return Scheduler;
|
||||
}
|
||||
|
||||
public async Task AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null)
|
||||
where T : IJob
|
||||
{
|
||||
var jobBuilder = JobBuilder.Create<T>()
|
||||
.WithIdentity(new JobKey(name, group));
|
||||
if (jobData != null)
|
||||
{
|
||||
foreach (var o in jobData)
|
||||
{
|
||||
jobBuilder.UsingJobData(o.Key, o.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!cronExpression.HasValue())
|
||||
{
|
||||
jobBuilder.StoreDurably(true);
|
||||
}
|
||||
|
||||
var job = jobBuilder.Build();
|
||||
if (cronExpression.HasValue())
|
||||
{
|
||||
ITrigger jobTrigger = TriggerBuilder.Create()
|
||||
.WithIdentity(name + "Trigger", group)
|
||||
.WithCronSchedule(cronExpression,
|
||||
x => x.WithMisfireHandlingInstructionFireAndProceed())
|
||||
.ForJob(name, group)
|
||||
.StartNow()
|
||||
.Build();
|
||||
await Scheduler.ScheduleJob(job, jobTrigger);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Scheduler.AddJob(job, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static async Task TriggerJob(string jobName, string group)
|
||||
{
|
||||
await Scheduler.TriggerJob(new JobKey(jobName, group));
|
||||
}
|
||||
|
||||
public static async Task TriggerJob(string jobName, string group, IDictionary<string, object> data)
|
||||
{
|
||||
await Scheduler.TriggerJob(new JobKey(jobName, group), new JobDataMap(data));
|
||||
}
|
||||
|
||||
public static async Task Start()
|
||||
{
|
||||
await Scheduler.Start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,14 +33,15 @@ namespace Ombi.Helpers
|
|||
{
|
||||
public class PlexHelper
|
||||
{
|
||||
private const string ImdbMatchExpression = "tt([0-9]{1,10})";
|
||||
private const string TvDbIdMatchExpression = "//[0-9]+/([0-9]{1,3})/([0-9]{1,3})";
|
||||
private const string ImdbMatchExpression = "tt([0-9]{1,10})";
|
||||
private const string TvDbIdMatchExpression = "//[0-9]+/?([0-9]{1,3})/?([0-9]{1,3})";
|
||||
|
||||
public static ProviderId GetProviderIdFromPlexGuid(string guid)
|
||||
{
|
||||
//com.plexapp.agents.thetvdb://269586/2/8?lang=en
|
||||
//com.plexapp.agents.themoviedb://390043?lang=en
|
||||
//com.plexapp.agents.imdb://tt2543164?lang=en
|
||||
// https://github.com/tidusjar/Ombi/issues/3277
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
return new ProviderId();
|
||||
|
@ -55,7 +56,7 @@ namespace Ombi.Helpers
|
|||
{
|
||||
TheTvDb = guidSplit[1]
|
||||
};
|
||||
} else
|
||||
}
|
||||
if (guid.Contains("themoviedb", CompareOptions.IgnoreCase))
|
||||
{
|
||||
return new ProviderId
|
||||
|
@ -63,7 +64,6 @@ namespace Ombi.Helpers
|
|||
TheMovieDb = guidSplit[1]
|
||||
};
|
||||
}
|
||||
else
|
||||
if (guid.Contains("imdb", CompareOptions.IgnoreCase))
|
||||
{
|
||||
return new ProviderId
|
||||
|
@ -71,74 +71,31 @@ namespace Ombi.Helpers
|
|||
ImdbId = guidSplit[1]
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled);
|
||||
var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled);
|
||||
var imdbMatch = imdbRegex.IsMatch(guid);
|
||||
if (imdbMatch)
|
||||
{
|
||||
var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled);
|
||||
var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled);
|
||||
var imdbMatch = imdbRegex.IsMatch(guid);
|
||||
if (imdbMatch)
|
||||
return new ProviderId
|
||||
{
|
||||
return new ProviderId
|
||||
{
|
||||
ImdbId = guidSplit[1]
|
||||
};
|
||||
}
|
||||
else
|
||||
ImdbId = guidSplit[1]
|
||||
};
|
||||
}
|
||||
|
||||
// Check if it matches the TvDb pattern
|
||||
var tvdbMatch = tvdbRegex.IsMatch(guid);
|
||||
if (tvdbMatch)
|
||||
{
|
||||
return new ProviderId
|
||||
{
|
||||
// Check if it matches the TvDb pattern
|
||||
var tvdbMatch = tvdbRegex.IsMatch(guid);
|
||||
if (tvdbMatch)
|
||||
{
|
||||
return new ProviderId
|
||||
{
|
||||
TheTvDb = guidSplit[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
TheTvDb = guidSplit[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
return new ProviderId();
|
||||
}
|
||||
|
||||
public static EpisodeModelHelper GetSeasonsAndEpisodesFromPlexGuid(string guid)
|
||||
{
|
||||
var ep = new EpisodeModelHelper();
|
||||
//com.plexapp.agents.thetvdb://269586/2/8?lang=en
|
||||
//com.plexapp.agents.themoviedb://390043?lang=en
|
||||
//com.plexapp.agents.imdb://tt2543164?lang=en
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
return null;
|
||||
try
|
||||
{
|
||||
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (guidSplit.Length > 2)
|
||||
{
|
||||
if (guid.Contains("thetvdb", CompareOptions.IgnoreCase))
|
||||
{
|
||||
ep.ProviderId = new ProviderId {TheTvDb = guidSplit[1]};
|
||||
}
|
||||
if (guid.Contains("themoviedb", CompareOptions.IgnoreCase))
|
||||
{
|
||||
ep.ProviderId = new ProviderId { TheMovieDb = guidSplit[1] };
|
||||
|
||||
}
|
||||
if (guid.Contains("imdb", CompareOptions.IgnoreCase))
|
||||
{
|
||||
ep.ProviderId = new ProviderId { ImdbId = guidSplit[1] };
|
||||
|
||||
}
|
||||
ep.SeasonNumber = int.Parse(guidSplit[2]);
|
||||
ep.EpisodeNumber = int.Parse(guidSplit[3]);
|
||||
}
|
||||
return ep;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return ep;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetPlexMediaUrl(string machineId, int mediaId)
|
||||
{
|
||||
var url =
|
||||
|
@ -147,13 +104,6 @@ namespace Ombi.Helpers
|
|||
}
|
||||
}
|
||||
|
||||
public class EpisodeModelHelper
|
||||
{
|
||||
public ProviderId ProviderId { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public int EpisodeNumber { get; set; }
|
||||
}
|
||||
|
||||
public class ProviderId
|
||||
{
|
||||
public string TheTvDb { get; set; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue