mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 17:22:54 -07:00
Plex DB
This commit is contained in:
parent
705a4fe653
commit
67b124148c
16 changed files with 365 additions and 10 deletions
11
PlexRequests.Core/IPlexReadOnlyDatabase.cs
Normal file
11
PlexRequests.Core/IPlexReadOnlyDatabase.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using PlexRequests.Store.Models.Plex;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public interface IPlexReadOnlyDatabase
|
||||
{
|
||||
IEnumerable<MetadataItems> GetItemsAddedAfterDate(DateTime dateTime);
|
||||
}
|
||||
}
|
68
PlexRequests.Core/PlexReadOnlyDatabase.cs
Normal file
68
PlexRequests.Core/PlexReadOnlyDatabase.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexReadOnlyDatabase.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.IO;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models.Plex;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class PlexReadOnlyDatabase : IPlexReadOnlyDatabase
|
||||
{
|
||||
public PlexReadOnlyDatabase(IPlexDatabase plexDatabase, ISettingsService<PlexSettings> plexSettings)
|
||||
{
|
||||
Plex = plexDatabase;
|
||||
|
||||
var settings = plexSettings.GetSettings();
|
||||
|
||||
if (!string.IsNullOrEmpty(settings.PlexDatabaseLocationOverride))
|
||||
{
|
||||
Plex.DbLocation = settings.PlexDatabaseLocationOverride;
|
||||
}
|
||||
else if (Type.GetType("Mono.Runtime") != null)
|
||||
{
|
||||
// Mono
|
||||
Plex.DbLocation = Path.Combine("/var/lib/plexmediaserver/Library/Application Support/", "Plex Media Server", "Plug-in Support", "Databases", "com.plexapp.plugins.library.db");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default Windows
|
||||
Plex.DbLocation = Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"), "Plex Media Server", "Plug-in Support", "Databases", "com.plexapp.plugins.library.db");
|
||||
}
|
||||
}
|
||||
private IPlexDatabase Plex { get; }
|
||||
|
||||
public IEnumerable<MetadataItems> GetItemsAddedAfterDate(DateTime dateTime)
|
||||
{
|
||||
return Plex.QueryMetadataItems("select * from metadata_items where added_at > @AddedAt",
|
||||
new { AddedAt = dateTime });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -69,6 +69,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheKeys.cs" />
|
||||
<Compile Include="IPlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="Notification\NotificationMessage.cs" />
|
||||
<Compile Include="Notification\NotificationMessageContent.cs" />
|
||||
<Compile Include="Notification\NotificationMessageCurlys.cs" />
|
||||
|
@ -85,6 +86,7 @@
|
|||
<Compile Include="Notification\Templates\EmailBasicTemplate.cs" />
|
||||
<Compile Include="Notification\Templates\IEmailBasicTemplate.cs" />
|
||||
<Compile Include="Notification\TransportType.cs" />
|
||||
<Compile Include="PlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||
|
|
|
@ -40,5 +40,6 @@ namespace PlexRequests.Core.SettingModels
|
|||
|
||||
public string PlexAuthToken { get; set; }
|
||||
public string MachineIdentifier { get; set; }
|
||||
public string PlexDatabaseLocationOverride { get; set; }
|
||||
}
|
||||
}
|
15
PlexRequests.Store/IPlexDatabase.cs
Normal file
15
PlexRequests.Store/IPlexDatabase.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using PlexRequests.Store.Models.Plex;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
{
|
||||
public interface IPlexDatabase
|
||||
{
|
||||
IEnumerable<MetadataItems> GetMetadata();
|
||||
string DbLocation { get; set; }
|
||||
Task<IEnumerable<MetadataItems>> GetMetadataAsync();
|
||||
IEnumerable<MetadataItems> QueryMetadataItems(string query, object param);
|
||||
}
|
||||
}
|
95
PlexRequests.Store/Models/Plex/MetadataItems.cs
Normal file
95
PlexRequests.Store/Models/Plex/MetadataItems.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: MetadataItems.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.Data.Linq.Mapping;
|
||||
|
||||
namespace PlexRequests.Store.Models.Plex
|
||||
{
|
||||
[Table(Name = "metadata_items")]
|
||||
public class MetadataItems
|
||||
{
|
||||
[Column(IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(Name = "library_section_id")]
|
||||
public int LibrarySectionId { get; set; }
|
||||
|
||||
[Column(Name = "parent_id")]
|
||||
public int ParentId { get; set; }
|
||||
|
||||
[Column(Name = "metadata_type")]
|
||||
public int MetadataType { get; set; }
|
||||
|
||||
[Column(Name = "guid")]
|
||||
public string Guid { get; set; }
|
||||
|
||||
[Column(Name = "media_item_count")]
|
||||
public int MediaItemCount { get; set; }
|
||||
|
||||
[Column(Name = "title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Column(Name = "title_sort")]
|
||||
public string TitleSort { get; set; }
|
||||
|
||||
[Column(Name = "OriginalTitle")]
|
||||
public string OriginalTitle { get; set; }
|
||||
|
||||
[Column(Name = "studio")]
|
||||
public string Studio { get; set; }
|
||||
[Column(Name = "rating")]
|
||||
public float Rating { get; set; }
|
||||
[Column(Name = "rating_count")]
|
||||
public int RatingCount { get; set; }
|
||||
[Column(Name = "tagline")]
|
||||
public string Tagline { get; set; }
|
||||
[Column(Name = "summary")]
|
||||
public string Summary { get; set; }
|
||||
[Column(Name = "trivia")]
|
||||
public string Trivia { get; set; }
|
||||
[Column(Name = "quotes")]
|
||||
public string Quotes { get; set; }
|
||||
[Column(Name = "content_rating")]
|
||||
public string ContentRating { get; set; }
|
||||
[Column(Name = "content_rating_age")]
|
||||
public int ContentRatingAge { get; set; }
|
||||
[Column(Name = "Index")]
|
||||
public int Index { get; set; }
|
||||
// SKIP Until Date Times
|
||||
|
||||
[Column(Name = "originally_available_at")]
|
||||
public DateTime OriginallyAvailableAt { get; set; }
|
||||
[Column(Name = "available_at")]
|
||||
public DateTime AvailableAt { get; set; }
|
||||
[Column(Name = "expires_at")]
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
// Skip RefreshedAt and Year
|
||||
[Column(Name = "added_at")]
|
||||
public DateTime AddedAt { get; set; }
|
||||
}
|
||||
}
|
91
PlexRequests.Store/PlexDatabase.cs
Normal file
91
PlexRequests.Store/PlexDatabase.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexDatabase.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.Data;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using Mono.Data.Sqlite;
|
||||
using PlexRequests.Store.Models.Plex;
|
||||
|
||||
namespace PlexRequests.Store
|
||||
{
|
||||
/// <summary>
|
||||
/// We should only ever READ, NEVER WRITE!
|
||||
/// </summary>
|
||||
public class PlexDatabase : IPlexDatabase
|
||||
{
|
||||
public PlexDatabase(SqliteFactory provider)
|
||||
{
|
||||
Factory = provider;
|
||||
}
|
||||
|
||||
private SqliteFactory Factory { get; }
|
||||
/// <summary>
|
||||
/// https://support.plex.tv/hc/en-us/articles/202915258-Where-is-the-Plex-Media-Server-data-directory-located-
|
||||
/// </summary>
|
||||
public string DbLocation { get; set; }
|
||||
|
||||
private IDbConnection DbConnection()
|
||||
{
|
||||
var fact = Factory.CreateConnection();
|
||||
if (fact == null)
|
||||
{
|
||||
throw new SqliteException("Factory returned null");
|
||||
}
|
||||
fact.ConnectionString = "Data Source=" + "Plex Path";
|
||||
return fact;
|
||||
}
|
||||
|
||||
public IEnumerable<MetadataItems> GetMetadata()
|
||||
{
|
||||
using (var con = DbConnection())
|
||||
{
|
||||
return con.GetAll<MetadataItems>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<MetadataItems>> GetMetadataAsync()
|
||||
{
|
||||
using (var con = DbConnection())
|
||||
{
|
||||
return await con.GetAllAsync<MetadataItems>();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<MetadataItems> QueryMetadataItems(string query, object param)
|
||||
{
|
||||
using (var con = DbConnection())
|
||||
{
|
||||
return con.Query<MetadataItems>(query, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,12 +64,15 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="DbConfiguration.cs" />
|
||||
<Compile Include="Entity.cs" />
|
||||
<Compile Include="IPlexDatabase.cs" />
|
||||
<Compile Include="Models\IssueBlobs.cs" />
|
||||
<Compile Include="Models\PlexEpisodes.cs" />
|
||||
<Compile Include="Models\PlexUsers.cs" />
|
||||
<Compile Include="Models\Plex\MetadataItems.cs" />
|
||||
<Compile Include="Models\ScheduledJobs.cs" />
|
||||
<Compile Include="Models\RequestLimit.cs" />
|
||||
<Compile Include="Models\UsersToNotify.cs" />
|
||||
<Compile Include="PlexDatabase.cs" />
|
||||
<Compile Include="Repository\BaseGenericRepository.cs" />
|
||||
<Compile Include="Repository\IRequestRepository.cs" />
|
||||
<Compile Include="Repository\ISettingsRepository.cs" />
|
||||
|
@ -120,6 +123,7 @@
|
|||
<Name>PlexRequests.Helpers</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
22
PlexRequests.UI/Content/bootstrap-switch.min.css
vendored
Normal file
22
PlexRequests.UI/Content/bootstrap-switch.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
22
PlexRequests.UI/Content/bootstrap-switch.min.js
vendored
Normal file
22
PlexRequests.UI/Content/bootstrap-switch.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -133,14 +133,6 @@ namespace PlexRequests.UI.Helpers
|
|||
var assetLocation = GetBaseUrl();
|
||||
|
||||
var content = GetContentUrl(assetLocation);
|
||||
var settings = GetSettings();
|
||||
if (string.IsNullOrEmpty(settings.ThemeName))
|
||||
{
|
||||
settings.ThemeName = Themes.PlexTheme;
|
||||
}
|
||||
if (settings.ThemeName == "PlexBootstrap.css") settings.ThemeName = Themes.PlexTheme;
|
||||
if (settings.ThemeName == "OriginalBootstrap.css") settings.ThemeName = Themes.OriginalTheme;
|
||||
|
||||
var startUrl = $"{content}/Content";
|
||||
|
||||
sb.AppendLine($"<script src=\"{startUrl}/angular.min.js\"></script>"); // Load angular first
|
||||
|
@ -161,6 +153,20 @@ namespace PlexRequests.UI.Helpers
|
|||
return helper.Raw(sb.ToString());
|
||||
}
|
||||
|
||||
public static IHtmlString LoadSettingsAssets(this HtmlHelpers helper)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var assetLocation = GetBaseUrl();
|
||||
|
||||
var content = GetContentUrl(assetLocation);
|
||||
|
||||
sb.AppendLine($"<script src=\"{content}/Content/bootstrap-switch.min.js\" type=\"text/javascript\"></script>");
|
||||
sb.AppendLine($"<link rel=\"stylesheet\" href=\"{content}/Content/bootstrap-switch.min.css\" type=\"text/css\"/>");
|
||||
|
||||
return helper.Raw(sb.ToString());
|
||||
}
|
||||
|
||||
|
||||
public static IHtmlString LoadRequestAssets(this HtmlHelpers helper)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
|
|
@ -45,6 +45,8 @@ namespace PlexRequests.UI.NinjectModules
|
|||
{
|
||||
Bind<ICacheProvider>().To<MemoryCacheProvider>().InSingletonScope();
|
||||
Bind<ISqliteConfiguration>().To<DbConfiguration>().WithConstructorArgument("provider", new SqliteFactory());
|
||||
Bind<IPlexDatabase>().To<PlexDatabase>().WithConstructorArgument("provider", new SqliteFactory());
|
||||
|
||||
|
||||
Bind<IUserMapper>().To<UserMapper>();
|
||||
Bind<ICustomUserMapper>().To<UserMapper>();
|
||||
|
|
|
@ -304,6 +304,12 @@
|
|||
<DependentUpon>base.css</DependentUpon>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\bootstrap-switch.min.css">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\bootstrap-switch.min.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\bootstrap.css">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<form class="form-horizontal" method="POST" id="mainForm">
|
||||
<fieldset>
|
||||
<legend>Plex Settings</legend>
|
||||
|
||||
@*<input id="advancedToggle" type="checkbox"/>*@ @*TODO*@
|
||||
<div class="form-group">
|
||||
<label for="Ip" class="control-label">Plex Hostname or IP</label>
|
||||
<div>
|
||||
|
@ -88,6 +88,13 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="PlexDatabaseLocationOverride" class="control-label">Plex Database Override</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " id="PlexDatabaseLocationOverride" name="PlexDatabaseLocationOverride" value="@Model.PlexDatabaseLocationOverride">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="authToken" class="control-label">Plex Authorization Token</label>
|
||||
<div class="">
|
||||
|
@ -129,6 +136,9 @@
|
|||
|
||||
<script>
|
||||
$(function () {
|
||||
|
||||
$("#advancedToggle").bootstrapSwitch();
|
||||
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
|
||||
$('#testPlex').click(function (e) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
@using PlexRequests.UI.Helpers
|
||||
@Html.LoadSettingsAssets()
|
||||
<div class="col-lg-3 col-md-3 col-sm-4">
|
||||
<div class="list-group table-of-contents">
|
||||
@Html.GetSidebarUrl(Context, "/admin", "Plex Request")
|
||||
|
|
|
@ -99,7 +99,6 @@
|
|||
$.ajax({
|
||||
url: url,
|
||||
success: function (result) {
|
||||
console.log("we win + " + result.url);
|
||||
if (result.url && result.url != "donationLinkError") {
|
||||
$("#customDonate").show();
|
||||
var donateLink = $("#customDonateHref");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue