mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 18:47:15 -07:00
Plex DB
This commit is contained in:
parent
705a4fe653
commit
67b124148c
16 changed files with 365 additions and 10 deletions
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue