mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 16:22:55 -07:00
This commit is contained in:
parent
ec49ab7389
commit
1a0e7cbe7b
6 changed files with 140 additions and 58 deletions
|
@ -28,6 +28,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models.Plex;
|
||||
|
@ -63,11 +64,19 @@ namespace PlexRequests.Core
|
|||
public IEnumerable<MetadataItems> GetItemsAddedAfterDate(DateTime dateTime)
|
||||
{
|
||||
// type 1 = Movie, type 4 = TV Episode
|
||||
return Plex.QueryMetadataItems(@"SELECT * FROM metadata_items
|
||||
var movies = Plex.QueryMetadataItems(@"SELECT * FROM metadata_items
|
||||
WHERE added_at > @AddedAt
|
||||
AND metadata_type in (1,4)
|
||||
AND title <> ''",
|
||||
new { AddedAt = dateTime });
|
||||
AND metadata_type = 1
|
||||
AND title <> ''", new { AddedAt = dateTime });
|
||||
|
||||
// Custom query to include the series title
|
||||
var tv = Plex.QueryMetadataItems(@"SELECT series.title AS SeriesTitle, mi.* FROM metadata_items mi
|
||||
INNER JOIN metadata_items season ON mi.parent_id = season.id
|
||||
INNER JOIN metadata_items series ON series.id = season.parent_id
|
||||
WHERE mi.added_at > @AddedAt
|
||||
AND mi.metadata_type = 4", new { AddedAt = dateTime });
|
||||
|
||||
return movies.Union(tv);
|
||||
}
|
||||
}
|
||||
}
|
71
PlexRequests.Services/Jobs/HtmlTemplateGenerator.cs
Normal file
71
PlexRequests.Services/Jobs/HtmlTemplateGenerator.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: HtmlTemplateGenerator.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.IO;
|
||||
using System.Text;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace PlexRequests.Services.Jobs
|
||||
{
|
||||
public abstract class HtmlTemplateGenerator
|
||||
{
|
||||
protected virtual void AddParagraph(ref StringBuilder stringBuilder, string text, int fontSize = 14, string fontWeight = "normal")
|
||||
{
|
||||
stringBuilder.AppendFormat("<p style=\"font-family: sans-serif; font-size: {1}px; font-weight: {2}; margin: 0; Margin-bottom: 15px;\">{0}</p>", text, fontSize, fontWeight);
|
||||
}
|
||||
|
||||
protected virtual void AddImageInsideTable(ref StringBuilder sb, string url)
|
||||
{
|
||||
sb.Append("<tr>");
|
||||
sb.Append("<td align=\"center\">");
|
||||
sb.AppendFormat(
|
||||
"<img src=\"{0}\" width=\"400px\" text-align=\"center\" />",
|
||||
url);
|
||||
sb.Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
protected virtual void Href(ref StringBuilder sb, string url)
|
||||
{
|
||||
sb.AppendFormat("<a href=\"{0}\">", url);
|
||||
}
|
||||
|
||||
protected virtual void EndTag(ref StringBuilder sb, string tag)
|
||||
{
|
||||
sb.AppendFormat("</{0}>", tag);
|
||||
}
|
||||
|
||||
protected virtual void Header(ref StringBuilder sb, int size, string text, string fontWeight = "normal")
|
||||
{
|
||||
sb.AppendFormat(
|
||||
"<h{0} style=\"font-family: sans-serif; font-weight: {2}; margin: 0; Margin-bottom: 15px;\">{1}</h{0}>",
|
||||
size, text, fontWeight);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ using Quartz;
|
|||
|
||||
namespace PlexRequests.Services.Jobs
|
||||
{
|
||||
public class RecentlyAdded : IJob, IRecentlyAdded
|
||||
public class RecentlyAdded : HtmlTemplateGenerator, IJob, IRecentlyAdded
|
||||
{
|
||||
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings,
|
||||
ISettingsService<EmailNotificationSettings> email,
|
||||
|
@ -146,7 +146,7 @@ namespace PlexRequests.Services.Jobs
|
|||
var sb = new StringBuilder();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
|
||||
var recentlyAdded = PlexDb.GetItemsAddedAfterDate(DateTime.Now.AddDays(-12)).ToList();
|
||||
var recentlyAdded = PlexDb.GetItemsAddedAfterDate(DateTime.Now.AddDays(-12)).ToList(); // TODO Date configurable
|
||||
|
||||
var movies = recentlyAdded.Where(x => x.metadata_type == MetadataTypeMovie);
|
||||
var tv = recentlyAdded.Where(x => x.metadata_type == MetadataTypeTv);
|
||||
|
@ -160,12 +160,12 @@ namespace PlexRequests.Services.Jobs
|
|||
Send(html, plexSettings, testEmail);
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<RecentlyAddedChild> movies, PlexSettings plexSettings,ref StringBuilder sb)
|
||||
private void GenerateMovieHtml(IEnumerable<RecentlyAddedChild> movies, PlexSettings plexSettings, ref StringBuilder sb)
|
||||
{
|
||||
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 movies)
|
||||
foreach (var movie in movies.OrderByDescending(x => x.addedAt))
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
|
@ -178,36 +178,24 @@ namespace PlexRequests.Services.Jobs
|
|||
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(plexGUID);
|
||||
var info = _movieApi.GetMovieInformation(imdbId).Result;
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append("<td align=\"center\">");
|
||||
sb.AppendFormat(
|
||||
"<img src=\"https://image.tmdb.org/t/p/w500{0}\" width=\"400px\" text-align=\"center\" />",
|
||||
info.BackdropPath);
|
||||
sb.Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
AddImageInsideTable(ref 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\">");
|
||||
|
||||
sb.AppendFormat(
|
||||
"<a href=\"https://www.imdb.com/title/{0}/\"><h3 style=\"font-family: sans-serif; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{1} {2}</p></a>",
|
||||
info.ImdbId, info.Title, info.ReleaseDate?.ToString("yyyy") ?? string.Empty);
|
||||
Href(ref sb, $"https://www.imdb.com/title/{info.ImdbId}/");
|
||||
Header(ref sb, 3, $"{info.Title} {info.ReleaseDate?.ToString("yyyy") ?? string.Empty}");
|
||||
EndTag(ref sb, "a");
|
||||
|
||||
if (info.Genres.Any())
|
||||
{
|
||||
sb.AppendFormat(
|
||||
"<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Genre: {0}</p>",
|
||||
string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray()));
|
||||
AddParagraph(ref sb, $"Genre: {string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray())}");
|
||||
}
|
||||
sb.AppendFormat(
|
||||
"<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{0}</p>",
|
||||
info.Overview);
|
||||
|
||||
sb.Append("<td");
|
||||
sb.Append("<hr>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("</tr>");
|
||||
AddParagraph(ref sb, info.Overview);
|
||||
|
||||
EndLoopHtml(ref sb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -229,7 +217,7 @@ namespace PlexRequests.Services.Jobs
|
|||
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 items)
|
||||
foreach (var movie in items.OrderByDescending(x => x.added_at))
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
|
@ -237,41 +225,35 @@ namespace PlexRequests.Services.Jobs
|
|||
plexGUID = movie.guid;
|
||||
|
||||
var imdbId = PlexHelper.GetProviderIdFromPlexGuid(plexGUID);
|
||||
|
||||
|
||||
var info = _movieApi.GetMovieInformation(imdbId).Result; // TODO remove this and get the image info from Plex https://github.com/jakewaldron/PlexEmail/blob/master/scripts/plexEmail.py#L391
|
||||
|
||||
sb.Append("<tr>");
|
||||
sb.Append("<td align=\"center\">");
|
||||
sb.AppendFormat(
|
||||
"<img src=\"https://image.tmdb.org/t/p/w500{0}\" width=\"400px\" text-align=\"center\" />",
|
||||
info.BackdropPath);
|
||||
sb.Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
sb.Append("<tr>");
|
||||
sb.Append(
|
||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
AddImageInsideTable(ref sb, $"https://image.tmdb.org/t/p/w500{info.BackdropPath}");
|
||||
|
||||
sb.AppendFormat(
|
||||
"<a href=\"https://www.imdb.com/title/{0}/\"><h3 style=\"font-family: sans-serif; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{1} {2:yyyy}</p></a>",
|
||||
imdbId, string.IsNullOrEmpty(movie.original_title) ? movie.title : movie.original_title + $" AKA {movie.title}", movie.originally_available_at);
|
||||
sb.Append("<tr>");
|
||||
sb.Append("<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
Href(ref sb, $"https://www.imdb.com/title/{info.ImdbId}/");
|
||||
var title = string.IsNullOrEmpty(movie.original_title)
|
||||
? $"{movie.title} {movie.originally_available_at:yyyy}"
|
||||
: $"{movie.original_title} AKA {movie.title} {movie.originally_available_at:yyyy}";
|
||||
|
||||
Header(ref sb, 3, title);
|
||||
EndTag(ref sb, "a");
|
||||
|
||||
if (!string.IsNullOrEmpty(movie.tagline))
|
||||
{
|
||||
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 15px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{0}</p>", movie.tagline);
|
||||
AddParagraph(ref sb, movie.tagline);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(movie.tags_genre))
|
||||
{
|
||||
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Genre: {0}</p>", PlexHelper.FormatGenres(movie.tags_genre));
|
||||
AddParagraph(ref sb, $"Genre: {PlexHelper.FormatGenres(movie.tags_genre)}");
|
||||
}
|
||||
|
||||
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{0}</p>", movie.summary);
|
||||
AddParagraph(ref sb, movie.summary);
|
||||
|
||||
sb.Append("<td");
|
||||
sb.Append("<hr>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("</tr>");
|
||||
EndLoopHtml(ref sb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -283,13 +265,14 @@ namespace PlexRequests.Services.Jobs
|
|||
sb.Append("</table><br/><br/>");
|
||||
}
|
||||
|
||||
[Obsolete("Use the new DB Version")]
|
||||
private void GenerateTvHtml(IEnumerable<RecentlyAddedChild> tv, PlexSettings plexSettings, ref StringBuilder sb)
|
||||
{
|
||||
// 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 tv)
|
||||
foreach (var t in tv.OrderByDescending(x => x.addedAt))
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
|
@ -349,12 +332,12 @@ namespace PlexRequests.Services.Jobs
|
|||
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 items)
|
||||
foreach (var t in items.OrderByDescending(x => x.added_at))
|
||||
{
|
||||
var plexGUID = string.Empty;
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
plexGUID = t.guid;
|
||||
var seasonInfo = PlexHelper.GetSeasonsAndEpisodesFromPlexGuid(plexGUID);
|
||||
|
||||
|
@ -373,8 +356,12 @@ namespace PlexRequests.Services.Jobs
|
|||
sb.Append("<tr>");
|
||||
sb.Append("<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||
|
||||
sb.AppendFormat("<a href=\"https://www.imdb.com/title/{0}/\"><h3 style=\"font-family: sans-serif; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{1} {2:yyyy}</p></a>",
|
||||
info.externals.imdb, string.IsNullOrEmpty(t.original_title) ? t.title : t.original_title + $" AKA {t.title}", t.originally_available_at); // Only the year
|
||||
var title = !string.IsNullOrEmpty(t.SeriesTitle)
|
||||
? $"{t.SeriesTitle} - {t.title} {t.originally_available_at:yyyy}"
|
||||
: $"{t.title}";
|
||||
|
||||
sb.AppendFormat("<a href=\"https://www.imdb.com/title/{0}/\"><h3 style=\"font-family: sans-serif; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{1}</p></a>",
|
||||
info.externals.imdb, title);
|
||||
|
||||
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Season: {0}, Episode: {1}</p>", seasonInfo.SeasonNumber, seasonInfo.EpisodeNumber);
|
||||
|
||||
|
@ -453,5 +440,15 @@ namespace PlexRequests.Services.Jobs
|
|||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void EndLoopHtml(ref StringBuilder sb)
|
||||
{
|
||||
sb.Append("<td");
|
||||
sb.Append("<hr>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -80,6 +80,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Interfaces\IJobRecord.cs" />
|
||||
<Compile Include="Interfaces\INotificationEngine.cs" />
|
||||
<Compile Include="Jobs\HtmlTemplateGenerator.cs" />
|
||||
<Compile Include="Jobs\IRecentlyAdded.cs" />
|
||||
<Compile Include="Jobs\JobRecord.cs" />
|
||||
<Compile Include="Jobs\JobNames.cs" />
|
||||
|
|
|
@ -63,5 +63,6 @@ namespace PlexRequests.Store.Models.Plex
|
|||
public DateTime expires_at { get; set; }
|
||||
// Skip RefreshedAt and Year
|
||||
public DateTime added_at { get; set; }
|
||||
public string SeriesTitle { get; set; } // Only used in a custom query for the TV Shows
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ using Ninject.Planning.Bindings.Resolvers;
|
|||
using NLog;
|
||||
|
||||
using Owin;
|
||||
|
||||
using PlexRequests.Services.Jobs;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Jobs;
|
||||
using PlexRequests.UI.NinjectModules;
|
||||
|
@ -67,6 +67,9 @@ namespace PlexRequests.UI
|
|||
Debug.WriteLine("Finished bootstrapper");
|
||||
var scheduler = new Scheduler();
|
||||
scheduler.StartScheduler();
|
||||
|
||||
var r = kernel.Get<IRecentlyAdded>();
|
||||
r.Test();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue