@ -1,4 +1,5 @@
#region Copyright
#region Copyright
// /************************************************************************
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// Copyright (c) 2016 Jamie Rees
// File: RecentlyAdded.cs
// File: RecentlyAdded.cs
@ -23,6 +24,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
// ************************************************************************/
# endregion
# endregion
using System ;
using System ;
@ -47,8 +49,10 @@ namespace PlexRequests.Services.Jobs
{
{
public class RecentlyAdded : IJob , IRecentlyAdded
public class RecentlyAdded : IJob , IRecentlyAdded
{
{
public RecentlyAdded ( IPlexApi api , ISettingsService < PlexSettings > plexSettings , ISettingsService < EmailNotificationSettings > email ,
public RecentlyAdded ( IPlexApi api , ISettingsService < PlexSettings > plexSettings ,
ISettingsService < ScheduledJobsSettings > scheduledService , IJobRecord rec , ISettingsService < PlexRequestSettings > plexRequest )
ISettingsService < EmailNotificationSettings > email ,
ISettingsService < ScheduledJobsSettings > scheduledService , IJobRecord rec ,
ISettingsService < PlexRequestSettings > plexRequest )
{
{
JobRecord = rec ;
JobRecord = rec ;
Api = api ;
Api = api ;
@ -131,27 +135,38 @@ namespace PlexRequests.Services.Jobs
Send ( html , plexSettings , testEmail ) ;
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 ( "<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%\">" ) ;
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 )
{
var plexGUID = string . Empty ;
try
{
{
var metaData = Api . GetMetadata ( plexSettings . PlexAuthToken , plexSettings . FullUri ,
var metaData = Api . GetMetadata ( plexSettings . PlexAuthToken , plexSettings . FullUri ,
movie . ratingKey . ToString ( ) ) ;
movie . ratingKey . ToString ( ) ) ;
var imdbId = PlexHelper . GetProviderIdFromPlexGuid ( metaData . Video . Guid ) ;
plexGUID = metaData . Video . Guid ;
var imdbId = PlexHelper . GetProviderIdFromPlexGuid ( plexGUID ) ;
var info = _movieApi . GetMovieInformation ( imdbId ) . Result ;
var info = _movieApi . GetMovieInformation ( imdbId ) . Result ;
sb . Append ( "<tr>" ) ;
sb . Append ( "<tr>" ) ;
sb . Append ( "<td align=\"center\">" ) ;
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 . AppendFormat (
"<img src=\"https://image.tmdb.org/t/p/w500{0}\" width=\"400px\" text-align=\"center\" />" ,
info . BackdropPath ) ;
sb . Append ( "</td>" ) ;
sb . Append ( "</td>" ) ;
sb . Append ( "</tr>" ) ;
sb . Append ( "</tr>" ) ;
sb . Append ( "<tr>" ) ;
sb . Append ( "<tr>" ) ;
sb . Append ( "<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">" ) ;
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>" ,
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 ) ;
info . ImdbId , info . Title , info . ReleaseDate ? . ToString ( "yyyy" ) ? ? string . Empty ) ;
if ( info . Genres . Any ( ) )
if ( info . Genres . Any ( ) )
@ -160,13 +175,21 @@ namespace PlexRequests.Services.Jobs
"<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Genre: {0}</p>" ,
"<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 ( ) ) ) ;
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 . 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 ( "<td" ) ;
sb . Append ( "<hr>" ) ;
sb . Append ( "<hr>" ) ;
sb . Append ( "<br>" ) ;
sb . Append ( "<br>" ) ;
sb . Append ( "<br>" ) ;
sb . Append ( "<br>" ) ;
sb . Append ( "</tr>" ) ;
sb . Append ( "</tr>" ) ;
}
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 ) ;
}
}
}
sb . Append ( "</table><br/><br/>" ) ;
sb . Append ( "</table><br/><br/>" ) ;
@ -176,13 +199,21 @@ namespace PlexRequests.Services.Jobs
{
{
// TV
// TV
sb . Append ( "<h1>New Episodes:</h1><br/><br/>" ) ;
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%\">" ) ;
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 )
{
{
var plexGUID = string . Empty ;
try
{
var parentMetaData = Api . GetMetadata ( plexSettings . PlexAuthToken , plexSettings . FullUri ,
var parentMetaData = Api . GetMetadata ( plexSettings . PlexAuthToken , plexSettings . FullUri ,
t . parentRatingKey . ToString ( ) ) ;
t . parentRatingKey . ToString ( ) ) ;
var info = TvApi . ShowLookupByTheTvDbId ( int . Parse ( PlexHelper . GetProviderIdFromPlexGuid ( parentMetaData . Directory . Guid ) ) ) ;
plexGUID = parentMetaData . Directory . Guid ;
var info = TvApi . ShowLookupByTheTvDbId ( int . Parse ( PlexHelper . GetProviderIdFromPlexGuid ( plexGUID ) ) ) ;
var banner = info . image ? . original ;
var banner = info . image ? . original ;
if ( ! string . IsNullOrEmpty ( banner ) )
if ( ! string . IsNullOrEmpty ( banner ) )
{
{
@ -209,6 +240,12 @@ namespace PlexRequests.Services.Jobs
sb . Append ( "<br>" ) ;
sb . Append ( "<br>" ) ;
sb . Append ( "</tr>" ) ;
sb . Append ( "</tr>" ) ;
}
}
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 ) ;
}
}
sb . Append ( "</table><br/><br/>" ) ;
sb . Append ( "</table><br/><br/>" ) ;
}
}