mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Merge branch 'dev' of https://github.com/tidusjar/PlexRequests.Net.git
This commit is contained in:
commit
f6bf6493b2
78 changed files with 2644 additions and 599 deletions
8
.github/ISSUE_TEMPLATE.md
vendored
8
.github/ISSUE_TEMPLATE.md
vendored
|
@ -14,6 +14,14 @@ V 1.XX.XX
|
|||
|
||||
Stable/Early Access Preview/development
|
||||
|
||||
#### Media Sever:
|
||||
|
||||
Plex/Emby
|
||||
|
||||
#### Media Server Version:
|
||||
|
||||
<!-- If appropriate --->
|
||||
|
||||
#### Operating System:
|
||||
|
||||
(Place text here)
|
||||
|
|
|
@ -14,5 +14,6 @@ namespace Ombi.Api.Interfaces
|
|||
EmbyItemContainer<EmbyLibrary> ViewLibrary(string apiKey, string userId, Uri baseUri);
|
||||
EmbyInformation GetInformation(string mediaId, EmbyMediaType type, string apiKey, string userId, Uri baseUri);
|
||||
EmbyUser LogIn(string username, string password, string apiKey, Uri baseUri);
|
||||
EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl);
|
||||
}
|
||||
}
|
|
@ -11,5 +11,6 @@ namespace Ombi.Api.Interfaces
|
|||
List<RadarrMovieResponse> GetMovies(string apiKey, Uri baseUrl);
|
||||
List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl);
|
||||
SystemStatus SystemStatus(string apiKey, Uri baseUrl);
|
||||
List<SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl);
|
||||
}
|
||||
}
|
63
Ombi.Api.Models/Emby/EmbySystemInfo.cs
Normal file
63
Ombi.Api.Models/Emby/EmbySystemInfo.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: EmbySystemInfo.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
namespace Ombi.Api.Models.Emby
|
||||
{
|
||||
public class EmbySystemInfo
|
||||
{
|
||||
public string SystemUpdateLevel { get; set; }
|
||||
public string OperatingSystemDisplayName { get; set; }
|
||||
public bool SupportsRunningAsService { get; set; }
|
||||
public string MacAddress { get; set; }
|
||||
public bool HasPendingRestart { get; set; }
|
||||
public bool SupportsLibraryMonitor { get; set; }
|
||||
public object[] InProgressInstallations { get; set; }
|
||||
public int WebSocketPortNumber { get; set; }
|
||||
public object[] CompletedInstallations { get; set; }
|
||||
public bool CanSelfRestart { get; set; }
|
||||
public bool CanSelfUpdate { get; set; }
|
||||
public object[] FailedPluginAssemblies { get; set; }
|
||||
public string ProgramDataPath { get; set; }
|
||||
public string ItemsByNamePath { get; set; }
|
||||
public string CachePath { get; set; }
|
||||
public string LogPath { get; set; }
|
||||
public string InternalMetadataPath { get; set; }
|
||||
public string TranscodingTempPath { get; set; }
|
||||
public int HttpServerPortNumber { get; set; }
|
||||
public bool SupportsHttps { get; set; }
|
||||
public int HttpsPortNumber { get; set; }
|
||||
public bool HasUpdateAvailable { get; set; }
|
||||
public bool SupportsAutoRunAtStartup { get; set; }
|
||||
public string EncoderLocationType { get; set; }
|
||||
public string SystemArchitecture { get; set; }
|
||||
public string LocalAddress { get; set; }
|
||||
public string WanAddress { get; set; }
|
||||
public string ServerName { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string OperatingSystem { get; set; }
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
|
@ -71,6 +71,7 @@
|
|||
<Compile Include="Emby\EmbySeriesItem.cs" />
|
||||
<Compile Include="Emby\EmbySeriesstudioinfo.cs" />
|
||||
<Compile Include="Emby\EmbyStudio.cs" />
|
||||
<Compile Include="Emby\EmbySystemInfo.cs" />
|
||||
<Compile Include="Emby\EmbyUser.cs" />
|
||||
<Compile Include="Emby\EmbyUserdata.cs" />
|
||||
<Compile Include="Emby\EmbyMovieInformation.cs" />
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
@ -77,13 +78,6 @@ namespace Ombi.Api
|
|||
|
||||
var response = client.Execute(request);
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
Log.Error(response.ErrorException);
|
||||
var message = "Error retrieving response. Check inner details for more info.";
|
||||
throw new ApiRequestException(message, response.ErrorException);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ using NLog;
|
|||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Emby;
|
||||
using Ombi.Helpers;
|
||||
using Polly;
|
||||
using RestSharp;
|
||||
|
||||
namespace Ombi.Api
|
||||
|
@ -71,6 +72,26 @@ namespace Ombi.Api
|
|||
return obj;
|
||||
}
|
||||
|
||||
public EmbySystemInfo GetSystemInformation(string apiKey, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest
|
||||
{
|
||||
Resource = "emby/System/Info",
|
||||
Method = Method.GET
|
||||
};
|
||||
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<EmbySystemInfo>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public EmbyItemContainer<EmbyLibrary> ViewLibrary(string apiKey, string userId, Uri baseUri)
|
||||
{
|
||||
var request = new RestRequest
|
||||
|
@ -142,29 +163,71 @@ namespace Ombi.Api
|
|||
TimeSpan.FromSeconds(5)
|
||||
});
|
||||
|
||||
switch (type)
|
||||
IRestResponse response = null;
|
||||
try
|
||||
{
|
||||
case EmbyMediaType.Movie:
|
||||
return new EmbyInformation
|
||||
{
|
||||
MovieInformation = policy.Execute(() => Api.ExecuteJson<EmbyMovieInformation>(request, baseUri))
|
||||
};
|
||||
case EmbyMediaType.Series:
|
||||
return new EmbyInformation
|
||||
{
|
||||
SeriesInformation =
|
||||
policy.Execute(() => Api.ExecuteJson<EmbySeriesInformation>(request, baseUri))
|
||||
};
|
||||
case EmbyMediaType.Music:
|
||||
break;
|
||||
case EmbyMediaType.Episode:
|
||||
return new EmbyInformation
|
||||
{
|
||||
EpisodeInformation =
|
||||
policy.Execute(() => Api.ExecuteJson<EmbyEpisodeInformation>(request, baseUri))
|
||||
};
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EmbyMediaType.Movie:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
|
||||
case EmbyMediaType.Series:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
case EmbyMediaType.Music:
|
||||
break;
|
||||
case EmbyMediaType.Episode:
|
||||
response = policy.Execute(() => Api.Execute(request, baseUri));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
var info = new EmbyInformation();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EmbyMediaType.Movie:
|
||||
return new EmbyInformation
|
||||
{
|
||||
MovieInformation = JsonConvert.DeserializeObject<EmbyMovieInformation>(response.Content)
|
||||
};
|
||||
case EmbyMediaType.Series:
|
||||
return new EmbyInformation
|
||||
{
|
||||
SeriesInformation = JsonConvert.DeserializeObject<EmbySeriesInformation>(response.Content)
|
||||
};
|
||||
case EmbyMediaType.Music:
|
||||
break;
|
||||
case EmbyMediaType.Episode:
|
||||
return new EmbyInformation
|
||||
{
|
||||
EpisodeInformation = JsonConvert.DeserializeObject<EmbyEpisodeInformation>(response.Content)
|
||||
};
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Could not get the media item's information");
|
||||
Log.Error(e);
|
||||
Log.Debug("ResponseContent");
|
||||
Log.Debug(response?.Content ?? "Empty");
|
||||
Log.Debug("ResponseStatusCode");
|
||||
Log.Debug(response?.StatusCode ?? HttpStatusCode.PreconditionFailed);
|
||||
|
||||
Log.Debug("ResponseError");
|
||||
Log.Debug(response?.ErrorMessage ?? "No Error");
|
||||
Log.Debug("ResponseException");
|
||||
Log.Debug(response?.ErrorException ?? new Exception());
|
||||
|
||||
|
||||
|
||||
throw;
|
||||
}
|
||||
return new EmbyInformation();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,20 @@ namespace Ombi.Api
|
|||
|
||||
return obj;
|
||||
}
|
||||
public List<SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl)
|
||||
{
|
||||
var request = new RestRequest { Resource = "/api/rootfolder", Method = Method.GET };
|
||||
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Radarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
TimeSpan.FromSeconds (1),
|
||||
TimeSpan.FromSeconds(2)
|
||||
});
|
||||
|
||||
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrRootFolder>>(request, baseUrl));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public RadarrAddMovie AddMovie(int tmdbId, string title, int year, int qualityId, string rootPath, string apiKey, Uri baseUrl, bool searchNow = false)
|
||||
{
|
||||
|
@ -94,7 +108,6 @@ namespace Ombi.Api
|
|||
request.AddHeader("X-Api-Key", apiKey);
|
||||
request.AddJsonBody(options);
|
||||
|
||||
RadarrAddMovie result;
|
||||
try
|
||||
{
|
||||
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling AddSeries for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||
|
|
|
@ -37,6 +37,8 @@ using TMDbLib.Objects.General;
|
|||
using TMDbLib.Objects.Movies;
|
||||
using TMDbLib.Objects.Search;
|
||||
using Movie = TMDbLib.Objects.Movies.Movie;
|
||||
using TMDbLib.Objects.People;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ombi.Api
|
||||
{
|
||||
|
@ -69,6 +71,11 @@ namespace Ombi.Api
|
|||
return movies?.Results ?? new List<MovieResult>();
|
||||
}
|
||||
|
||||
private async Task<Movie> GetMovie(int id)
|
||||
{
|
||||
return await Client.GetMovie(id);
|
||||
}
|
||||
|
||||
public TmdbMovieDetails GetMovieInformationWithVideos(int tmdbId)
|
||||
{
|
||||
var request = new RestRequest { Resource = "movie/{movieId}", Method = Method.GET };
|
||||
|
@ -100,5 +107,49 @@ namespace Ombi.Api
|
|||
var movies = await Client.GetMovie(imdbId);
|
||||
return movies ?? new Movie();
|
||||
}
|
||||
|
||||
public async Task<List<Movie>> SearchPerson(string searchTerm)
|
||||
{
|
||||
return await SearchPerson(searchTerm, null);
|
||||
}
|
||||
|
||||
public async Task<List<Movie>> SearchPerson(string searchTerm, Func<int, string, string, Task<bool>> alreadyAvailable)
|
||||
{
|
||||
SearchContainer<SearchPerson> result = await Client.SearchPerson(searchTerm);
|
||||
|
||||
var people = result?.Results ?? new List<SearchPerson>();
|
||||
var person = (people.Count != 0 ? people[0] : null);
|
||||
var movies = new List<Movie>();
|
||||
var counter = 0;
|
||||
try
|
||||
{
|
||||
if (person != null)
|
||||
{
|
||||
var credits = await Client.GetPersonMovieCredits(person.Id);
|
||||
|
||||
// grab results from both cast and crew, prefer items in cast. we can handle directors like this.
|
||||
List<Movie> movieResults = (from MovieRole role in credits.Cast select new Movie() { Id = role.Id, Title = role.Title, ReleaseDate = role.ReleaseDate }).ToList();
|
||||
movieResults.AddRange((from MovieJob job in credits.Crew select new Movie() { Id = job.Id, Title = job.Title, ReleaseDate = job.ReleaseDate }).ToList());
|
||||
|
||||
//only get the first 10 movies and delay a bit between each request so we don't overload the API
|
||||
foreach (var m in movieResults)
|
||||
{
|
||||
if (counter == 10)
|
||||
break;
|
||||
if (alreadyAvailable == null || !(await alreadyAvailable(m.Id, m.Title, m.ReleaseDate.Value.Year.ToString())))
|
||||
{
|
||||
movies.Add(await GetMovie(m.Id));
|
||||
counter++;
|
||||
}
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Log(LogLevel.Error, e);
|
||||
}
|
||||
return movies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Ombi.Api.Models.Tv;
|
||||
using RestSharp;
|
||||
|
@ -90,21 +91,29 @@ namespace Ombi.Api
|
|||
};
|
||||
request.AddUrlSegment("id", theTvDbId.ToString());
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
|
||||
var obj = Api.Execute<TvMazeShow>(request, new Uri(Uri));
|
||||
|
||||
var episodes = EpisodeLookup(obj.id).ToList();
|
||||
|
||||
foreach (var e in episodes)
|
||||
try
|
||||
{
|
||||
obj.Season.Add(new TvMazeCustomSeason
|
||||
{
|
||||
SeasonNumber = e.season,
|
||||
EpisodeNumber = e.number
|
||||
});
|
||||
}
|
||||
var result = Api.Execute(request, new Uri(Uri));
|
||||
var obj = JsonConvert.DeserializeObject<TvMazeShow>(result.Content);
|
||||
|
||||
return obj;
|
||||
var episodes = EpisodeLookup(obj.id).ToList();
|
||||
|
||||
foreach (var e in episodes)
|
||||
{
|
||||
obj.Season.Add(new TvMazeCustomSeason
|
||||
{
|
||||
SeasonNumber = e.season,
|
||||
EpisodeNumber = e.number
|
||||
});
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TvMazeSeasons> GetSeasons(int id)
|
||||
|
|
54
Ombi.Common/EnvironmentInfo/OsInfo.cs
Normal file
54
Ombi.Common/EnvironmentInfo/OsInfo.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Ombi.Common.EnvironmentInfo
|
||||
{
|
||||
public class OsInfo
|
||||
{
|
||||
public static Os Os { get; }
|
||||
|
||||
public static bool IsNotWindows => !IsWindows;
|
||||
public static bool IsLinux => Os == Os.Linux;
|
||||
public static bool IsOsx => Os == Os.Osx;
|
||||
public static bool IsWindows => Os == Os.Windows;
|
||||
|
||||
static OsInfo()
|
||||
{
|
||||
var platform = Environment.OSVersion.Platform;
|
||||
|
||||
switch (platform)
|
||||
{
|
||||
case PlatformID.Win32NT:
|
||||
{
|
||||
Os = Os.Windows;
|
||||
break;
|
||||
}
|
||||
case PlatformID.MacOSX:
|
||||
case PlatformID.Unix:
|
||||
{
|
||||
// Sometimes Mac OS reports itself as Unix
|
||||
if (Directory.Exists("/System/Library/CoreServices/") &&
|
||||
(File.Exists("/System/Library/CoreServices/SystemVersion.plist") ||
|
||||
File.Exists("/System/Library/CoreServices/ServerVersion.plist"))
|
||||
)
|
||||
{
|
||||
Os = Os.Osx;
|
||||
}
|
||||
else
|
||||
{
|
||||
Os = Os.Linux;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Os
|
||||
{
|
||||
Windows,
|
||||
Linux,
|
||||
Osx
|
||||
}
|
||||
}
|
42
Ombi.Common/EnvironmentInfo/PlatformInfo.cs
Normal file
42
Ombi.Common/EnvironmentInfo/PlatformInfo.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
|
||||
namespace Ombi.Common.EnvironmentInfo
|
||||
{
|
||||
public enum PlatformType
|
||||
{
|
||||
DotNet = 0,
|
||||
Mono = 1
|
||||
}
|
||||
|
||||
public interface IPlatformInfo
|
||||
{
|
||||
Version Version { get; }
|
||||
}
|
||||
|
||||
public abstract class PlatformInfo : IPlatformInfo
|
||||
{
|
||||
static PlatformInfo()
|
||||
{
|
||||
Platform = Type.GetType("Mono.Runtime") != null ? PlatformType.Mono : PlatformType.DotNet;
|
||||
}
|
||||
|
||||
public static PlatformType Platform { get; }
|
||||
public static bool IsMono => Platform == PlatformType.Mono;
|
||||
public static bool IsDotNet => Platform == PlatformType.DotNet;
|
||||
|
||||
public static string PlatformName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDotNet)
|
||||
{
|
||||
return ".NET";
|
||||
}
|
||||
|
||||
return "Mono";
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Version Version { get; }
|
||||
}
|
||||
}
|
61
Ombi.Common/Ombi.Common.csproj
Normal file
61
Ombi.Common/Ombi.Common.csproj
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BFD45569-90CF-47CA-B575-C7B0FF97F67B}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Ombi.Common</RootNamespace>
|
||||
<AssemblyName>Ombi.Common</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EnvironmentInfo\OsInfo.cs" />
|
||||
<Compile Include="EnvironmentInfo\PlatformInfo.cs" />
|
||||
<Compile Include="Processes\ProcessInfo.cs" />
|
||||
<Compile Include="Processes\ProcessOutput.cs" />
|
||||
<Compile Include="Processes\ProcessProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
20
Ombi.Common/Processes/ProcessInfo.cs
Normal file
20
Ombi.Common/Processes/ProcessInfo.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Common.Processes
|
||||
{
|
||||
public class ProcessInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string StartPath { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}:{1} [{2}]", Id, Name ?? "Unknown", StartPath ?? "Unknown");
|
||||
}
|
||||
}
|
||||
}
|
59
Ombi.Common/Processes/ProcessOutput.cs
Normal file
59
Ombi.Common/Processes/ProcessOutput.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ombi.Common.Processes
|
||||
{
|
||||
public class ProcessOutput
|
||||
{
|
||||
public int ExitCode { get; set; }
|
||||
public List<ProcessOutputLine> Lines { get; set; }
|
||||
|
||||
public ProcessOutput()
|
||||
{
|
||||
Lines = new List<ProcessOutputLine>();
|
||||
}
|
||||
|
||||
public List<ProcessOutputLine> Standard
|
||||
{
|
||||
get
|
||||
{
|
||||
return Lines.Where(c => c.Level == ProcessOutputLevel.Standard).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ProcessOutputLine> Error
|
||||
{
|
||||
get
|
||||
{
|
||||
return Lines.Where(c => c.Level == ProcessOutputLevel.Error).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessOutputLine
|
||||
{
|
||||
public ProcessOutputLevel Level { get; set; }
|
||||
public string Content { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
|
||||
public ProcessOutputLine(ProcessOutputLevel level, string content)
|
||||
{
|
||||
Level = level;
|
||||
Content = content;
|
||||
Time = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0} - {1} - {2}", Time, Level, Content);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProcessOutputLevel
|
||||
{
|
||||
Standard = 0,
|
||||
Error = 1
|
||||
}
|
||||
}
|
343
Ombi.Common/Processes/ProcessProvider.cs
Normal file
343
Ombi.Common/Processes/ProcessProvider.cs
Normal file
|
@ -0,0 +1,343 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Ombi.Common.EnvironmentInfo;
|
||||
|
||||
namespace Ombi.Common.Processes
|
||||
{
|
||||
public interface IProcessProvider
|
||||
{
|
||||
int GetCurrentProcessId();
|
||||
ProcessInfo GetCurrentProcess();
|
||||
ProcessInfo GetProcessById(int id);
|
||||
List<ProcessInfo> FindProcessByName(string name);
|
||||
void OpenDefaultBrowser(string url);
|
||||
void WaitForExit(System.Diagnostics.Process process);
|
||||
void SetPriority(int processId, ProcessPriorityClass priority);
|
||||
void KillAll(string processName);
|
||||
void Kill(int processId);
|
||||
bool Exists(int processId);
|
||||
bool Exists(string processName);
|
||||
ProcessPriorityClass GetCurrentProcessPriority();
|
||||
System.Diagnostics.Process Start(string path, string args = null, StringDictionary environmentVariables = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null);
|
||||
System.Diagnostics.Process SpawnNewProcess(string path, string args = null, StringDictionary environmentVariables = null);
|
||||
ProcessOutput StartAndCapture(string path, string args = null, StringDictionary environmentVariables = null);
|
||||
}
|
||||
|
||||
public class ProcessProvider : IProcessProvider
|
||||
{
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public const string OmbiProcessName = "Ombi";
|
||||
|
||||
//public ProcessProvider(Logger logger)
|
||||
//{
|
||||
// _logger = logger;
|
||||
//}
|
||||
|
||||
public int GetCurrentProcessId()
|
||||
{
|
||||
return Process.GetCurrentProcess().Id;
|
||||
}
|
||||
|
||||
public ProcessInfo GetCurrentProcess()
|
||||
{
|
||||
return ConvertToProcessInfo(Process.GetCurrentProcess());
|
||||
}
|
||||
|
||||
public bool Exists(int processId)
|
||||
{
|
||||
return GetProcessById(processId) != null;
|
||||
}
|
||||
|
||||
public bool Exists(string processName)
|
||||
{
|
||||
return GetProcessesByName(processName).Any();
|
||||
}
|
||||
|
||||
public ProcessPriorityClass GetCurrentProcessPriority()
|
||||
{
|
||||
return Process.GetCurrentProcess().PriorityClass;
|
||||
}
|
||||
|
||||
public ProcessInfo GetProcessById(int id)
|
||||
{
|
||||
_logger.Debug("Finding process with Id:{0}", id);
|
||||
|
||||
var processInfo = ConvertToProcessInfo(Process.GetProcesses().FirstOrDefault(p => p.Id == id));
|
||||
|
||||
if (processInfo == null)
|
||||
{
|
||||
_logger.Warn("Unable to find process with ID {0}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Found process {0}", processInfo.ToString());
|
||||
}
|
||||
|
||||
return processInfo;
|
||||
}
|
||||
|
||||
public List<ProcessInfo> FindProcessByName(string name)
|
||||
{
|
||||
return GetProcessesByName(name).Select(ConvertToProcessInfo).Where(c => c != null).ToList();
|
||||
}
|
||||
|
||||
public void OpenDefaultBrowser(string url)
|
||||
{
|
||||
_logger.Info("Opening URL [{0}]", url);
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo(url)
|
||||
{
|
||||
UseShellExecute = true
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
}
|
||||
|
||||
public Process Start(string path, string args = null, StringDictionary environmentVariables = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null)
|
||||
{
|
||||
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
args = GetMonoArgs(path, args);
|
||||
path = "mono";
|
||||
}
|
||||
|
||||
var logger = LogManager.GetLogger(new FileInfo(path).Name);
|
||||
|
||||
var startInfo = new ProcessStartInfo(path, args)
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardInput = true
|
||||
};
|
||||
|
||||
if (environmentVariables != null)
|
||||
{
|
||||
foreach (DictionaryEntry environmentVariable in environmentVariables)
|
||||
{
|
||||
startInfo.EnvironmentVariables.Add(environmentVariable.Key.ToString(), environmentVariable.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debug("Starting {0} {1}", path, args);
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
|
||||
process.OutputDataReceived += (sender, eventArgs) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
||||
|
||||
logger.Debug(eventArgs.Data);
|
||||
|
||||
onOutputDataReceived?.Invoke(eventArgs.Data);
|
||||
};
|
||||
|
||||
process.ErrorDataReceived += (sender, eventArgs) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
||||
|
||||
logger.Error(eventArgs.Data);
|
||||
|
||||
onErrorDataReceived?.Invoke(eventArgs.Data);
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
process.BeginErrorReadLine();
|
||||
process.BeginOutputReadLine();
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
public Process SpawnNewProcess(string path, string args = null, StringDictionary environmentVariables = null)
|
||||
{
|
||||
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
args = GetMonoArgs(path, args);
|
||||
path = "mono";
|
||||
}
|
||||
|
||||
_logger.Debug("Starting {0} {1}", path, args);
|
||||
|
||||
var startInfo = new ProcessStartInfo(path, args);
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
public ProcessOutput StartAndCapture(string path, string args = null, StringDictionary environmentVariables = null)
|
||||
{
|
||||
var output = new ProcessOutput();
|
||||
var process = Start(path, args, environmentVariables, s => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Standard, s)),
|
||||
error => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Error, error)));
|
||||
|
||||
process.WaitForExit();
|
||||
output.ExitCode = process.ExitCode;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public void WaitForExit(Process process)
|
||||
{
|
||||
_logger.Debug("Waiting for process {0} to exit.", process.ProcessName);
|
||||
|
||||
process.WaitForExit();
|
||||
}
|
||||
|
||||
public void SetPriority(int processId, ProcessPriorityClass priority)
|
||||
{
|
||||
var process = Process.GetProcessById(processId);
|
||||
|
||||
_logger.Info("Updating [{0}] process priority from {1} to {2}",
|
||||
process.ProcessName,
|
||||
process.PriorityClass,
|
||||
priority);
|
||||
|
||||
process.PriorityClass = priority;
|
||||
}
|
||||
|
||||
public void Kill(int processId)
|
||||
{
|
||||
var process = Process.GetProcesses().FirstOrDefault(p => p.Id == processId);
|
||||
|
||||
if (process == null)
|
||||
{
|
||||
_logger.Warn("Cannot find process with id: {0}", processId);
|
||||
return;
|
||||
}
|
||||
|
||||
process.Refresh();
|
||||
|
||||
if (process.Id != Process.GetCurrentProcess().Id && process.HasExited)
|
||||
{
|
||||
_logger.Debug("Process has already exited");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("[{0}]: Killing process", process.Id);
|
||||
process.Kill();
|
||||
_logger.Info("[{0}]: Waiting for exit", process.Id);
|
||||
process.WaitForExit();
|
||||
_logger.Info("[{0}]: Process terminated successfully", process.Id);
|
||||
}
|
||||
|
||||
public void KillAll(string processName)
|
||||
{
|
||||
var processes = GetProcessesByName(processName);
|
||||
|
||||
_logger.Debug("Found {0} processes to kill", processes.Count);
|
||||
|
||||
foreach (var processInfo in processes)
|
||||
{
|
||||
if (processInfo.Id == Process.GetCurrentProcess().Id)
|
||||
{
|
||||
_logger.Debug("Tried killing own process, skipping: {0} [{1}]", processInfo.Id, processInfo.ProcessName);
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.Debug("Killing process: {0} [{1}]", processInfo.Id, processInfo.ProcessName);
|
||||
Kill(processInfo.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private ProcessInfo ConvertToProcessInfo(Process process)
|
||||
{
|
||||
if (process == null) return null;
|
||||
|
||||
process.Refresh();
|
||||
|
||||
ProcessInfo processInfo = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (process.Id <= 0) return null;
|
||||
|
||||
processInfo = new ProcessInfo
|
||||
{
|
||||
Id = process.Id,
|
||||
Name = process.ProcessName,
|
||||
StartPath = GetExeFileName(process)
|
||||
};
|
||||
|
||||
if (process.Id != Process.GetCurrentProcess().Id && process.HasExited)
|
||||
{
|
||||
processInfo = null;
|
||||
}
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
_logger.Warn(e, "Couldn't get process info for " + process.ProcessName);
|
||||
}
|
||||
|
||||
return processInfo;
|
||||
|
||||
}
|
||||
|
||||
private static string GetExeFileName(Process process)
|
||||
{
|
||||
if (process.MainModule.FileName != "mono.exe")
|
||||
{
|
||||
return process.MainModule.FileName;
|
||||
}
|
||||
|
||||
return process.Modules.Cast<ProcessModule>().FirstOrDefault(module => module.ModuleName.ToLower().EndsWith(".exe")).FileName;
|
||||
}
|
||||
|
||||
private List<System.Diagnostics.Process> GetProcessesByName(string name)
|
||||
{
|
||||
//TODO: move this to an OS specific class
|
||||
|
||||
var monoProcesses = Process.GetProcessesByName("mono")
|
||||
.Union(Process.GetProcessesByName("mono-sgen"))
|
||||
.Where(process =>
|
||||
process.Modules.Cast<ProcessModule>()
|
||||
.Any(module =>
|
||||
module.ModuleName.ToLower() == name.ToLower() + ".exe"));
|
||||
|
||||
var processes = Process.GetProcessesByName(name)
|
||||
.Union(monoProcesses).ToList();
|
||||
|
||||
_logger.Debug("Found {0} processes with the name: {1}", processes.Count, name);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var process in processes)
|
||||
{
|
||||
_logger.Debug(" - [{0}] {1}", process.Id, process.ProcessName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Don't crash on gettings some log data.
|
||||
}
|
||||
|
||||
return processes;
|
||||
}
|
||||
|
||||
private string GetMonoArgs(string path, string args)
|
||||
{
|
||||
return string.Format("--debug {0} {1}", path, args);
|
||||
}
|
||||
}
|
||||
}
|
36
Ombi.Common/Properties/AssemblyInfo.cs
Normal file
36
Ombi.Common/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Ombi.Common")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Ombi.Common")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("bfd45569-90cf-47ca-b575-c7b0ff97f67b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
203
Ombi.Common/ServiceProvider.cs
Normal file
203
Ombi.Common/ServiceProvider.cs
Normal file
|
@ -0,0 +1,203 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: ServiceProvider.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using NLog;
|
||||
using Ombi.Common.Processes;
|
||||
|
||||
namespace Ombi.Common
|
||||
{
|
||||
public interface IServiceProvider
|
||||
{
|
||||
bool ServiceExist(string name);
|
||||
bool IsServiceRunning(string name);
|
||||
void Install(string serviceName);
|
||||
void Run(ServiceBase service);
|
||||
ServiceController GetService(string serviceName);
|
||||
void Stop(string serviceName);
|
||||
void Start(string serviceName);
|
||||
ServiceControllerStatus GetStatus(string serviceName);
|
||||
void Restart(string serviceName);
|
||||
}
|
||||
|
||||
public class ServiceProvider : IServiceProvider
|
||||
{
|
||||
public const string OmbiServiceName = "Ombi";
|
||||
|
||||
private readonly IProcessProvider _processProvider;
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
public ServiceProvider(IProcessProvider processProvider)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
}
|
||||
|
||||
public virtual bool ServiceExist(string name)
|
||||
{
|
||||
_logger.Debug("Checking if service {0} exists.", name);
|
||||
return
|
||||
ServiceController.GetServices().Any(
|
||||
s => string.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public virtual bool IsServiceRunning(string name)
|
||||
{
|
||||
_logger.Debug("Checking if '{0}' service is running", name);
|
||||
|
||||
var service = ServiceController.GetServices()
|
||||
.SingleOrDefault(s => string.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
return service != null && (
|
||||
service.Status != ServiceControllerStatus.Stopped ||
|
||||
service.Status == ServiceControllerStatus.StopPending ||
|
||||
service.Status == ServiceControllerStatus.Paused ||
|
||||
service.Status == ServiceControllerStatus.PausePending);
|
||||
}
|
||||
|
||||
public virtual void Install(string serviceName)
|
||||
{
|
||||
_logger.Info("Installing service '{0}'", serviceName);
|
||||
|
||||
|
||||
var installer = new ServiceProcessInstaller
|
||||
{
|
||||
Account = ServiceAccount.LocalSystem
|
||||
};
|
||||
|
||||
var serviceInstaller = new ServiceInstaller();
|
||||
|
||||
|
||||
string[] cmdline = { @"/assemblypath=" + Process.GetCurrentProcess().MainModule.FileName };
|
||||
|
||||
var context = new InstallContext("service_install.log", cmdline);
|
||||
serviceInstaller.Context = context;
|
||||
serviceInstaller.DisplayName = serviceName;
|
||||
serviceInstaller.ServiceName = serviceName;
|
||||
serviceInstaller.Description = "Ombi Application Server";
|
||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||
serviceInstaller.ServicesDependedOn = new[] { "EventLog", "Tcpip", "http" };
|
||||
|
||||
serviceInstaller.Parent = installer;
|
||||
|
||||
serviceInstaller.Install(new ListDictionary());
|
||||
|
||||
_logger.Info("Service Has installed successfully.");
|
||||
}
|
||||
|
||||
public virtual void Run(ServiceBase service)
|
||||
{
|
||||
ServiceBase.Run(service);
|
||||
}
|
||||
|
||||
public virtual ServiceController GetService(string serviceName)
|
||||
{
|
||||
return ServiceController.GetServices().FirstOrDefault(c => string.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public virtual void Stop(string serviceName)
|
||||
{
|
||||
_logger.Info("Stopping {0} Service...", serviceName);
|
||||
var service = GetService(serviceName);
|
||||
if (service == null)
|
||||
{
|
||||
_logger.Warn("Unable to stop {0}. no service with that name exists.", serviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Service is currently {0}", service.Status);
|
||||
|
||||
if (service.Status != ServiceControllerStatus.Stopped)
|
||||
{
|
||||
service.Stop();
|
||||
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
|
||||
|
||||
service.Refresh();
|
||||
if (service.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
_logger.Info("{0} has stopped successfully.", serviceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error("Service stop request has timed out. {0}", service.Status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn("Service {0} is already in stopped state.", service.ServiceName);
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceControllerStatus GetStatus(string serviceName)
|
||||
{
|
||||
return GetService(serviceName).Status;
|
||||
}
|
||||
|
||||
public void Start(string serviceName)
|
||||
{
|
||||
_logger.Info("Starting {0} Service...", serviceName);
|
||||
var service = GetService(serviceName);
|
||||
if (service == null)
|
||||
{
|
||||
_logger.Warn("Unable to start '{0}' no service with that name exists.", serviceName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (service.Status != ServiceControllerStatus.Paused && service.Status != ServiceControllerStatus.Stopped)
|
||||
{
|
||||
_logger.Warn("Service is in a state that can't be started. Current status: {0}", service.Status);
|
||||
}
|
||||
|
||||
service.Start();
|
||||
|
||||
service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(60));
|
||||
service.Refresh();
|
||||
|
||||
if (service.Status == ServiceControllerStatus.Running)
|
||||
{
|
||||
_logger.Info("{0} has started successfully.", serviceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error("Service start request has timed out. {0}", service.Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void Restart(string serviceName)
|
||||
{
|
||||
var args = string.Format("/C net.exe stop \"{0}\" && net.exe start \"{0}\"", serviceName);
|
||||
|
||||
_processProvider.Start("cmd.exe", args);
|
||||
}
|
||||
}
|
||||
}
|
4
Ombi.Common/packages.config
Normal file
4
Ombi.Common/packages.config
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.3.6" targetFramework="net452" />
|
||||
</packages>
|
|
@ -27,26 +27,37 @@
|
|||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using NLog;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Store;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Models.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
using Quartz.Collection;
|
||||
|
||||
namespace Ombi.Core.Migration.Migrations
|
||||
{
|
||||
[Migration(22000, "v2.20.0.0")]
|
||||
public class Version2200 : BaseMigration, IMigration
|
||||
{
|
||||
public Version2200(ISettingsService<CustomizationSettings> custom, ISettingsService<PlexSettings> ps)
|
||||
public Version2200(ISettingsService<CustomizationSettings> custom, ISettingsService<PlexSettings> ps, IRepository<RecentlyAddedLog> log,
|
||||
IRepository<PlexContent> content, IRepository<PlexEpisodes> plexEp)
|
||||
{
|
||||
Customization = custom;
|
||||
PlexSettings = ps;
|
||||
Log = log;
|
||||
PlexContent = content;
|
||||
PlexEpisodes = plexEp;
|
||||
}
|
||||
|
||||
public int Version => 22000;
|
||||
private ISettingsService<CustomizationSettings> Customization { get; set; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; set; }
|
||||
|
||||
private ISettingsService<CustomizationSettings> Customization { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private IRepository<RecentlyAddedLog> Log { get; }
|
||||
private IRepository<PlexContent> PlexContent { get; }
|
||||
private IRepository<PlexEpisodes> PlexEpisodes { get; }
|
||||
|
||||
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
@ -56,12 +67,46 @@ namespace Ombi.Core.Migration.Migrations
|
|||
UpdateCustomSettings();
|
||||
AddNewColumns(con);
|
||||
UpdateSchema(con, Version);
|
||||
UpdateRecentlyAdded(con);
|
||||
}
|
||||
|
||||
private void UpdateRecentlyAdded(IDbConnection con)
|
||||
{
|
||||
var allContent = PlexContent.GetAll();
|
||||
|
||||
var content = new HashSet<RecentlyAddedLog>();
|
||||
foreach (var plexContent in allContent)
|
||||
{
|
||||
content.Add(new RecentlyAddedLog
|
||||
{
|
||||
AddedAt = DateTime.UtcNow,
|
||||
ProviderId = plexContent.ProviderId
|
||||
});
|
||||
}
|
||||
|
||||
Log.BatchInsert(content, "RecentlyAddedLog");
|
||||
|
||||
var allEp = PlexEpisodes.GetAll();
|
||||
content.Clear();
|
||||
foreach (var ep in allEp)
|
||||
{
|
||||
content.Add(new RecentlyAddedLog
|
||||
{
|
||||
AddedAt = DateTime.UtcNow,
|
||||
ProviderId = ep.ProviderId
|
||||
});
|
||||
}
|
||||
|
||||
Log.BatchInsert(content, "RecentlyAddedLog");
|
||||
}
|
||||
|
||||
private void AddNewColumns(IDbConnection con)
|
||||
{
|
||||
con.AlterTable("EmbyContent", "ADD", "AddedAt", true, "VARCHAR(50)");
|
||||
con.AlterTable("EmbyEpisodes", "ADD", "AddedAt", true, "VARCHAR(50)");
|
||||
|
||||
con.AlterTable("PlexContent", "ADD", "ItemID", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexContent", "ADD", "AddedAt", true, "VARCHAR(100)");
|
||||
}
|
||||
|
||||
private void UpdatePlexSettings()
|
||||
|
|
169
Ombi.Core.Tests/MovieSenderTests.cs
Normal file
169
Ombi.Core.Tests/MovieSenderTests.cs
Normal file
|
@ -0,0 +1,169 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: MovieSenderTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ombi.Api;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Radarr;
|
||||
using Ombi.Api.Models.Sonarr;
|
||||
using Ombi.Api.Models.Watcher;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store;
|
||||
using Ploeh.AutoFixture;
|
||||
|
||||
namespace Ombi.Core.Tests
|
||||
{
|
||||
public class MovieSenderTests
|
||||
{
|
||||
private MovieSender Sender { get; set; }
|
||||
private Mock<ISettingsService<CouchPotatoSettings>> CpMock { get; set; }
|
||||
private Mock<ISettingsService<WatcherSettings>> WatcherMock { get; set; }
|
||||
private Mock<ISettingsService<RadarrSettings>> RadarrMock { get; set; }
|
||||
private Mock<ICouchPotatoApi> CpApiMock { get; set; }
|
||||
private Mock<IWatcherApi> WatcherApiMock { get; set; }
|
||||
private Mock<IRadarrApi> RadarrApiMock { get; set; }
|
||||
private Mock<ICacheProvider> CacheMock { get; set; }
|
||||
|
||||
private Fixture F { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
F = new Fixture();
|
||||
CpMock = new Mock<ISettingsService<CouchPotatoSettings>>();
|
||||
WatcherMock = new Mock<ISettingsService<WatcherSettings>>();
|
||||
RadarrApiMock = new Mock<IRadarrApi>();
|
||||
RadarrMock = new Mock<ISettingsService<RadarrSettings>>();
|
||||
CpApiMock = new Mock<ICouchPotatoApi>();
|
||||
WatcherApiMock = new Mock<IWatcherApi>();
|
||||
CacheMock = new Mock<ICacheProvider>();
|
||||
|
||||
|
||||
RadarrMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<RadarrSettings>().With(x => x.Enabled, false).Create());
|
||||
WatcherMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<WatcherSettings>().With(x => x.Enabled, false).Create());
|
||||
CpMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<CouchPotatoSettings>().With(x => x.Enabled, false).Create());
|
||||
|
||||
Sender = new MovieSender(CpMock.Object, WatcherMock.Object, CpApiMock.Object, WatcherApiMock.Object, RadarrApiMock.Object, RadarrMock.Object, CacheMock.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendRadarrMovie()
|
||||
{
|
||||
RadarrMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<RadarrSettings>().With(x => x.Enabled, true).Create());
|
||||
RadarrApiMock.Setup(x => x.AddMovie(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<bool>())).Returns(new RadarrAddMovie { title = "Abc" });
|
||||
|
||||
CacheMock.Setup(x => x.GetOrSet<List<SonarrRootFolder>>(CacheKeys.RadarrRootFolders, It.IsAny<Func<List<SonarrRootFolder>>>(), It.IsAny<int>()))
|
||||
.Returns(F.CreateMany<SonarrRootFolder>().ToList());
|
||||
|
||||
var model = F.Create<RequestedModel>();
|
||||
|
||||
var result = await Sender.Send(model, 2.ToString());
|
||||
|
||||
|
||||
Assert.That(result.Result, Is.True);
|
||||
Assert.That(result.Error, Is.False);
|
||||
Assert.That(result.MovieSendingEnabled, Is.True);
|
||||
|
||||
RadarrApiMock.Verify(x => x.AddMovie(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>(), 2, It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendRadarrMovie_SendingFailed()
|
||||
{
|
||||
RadarrMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<RadarrSettings>().With(x => x.Enabled, true).Create());
|
||||
RadarrApiMock.Setup(x => x.AddMovie(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<bool>())).Returns(new RadarrAddMovie { Error = new RadarrError{message = "Movie Already Added"}});
|
||||
|
||||
CacheMock.Setup(x => x.GetOrSet<List<SonarrRootFolder>>(CacheKeys.RadarrRootFolders, It.IsAny<Func<List<SonarrRootFolder>>>(), It.IsAny<int>()))
|
||||
.Returns(F.CreateMany<SonarrRootFolder>().ToList());
|
||||
|
||||
var model = F.Create<RequestedModel>();
|
||||
|
||||
var result = await Sender.Send(model, 2.ToString());
|
||||
|
||||
|
||||
Assert.That(result.Result, Is.False);
|
||||
Assert.That(result.Error, Is.True);
|
||||
Assert.That(result.MovieSendingEnabled, Is.True);
|
||||
|
||||
RadarrApiMock.Verify(x => x.AddMovie(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>(), 2, It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendCpMovie()
|
||||
{
|
||||
CpMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<CouchPotatoSettings>().With(x => x.Enabled, true).Create());
|
||||
CpApiMock.Setup(x => x.AddMovie(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<string>())).Returns(true);
|
||||
|
||||
var model = F.Create<RequestedModel>();
|
||||
|
||||
var result = await Sender.Send(model);
|
||||
|
||||
Assert.That(result.Result, Is.True);
|
||||
Assert.That(result.Error, Is.False);
|
||||
Assert.That(result.MovieSendingEnabled, Is.True);
|
||||
|
||||
CpApiMock.Verify(x => x.AddMovie(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<Uri>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SendWatcherMovie()
|
||||
{
|
||||
WatcherMock.Setup(x => x.GetSettingsAsync())
|
||||
.ReturnsAsync(F.Build<WatcherSettings>().With(x => x.Enabled, true).Create());
|
||||
WatcherApiMock.Setup(x => x.AddMovie(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(F.Create<WatcherAddMovieResult>());
|
||||
|
||||
var model = F.Create<RequestedModel>();
|
||||
|
||||
var result = await Sender.Send(model);
|
||||
|
||||
Assert.That(result.Result, Is.True);
|
||||
Assert.That(result.Error, Is.False);
|
||||
Assert.That(result.MovieSendingEnabled, Is.True);
|
||||
|
||||
WatcherApiMock.Verify(x => x.AddMovie(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@
|
|||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="AuthenticationSettingsTests.cs" />
|
||||
<Compile Include="MovieSenderTests.cs" />
|
||||
<Compile Include="NotificationMessageResolverTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -68,6 +69,18 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api.Interfaces\Ombi.Api.Interfaces.csproj">
|
||||
<Project>{95834072-A675-415D-AA8F-877C91623810}</Project>
|
||||
<Name>Ombi.Api.Interfaces</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Api.Models\Ombi.Api.Models.csproj">
|
||||
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
|
||||
<Name>Ombi.Api.Models</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj">
|
||||
<Project>{8CB8D235-2674-442D-9C6A-35FCAEEB160D}</Project>
|
||||
<Name>Ombi.Api</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj">
|
||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||
<Name>Ombi.Core</Name>
|
||||
|
@ -76,6 +89,10 @@
|
|||
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
||||
<Name>Ombi.Helpers</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Store\Ombi.Store.csproj">
|
||||
<Project>{92433867-2B7B-477B-A566-96C382427525}</Project>
|
||||
<Name>Ombi.Store</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
|
|
|
@ -50,5 +50,6 @@ namespace Ombi.Core
|
|||
public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings);
|
||||
public const string LastestProductVersion = nameof(LastestProductVersion);
|
||||
public const string SonarrRootFolders = nameof(SonarrRootFolders);
|
||||
public const string RadarrRootFolders = nameof(RadarrRootFolders);
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ namespace Ombi.Core
|
|||
|
||||
// Artist is now active
|
||||
// Add album
|
||||
var albumResult = await Api.AddAlbum(Settings.ApiKey, Settings.FullUri, request.MusicBrainzId);
|
||||
var albumResult = await Api.AddAlbum(Settings.ApiKey, Settings.FullUri, request.ReleaseId);
|
||||
if (!albumResult)
|
||||
{
|
||||
Log.Error("Couldn't add the album to headphones");
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Core
|
||||
|
@ -37,7 +39,8 @@ namespace Ombi.Core
|
|||
public class MovieSender : IMovieSender
|
||||
{
|
||||
public MovieSender(ISettingsService<CouchPotatoSettings> cp, ISettingsService<WatcherSettings> watcher,
|
||||
ICouchPotatoApi cpApi, IWatcherApi watcherApi, IRadarrApi radarrApi, ISettingsService<RadarrSettings> radarrSettings)
|
||||
ICouchPotatoApi cpApi, IWatcherApi watcherApi, IRadarrApi radarrApi, ISettingsService<RadarrSettings> radarrSettings,
|
||||
ICacheProvider cache)
|
||||
{
|
||||
CouchPotatoSettings = cp;
|
||||
WatcherSettings = watcher;
|
||||
|
@ -45,6 +48,7 @@ namespace Ombi.Core
|
|||
WatcherApi = watcherApi;
|
||||
RadarrSettings = radarrSettings;
|
||||
RadarrApi = radarrApi;
|
||||
Cache = cache;
|
||||
}
|
||||
|
||||
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
||||
|
@ -53,6 +57,7 @@ namespace Ombi.Core
|
|||
private IRadarrApi RadarrApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private IWatcherApi WatcherApi { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public async Task<MovieSenderResult> Send(RequestedModel model, string qualityId = "")
|
||||
|
@ -73,7 +78,7 @@ namespace Ombi.Core
|
|||
|
||||
if (radarrSettings.Enabled)
|
||||
{
|
||||
return SendToRadarr(model, radarrSettings);
|
||||
return SendToRadarr(model, radarrSettings, qualityId);
|
||||
}
|
||||
|
||||
return new MovieSenderResult { Result = false, MovieSendingEnabled = false };
|
||||
|
@ -102,16 +107,26 @@ namespace Ombi.Core
|
|||
return new MovieSenderResult { Result = result, MovieSendingEnabled = true };
|
||||
}
|
||||
|
||||
private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings)
|
||||
private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings, string qualityId)
|
||||
{
|
||||
var qualityProfile = 0;
|
||||
int.TryParse(settings.QualityProfile, out qualityProfile);
|
||||
var result = RadarrApi.AddMovie(model.ProviderId, model.Title, model.ReleaseDate.Year, qualityProfile, settings.RootPath, settings.ApiKey, settings.FullUri, true);
|
||||
if (!string.IsNullOrEmpty(qualityId)) // try to parse the passed in quality, otherwise use the settings default quality
|
||||
{
|
||||
int.TryParse(qualityId, out qualityProfile);
|
||||
}
|
||||
|
||||
if (qualityProfile <= 0)
|
||||
{
|
||||
int.TryParse(settings.QualityProfile, out qualityProfile);
|
||||
}
|
||||
|
||||
var rootFolderPath = model.RootFolderSelected <= 0 ? settings.FullRootPath : GetRootPath(model.RootFolderSelected, settings);
|
||||
var result = RadarrApi.AddMovie(model.ProviderId, model.Title, model.ReleaseDate.Year, qualityProfile, rootFolderPath, settings.ApiKey, settings.FullUri, true);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Error?.message))
|
||||
{
|
||||
Log.Error(result.Error.message);
|
||||
return new MovieSenderResult { Result = false, Error = true};
|
||||
return new MovieSenderResult { Result = false, Error = true , MovieSendingEnabled = true};
|
||||
}
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
{
|
||||
|
@ -119,5 +134,16 @@ namespace Ombi.Core
|
|||
}
|
||||
return new MovieSenderResult { Result = false, MovieSendingEnabled = true };
|
||||
}
|
||||
|
||||
private string GetRootPath(int pathId, RadarrSettings sonarrSettings)
|
||||
{
|
||||
var rootFoldersResult = Cache.GetOrSet(CacheKeys.RadarrRootFolders, () => RadarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri));
|
||||
|
||||
foreach (var r in rootFoldersResult.Where(r => r.id == pathId))
|
||||
{
|
||||
return r.path;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ namespace Ombi.Core.SettingModels
|
|||
public int Port { get; set; }
|
||||
public string BaseUrl { get; set; }
|
||||
public bool SearchForMovies { get; set; }
|
||||
public bool SearchForActors { get; set; }
|
||||
public bool SearchForTvShows { get; set; }
|
||||
public bool SearchForMusic { get; set; }
|
||||
[Obsolete("Use the user management settings")]
|
||||
|
|
|
@ -32,6 +32,6 @@ namespace Ombi.Core.SettingModels
|
|||
public string ApiKey { get; set; }
|
||||
public string QualityProfile { get; set; }
|
||||
public string RootPath { get; set; }
|
||||
|
||||
public string FullRootPath { get; set; }
|
||||
}
|
||||
}
|
|
@ -77,6 +77,7 @@ namespace Ombi.Core
|
|||
{
|
||||
SearchForMovies = true,
|
||||
SearchForTvShows = true,
|
||||
SearchForActors = true,
|
||||
BaseUrl = baseUrl ?? string.Empty,
|
||||
CollectAnalyticData = true,
|
||||
};
|
||||
|
|
|
@ -202,6 +202,7 @@ namespace Ombi.Core.StatusChecker
|
|||
|
||||
public async Task<Uri> OAuth(string url, ISession session)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var csrf = StringCipher.Encrypt(Guid.NewGuid().ToString("N"), "CSRF");
|
||||
session[SessionKeys.CSRF] = csrf;
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Ombi.Helpers.Tests
|
|||
var consts = typeof(UserClaims).GetConstantsValues<string>();
|
||||
Assert.That(consts.Contains("Admin"),Is.True);
|
||||
Assert.That(consts.Contains("PowerUser"),Is.True);
|
||||
Assert.That(consts.Contains("User"),Is.True);
|
||||
Assert.That(consts.Contains("RegularUser"),Is.True);
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> TypeData
|
||||
|
@ -59,14 +59,7 @@ namespace Ombi.Helpers.Tests
|
|||
yield return new TestCaseData(typeof(int)).Returns(new string[0]).SetName("NoPropeties Class");
|
||||
yield return new TestCaseData(typeof(IEnumerable<>)).Returns(new string[0]).SetName("Interface");
|
||||
yield return new TestCaseData(typeof(string)).Returns(new[] { "Chars", "Length" }).SetName("String");
|
||||
yield return new TestCaseData(typeof(RequestedModel)).Returns(
|
||||
new[]
|
||||
{
|
||||
"ProviderId", "ImdbId", "TvDbId", "Overview", "Title", "PosterPath", "ReleaseDate", "Type",
|
||||
"Status", "Approved", "RequestedBy", "RequestedDate", "Available", "Issues", "OtherMessage", "AdminNote",
|
||||
"SeasonList", "SeasonCount", "SeasonsRequested", "MusicBrainzId", "RequestedUsers","ArtistName",
|
||||
"ArtistId","IssueId","Episodes", "Denied", "DeniedReason", "AllUsers","CanApprove","Id",
|
||||
}).SetName("Requested Model");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,15 +37,15 @@ namespace Ombi.Services.Interfaces
|
|||
void Start();
|
||||
void CheckAndUpdateAll();
|
||||
IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content);
|
||||
bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null);
|
||||
bool IsMovieAvailable(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null);
|
||||
IEnumerable<PlexContent> GetPlexTvShows(IEnumerable<PlexContent> content);
|
||||
bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
|
||||
bool IsTvShowAvailable(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null);
|
||||
IEnumerable<PlexContent> GetPlexAlbums(IEnumerable<PlexContent> content);
|
||||
bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist);
|
||||
bool IsAlbumAvailable(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist);
|
||||
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
|
||||
PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist);
|
||||
PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null);
|
||||
PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
|
||||
PlexContent GetAlbum(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist);
|
||||
PlexContent GetMovie(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null);
|
||||
PlexContent GetTvShow(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null);
|
||||
/// <summary>
|
||||
/// Gets the episode's stored in the cache.
|
||||
/// </summary>
|
||||
|
|
|
@ -161,15 +161,15 @@ namespace Ombi.Services.Jobs
|
|||
return content.Where(x => x.Type == EmbyMediaType.Movie);
|
||||
}
|
||||
|
||||
public bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId)
|
||||
public bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
|
||||
{
|
||||
var movie = GetMovie(embyMovies, title, year, providerId);
|
||||
return movie != null;
|
||||
}
|
||||
|
||||
public EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId)
|
||||
public EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
|
||||
{
|
||||
if (embyMovies.Length == 0)
|
||||
if (embyMovies.Count() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -200,14 +200,14 @@ namespace Ombi.Services.Jobs
|
|||
return content.Where(x => x.Type == EmbyMediaType.Series);
|
||||
}
|
||||
|
||||
public bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null)
|
||||
public bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null)
|
||||
{
|
||||
var show = GetTvShow(embyShows, title, year, providerId, seasons);
|
||||
return show != null;
|
||||
}
|
||||
|
||||
|
||||
public EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId,
|
||||
public EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId,
|
||||
int[] seasons = null)
|
||||
{
|
||||
foreach (var show in embyShows)
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace Ombi.Services.Jobs
|
|||
}
|
||||
|
||||
// Insert the new items
|
||||
var result = Repo.BatchInsert(model, TableName, typeof(EmbyEpisodes).GetPropertyNames());
|
||||
var result = Repo.BatchInsert(model, TableName);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace Ombi.Services.Jobs
|
|||
IEnumerable<EmbyContent> GetEmbyTvShows(IEnumerable<EmbyContent> content);
|
||||
Task<IEnumerable<EmbyEpisodes>> GetEpisodes();
|
||||
Task<IEnumerable<EmbyEpisodes>> GetEpisodes(int theTvDbId);
|
||||
EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId);
|
||||
EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
|
||||
EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
|
||||
EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
|
||||
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
|
||||
bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId);
|
||||
bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
|
||||
bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
|
||||
bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
|
||||
void Start();
|
||||
}
|
||||
}
|
|
@ -194,15 +194,15 @@ namespace Ombi.Services.Jobs
|
|||
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Movie);
|
||||
}
|
||||
|
||||
public bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null)
|
||||
public bool IsMovieAvailable(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null)
|
||||
{
|
||||
var movie = GetMovie(plexMovies, title, year, providerId);
|
||||
return movie != null;
|
||||
}
|
||||
|
||||
public PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null)
|
||||
public PlexContent GetMovie(IEnumerable<PlexContent> plexMovies, string title, string year, string providerId = null)
|
||||
{
|
||||
if (plexMovies.Length == 0)
|
||||
if (plexMovies.Count() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -236,14 +236,14 @@ namespace Ombi.Services.Jobs
|
|||
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Show);
|
||||
}
|
||||
|
||||
public bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null)
|
||||
public bool IsTvShowAvailable(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null, int[] seasons = null)
|
||||
{
|
||||
var show = GetTvShow(plexShows, title, year, providerId, seasons);
|
||||
return show != null;
|
||||
}
|
||||
|
||||
|
||||
public PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null,
|
||||
public PlexContent GetTvShow(IEnumerable<PlexContent> plexShows, string title, string year, string providerId = null,
|
||||
int[] seasons = null)
|
||||
{
|
||||
var advanced = !string.IsNullOrEmpty(providerId);
|
||||
|
@ -345,14 +345,14 @@ namespace Ombi.Services.Jobs
|
|||
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Artist);
|
||||
}
|
||||
|
||||
public bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist)
|
||||
public bool IsAlbumAvailable(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist)
|
||||
{
|
||||
return plexAlbums.Any(x =>
|
||||
x.Title.Contains(title) &&
|
||||
x.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist)
|
||||
public PlexContent GetAlbum(IEnumerable<PlexContent> plexAlbums, string title, string year, string artist)
|
||||
{
|
||||
return plexAlbums.FirstOrDefault(x =>
|
||||
x.Title.Contains(title) &&
|
||||
|
|
|
@ -115,7 +115,8 @@ namespace Ombi.Services.Jobs
|
|||
ReleaseYear = video.Year,
|
||||
Title = video.Title,
|
||||
ProviderId = video.ProviderId,
|
||||
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, video.RatingKey)
|
||||
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, video.RatingKey),
|
||||
ItemId = video.RatingKey
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +146,7 @@ namespace Ombi.Services.Jobs
|
|||
ProviderId = x.ProviderId,
|
||||
Seasons = x.Seasons?.Select(d => PlexHelper.GetSeasonNumberFromTitle(d.Title)).ToArray(),
|
||||
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, x.RatingKey),
|
||||
ItemId= x.RatingKey
|
||||
|
||||
}));
|
||||
}
|
||||
|
@ -271,7 +273,8 @@ namespace Ombi.Services.Jobs
|
|||
ReleaseYear = m.ReleaseYear ?? string.Empty,
|
||||
Title = m.Title,
|
||||
Type = Store.Models.Plex.PlexMediaType.Movie,
|
||||
Url = m.Url
|
||||
Url = m.Url,
|
||||
ItemId = m.ItemId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -311,7 +314,8 @@ namespace Ombi.Services.Jobs
|
|||
Title = t.Title,
|
||||
Type = Store.Models.Plex.PlexMediaType.Show,
|
||||
Url = t.Url,
|
||||
Seasons = ByteConverterHelper.ReturnBytes(t.Seasons)
|
||||
Seasons = ByteConverterHelper.ReturnBytes(t.Seasons),
|
||||
ItemId = t.ItemId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +356,7 @@ namespace Ombi.Services.Jobs
|
|||
ReleaseYear = a.ReleaseYear ?? string.Empty,
|
||||
Title = a.Title,
|
||||
Type = Store.Models.Plex.PlexMediaType.Artist,
|
||||
Url = a.Url
|
||||
Url = a.Url,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace Ombi.Services.Jobs
|
|||
Repo.DeleteAll(TableName);
|
||||
|
||||
// Insert the new items
|
||||
var result = Repo.BatchInsert(entities.Select(x => x.Key).ToList(), TableName, typeof(PlexEpisodes).GetPropertyNames());
|
||||
var result = Repo.BatchInsert(entities.Select(x => x.Key).ToList(), TableName);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
|
|
@ -228,7 +228,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
AddParagraph(sb, info.Overview);
|
||||
}
|
||||
catch (RequestLimitExceededException limit)
|
||||
catch (Exception limit)
|
||||
{
|
||||
// We have hit a limit, we need to now wait.
|
||||
Thread.Sleep(TimeSpan.FromSeconds(10));
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
{
|
||||
public interface IPlexNewsletter
|
||||
{
|
||||
string GetNewsletterHtml(bool test);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
#region Copyright
|
||||
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: RecentlyAddedModel.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Ombi.Api;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Emby;
|
||||
using Ombi.Api.Models.Plex;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Services.Jobs.Templates;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Models.Emby;
|
||||
using Ombi.Store.Models.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
using TMDbLib.Objects.Exceptions;
|
||||
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
|
||||
using PlexMediaType = Ombi.Store.Models.Plex.PlexMediaType;
|
||||
|
||||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
{
|
||||
public class PlexRecentlyAddedNewsletter : HtmlTemplateGenerator, IPlexNewsletter
|
||||
{
|
||||
public PlexRecentlyAddedNewsletter(IPlexApi api, ISettingsService<PlexSettings> plexSettings,
|
||||
ISettingsService<EmailNotificationSettings> email,
|
||||
ISettingsService<NewletterSettings> newsletter, IRepository<RecentlyAddedLog> log,
|
||||
IRepository<PlexContent> embyContent, IRepository<PlexEpisodes> episodes)
|
||||
{
|
||||
Api = api;
|
||||
PlexSettings = plexSettings;
|
||||
EmailSettings = email;
|
||||
NewsletterSettings = newsletter;
|
||||
Content = embyContent;
|
||||
MovieApi = new TheMovieDbApi();
|
||||
TvApi = new TvMazeApi();
|
||||
Episodes = episodes;
|
||||
RecentlyAddedLog = log;
|
||||
}
|
||||
|
||||
private IPlexApi Api { get; }
|
||||
private TheMovieDbApi MovieApi { get; }
|
||||
private TvMazeApi TvApi { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<EmailNotificationSettings> EmailSettings { get; }
|
||||
private ISettingsService<NewletterSettings> NewsletterSettings { get; }
|
||||
private IRepository<PlexContent> Content { get; }
|
||||
private IRepository<PlexEpisodes> Episodes { get; }
|
||||
private IRepository<RecentlyAddedLog> RecentlyAddedLog { get; }
|
||||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string GetNewsletterHtml(bool test)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetHtml(test);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private class PlexRecentlyAddedModel
|
||||
{
|
||||
public PlexMetadata Metadata { get; set; }
|
||||
public PlexContent Content { get; set; }
|
||||
}
|
||||
|
||||
private string GetHtml(bool test)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
|
||||
var plexContent = Content.GetAll().ToList();
|
||||
|
||||
var series = plexContent.Where(x => x.Type == PlexMediaType.Show).ToList();
|
||||
var episodes = Episodes.GetAll().ToList();
|
||||
var movie = plexContent.Where(x => x.Type == PlexMediaType.Movie).ToList();
|
||||
|
||||
var recentlyAdded = RecentlyAddedLog.GetAll().ToList();
|
||||
|
||||
var firstRun = !recentlyAdded.Any();
|
||||
|
||||
var filteredMovies = movie.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
var filteredEp = episodes.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
|
||||
|
||||
var info = new List<PlexRecentlyAddedModel>();
|
||||
foreach (var m in filteredMovies)
|
||||
{
|
||||
var i = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri, m.ItemId);
|
||||
info.Add(new PlexRecentlyAddedModel
|
||||
{
|
||||
Metadata = i,
|
||||
Content = m
|
||||
});
|
||||
}
|
||||
GenerateMovieHtml(info, sb);
|
||||
|
||||
info.Clear();
|
||||
foreach (var t in series)
|
||||
{
|
||||
var i = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri, t.ItemId);
|
||||
|
||||
//var ep = filteredEp.Where(x => x.ShowTitle == t.Title);
|
||||
info.Add(new PlexRecentlyAddedModel
|
||||
{
|
||||
Metadata = i,
|
||||
Content = t
|
||||
});
|
||||
//if (ep.Any())
|
||||
//{
|
||||
// var episodeList = new List<EmbyEpisodeInformation>();
|
||||
// foreach (var embyEpisodese in ep)
|
||||
// {
|
||||
// var epInfo = Api.GetInformation(embyEpisodese.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Episode,
|
||||
// embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
// episodeList.Add(epInfo.EpisodeInformation);
|
||||
// }
|
||||
// info.Add(new EmbyRecentlyAddedModel
|
||||
// {
|
||||
// EmbyContent = t,
|
||||
// EmbyInformation = i,
|
||||
// EpisodeInformation = episodeList
|
||||
// });
|
||||
//}
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
Log.Debug("Loaded the template");
|
||||
|
||||
if (!test || firstRun)
|
||||
{
|
||||
foreach (var a in filteredMovies)
|
||||
{
|
||||
RecentlyAddedLog.Insert(new RecentlyAddedLog
|
||||
{
|
||||
ProviderId = a.ProviderId,
|
||||
AddedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
foreach (var a in filteredEp)
|
||||
{
|
||||
RecentlyAddedLog.Insert(new RecentlyAddedLog
|
||||
{
|
||||
ProviderId = a.ProviderId,
|
||||
AddedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
return escapedHtml;
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<PlexRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
{
|
||||
var movies = recentlyAddedMovies?.ToList() ?? new List<PlexRecentlyAddedModel>();
|
||||
if (!movies.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var orderedMovies = movies.OrderByDescending(x => x.Content.AddedAt).ToList();
|
||||
sb.Append("<h1>New Movies:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var movie in orderedMovies)
|
||||
{
|
||||
// We have a try within a try so we can catch the rate limit without ending the loop (finally block)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(movie.Metadata.Video.Guid);
|
||||
var info = MovieApi.GetMovieInformation(imdbId).Result;
|
||||
if (info == null)
|
||||
{
|
||||
throw new Exception($"Movie with Imdb id {imdbId} returned null from the MovieApi");
|
||||
}
|
||||
AddImageInsideTable(sb, $"https://image.tmdb.org/t/p/w500{info.BackdropPath}");
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.ImdbId}/");
|
||||
Header(sb, 3, $"{info.Title} {info.ReleaseDate?.ToString("yyyy") ?? string.Empty}");
|
||||
EndTag(sb, "a");
|
||||
|
||||
if (info.Genres.Any())
|
||||
{
|
||||
AddParagraph(sb,
|
||||
$"Genre: {string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, info.Overview);
|
||||
}
|
||||
catch (RequestLimitExceededException limit)
|
||||
{
|
||||
// We have hit a limit, we need to now wait.
|
||||
Thread.Sleep(TimeSpan.FromSeconds(10));
|
||||
Log.Info(limit);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error("Error for movie with IMDB Id = {0}", movie.Metadata.Video.Guid);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
private class TvModel
|
||||
{
|
||||
public EmbySeriesInformation Series { get; set; }
|
||||
public List<EmbyEpisodeInformation> Episodes { get; set; }
|
||||
}
|
||||
private void GenerateTvHtml(IEnumerable<PlexRecentlyAddedModel> recenetlyAddedTv, StringBuilder sb)
|
||||
{
|
||||
var tv = recenetlyAddedTv?.ToList() ?? new List<PlexRecentlyAddedModel>();
|
||||
|
||||
if (!tv.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var orderedTv = tv.OrderByDescending(x => x.Content.AddedAt).ToList();
|
||||
|
||||
// TV
|
||||
sb.Append("<h1>New Episodes:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var t in orderedTv)
|
||||
{
|
||||
//var seriesItem = t.EmbyInformation.SeriesInformation;
|
||||
//var relatedEpisodes = t.EpisodeInformation;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(t.Metadata.Directory.Guid)));
|
||||
|
||||
var banner = info.image?.original;
|
||||
if (!string.IsNullOrEmpty(banner))
|
||||
{
|
||||
banner = banner.Replace("http", "https"); // Always use the Https banners
|
||||
}
|
||||
AddImageInsideTable(sb, banner);
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
var title = $"{t.Content.Title} {t.Content.ReleaseYear}";
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
|
||||
Header(sb, 3, title);
|
||||
EndTag(sb, "a");
|
||||
|
||||
//var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
|
||||
// (key, g) => new
|
||||
// {
|
||||
// ParentIndexNumber = key,
|
||||
// IndexNumber = g.ToList()
|
||||
// }
|
||||
//);
|
||||
// Group the episodes
|
||||
//foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
|
||||
//{
|
||||
// var epSb = new StringBuilder();
|
||||
// for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
|
||||
// {
|
||||
// var ep = embyEpisodeInformation.IndexNumber[i];
|
||||
// if (i < embyEpisodeInformation.IndexNumber.Count)
|
||||
// {
|
||||
// epSb.Append($"{ep.IndexNumber},");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// epSb.Append(ep);
|
||||
// }
|
||||
// }
|
||||
// AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
|
||||
//}
|
||||
|
||||
if (info.genres.Any())
|
||||
{
|
||||
AddParagraph(sb, $"Genre: {string.Join(", ", info.genres.Select(x => x.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, string.IsNullOrEmpty(t.Metadata.Directory.Summary) ? t.Metadata.Directory.Summary : info.summary);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void EndLoopHtml(StringBuilder sb)
|
||||
{
|
||||
//NOTE: BR have to be in TD's as per html spec or it will be put outside of the table...
|
||||
//Source: http://stackoverflow.com/questions/6588638/phantom-br-tag-rendered-by-browsers-prior-to-table-tag
|
||||
sb.Append("<hr />");
|
||||
sb.Append("<br />");
|
||||
sb.Append("<br />");
|
||||
sb.Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -53,18 +53,19 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
public RecentlyAddedNewsletter(IPlexApi api, ISettingsService<PlexSettings> plexSettings,
|
||||
ISettingsService<EmailNotificationSettings> email, IJobRecord rec,
|
||||
ISettingsService<NewletterSettings> newsletter,
|
||||
IPlexReadOnlyDatabase db, IUserHelper userHelper, IEmbyAddedNewsletter embyNews,
|
||||
ISettingsService<EmbySettings> embyS)
|
||||
IUserHelper userHelper, IEmbyAddedNewsletter embyNews,
|
||||
ISettingsService<EmbySettings> embyS,
|
||||
IPlexNewsletter plex)
|
||||
{
|
||||
JobRecord = rec;
|
||||
Api = api;
|
||||
PlexSettings = plexSettings;
|
||||
EmailSettings = email;
|
||||
NewsletterSettings = newsletter;
|
||||
PlexDb = db;
|
||||
UserHelper = userHelper;
|
||||
EmbyNewsletter = embyNews;
|
||||
EmbySettings = embyS;
|
||||
PlexNewsletter = plex;
|
||||
}
|
||||
|
||||
private IPlexApi Api { get; }
|
||||
|
@ -75,9 +76,9 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
private ISettingsService<EmailNotificationSettings> EmailSettings { get; }
|
||||
private ISettingsService<NewletterSettings> NewsletterSettings { get; }
|
||||
private IJobRecord JobRecord { get; }
|
||||
private IPlexReadOnlyDatabase PlexDb { get; }
|
||||
private IUserHelper UserHelper { get; }
|
||||
private IEmbyAddedNewsletter EmbyNewsletter { get; }
|
||||
private IPlexNewsletter PlexNewsletter { get; }
|
||||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
@ -144,331 +145,18 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
else
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
Log.Debug("Got Plex Settings");
|
||||
|
||||
var libs = Api.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
Log.Debug("Getting Plex Library Sections");
|
||||
|
||||
var tvSections = libs.Directories.Where(x => x.type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)); // We could have more than 1 lib
|
||||
Log.Debug("Filtered sections for TV");
|
||||
var movieSection = libs.Directories.Where(x => x.type.Equals(PlexMediaType.Movie.ToString(), StringComparison.CurrentCultureIgnoreCase)); // We could have more than 1 lib
|
||||
Log.Debug("Filtered sections for Movies");
|
||||
|
||||
var plexVersion = Api.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri).Version;
|
||||
|
||||
var html = string.Empty;
|
||||
if (plexVersion.StartsWith("1.3"))
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
var tvMetadata = new List<Metadata>();
|
||||
var movieMetadata = new List<Metadata>();
|
||||
foreach (var tvSection in tvSections)
|
||||
{
|
||||
var item = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri,
|
||||
tvSection?.Key);
|
||||
if (item?.MediaContainer?.Metadata != null)
|
||||
{
|
||||
tvMetadata.AddRange(item?.MediaContainer?.Metadata);
|
||||
}
|
||||
}
|
||||
Log.Debug("Got RecentlyAdded TV Shows");
|
||||
foreach (var movie in movieSection)
|
||||
{
|
||||
var recentlyAddedMovies = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri, movie?.Key);
|
||||
if (recentlyAddedMovies?.MediaContainer?.Metadata != null)
|
||||
{
|
||||
movieMetadata.AddRange(recentlyAddedMovies?.MediaContainer?.Metadata);
|
||||
}
|
||||
}
|
||||
Log.Debug("Got RecentlyAdded Movies");
|
||||
var html = PlexNewsletter.GetNewsletterHtml(testEmail);
|
||||
|
||||
Log.Debug("Started Generating Movie HTML");
|
||||
GenerateMovieHtml(movieMetadata, plexSettings, sb);
|
||||
Log.Debug("Finished Generating Movie HTML");
|
||||
Log.Debug("Started Generating TV HTML");
|
||||
GenerateTvHtml(tvMetadata, plexSettings, sb);
|
||||
Log.Debug("Finished Generating TV HTML");
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
html = template.LoadTemplate(sb.ToString());
|
||||
Log.Debug("Loaded the template");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Old API
|
||||
var tvChild = new List<RecentlyAddedChild>();
|
||||
var movieChild = new List<RecentlyAddedChild>();
|
||||
foreach (var tvSection in tvSections)
|
||||
{
|
||||
var recentlyAddedTv = Api.RecentlyAddedOld(plexSettings.PlexAuthToken, plexSettings.FullUri, tvSection?.Key);
|
||||
if (recentlyAddedTv?._children != null)
|
||||
{
|
||||
tvChild.AddRange(recentlyAddedTv?._children);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Debug("Got RecentlyAdded TV Shows");
|
||||
foreach (var movie in movieSection)
|
||||
{
|
||||
var recentlyAddedMovies = Api.RecentlyAddedOld(plexSettings.PlexAuthToken, plexSettings.FullUri, movie?.Key);
|
||||
if (recentlyAddedMovies?._children != null)
|
||||
{
|
||||
tvChild.AddRange(recentlyAddedMovies?._children);
|
||||
}
|
||||
}
|
||||
Log.Debug("Got RecentlyAdded Movies");
|
||||
|
||||
Log.Debug("Started Generating Movie HTML");
|
||||
GenerateMovieHtml(movieChild, plexSettings, sb);
|
||||
Log.Debug("Finished Generating Movie HTML");
|
||||
Log.Debug("Started Generating TV HTML");
|
||||
GenerateTvHtml(tvChild, plexSettings, sb);
|
||||
Log.Debug("Finished Generating TV HTML");
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
html = template.LoadTemplate(sb.ToString());
|
||||
Log.Debug("Loaded the template");
|
||||
}
|
||||
string escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, escapedHtml, testEmail);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(List<RecentlyAddedChild> movies, PlexSettings plexSettings, StringBuilder sb)
|
||||
{
|
||||
var orderedMovies = movies.OrderByDescending(x => x?.addedAt.UnixTimeStampToDateTime()).ToList() ?? new List<RecentlyAddedChild>();
|
||||
sb.Append("<h1>New Movies:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var movie in orderedMovies)
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
{
|
||||
var metaData = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
|
||||
movie.ratingKey.ToString());
|
||||
|
||||
plexGUID = metaData.Video.Guid;
|
||||
|
||||
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(plexGUID);
|
||||
var info = _movieApi.GetMovieInformation(imdbId).Result;
|
||||
if (info == null)
|
||||
{
|
||||
throw new Exception($"Movie with Imdb id {imdbId} returned null from the MovieApi");
|
||||
}
|
||||
AddImageInsideTable(sb, $"https://image.tmdb.org/t/p/w500{info.BackdropPath}");
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.ImdbId}/");
|
||||
Header(sb, 3, $"{info.Title} {info.ReleaseDate?.ToString("yyyy") ?? string.Empty}");
|
||||
EndTag(sb, "a");
|
||||
|
||||
if (info.Genres.Any())
|
||||
{
|
||||
AddParagraph(sb,
|
||||
$"Genre: {string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, info.Overview);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error(
|
||||
"Exception when trying to process a Movie, either in getting the metadata from Plex OR getting the information from TheMovieDB, Plex GUID = {0}",
|
||||
plexGUID);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(List<Metadata> movies, PlexSettings plexSettings, StringBuilder sb)
|
||||
{
|
||||
var orderedMovies = movies.OrderByDescending(x => x?.addedAt.UnixTimeStampToDateTime()).ToList() ?? new List<Metadata>();
|
||||
sb.Append("<h1>New Movies:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var movie in orderedMovies)
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
{
|
||||
var metaData = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
|
||||
movie.ratingKey.ToString());
|
||||
|
||||
plexGUID = metaData.Video.Guid;
|
||||
|
||||
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(plexGUID);
|
||||
var info = _movieApi.GetMovieInformation(imdbId).Result;
|
||||
if (info == null)
|
||||
{
|
||||
throw new Exception($"Movie with Imdb id {imdbId} returned null from the MovieApi");
|
||||
}
|
||||
AddImageInsideTable(sb, $"https://image.tmdb.org/t/p/w500{info.BackdropPath}");
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.ImdbId}/");
|
||||
Header(sb, 3, $"{info.Title} {info.ReleaseDate?.ToString("yyyy") ?? string.Empty}");
|
||||
EndTag(sb, "a");
|
||||
|
||||
if (info.Genres.Any())
|
||||
{
|
||||
AddParagraph(sb,
|
||||
$"Genre: {string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, info.Overview);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error(
|
||||
"Exception when trying to process a Movie, either in getting the metadata from Plex OR getting the information from TheMovieDB, Plex GUID = {0}",
|
||||
plexGUID);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
private void GenerateTvHtml(List<RecentlyAddedChild> tv, PlexSettings plexSettings, StringBuilder sb)
|
||||
{
|
||||
var orderedTv = tv.OrderByDescending(x => x?.addedAt.UnixTimeStampToDateTime()).ToList();
|
||||
// TV
|
||||
sb.Append("<h1>New Episodes:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var t in orderedTv)
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
{
|
||||
|
||||
var parentMetaData = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
|
||||
t.parentRatingKey.ToString());
|
||||
|
||||
plexGUID = parentMetaData.Directory.Guid;
|
||||
|
||||
var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(plexGUID)));
|
||||
|
||||
var banner = info.image?.original;
|
||||
if (!string.IsNullOrEmpty(banner))
|
||||
{
|
||||
banner = banner.Replace("http", "https"); // Always use the Https banners
|
||||
}
|
||||
AddImageInsideTable(sb, banner);
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
var title = $"{t.grandparentTitle} - {t.title} {t.originallyAvailableAt?.Substring(0, 4)}";
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
|
||||
Header(sb, 3, title);
|
||||
EndTag(sb, "a");
|
||||
|
||||
AddParagraph(sb, $"Season: {t.parentIndex}, Episode: {t.index}");
|
||||
if (info.genres.Any())
|
||||
{
|
||||
AddParagraph(sb, $"Genre: {string.Join(", ", info.genres.Select(x => x.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, string.IsNullOrEmpty(t.summary) ? info.summary : t.summary);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error(
|
||||
"Exception when trying to process a TV Show, either in getting the metadata from Plex OR getting the information from TVMaze, Plex GUID = {0}",
|
||||
plexGUID);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, html, testEmail);
|
||||
}
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
private void GenerateTvHtml(List<Metadata> tv, PlexSettings plexSettings, StringBuilder sb)
|
||||
{
|
||||
var orderedTv = tv.OrderByDescending(x => x?.addedAt.UnixTimeStampToDateTime()).ToList();
|
||||
// TV
|
||||
sb.Append("<h1>New Episodes:</h1><br /><br />");
|
||||
sb.Append(
|
||||
"<table border=\"0\" cellpadding=\"0\" align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
|
||||
foreach (var t in orderedTv)
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
{
|
||||
|
||||
var parentMetaData = Api.GetMetadata(plexSettings.PlexAuthToken, plexSettings.FullUri,
|
||||
t.parentRatingKey.ToString());
|
||||
|
||||
plexGUID = parentMetaData.Directory.Guid;
|
||||
|
||||
var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(plexGUID)));
|
||||
|
||||
var banner = info.image?.original;
|
||||
if (!string.IsNullOrEmpty(banner))
|
||||
{
|
||||
banner = banner.Replace("http", "https"); // Always use the Https banners
|
||||
}
|
||||
AddImageInsideTable(sb, banner);
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
var title = $"{t.grandparentTitle} - {t.title} {t.originallyAvailableAt?.Substring(0, 4)}";
|
||||
|
||||
Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
|
||||
Header(sb, 3, title);
|
||||
EndTag(sb, "a");
|
||||
|
||||
AddParagraph(sb, $"Season: {t.parentIndex}, Episode: {t.index}");
|
||||
if (info.genres.Any())
|
||||
{
|
||||
AddParagraph(sb, $"Genre: {string.Join(", ", info.genres.Select(x => x.ToString()).ToArray())}");
|
||||
}
|
||||
|
||||
AddParagraph(sb, string.IsNullOrEmpty(t.summary) ? info.summary : t.summary);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error(
|
||||
"Exception when trying to process a TV Show, either in getting the metadata from Plex OR getting the information from TVMaze, Plex GUID = {0}",
|
||||
plexGUID);
|
||||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
}
|
||||
|
||||
|
||||
private void SendMassEmail(string html, string subject, bool testEmail)
|
||||
{
|
||||
var settings = EmailSettings.GetSettings();
|
||||
|
@ -507,7 +195,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
SendMail(settings, message);
|
||||
}
|
||||
|
||||
// TODO Emby
|
||||
|
||||
private void SendNewsletter(NewletterSettings newletterSettings, string html, bool testEmail = false, string subject = "New Content on Plex!")
|
||||
{
|
||||
Log.Debug("Entering SendNewsletter");
|
||||
|
@ -588,17 +276,5 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void EndLoopHtml(StringBuilder sb)
|
||||
{
|
||||
//NOTE: BR have to be in TD's as per html spec or it will be put outside of the table...
|
||||
//Source: http://stackoverflow.com/questions/6588638/phantom-br-tag-rendered-by-browsers-prior-to-table-tag
|
||||
sb.Append("<hr />");
|
||||
sb.Append("<br />");
|
||||
sb.Append("<br />");
|
||||
sb.Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -7,5 +7,6 @@
|
|||
public string ReleaseYear { get; set; }
|
||||
public string ProviderId { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
public string ProviderId { get; set; }
|
||||
public int[] Seasons { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,9 @@
|
|||
<Compile Include="Jobs\EmbyEpisodeCacher.cs" />
|
||||
<Compile Include="Jobs\EmbyUserChecker.cs" />
|
||||
<Compile Include="Jobs\RadarrCacher.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\PlexRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\EmbyRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\IPlexNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\IEmbyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\Templates\MassEmailTemplate.cs" />
|
||||
<Compile Include="Jobs\WatcherCacher.cs" />
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Data.Linq.Mapping;
|
||||
|
||||
namespace Ombi.Store.Models.Plex
|
||||
|
@ -47,5 +48,8 @@ namespace Ombi.Store.Models.Plex
|
|||
/// Only used for Albums
|
||||
/// </summary>
|
||||
public string Artist { get; set; }
|
||||
|
||||
public string ItemId { get; set; }
|
||||
public DateTime AddedAt { get; set; }
|
||||
}
|
||||
}
|
|
@ -286,7 +286,7 @@ namespace Ombi.Store.Repository
|
|||
}
|
||||
}
|
||||
|
||||
public bool BatchInsert(IEnumerable<T> entities, string tableName, params string[] values)
|
||||
public bool BatchInsert(IEnumerable<T> entities, string tableName)
|
||||
{
|
||||
// If we have nothing to update, then it didn't fail...
|
||||
var enumerable = entities as T[] ?? entities.ToArray();
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace Ombi.Store.Repository
|
|||
bool UpdateAll(IEnumerable<T> entity);
|
||||
Task<bool> UpdateAllAsync(IEnumerable<T> entity);
|
||||
|
||||
bool BatchInsert(IEnumerable<T> entities, string tableName, params string[] values);
|
||||
bool BatchInsert(IEnumerable<T> entities, string tableName);
|
||||
|
||||
IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func);
|
||||
Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func);
|
||||
|
|
|
@ -68,6 +68,8 @@ namespace Ombi.Store
|
|||
[JsonIgnore]
|
||||
public bool CanApprove => !Approved && !Available;
|
||||
|
||||
public string ReleaseId { get; set; }
|
||||
|
||||
public bool UserHasRequested(string username)
|
||||
{
|
||||
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
|
||||
|
|
|
@ -174,7 +174,10 @@ CREATE TABLE IF NOT EXISTS PlexContent
|
|||
Url VARCHAR(100) NOT NULL,
|
||||
Artist VARCHAR(100),
|
||||
Seasons BLOB,
|
||||
Type INTEGER NOT NULL
|
||||
Type INTEGER NOT NULL,
|
||||
ItemID VARCHAR(100) NOT NULL,
|
||||
|
||||
AddedAt VARCHAR(100) NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS PlexContent_Id ON PlexContent (Id);
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ using Ombi.UI.Modules.Admin;
|
|||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[Ignore("Needs rework")]
|
||||
public class AdminModuleTests
|
||||
{
|
||||
private Mock<ISettingsService<PlexRequestSettings>> PlexRequestMock { get; set; }
|
||||
|
|
|
@ -44,6 +44,7 @@ using Ombi.UI.Modules;
|
|||
namespace Ombi.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[Ignore("Needs rewrite")]
|
||||
public class UserLoginModuleTests
|
||||
{
|
||||
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
||||
|
|
45
Ombi.UI/Content/requests.js
vendored
45
Ombi.UI/Content/requests.js
vendored
|
@ -95,7 +95,10 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
|||
//if ($tvl.mixItUp('isLoaded')) $tvl.mixItUp('destroy');
|
||||
//$tvl.mixItUp(mixItUpConfig(activeState)); // init or reinit
|
||||
}
|
||||
if (target === "#MoviesTab") {
|
||||
if (target === "#MoviesTab" || target === "#ActorsTab") {
|
||||
if (target === "#ActorsTab") {
|
||||
actorLoad();
|
||||
}
|
||||
$('#approveMovies,#deleteMovies').show();
|
||||
if ($tvl.mixItUp('isLoaded')) {
|
||||
activeState = $tvl.mixItUp('getState');
|
||||
|
@ -564,16 +567,21 @@ $(document).on("click", ".change-root-folder", function (e) {
|
|||
e.preventDefault();
|
||||
var $this = $(this);
|
||||
var $button = $this.parents('.btn-split').children('.change').first();
|
||||
var rootFolderId = e.target.id
|
||||
var rootFolderId = e.target.id;
|
||||
var $form = $this.parents('form').first();
|
||||
|
||||
var requestId = $button.attr('id');
|
||||
|
||||
if ($button.text() === " Loading...") {
|
||||
return;
|
||||
}
|
||||
|
||||
loadingButton($button.attr('id'), "success");
|
||||
loadingButton(requestId, "success");
|
||||
|
||||
changeRootFolder($form, rootFolderId, function () {
|
||||
if ($('#' + requestId + "rootPathMain").length) {
|
||||
$('#' + requestId + "currentRootPath").text($this.text);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -733,6 +741,37 @@ function initLoad() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
function actorLoad() {
|
||||
var $ml = $('#actorMovieList');
|
||||
if ($ml.mixItUp('isLoaded')) {
|
||||
activeState = $ml.mixItUp('getState');
|
||||
$ml.mixItUp('destroy');
|
||||
}
|
||||
$ml.html("");
|
||||
|
||||
var $newOnly = $('#searchNewOnly').val();
|
||||
var url = createBaseUrl(base, '/requests/actor' + (!!$newOnly ? '/new' : ''));
|
||||
$.ajax(url).success(function (results) {
|
||||
if (results.length > 0) {
|
||||
results.forEach(function (result) {
|
||||
var context = buildRequestContext(result, "movie");
|
||||
var html = searchTemplate(context);
|
||||
$ml.append(html);
|
||||
});
|
||||
|
||||
|
||||
$('.customTooltip').tooltipster({
|
||||
contentCloning: true
|
||||
});
|
||||
}
|
||||
else {
|
||||
$ml.html(noResultsHtml.format("movie"));
|
||||
}
|
||||
$ml.mixItUp(mixItUpConfig());
|
||||
});
|
||||
};
|
||||
|
||||
function movieLoad() {
|
||||
var $ml = $('#movieList');
|
||||
if ($ml.mixItUp('isLoaded')) {
|
||||
|
|
48
Ombi.UI/Content/search.js
vendored
48
Ombi.UI/Content/search.js
vendored
|
@ -63,6 +63,26 @@ $(function () {
|
|||
|
||||
});
|
||||
|
||||
// Type in actor search
|
||||
$("#actorSearchContent").on("input", function () {
|
||||
triggerActorSearch();
|
||||
});
|
||||
|
||||
// if they toggle the checkbox, we want to refresh our search
|
||||
$("#actorsSearchNew").click(function () {
|
||||
triggerActorSearch();
|
||||
});
|
||||
|
||||
function triggerActorSearch()
|
||||
{
|
||||
if (searchTimer) {
|
||||
clearTimeout(searchTimer);
|
||||
}
|
||||
searchTimer = setTimeout(function () {
|
||||
moviesFromActor();
|
||||
}.bind(this), 800);
|
||||
}
|
||||
|
||||
$('#moviesComingSoon').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
moviesComingSoon();
|
||||
|
@ -300,7 +320,7 @@ $(function () {
|
|||
function movieSearch() {
|
||||
var query = $("#movieSearchContent").val();
|
||||
var url = createBaseUrl(base, '/search/movie/');
|
||||
query ? getMovies(url + query) : resetMovies();
|
||||
query ? getMovies(url + query) : resetMovies("#movieList");
|
||||
}
|
||||
|
||||
function moviesComingSoon() {
|
||||
|
@ -313,6 +333,13 @@ $(function () {
|
|||
getMovies(url);
|
||||
}
|
||||
|
||||
function moviesFromActor() {
|
||||
var query = $("#actorSearchContent").val();
|
||||
var $newOnly = $('#actorsSearchNew')[0].checked;
|
||||
var url = createBaseUrl(base, '/search/actor/' + (!!$newOnly ? 'new/' : ''));
|
||||
query ? getMovies(url + query, "#actorMovieList", "#actorSearchButton") : resetMovies("#actorMovieList");
|
||||
}
|
||||
|
||||
function popularShows() {
|
||||
var url = createBaseUrl(base, '/search/tv/popular');
|
||||
getTvShows(url, true);
|
||||
|
@ -330,30 +357,31 @@ $(function () {
|
|||
getTvShows(url, true);
|
||||
}
|
||||
|
||||
function getMovies(url) {
|
||||
resetMovies();
|
||||
|
||||
$('#movieSearchButton').attr("class", "fa fa-spinner fa-spin");
|
||||
function getMovies(url, target, button) {
|
||||
target = target || "#movieList";
|
||||
button = button || "#movieSearchButton";
|
||||
resetMovies(target);
|
||||
$(button).attr("class", "fa fa-spinner fa-spin");
|
||||
$.ajax(url).success(function (results) {
|
||||
if (results.length > 0) {
|
||||
results.forEach(function (result) {
|
||||
var context = buildMovieContext(result);
|
||||
|
||||
var html = searchTemplate(context);
|
||||
$("#movieList").append(html);
|
||||
$(target).append(html);
|
||||
|
||||
checkNetflix(context.title, context.id);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$("#movieList").html(noResultsHtml);
|
||||
$(target).html(noResultsHtml);
|
||||
}
|
||||
$('#movieSearchButton').attr("class", "fa fa-search");
|
||||
$(button).attr("class", "fa fa-search");
|
||||
});
|
||||
};
|
||||
|
||||
function resetMovies() {
|
||||
$("#movieList").html("");
|
||||
function resetMovies(target) {
|
||||
$(target).html("");
|
||||
}
|
||||
|
||||
function tvSearch() {
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
|
||||
Post["/", true] = async (x, ct) => await SaveAdmin();
|
||||
|
||||
Post["/requestauth"] = _ => RequestAuthToken();
|
||||
Post["/requestauth", true] = async (x, ct) => await RequestAuthToken();
|
||||
|
||||
Get["/getusers"] = _ => GetUsers();
|
||||
|
||||
|
@ -319,7 +319,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
: new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" });
|
||||
}
|
||||
|
||||
private Response RequestAuthToken()
|
||||
private async Task<Response> RequestAuthToken()
|
||||
{
|
||||
var user = this.Bind<PlexAuth>();
|
||||
|
||||
|
@ -335,11 +335,11 @@ namespace Ombi.UI.Modules.Admin
|
|||
return Response.AsJson(new { Result = false, Message = "Incorrect username or password!" });
|
||||
}
|
||||
|
||||
var oldSettings = PlexService.GetSettings();
|
||||
var oldSettings = await PlexService.GetSettingsAsync();
|
||||
if (oldSettings != null)
|
||||
{
|
||||
oldSettings.PlexAuthToken = model.user.authentication_token;
|
||||
PlexService.SaveSettings(oldSettings);
|
||||
await PlexService.SaveSettingsAsync(oldSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -347,10 +347,14 @@ namespace Ombi.UI.Modules.Admin
|
|||
{
|
||||
PlexAuthToken = model.user.authentication_token
|
||||
};
|
||||
PlexService.SaveSettings(newModel);
|
||||
await PlexService.SaveSettingsAsync(newModel);
|
||||
}
|
||||
|
||||
return Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token });
|
||||
var server = PlexApi.GetServer(model.user.authentication_token);
|
||||
var machine =
|
||||
server.Server.FirstOrDefault(x => x.AccessToken == model.user.authentication_token)?.MachineIdentifier;
|
||||
|
||||
return Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token, Identifier = machine });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
|
||||
|
||||
Post["/sonarrrootfolders"] = _ => GetSonarrRootFolders();
|
||||
Post["/radarrrootfolders"] = _ => GetSonarrRootFolders();
|
||||
|
||||
Get["/watcher", true] = async (x, ct) => await Watcher();
|
||||
Post["/watcher", true] = async (x, ct) => await SaveWatcher();
|
||||
|
@ -191,7 +192,22 @@ namespace Ombi.UI.Modules.Admin
|
|||
{
|
||||
var settings = this.Bind<SonarrSettings>();
|
||||
|
||||
var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
|
||||
// set the cache
|
||||
if (rootFolders != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.SonarrRootFolders, rootFolders);
|
||||
}
|
||||
|
||||
return Response.AsJson(rootFolders);
|
||||
}
|
||||
|
||||
private Response GetRadarrRootFolders()
|
||||
{
|
||||
var settings = this.Bind<RadarrSettings>();
|
||||
|
||||
var rootFolders = RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
|
||||
// set the cache
|
||||
if (rootFolders != null)
|
||||
|
|
|
@ -94,6 +94,8 @@ namespace Ombi.UI.Modules.Admin
|
|||
|
||||
private async Task<Response> ScheduleRun(string key)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
if (key.Equals(JobNames.PlexCacher, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
PlexContentCacher.CacheContent();
|
||||
|
|
|
@ -40,12 +40,15 @@ namespace Ombi.UI.Modules
|
|||
public class LandingPageModule : BaseModule
|
||||
{
|
||||
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing,
|
||||
ISettingsService<PlexSettings> ps, IPlexApi pApi, IResourceLinker linker, ISecurityExtensions security) : base("landing", settingsService, security)
|
||||
ISettingsService<PlexSettings> ps, IPlexApi pApi, IResourceLinker linker, ISecurityExtensions security, ISettingsService<EmbySettings> emby,
|
||||
IEmbyApi embyApi) : base("landing", settingsService, security)
|
||||
{
|
||||
LandingSettings = landing;
|
||||
PlexSettings = ps;
|
||||
PlexApi = pApi;
|
||||
Linker = linker;
|
||||
EmbySettings = emby;
|
||||
EmbyApi = embyApi;
|
||||
|
||||
Get["LandingPageIndex","/", true] = async (x, ct) =>
|
||||
{
|
||||
|
@ -75,26 +78,49 @@ namespace Ombi.UI.Modules
|
|||
|
||||
private ISettingsService<LandingPageSettings> LandingSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private IEmbyApi EmbyApi { get; }
|
||||
private IResourceLinker Linker { get; }
|
||||
|
||||
private async Task<Response> CheckStatus()
|
||||
{
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip))
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
return Response.AsJson(status != null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip))
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
return Response.AsJson(status != null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
}
|
||||
|
||||
var emby = await EmbySettings.GetSettingsAsync();
|
||||
if (emby.Enable)
|
||||
{
|
||||
if (string.IsNullOrEmpty(emby.AdministratorId) || string.IsNullOrEmpty(emby.Ip))
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = EmbyApi.GetSystemInformation(emby.ApiKey, emby.FullUri);
|
||||
return Response.AsJson(status?.Version != null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
}
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -69,7 +69,9 @@ namespace Ombi.UI.Modules
|
|||
IEmbyNotificationEngine embyEngine,
|
||||
ISecurityExtensions security,
|
||||
ISettingsService<CustomizationSettings> customSettings,
|
||||
ISettingsService<EmbySettings> embyS) : base("requests", prSettings, security)
|
||||
ISettingsService<EmbySettings> embyS,
|
||||
ISettingsService<RadarrSettings> radarr,
|
||||
IRadarrApi radarrApi) : base("requests", prSettings, security)
|
||||
{
|
||||
Service = service;
|
||||
PrSettings = prSettings;
|
||||
|
@ -87,6 +89,8 @@ namespace Ombi.UI.Modules
|
|||
EmbyNotificationEngine = embyEngine;
|
||||
CustomizationSettings = customSettings;
|
||||
EmbySettings = embyS;
|
||||
Radarr = radarr;
|
||||
RadarrApi = radarrApi;
|
||||
|
||||
Get["/", true] = async (x, ct) => await LoadRequests();
|
||||
Get["/movies", true] = async (x, ct) => await GetMovies();
|
||||
|
@ -115,8 +119,10 @@ namespace Ombi.UI.Modules
|
|||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||||
private ISettingsService<RadarrSettings> Radarr { get; }
|
||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private IRadarrApi RadarrApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
|
@ -144,28 +150,58 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
|
||||
List<QualityModel> qualities = new List<QualityModel>();
|
||||
var rootFolders = new List<RootFolderModel>();
|
||||
|
||||
var radarr = await Radarr.GetSettingsAsync();
|
||||
if (IsAdmin)
|
||||
{
|
||||
var cpSettings = CpSettings.GetSettings();
|
||||
if (cpSettings.Enabled)
|
||||
try
|
||||
{
|
||||
try
|
||||
var cpSettings = await CpSettings.GetSettingsAsync();
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
try
|
||||
{
|
||||
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
||||
});
|
||||
if (result != null)
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
{
|
||||
return
|
||||
await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey))
|
||||
.ConfigureAwait(false);
|
||||
});
|
||||
if (result != null)
|
||||
{
|
||||
qualities =
|
||||
result.list.Select(x => new QualityModel {Id = x._id, Name = x.label}).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
qualities = result.list.Select(x => new QualityModel { Id = x._id, Name = x.label }).ToList();
|
||||
Log.Info(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
if (radarr.Enabled)
|
||||
{
|
||||
Log.Info(e);
|
||||
var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetRootFolders(radarr.ApiKey, radarr.FullUri));
|
||||
});
|
||||
|
||||
rootFolders =
|
||||
rootFoldersResult.Select(
|
||||
x => new RootFolderModel {Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace})
|
||||
.ToList();
|
||||
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.RadarrQualityProfiles, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetProfiles(radarr.ApiKey, radarr.FullUri));
|
||||
});
|
||||
qualities = result.Select(x => new QualityModel { Id = x.id.ToString(), Name = x.name }).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,6 +230,9 @@ namespace Ombi.UI.Modules
|
|||
Denied = movie.Denied,
|
||||
DeniedReason = movie.DeniedReason,
|
||||
Qualities = qualities.ToArray(),
|
||||
HasRootFolders = rootFolders.Any(),
|
||||
RootFolders = rootFolders.ToArray(),
|
||||
CurrentRootPath = radarr.Enabled ? GetRootPath(movie.RootFolderSelected, radarr).Result : null
|
||||
}).ToList();
|
||||
|
||||
return Response.AsJson(viewModel);
|
||||
|
@ -260,7 +299,7 @@ namespace Ombi.UI.Modules
|
|||
Status = tv.Status,
|
||||
ImdbId = tv.ImdbId,
|
||||
Id = tv.Id,
|
||||
PosterPath = tv.PosterPath.Contains("http:") ? tv.PosterPath.Replace("http:", "https:") : tv.PosterPath, // We make the poster path https on request, but this is just incase
|
||||
PosterPath = tv.PosterPath?.Contains("http:") ?? false ? tv.PosterPath?.Replace("http:", "https:") : tv.PosterPath ?? string.Empty, // We make the poster path https on request, but this is just incase
|
||||
ReleaseDate = tv.ReleaseDate,
|
||||
ReleaseDateTicks = tv.ReleaseDate.Ticks,
|
||||
RequestedDate = tv.RequestedDate,
|
||||
|
@ -313,6 +352,32 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetRootPath(int pathId, RadarrSettings radarrSettings)
|
||||
{
|
||||
var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetRootFolders(radarrSettings.ApiKey, radarrSettings.FullUri));
|
||||
});
|
||||
|
||||
foreach (var r in rootFoldersResult.Where(r => r.id == pathId))
|
||||
{
|
||||
return r.path;
|
||||
}
|
||||
|
||||
int outRoot;
|
||||
var defaultPath = int.TryParse(radarrSettings.RootPath, out outRoot);
|
||||
|
||||
if (defaultPath)
|
||||
{
|
||||
// Return default path
|
||||
return rootFoldersResult.FirstOrDefault(x => x.id.Equals(outRoot))?.path ?? string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rootFoldersResult.FirstOrDefault()?.path ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Response> GetAlbumRequests()
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace Ombi.UI.Modules
|
|||
|
||||
public async Task<Response> Netflix(string title)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var result = NetflixApi.CheckNetflix(title);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Message))
|
||||
|
|
|
@ -121,6 +121,8 @@ namespace Ombi.UI.Modules
|
|||
|
||||
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
|
||||
|
||||
Get["actor/{searchTerm}", true] = async (x, ct) => await SearchPerson((string)x.searchTerm);
|
||||
Get["actor/new/{searchTerm}", true] = async (x, ct) => await SearchPerson((string)x.searchTerm, true);
|
||||
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
||||
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
||||
Get["music/{searchTerm}", true] = async (x, ct) => await SearchAlbum((string)x.searchTerm);
|
||||
|
@ -182,9 +184,18 @@ namespace Ombi.UI.Modules
|
|||
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private long _plexMovieCacheTime = 0;
|
||||
private IEnumerable<PlexContent> _plexMovies = null;
|
||||
|
||||
private long _embyMovieCacheTime = 0;
|
||||
private IEnumerable<EmbyContent> _embyMovies = null;
|
||||
|
||||
|
||||
private long _dbMovieCacheTime = 0;
|
||||
private Dictionary<int, RequestedModel> _dbMovies = null;
|
||||
|
||||
private async Task<Negotiator> RequestLoad()
|
||||
{
|
||||
|
||||
var settings = await PrService.GetSettingsAsync();
|
||||
var custom = await CustomizationSettings.GetSettingsAsync();
|
||||
var emby = await EmbySettings.GetSettingsAsync();
|
||||
|
@ -222,6 +233,53 @@ namespace Ombi.UI.Modules
|
|||
return await ProcessMovies(MovieSearchType.Search, searchTerm);
|
||||
}
|
||||
|
||||
private async Task<Response> SearchPerson(string searchTerm)
|
||||
{
|
||||
var movies = TransformMovieListToMovieResultList(await MovieApi.SearchPerson(searchTerm));
|
||||
return await TransformMovieResultsToResponse(movies);
|
||||
}
|
||||
|
||||
private async Task<Response> SearchPerson(string searchTerm, bool filterExisting)
|
||||
{
|
||||
var movies = TransformMovieListToMovieResultList(await MovieApi.SearchPerson(searchTerm, AlreadyAvailable));
|
||||
return await TransformMovieResultsToResponse(movies);
|
||||
}
|
||||
|
||||
private async Task<bool> AlreadyAvailable(int id, string title, string year)
|
||||
{
|
||||
var plexSettings = await PlexService.GetSettingsAsync();
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
|
||||
return IsMovieInCache(id, String.Empty) ||
|
||||
(plexSettings.Enable && PlexChecker.IsMovieAvailable(PlexMovies(), title, year)) ||
|
||||
(embySettings.Enable && EmbyChecker.IsMovieAvailable(EmbyMovies(), title, year, String.Empty));
|
||||
}
|
||||
|
||||
private IEnumerable<PlexContent> PlexMovies()
|
||||
{ long now = DateTime.Now.Ticks;
|
||||
if(_plexMovies == null || (now - _plexMovieCacheTime) > 10000)
|
||||
{
|
||||
var content = PlexContentRepository.GetAll();
|
||||
_plexMovies = PlexChecker.GetPlexMovies(content);
|
||||
_plexMovieCacheTime = now;
|
||||
}
|
||||
|
||||
return _plexMovies;
|
||||
}
|
||||
|
||||
private IEnumerable<EmbyContent> EmbyMovies()
|
||||
{
|
||||
long now = DateTime.Now.Ticks;
|
||||
if (_embyMovies == null || (now - _embyMovieCacheTime) > 10000)
|
||||
{
|
||||
var content = EmbyContentRepository.GetAll();
|
||||
_embyMovies = EmbyChecker.GetEmbyMovies(content);
|
||||
_embyMovieCacheTime = now;
|
||||
}
|
||||
|
||||
return _embyMovies;
|
||||
}
|
||||
|
||||
private Response GetTvPoster(int theTvDbId)
|
||||
{
|
||||
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||||
|
@ -233,15 +291,10 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
return banner;
|
||||
}
|
||||
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||||
{
|
||||
List<MovieResult> apiMovies;
|
||||
|
||||
switch (searchType)
|
||||
{
|
||||
case MovieSearchType.Search:
|
||||
var movies = await MovieApi.SearchMovie(searchTerm).ConfigureAwait(false);
|
||||
apiMovies = movies.Select(x =>
|
||||
private List<MovieResult> TransformSearchMovieListToMovieResultList(List<TMDbLib.Objects.Search.SearchMovie> searchMovies)
|
||||
{
|
||||
return searchMovies.Select(x =>
|
||||
new MovieResult
|
||||
{
|
||||
Adult = x.Adult,
|
||||
|
@ -260,6 +313,39 @@ namespace Ombi.UI.Modules
|
|||
VoteCount = x.VoteCount
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private List<MovieResult> TransformMovieListToMovieResultList(List<TMDbLib.Objects.Movies.Movie> movies)
|
||||
{
|
||||
return movies.Select(x =>
|
||||
new MovieResult
|
||||
{
|
||||
Adult = x.Adult,
|
||||
BackdropPath = x.BackdropPath,
|
||||
GenreIds = x.Genres.Select(y => y.Id).ToList(),
|
||||
Id = x.Id,
|
||||
OriginalLanguage = x.OriginalLanguage,
|
||||
OriginalTitle = x.OriginalTitle,
|
||||
Overview = x.Overview,
|
||||
Popularity = x.Popularity,
|
||||
PosterPath = x.PosterPath,
|
||||
ReleaseDate = x.ReleaseDate,
|
||||
Title = x.Title,
|
||||
Video = x.Video,
|
||||
VoteAverage = x.VoteAverage,
|
||||
VoteCount = x.VoteCount
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||||
{
|
||||
List<MovieResult> apiMovies;
|
||||
|
||||
switch (searchType)
|
||||
{
|
||||
case MovieSearchType.Search:
|
||||
var movies = await MovieApi.SearchMovie(searchTerm).ConfigureAwait(false);
|
||||
apiMovies = TransformSearchMovieListToMovieResultList(movies);
|
||||
break;
|
||||
case MovieSearchType.CurrentlyPlaying:
|
||||
apiMovies = await MovieApi.GetCurrentPlayingMovies();
|
||||
|
@ -272,20 +358,31 @@ namespace Ombi.UI.Modules
|
|||
break;
|
||||
}
|
||||
|
||||
var allResults = await RequestService.GetAllAsync();
|
||||
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||||
return await TransformMovieResultsToResponse(apiMovies);
|
||||
}
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
var dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
private async Task<Dictionary<int, RequestedModel>> RequestedMovies()
|
||||
{
|
||||
long now = DateTime.Now.Ticks;
|
||||
if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000)
|
||||
{
|
||||
var allResults = await RequestService.GetAllAsync();
|
||||
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
_dbMovieCacheTime = now;
|
||||
}
|
||||
return _dbMovies;
|
||||
}
|
||||
|
||||
var cpCached = CpCacher.QueuedIds();
|
||||
var watcherCached = WatcherCacher.QueuedIds();
|
||||
var radarrCached = RadarrCacher.QueuedIds();
|
||||
|
||||
private async Task<Response> TransformMovieResultsToResponse(List<MovieResult> movies)
|
||||
{
|
||||
await Task.Yield();
|
||||
var viewMovies = new List<SearchMovieViewModel>();
|
||||
var counter = 0;
|
||||
foreach (var movie in apiMovies)
|
||||
Dictionary<int, RequestedModel> dbMovies = await RequestedMovies();
|
||||
foreach (var movie in movies)
|
||||
{
|
||||
var viewMovie = new SearchMovieViewModel
|
||||
{
|
||||
|
@ -354,7 +451,7 @@ namespace Ombi.UI.Modules
|
|||
viewMovie.Available = true;
|
||||
}
|
||||
}
|
||||
else if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db
|
||||
if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db
|
||||
{
|
||||
var dbm = dbMovies[movie.Id];
|
||||
|
||||
|
@ -362,20 +459,11 @@ namespace Ombi.UI.Modules
|
|||
viewMovie.Approved = dbm.Approved;
|
||||
viewMovie.Available = dbm.Available;
|
||||
}
|
||||
else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db
|
||||
else if (canSee)
|
||||
{
|
||||
viewMovie.Approved = true;
|
||||
viewMovie.Requested = true;
|
||||
}
|
||||
else if (watcherCached.Contains(viewMovie.ImdbId) && canSee) // compare to the watcher db
|
||||
{
|
||||
viewMovie.Approved = true;
|
||||
viewMovie.Requested = true;
|
||||
}
|
||||
else if (radarrCached.Contains(movie.Id) && canSee)
|
||||
{
|
||||
viewMovie.Approved = true;
|
||||
viewMovie.Requested = true;
|
||||
bool exists = IsMovieInCache(movie, viewMovie.ImdbId);
|
||||
viewMovie.Approved = exists;
|
||||
viewMovie.Requested = exists;
|
||||
}
|
||||
viewMovies.Add(viewMovie);
|
||||
}
|
||||
|
@ -383,6 +471,19 @@ namespace Ombi.UI.Modules
|
|||
return Response.AsJson(viewMovies);
|
||||
}
|
||||
|
||||
private bool IsMovieInCache(MovieResult movie, string imdbId)
|
||||
{ int id = movie.Id;
|
||||
return IsMovieInCache(id, imdbId);
|
||||
}
|
||||
|
||||
private bool IsMovieInCache(int id, string imdbId)
|
||||
{ var cpCached = CpCacher.QueuedIds();
|
||||
var watcherCached = WatcherCacher.QueuedIds();
|
||||
var radarrCached = RadarrCacher.QueuedIds();
|
||||
|
||||
return cpCached.Contains(id) || watcherCached.Contains(imdbId) || radarrCached.Contains(id);
|
||||
}
|
||||
|
||||
private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests,
|
||||
Dictionary<int, RequestedModel> moviesInDb)
|
||||
{
|
||||
|
@ -437,6 +538,11 @@ namespace Ombi.UI.Modules
|
|||
{
|
||||
var show = anticipatedShow.Show;
|
||||
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||||
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||||
if (result == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var model = new SearchTvShowViewModel
|
||||
{
|
||||
|
@ -466,6 +572,12 @@ namespace Ombi.UI.Modules
|
|||
{
|
||||
var show = watched.Show;
|
||||
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||||
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||||
if (result == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var model = new SearchTvShowViewModel
|
||||
{
|
||||
FirstAired = show.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||
|
@ -494,6 +606,12 @@ namespace Ombi.UI.Modules
|
|||
{
|
||||
var show = watched.Show;
|
||||
var theTvDbId = int.Parse(show.Ids.Tvdb.ToString());
|
||||
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
||||
if (result == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var model = new SearchTvShowViewModel
|
||||
{
|
||||
FirstAired = show.FirstAired?.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||
|
@ -1395,6 +1513,7 @@ namespace Ombi.UI.Modules
|
|||
{
|
||||
Title = albumInfo.title,
|
||||
MusicBrainzId = albumInfo.id,
|
||||
ReleaseId = releaseId,
|
||||
Overview = albumInfo.disambiguation,
|
||||
PosterPath = img,
|
||||
Type = RequestType.Album,
|
||||
|
|
|
@ -67,6 +67,7 @@ namespace Ombi.UI.NinjectModules
|
|||
Bind<IEmbyEpisodeCacher>().To<EmbyEpisodeCacher>();
|
||||
Bind<IEmbyUserChecker>().To<EmbyUserChecker>();
|
||||
Bind<IEmbyAddedNewsletter>().To<EmbyAddedNewsletter>();
|
||||
Bind<IPlexNewsletter>().To<PlexRecentlyAddedNewsletter>();
|
||||
|
||||
|
||||
Bind<IAnalytics>().To<Analytics>();
|
||||
|
|
|
@ -1,76 +1,96 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 1.3
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">1.3</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1">this is my long string</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
[base64 mime encoded serialized .NET Framework object]
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
[base64 mime encoded string representing a byte array form of the .NET Framework object]
|
||||
</data>
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
|
@ -89,13 +109,13 @@
|
|||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="UserLogin_Title" xml:space="preserve">
|
||||
<value>Login</value>
|
||||
|
@ -191,6 +211,9 @@
|
|||
<data name="Search_Albums" xml:space="preserve">
|
||||
<value>Albums</value>
|
||||
</data>
|
||||
<data name="Search_NewOnly" xml:space="preserve">
|
||||
<value>Don't include titles that are already requested/available</value>
|
||||
</data>
|
||||
<data name="Search_Paragraph" xml:space="preserve">
|
||||
<value>Want to watch something that is not currently on {0}?! No problem! Just search for it below and request it!</value>
|
||||
</data>
|
||||
|
@ -473,4 +496,7 @@
|
|||
<data name="UserLogin_AdminUsePassword" xml:space="preserve">
|
||||
<value>If you are an administrator, please use the other login page</value>
|
||||
</data>
|
||||
<data name="Search_Actors" xml:space="preserve">
|
||||
<value>Actors</value>
|
||||
</data>
|
||||
</root>
|
18
Ombi.UI/Resources/UI1.Designer.cs
generated
18
Ombi.UI/Resources/UI1.Designer.cs
generated
|
@ -717,6 +717,15 @@ namespace Ombi.UI.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Actors.
|
||||
/// </summary>
|
||||
public static string Search_Actors {
|
||||
get {
|
||||
return ResourceManager.GetString("Search_Actors", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Albums.
|
||||
/// </summary>
|
||||
|
@ -879,6 +888,15 @@ namespace Ombi.UI.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Don't include titles that are already requested/available.
|
||||
/// </summary>
|
||||
public static string Search_NewOnly {
|
||||
get {
|
||||
return ResourceManager.GetString("Search_NewOnly", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Not Requested yet.
|
||||
/// </summary>
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Ombi.UI.Validators
|
|||
RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key.");
|
||||
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
|
||||
RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port.");
|
||||
RuleFor(request => request.QualityProfile).NotEmpty().WithMessage("You must specify a Quality Profile.");
|
||||
RuleFor(request => request.QualityProfile).NotEmpty().NotNull().WithMessage("You must specify a Quality Profile.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -222,6 +222,7 @@
|
|||
if (response.result === true) {
|
||||
generateNotify("Success!", "success");
|
||||
$('#authToken').val(response.authToken);
|
||||
$('#MachineIdentifier').val(response.identifier);
|
||||
} else {
|
||||
generateNotify(response.message, "warning");
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
|
||||
@Html.Checkbox(Model.SearchForMovies,"SearchForMovies","Search for Movies")
|
||||
|
||||
@Html.Checkbox(Model.SearchForActors,"SearchForActors","Search for Movies by Actor")
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
|
|
|
@ -103,13 +103,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
@*<div class="form-group">
|
||||
<label for="RootPath" class="control-label">Root save directory for TV shows</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " placeholder="C:\Media\Tv" id="RootPath" name="RootPath" value="@Model.RootPath">
|
||||
<label>Enter the root folder where tv shows are saved. For example <strong>C:\Media\TV</strong>.</label>
|
||||
</div>
|
||||
</div>*@
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
|
|
|
@ -11,11 +11,20 @@
|
|||
{
|
||||
port = Model.Port;
|
||||
}
|
||||
|
||||
var rootFolder = string.Empty;
|
||||
if (!string.IsNullOrEmpty(Model.RootPath))
|
||||
|
||||
{
|
||||
rootFolder = Model.RootPath.Replace("/", "//");
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
<form class="form-horizontal" method="POST" id="mainForm">
|
||||
<fieldset>
|
||||
<legend>Radarr Settings</legend>
|
||||
|
||||
<input hidden="hidden" name="FullRootPath" id="fullRootPath" value="@Model.FullRootPath" />
|
||||
@Html.Checkbox(Model.Enabled, "Enabled", "Enabled")
|
||||
|
||||
|
||||
|
@ -64,10 +73,17 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="RootPath" class="control-label">Root save directory for Movies</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " placeholder="C:\Media\Movies" id="RootPath" name="RootPath" value="@Model.RootPath">
|
||||
<label>Enter the root folder where movies are saved. For example <strong>C:\Media\Movies</strong>.</label>
|
||||
<button type="submit" id="getRootFolders" class="btn btn-primary-outline">Get Root Folders <div id="getRootFolderSpinner" /></button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="selectRootFolder" class="control-label">Default Root Folders</label>
|
||||
<div id="rootFolders">
|
||||
<select class="form-control form-control-custom" id="selectRootFolder"></select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -128,6 +144,39 @@
|
|||
}
|
||||
</text>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(Model.RootPath))
|
||||
{
|
||||
<text>
|
||||
|
||||
console.log('Hit root folders..');
|
||||
|
||||
var rootFolderSelected = '@rootFolder';
|
||||
if (!rootFolderSelected) {
|
||||
return;
|
||||
}
|
||||
var $form = $("#mainForm");
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: $form.serialize(),
|
||||
url: "sonarrrootfolders",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
response.forEach(function(result) {
|
||||
$('#selectedRootFolder').html("");
|
||||
if (result.id == rootFolderSelected) {
|
||||
$("#selectRootFolder").append("<option selected='selected' value='" + result.id + "'>" + result.path + "</option>");
|
||||
} else {
|
||||
$("#selectRootFolder").append("<option value='" + result.id + "'>" + result.path + "</option>");
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
</text>
|
||||
}
|
||||
|
||||
|
||||
$('#save').click(function(e) {
|
||||
|
@ -138,11 +187,14 @@
|
|||
return;
|
||||
}
|
||||
var qualityProfile = $("#profiles option:selected").val();
|
||||
var rootFolder = $("#rootFolders option:selected").val();
|
||||
var rootFolderPath = $('#rootFolders option:selected').text();
|
||||
$('#fullRootPath').val(rootFolderPath);
|
||||
|
||||
var $form = $("#mainForm");
|
||||
|
||||
var data = $form.serialize();
|
||||
data = data + "&qualityProfile=" + qualityProfile;
|
||||
data = data + "&qualityProfile=" + qualityProfile + "&rootPath=" + rootFolder;
|
||||
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
|
@ -202,6 +254,45 @@
|
|||
});
|
||||
});
|
||||
|
||||
$('#getRootFolders').click(function (e) {
|
||||
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-spinner fa-spin");
|
||||
e.preventDefault();
|
||||
if (!$('#Ip').val()) {
|
||||
generateNotify("Please enter a valid IP/Hostname.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
if (!$('#portNumber').val()) {
|
||||
generateNotify("Please enter a valid Port Number.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
if (!$('#ApiKey').val()) {
|
||||
generateNotify("Please enter a valid ApiKey.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
var $form = $("#mainForm");
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: $form.serialize(),
|
||||
url: "radarrrootfolders",
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
response.forEach(function (result) {
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-check");
|
||||
$("#selectRootFolder").append("<option value='" + result.id + "'>" + result.path + "</option>");
|
||||
});
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
$('#testRadarr').click(function (e) {
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@
|
|||
<div>@UI.Requests_RequestedDate: {{requestedDate}}</div>
|
||||
{{#if admin}}
|
||||
{{#if currentRootPath}}
|
||||
<div>Root Path: {{currentRootPath}}</div>
|
||||
<div class="{{requestId}}rootPathMain">Root Path: <span id="{{requestId}}currentRootPath">{{currentRootPath}}</span></div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<div>
|
||||
|
@ -285,14 +285,14 @@
|
|||
<input name="requestId" type="text" value="{{requestId}}" hidden="hidden" />
|
||||
{{#if_eq hasRootFolders true}}
|
||||
<div class="btn-group btn-split">
|
||||
<button type="button" class="btn btn-sm btn-success-outline approve" id="{{requestId}}" custom-button="{{requestId}}">@*<i class="fa fa-plus"></i>*@ Change Root Folder</button>
|
||||
<button type="button" class="btn btn-sm btn-success-outline" id="changeRootFolderBtn{{requestId}}" custom-button="{{requestId}}">@*<i class="fa fa-plus"></i>*@ Change Root Folder</button>
|
||||
<button type="button" class="btn btn-success-outline dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="caret"></span>
|
||||
<span class="sr-only">@UI.Requests_ToggleDropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{{#each rootFolders}}
|
||||
<li><a href="#" class="change-root-folder" id="{{id}}">{{path}}</a></li>
|
||||
<li><a href="#" class="change-root-folder" id="{{id}}" requestId="{{requestId}}">{{path}}</a></li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -27,6 +27,13 @@
|
|||
<a id="movieTabButton" href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab"><i class="fa fa-film"></i> @UI.Search_Movies</a>
|
||||
|
||||
</li>
|
||||
@if (Model.Settings.SearchForActors)
|
||||
{
|
||||
<li role="presentation">
|
||||
<a id="actorTabButton" href="#ActorsTab" aria-controls="profile" role="tab" data-toggle="tab"><i class="fa fa-users"></i> @UI.Search_Actors</a>
|
||||
|
||||
</li>
|
||||
}
|
||||
}
|
||||
@if (Model.Settings.SearchForTvShows)
|
||||
{
|
||||
|
@ -72,8 +79,28 @@
|
|||
<div id="movieList">
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (Model.Settings.SearchForActors)
|
||||
{
|
||||
<!-- Actors tab -->
|
||||
<div role="tabpanel" class="tab-pane" id="ActorsTab">
|
||||
<div class="input-group">
|
||||
<input id="actorSearchContent" type="text" class="form-control form-control-custom form-control-search form-control-withbuttons">
|
||||
<div class="input-group-addon">
|
||||
<i id="actorSearchButton" class="fa fa-search"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<input type="checkbox" id="actorsSearchNew" name="actorsSearchNew"><label for="actorsSearchNew">@UI.Search_NewOnly</label>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<!-- Movie content -->
|
||||
<div id="actorMovieList">
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@if (Model.Settings.SearchForTvShows)
|
||||
{
|
||||
|
@ -123,7 +150,7 @@
|
|||
}
|
||||
|
||||
|
||||
<script id="search-templateNew" type="text/x-handlebars-template">
|
||||
<script id="search-templateNew" type="text/x-handlebars-template">
|
||||
<div class="row">
|
||||
<div id="{{id}}imgDiv" class="col-sm-2">
|
||||
|
||||
|
@ -287,7 +314,7 @@
|
|||
</script>
|
||||
|
||||
<!-- Movie and TV Results template -->
|
||||
<script id="search-template" type="text/x-handlebars-template">
|
||||
<script id="search-template" type="text/x-handlebars-template">
|
||||
<div class="row">
|
||||
<div id="{{id}}imgDiv" class="col-sm-2">
|
||||
|
||||
|
@ -379,7 +406,7 @@
|
|||
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> @UI.Search_Available</button><br />
|
||||
{{else}}
|
||||
{{#if_eq enableTvRequestsForOnlySeries true}}
|
||||
<button id="{{id}}" style="text-align: right" class="btn {{#if available}}btn-success-outline{{else}}btn-primary-outline{{/if}} btn-primary-outline dropdownTv" season-select="0" type="button"><i class="fa fa-plus"></i> @UI.Search_Request</button>
|
||||
<button id="{{id}}" style="text-align: right" class="btn {{#if available}}btn-success-outline{{else}}btn-primary-outline dropdownTv{{/if}} btn-primary-outline" season-select="0" type="button" {{#if available}}disabled{{/if}}><i class="fa fa-plus"></i> {{#if available}}@UI.Search_Available{{else}}@UI.Search_Request{{/if}}</button>
|
||||
{{else}}
|
||||
<div class="dropdown">
|
||||
<button id="{{id}}" class="btn {{#if available}}btn-success-outline{{else}}btn-primary-outline{{/if}} dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
|
|
35
Ombi.Updater/AppType.cs
Normal file
35
Ombi.Updater/AppType.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: AppType.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
namespace Ombi.Updater
|
||||
{
|
||||
public enum AppType
|
||||
{
|
||||
Normal,
|
||||
Console,
|
||||
Service
|
||||
}
|
||||
}
|
39
Ombi.Updater/DetectApplicationType.cs
Normal file
39
Ombi.Updater/DetectApplicationType.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using Ombi.Common;
|
||||
using Ombi.Common.EnvironmentInfo;
|
||||
using Ombi.Common.Processes;
|
||||
|
||||
namespace Ombi.Updater
|
||||
{
|
||||
public class DetectApplicationType
|
||||
{
|
||||
public DetectApplicationType()
|
||||
{
|
||||
_processProvider = new ProcessProvider();
|
||||
_serviceProvider = new ServiceProvider(_processProvider);
|
||||
}
|
||||
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
public AppType GetAppType()
|
||||
{
|
||||
if (OsInfo.IsNotWindows)
|
||||
{
|
||||
// Technically it is the console, but it has been renamed for mono (Linux/OS X)
|
||||
return AppType.Normal;
|
||||
}
|
||||
|
||||
if (_serviceProvider.ServiceExist(ServiceProvider.OmbiServiceName)
|
||||
)
|
||||
{
|
||||
return AppType.Service;
|
||||
}
|
||||
|
||||
if (_processProvider.Exists(ProcessProvider.OmbiProcessName))
|
||||
{
|
||||
return AppType.Console;
|
||||
}
|
||||
|
||||
return AppType.Normal;
|
||||
}
|
||||
}
|
||||
}
|
57
Ombi.Updater/InstallService.cs
Normal file
57
Ombi.Updater/InstallService.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: InstallService.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using Ombi.Common;
|
||||
using Ombi.Common.EnvironmentInfo;
|
||||
using Ombi.Common.Processes;
|
||||
|
||||
namespace Ombi.Updater
|
||||
{
|
||||
public class InstallService
|
||||
{
|
||||
public void Start(string installFolder)
|
||||
{
|
||||
var dector = new DetectApplicationType();
|
||||
var processProvider = new ProcessProvider();
|
||||
|
||||
var processId = processProvider.FindProcessByName(ProcessProvider.OmbiProcessName)?.FirstOrDefault()?.Id ?? -1;
|
||||
|
||||
// Log if process is -1
|
||||
|
||||
var appType = dector.GetAppType();
|
||||
processProvider.FindProcessByName(ProcessProvider.OmbiProcessName);
|
||||
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
var terminator = new TerminateOmbi(new ServiceProvider(processProvider), processProvider);
|
||||
terminator.Terminate(processId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<OutputPath>bin\Debug\Updater\</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
@ -22,12 +22,15 @@
|
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<OutputPath>bin\Release\Updater\</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Polly, Version=4.3.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Polly-Signed.4.3.0\lib\net45\Polly.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -38,12 +41,20 @@
|
|||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppType.cs" />
|
||||
<Compile Include="DetectApplicationType.cs" />
|
||||
<Compile Include="InstallService.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TerminateOmbi.cs" />
|
||||
<Compile Include="Updater.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Common\Ombi.Common.csproj">
|
||||
<Project>{bfd45569-90cf-47ca-b575-c7b0ff97f67b}</Project>
|
||||
<Name>Ombi.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj">
|
||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||
<Name>Ombi.Core</Name>
|
||||
|
|
88
Ombi.Updater/TerminateOmbi.cs
Normal file
88
Ombi.Updater/TerminateOmbi.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: TerminateOmbi.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NLog;
|
||||
using Ombi.Common;
|
||||
using Ombi.Common.EnvironmentInfo;
|
||||
using Ombi.Common.Processes;
|
||||
using IServiceProvider = Ombi.Common.IServiceProvider;
|
||||
|
||||
namespace Ombi.Updater
|
||||
{
|
||||
public interface ITerminateOmbi
|
||||
{
|
||||
void Terminate(int processId);
|
||||
}
|
||||
|
||||
public class TerminateOmbi : ITerminateOmbi
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IProcessProvider _processProvider;
|
||||
|
||||
private static Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public TerminateOmbi(IServiceProvider serviceProvider, IProcessProvider processProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_processProvider = processProvider;
|
||||
}
|
||||
|
||||
public void Terminate(int processId)
|
||||
{
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
_logger.Info("Stopping all running services");
|
||||
|
||||
if (_serviceProvider.ServiceExist(ServiceProvider.OmbiServiceName))
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.Info("NzbDrone Service is installed and running");
|
||||
_serviceProvider.Stop(ServiceProvider.OmbiServiceName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "couldn't stop service");
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info("Killing all running processes");
|
||||
|
||||
_processProvider.KillAll(ProcessProvider.OmbiProcessName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Info("Killing all running processes");
|
||||
|
||||
_processProvider.KillAll(ProcessProvider.OmbiProcessName);
|
||||
|
||||
_processProvider.Kill(processId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.3.6" targetFramework="net45" />
|
||||
<package id="Polly-Signed" version="4.3.0" targetFramework="net45" />
|
||||
</packages>
|
10
Ombi.sln
10
Ombi.sln
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26206.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.UI", "Ombi.UI\Ombi.UI.csproj", "{68F5F5F3-B8BB-4911-875F-6F00AAE04EA6}"
|
||||
EndProject
|
||||
|
@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Helpers.Tests", "Ombi.
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Core.Migration", "Ombi.Core.Migration\Ombi.Core.Migration.csproj", "{8406EE57-D533-47C0-9302-C6B5F8C31E55}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Common", "Ombi.Common\Ombi.Common.csproj", "{BFD45569-90CF-47CA-B575-C7B0FF97F67B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -97,6 +99,10 @@ Global
|
|||
{8406EE57-D533-47C0-9302-C6B5F8C31E55}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8406EE57-D533-47C0-9302-C6B5F8C31E55}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8406EE57-D533-47C0-9302-C6B5F8C31E55}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BFD45569-90CF-47CA-B575-C7B0FF97F67B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BFD45569-90CF-47CA-B575-C7B0FF97F67B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BFD45569-90CF-47CA-B575-C7B0FF97F67B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BFD45569-90CF-47CA-B575-C7B0FF97F67B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
16
README.md
16
README.md
|
@ -8,20 +8,20 @@ ____
|
|||
[](https://github.com/tidusjar/Ombi)
|
||||
[](http://waffle.io/tidusjar/Ombi)
|
||||
|
||||
[](https://github.com/tidusjar/Ombi/issues/new) [](http://feathub.com/tidusjar/Ombi)
|
||||
|
||||
| Service | Master | Early Access | Dev |
|
||||
|----------|:---------------------------:|:----------------------------:|:----------------------------:|
|
||||
| AppVeyor | [](https://ci.appveyor.com/project/tidusjar/requestplex/branch/master) | [](https://ci.appveyor.com/project/tidusjar/requestplex/branch/eap) | [](https://ci.appveyor.com/project/tidusjar/requestplex/branch/dev)
|
||||
| Travis | [](https://travis-ci.org/tidusjar/Ombi) | [](https://travis-ci.org/tidusjar/Ombi) | [](https://travis-ci.org/tidusjar/Ombi)
|
||||
|
||||
| Download |[](https://github.com/tidusjar/Ombi/releases) | [](https://ci.appveyor.com/project/tidusjar/requestplex/branch/eap/artifacts) | [](https://ci.appveyor.com/project/tidusjar/requestplex/branch/dev/artifacts) |
|
||||
# Features
|
||||
Here some of the features Ombi has:
|
||||
* All your users to Request Movies, TV Shows (Whole series, whole seaons or even single episodes!) and Albums
|
||||
* Easily manage your requests
|
||||
|
||||
* User management system (supports plex.tv accounts and local accounts) [NEW]
|
||||
* Sending newsletters [NEW]
|
||||
* Fault Queue for requests (Buffer requests if Sonar/Couchpotato/SickRage is offline) [NEW]
|
||||
|
||||
* User management system (supports plex.tv accounts and local accounts)
|
||||
* Sending newsletters
|
||||
* Fault Queue for requests (Buffer requests if Sonar/Couchpotato/SickRage is offline)
|
||||
* Allow your users to report issues and manage them separately
|
||||
* A landing page that will give you the availability of your Plex server and also add custom notification text to inform your users of downtime.
|
||||
* Allow your users to get notifications!
|
||||
|
@ -35,9 +35,12 @@ Here some of the features Ombi has:
|
|||
### Integration
|
||||
We integrate with the following applications:
|
||||
* Plex server 1.2 (and higher)
|
||||
* Emby (beta)
|
||||
* Sonarr
|
||||
* SickRage
|
||||
* CouchPotato
|
||||
* Radarr (beta)
|
||||
* Watcher (beta)
|
||||
* Headphones
|
||||
|
||||
### Notifications
|
||||
|
@ -46,6 +49,7 @@ Supported notifications:
|
|||
* Pushbullet
|
||||
* Pushover
|
||||
* Slack
|
||||
* Discord
|
||||
* Weekly Recently Added email notification to all of your Plex Users!
|
||||
|
||||
# Feature Requests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue