Redo newsletter CSS

This commit is contained in:
JonnyWong16 2018-01-11 00:38:36 -08:00
parent a13d93f239
commit 4577704f19
11 changed files with 1561 additions and 728 deletions

View file

@ -443,6 +443,7 @@
}
function sendTestNewsletter() {
showMsg('<i class="fa fa-refresh fa-spin"></i>&nbsp; Generating Newsletter', false);
$.ajax({
url: 'send_newsletter',
data: {

View file

@ -750,6 +750,7 @@
});
function sendTestNotification() {
showMsg('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sending Notification', false);
if ('${notifier["agent_name"]}' !== 'browser') {
$.ajax({
url: 'send_notification',

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,883 @@
<% from notification_handler import PILLOW %>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Tautulli ${title} Newsletter</title>
<style>
/* -------------------------------------
GLOBAL RESETS
------------------------------------- */
img {
border: none;
-ms-interpolation-mode: bicubic;
max-width: 100%;
}
body {
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 14px;
line-height: 1.4;
margin: 0;
padding: 0;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
table {
border-collapse: separate;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
width: 100%;
}
table td {
font-family: sans-serif;
font-size: 14px;
vertical-align: top;
}
/* -------------------------------------
BODY & CONTAINER
------------------------------------- */
.body {
width: 100%;
}
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display: block;
margin: 0 auto !important;
/* makes it centered */
max-width: 1046px;
padding: 10px;
width: 1046px;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
box-sizing: border-box;
display: block;
margin: 0 auto;
max-width: 1046px;
padding: 10px;
}
/* -------------------------------------
HEADER, FOOTER, MAIN
------------------------------------- */
.main {
background: #282A2D;
border-radius: 3px;
width: 100%;
color: #ffffff;
}
.wrapper {
box-sizing: border-box;
padding: 5px;
overflow: auto;
}
.content-block {
padding-bottom: 10px;
padding-top: 10px;
}
.footer {
clear: both;
margin-top: 10px;
text-align: center;
width: 100%;
font-size: 12px;
}
.footer-bar {
margin-left: auto;
margin-right: auto;
width: 200px;
border-top: 1px solid #E5A00D;
}
.footer td,
.footer p,
.footer span,
.footer a {
color: #fff;
font-size: 12px;
text-align: center;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1,
h2,
h3,
h4 {
color: #ffffff;
font-family: sans-serif;
font-weight: 400;
margin: 0;
}
p,
ul,
ol {
font-family: sans-serif;
font-size: 14px;
font-weight: 400;
margin: 0;
margin-bottom: 15px;
}
p li,
ul li,
ol li {
list-style-position: inside;
margin-left: 5px;
}
a {
color: #3498db;
text-decoration: underline;
}
/* -------------------------------------
BUTTONS
------------------------------------- */
.btn {
box-sizing: border-box;
width: 100%;
}
.btn > tbody > tr > td {
padding-bottom: 15px;
}
.btn table {
width: auto;
}
.btn table td {
background-color: #ffffff;
border-radius: 5px;
text-align: center;
}
.btn a {
background-color: #ffffff;
border: solid 1px #3498db;
border-radius: 5px;
box-sizing: border-box;
color: #3498db;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: bold;
margin: 0;
padding: 12px 25px;
text-decoration: none;
text-transform: capitalize;
}
.btn-primary table td {
background-color: #3498db;
}
.btn-primary a {
background-color: #3498db;
border-color: #3498db;
color: #ffffff;
}
/* -------------------------------------
OTHER STYLES THAT MIGHT BE USEFUL
------------------------------------- */
.last {
margin-bottom: 0;
}
.first {
margin-top: 0;
}
.align-center {
text-align: center;
}
.align-right {
text-align: right;
}
.align-left {
text-align: left;
}
.clear {
clear: both;
}
.mt0 {
margin-top: 0;
}
.mb0 {
margin-bottom: 0;
}
.mb5 {
margin-bottom: 5px;
}
.nowrap {
white-space: nowrap;
}
.preheader {
color: transparent;
display: none;
height: 0;
max-height: 0;
max-width: 0;
opacity: 0;
overflow: hidden;
mso-hide: all;
visibility: hidden;
width: 0;
}
.powered-by a {
text-decoration: underline;
}
/* -------------------------------------
HEADER
------------------------------------- */
.header {
background: url(https://i.imgur.com/oqMQJxp.png) no-repeat;
background-position: calc(50% - 20px) 50%;
background-size: contain;
width: 100%;
height: 100px;
}
.dates {
font-size: 20px;
text-align: center;
}
/* -------------------------------------
MEDIA SECTIONS
------------------------------------- */
h2 {
font-size: 30px;
font-weight: 300;
margin: 20px 10px 0 10px;
text-align: center;
}
h3 {
font-size: 25px;
font-weight: 300;
margin: 0 0 10px 0;
}
img.sub-header-icon {
height: 30px;
vertical-align: middle;
margin-right: 5px;
margin-bottom: 5px;
}
.sub-header > div {
margin-left: auto;
margin-right: auto;
font-size: 30px;
text-align: center;
}
.sub-header-bar {
width: 200px;
border-top: 1px solid #E5A00D;
margin-bottom: 15px;
}
.sub-header-title {
font-weight: lighter;
}
.sub-header-count .count {
color: #E9A049;
}
.sub-header-count .count-units {
color: #aaaaaa;
font-size: 20px;
text-transform: uppercase;
}
/* -------------------------------------
MEDIA CARDS
------------------------------------- */
.card-instance {
float: left;
width: 500px;
margin: 3px;
border: 1px solid rgba(255,255,255,.1);
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-size: 12px;
overflow: hidden;
position: relative;
}
.card-instance.movie,
.card-instance.show {
height: 235px;
}
.card-instance.album {
height: 160px;
}
.card-instance.odd {
float: none !important;
margin: 3px auto !important;
}
.card-background {
background-color: #3F4245;
background-position: center;
background-size: cover;
width: 100%;
height: 100%;
}
.card-background-preview {
background-color: #3F4245;
background-position: center;
background-size: cover;
opacity: 0.40;
-webkit-filter: blur(3px);
filter: blur(3px);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 0;
}
.card-poster-container {
width: 150px;
margin: 3px;
border: 1px solid rgba(255,255,255,.1);
float: left;
position: relative;
z-index: 1;
}
.card-instance.movie .card-poster-container,
.card-instance.show .card-poster-container{
height: 225px;
}
.card-instance.album .card-poster-container {
height: 150px;
}
.card-poster {
background-color: #3F4245;
background-position: center;
background-size: cover;
height: 100%;
width: 100%;
}
.card-poster-overlay {
background: rgba(0, 0, 0, 0.75) url(http://tautulli.com/images/plex-logo-reversed-flat-transparent.png) center no-repeat;
background-size: 80px;
width: 100%;
height: 100%;
border: 3px solid #E9A049;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
display: none;
}
.card-info-container {
margin: 4px;
width: 332px;
float: left;
position: relative;
z-index: 1;
}
.card-instance.movie .card-info-container,
.card-instance.show .card-info-container{
height: 225px;
}
.card-instance.album .card-info-container {
height: 150px;
}
.card-info-container > div {
padding: 5px;
text-overflow: ellipsis;
overflow: hidden;
}
.card-info-title {
border-bottom: 1px solid rgba(255, 255, 255, .1);
line-height: 20px;
font-size: 15px;
}
.card-info-title a {
text-decoration: none;
color: #ffffff;
}
.card-info-body > div {
color: #ffffff;
font-size: 12px;
text-overflow: ellipsis;
overflow: hidden;
}
.card-instance.movie .card-info-body,
.card-instance.show .card-info-body {
min-height: 157px;
}
.card-instance.album .card-info-body {
min-height: 82px;
}
.card-info-footer {
font-size: 10px;
}
.card-info-footer .star-rating {
width: 60px;
font-size: 14px;
line-height: 17px;
float: right;
}
.star-rating-full {
color: #E9A049;
direction: ltr;
padding: 0;
overflow: hidden;
float: left;
}
.star-rating-empty {
color: #aaaaaa;
direction: rtl;
padding: 0;
overflow: hidden;
float: left;
}
.star-rating span {
display: inline-block;
text-align: center;
width: 12px;
}
.badge {
display: inline-block;
min-width: 10px;
padding: 3px 7px;
font-size: 11px;
font-style: normal;
line-height: 1;
color: #fff;
text-align: center;
white-space: nowrap;
vertical-align: middle;
background-color: rgba(0, 0, 0, .25);
border-radius: 2px;
}
/* -------------------------------------
RESPONSIVE AND MOBILE FRIENDLY STYLES
------------------------------------- */
@media only screen and (max-width: 620px) {
table[class=body] .header {
background-position: center !important;
}
table[class=body] h1 {
font-size: 28px !important;
margin-bottom: 10px !important;
}
table[class=body] .dates {
font-size: 16px !important;
}
table[class=body] .sub-header > div {
font-size: 20px !important;
}
table[class=body] .sub-header-title {
font-size: 20px !important;
}
table[class=body] img.sub-header-icon {
height: 20px !important;
}
table[class=body] .count {
font-size: 20px !important;
}
table[class=body] .count-units {
font-size: 14px !important;
}
table[class=body] .card-instance {
margin: 3px auto;
float: none;
}
table[class=body] .content {
padding: 0 !important;
}
table[class=body] .container {
padding: 0 !important;
width: 100% !important;
}
table[class=body] .main {
border-left-width: 0 !important;
border-radius: 0 !important;
border-right-width: 0 !important;
}
}
/* -------------------------------------
PRESERVE THESE STYLES IN THE HEAD
------------------------------------- */
@media all {
.ExternalClass {
width: 100%;
}
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
.apple-link a {
color: inherit !important;
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: none !important;
}
.btn-primary table td:hover {
background-color: #34495e !important;
}
.btn-primary a:hover {
background-color: #34495e !important;
border-color: #34495e !important;
}
}
</style>
</head>
<body class="">
<table border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td class="container">
<div class="content">
<!-- START CENTERED WHITE CONTAINER -->
<span class="preheader">Tautulli ${title} Newsletter (${parameters['start_date']} - ${parameters['end_date']})</span>
<table border="0" cellpadding="0" cellspacing="0" class="main">
<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper newsletter-header">
<div class="header"></div>
<div class="dates">${parameters['start_date']} - ${parameters['end_date']}</div>
</td>
</tr>
<tr>
<td>
% if recently_added.get('movie'):
<div class="wrapper">
<div class="sub-header">
<div class="sub-header-bar"></div>
<div class="sub-header-title">
<img src="http://tautulli.com/images/libraries/movie.png" class="sub-header-icon"/> Recently Added Movies
</div>
<div class="sub-header-count">
<span class="count">${len(recently_added['movie'])}</span> <span class="count-units">movie${'s' if len(recently_added['movie']) > 1 else ''}</span>
</div>
</div>
</div>
<div class="wrapper">
% for movie in recently_added['movie']:
% if loop.index == len(recently_added['movie'])-1 and loop.index % 2 == 0:
<div class="card-instance movie odd">
% else:
<div class="card-instance movie">
% endif
% if PILLOW:
% if preview:
<div class="card-background">
<div class="card-background-preview" style="background-image: url(${'pms_image_proxy?img=' + movie['art'] + '&width=500&height=280&fallback=art&refresh=true'});"></div>
% else:
<div class="card-background" style="background-image: url(${movie['art_url']});">
% endif
% else:
<div class="card-background">
% endif
<div class="card-poster-container">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${movie['rating_key']}" title="${movie['title']}" target="_blank">
<div class="card-poster" style="background-image: url(${'pms_image_proxy?img=' + movie['thumb'] + '&width=300&height=450&fallback=poster&refresh=true' if preview else movie['poster_url']})">
<div class="card-poster-overlay"></div>
</div>
</a>
</div>
<div class="card-info-container">
<div class="card-info-title nowrap">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${movie['rating_key']}" title="${movie['title']}" target="_blank">${movie['title']}</a>
</div>
<div class="card-info-body">
% if movie['tagline']:
<div class="nowrap mb5">
<em>${movie['tagline']}</em>
</div>
% endif
<div>
${movie['summary'][:450] + (movie['summary'][450:] and '...')}
</div>
</div>
<div class="card-info-footer nowrap">
% if movie['year']:
<span class="badge">${movie['year']}</span>
% endif
% if movie['content_rating']:
<span class="badge">${movie['content_rating']}</span>
% endif
% if movie['duration']:
<span class="badge">${int(int(movie['duration'])/60000)} mins</span>
% endif
% if movie['rating']:
<span class="star-rating">
<div class="star-rating-full nowrap" style="width: ${float(movie['rating'])/0.1}%">
<span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span>
</div>
<div class="star-rating-empty" style="width: ${100-float(movie['rating'])/0.1}%">
<span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span>
</div>
</span>
% endif
</div>
</div>
</div>
</div>
% endfor
</div>
% endif
% if recently_added.get('show'):
<div class="wrapper">
<div class="sub-header">
<div class="sub-header-bar"></div>
<div class="sub-header-title">
<img src="http://tautulli.com/images/libraries/show.png" class="sub-header-icon"/> Recently Added TV Shows
</div>
<div class="sub-header-count">
<span class="count">${len(recently_added['show'])}</span> <span class="count-units">show${'s' if len(recently_added['show']) > 1 else ''}</span> /
<% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %>
<span class="count">${total_episodes}</span> <span class="count-units">episode${'s' if total > 1 else ''}</span>
</div>
</div>
</div>
<div class="wrapper">
% for show in recently_added['show']:
<%
if show['season_count'] == 1 and show['season'][0]['episode_count'] == 1:
link_rating_key = show['season'][0]['episode'][0]['rating_key']
link_title = show['title'] + " - " + show['season'][0]['episode'][0]['title']
else:
link_rating_key = show['rating_key']
link_title = show['title']
%>
% if loop.index == len(recently_added['show'])-1 and loop.index % 2 == 0:
<div class="card-instance show odd">
% else:
<div class="card-instance show">
% endif
% if PILLOW:
% if preview:
<div class="card-background">
<div class="card-background-preview" style="background-image: url(${'pms_image_proxy?img=' + show['art'] + '&width=500&height=280&fallback=art&refresh=true'});"></div>
% else:
<div class="card-background" style="background-image: url(${show['art_url']});">
% endif
% else:
<div class="card-background">
% endif
<div class="card-poster-container">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${link_rating_key}" title="${link_title}" target="_blank">
<div class="card-poster" style="background-image: url(${'pms_image_proxy?img=' + show['thumb'] + '&width=300&height=450&fallback=poster&refresh=true' if preview else show['poster_url']});">
<div class="card-poster-overlay"></div>
</div>
</a>
</div>
<div class="card-info-container">
<div class="card-info-title nowrap">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${link_rating_key}" title="${link_title}" target="_blank">${show['title']}</a>
</div>
<div class="card-info-body">
<div class="nowrap mb5">
% if show['season_count'] > 1:
<em>${show['season_count']} seasons /</em>
% endif
<% total_show_episodes = sum(s['episode_count'] for s in show['season']) %>
<em>${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''}</em>
</div>
<div class="nowrap mb5">
% for i, season in enumerate(show['season'][:8]):
Season ${season['media_index']} &middot;
% if season['episode_count'] == 1:
Episode ${season['episode'][0]['media_index']} - ${season['episode'][0]['title']}
% else:
Episodes ${season['episode_range']}
% endif
% if i < min(show['season_count'], 7):
<br>
% elif i == 7 and show['season_count'] > 8:
...plus ${show['season_count'] - 8} more seasons!
% endif
% endfor
</div>
<div>
% if show['season_count'] == 1 and show['season'][0]['episode_count'] == 1:
${show['season'][0]['episode'][0]['summary'][:350] + (show['season'][0]['episode'][0]['summary'][350:] and '...')}
% else:
<% length = max(0, 350 - 50 * (show['season_count'] - 1)) %>
% if length:
${show['summary'][:length] + (show['summary'][length:] and '...')}
% endif
% endif
</div>
</div>
<div class="card-info-footer nowrap">
% if show['studio']:
<span class="badge">${show['studio']}</span>
% endif
% if show['year']:
<span class="badge">${show['year']}</span>
% endif
% if show['content_rating']:
<span class="badge">${show['content_rating']}</span>
% endif
% if show['duration']:
<span class="badge">${int(int(show['duration'])/60000)} mins</span>
% endif
% if show['rating']:
<span class="star-rating">
<div class="star-rating-full nowrap" style="width: ${float(show['rating'])/0.1}%">
<span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span>
</div>
<div class="star-rating-empty" style="width: ${100-float(show['rating'])/0.1}%">
<span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span>
</div>
</span>
% endif
</div>
</div>
</div>
</div>
% endfor
</div>
% endif
% if recently_added.get('artist'):
<div class="wrapper">
<div class="sub-header">
<div class="sub-header-bar"></div>
<div class="sub-header-title">
<img src="http://tautulli.com/images/libraries/artist.png" class="sub-header-icon"/> Recently Added Music
</div>
<div class="sub-header-count">
<span class="count">${len(recently_added['artist'])}</span> <span class="count-units">artist${'s' if len(recently_added['artist']) > 1 else ''}</span> /
<% total_albums = sum(artist['album_count'] for artist in recently_added['artist']) %>
<span class="count">${total_albums}</span> <span class="count-units">album${'s' if total > 1 else ''}</span>
</div>
</div>
</div>
<div class="wrapper">
<% album_count = 0 %>
% for artist in recently_added['artist']:
% for album in artist['album']:
<% album_count += 1 %>
% if album_count == total_albums and album_count % 2 == 1:
<div class="card-instance album odd">
% else:
<div class="card-instance album">
% endif
% if PILLOW:
% if preview:
<div class="card-background">
<div class="card-background-preview" style="background-image: url(${'pms_image_proxy?img=' + album['art'] + '&width=500&height=280&fallback=art&refresh=true'});"></div>
% else:
<div class="card-background" style="background-image: url(${album['art_url']});">
% endif
% else:
<div class="card-background">
% endif
<div class="card-poster-container">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${album['rating_key']}" title="${album['title']}" target="_blank">
<div class="card-poster" style="background-image: url(${'pms_image_proxy?img=' + album['thumb'] + '&width=300&height=450&fallback=poster&refresh=true' if preview else album['poster_url']});">
<div class="card-poster-overlay"></div>
</div>
</a>
</div>
<div class="card-info-container">
<div class="card-info-title nowrap">
<a href="${plexpy_config['pms_web_url']}#!/server/${plexpy_config['pms_identifier']}/details?key=%2Flibrary%2Fmetadata%2F${album['rating_key']}" title="${album['title']}" target="_blank">${album['title']}</a>
</div>
<div class="card-info-body">
<div class="nowrap mb5">
<em>${artist['title']} &middot; ${album['track_count']} track${'s' if album['track_count'] > 1 else ''}</em>
</div>
% if artist['title'].lower() != 'various artists':
<div>
${album['summary'][:200] + (album['summary'][200:] and '...')}
</div>
% endif
</div>
<div class="card-info-footer nowrap">
% if album['year']:
<span class="badge">${album['year']}</span>
% endif
% if album['genres']:
% for genre in album['genres'][:2]:
<span class="badge">${genre}</span>
% endfor
% endif
% if album['rating']:
<span class="star-rating">
<div class="star-rating-full nowrap" style="width: ${float(album['rating'])/0.1}%">
<span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span><span>&#9733;</span>
</div>
<div class="star-rating-empty" style="width: ${100-float(album['rating'])/0.1}%">
<span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span><span>&#9734;</span>
</div>
</span>
% endif
</div>
</div>
</div>
</div>
% endfor
% endfor
</div>
% endif
<!-- START FOOTER -->
<div class="footer">
<div class="footer-bar"></div>
<div class="content-block powered-by">
Newsletter generated by <a href="http://tautulli.com" target="_blank">Tautulli</a>.
</div>
</div>
<!-- END FOOTER -->
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
</tr>
</table>
</body>
</html>

View file

@ -634,6 +634,12 @@ def dbcheck():
'rating_key INTEGER, poster_title TEXT, poster_url TEXT, delete_hash TEXT)'
)
# art_urls table :: This table keeps record of the notification art urls
c_db.execute(
'CREATE TABLE IF NOT EXISTS art_urls (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'rating_key INTEGER, art_title TEXT, art_url TEXT, blur_art_url TEXT)'
)
# recently_added table :: This table keeps record of recently added items
c_db.execute(
'CREATE TABLE IF NOT EXISTS recently_added (id INTEGER PRIMARY KEY AUTOINCREMENT, '

View file

@ -31,6 +31,10 @@ DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png"
DEFAULT_COVER_THUMB = "interfaces/default/images/cover.png"
DEFAULT_ART = "interfaces/default/images/art.png"
ONLINE_POSTER_THUMB = "http://tautulli.com/images/poster.png"
ONLINE_COVER_THUMB = "http://tautulli.com/images/cover.png"
ONLINE_ART = "http://tautulli.com/images/art.png"
MEDIA_TYPE_HEADERS = {
'movie': 'Movies',
'show': 'TV Shows',

View file

@ -1106,7 +1106,7 @@ class DataFactory(object):
return ip_address
def get_poster_info(self, rating_key='', metadata=None):
def get_poster_info(self, rating_key='', metadata=None, art=False):
monitor_db = database.MonitorDatabase()
poster_key = ''
@ -1124,25 +1124,39 @@ class DataFactory(object):
if poster_key:
try:
query = 'SELECT poster_title, poster_url FROM poster_urls ' \
'WHERE rating_key = ?'
if art:
query = 'SELECT art_title, art_url, blur_art_url FROM art_urls ' \
'WHERE rating_key = ?'
else:
query = 'SELECT poster_title, poster_url FROM poster_urls ' \
'WHERE rating_key = ?'
poster_info = monitor_db.select_single(query, args=[poster_key])
except Exception as e:
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for get_poster_url: %s." % e)
return poster_info
def set_poster_url(self, rating_key='', poster_title='', poster_url='', delete_hash=''):
def set_poster_url(self, rating_key='', poster_title='', poster_url='', delete_hash='', art=False, blur=False):
monitor_db = database.MonitorDatabase()
if str(rating_key).isdigit():
keys = {'rating_key': int(rating_key)}
values = {'poster_title': poster_title,
'poster_url': poster_url,
'delete_hash': delete_hash}
if art:
table = 'art_urls'
values = {'art_title': poster_title,
'delete_hash': delete_hash}
if blur:
values['blur_art_url'] = poster_url
else:
values['art_url'] = poster_url
else:
table = 'poster_urls'
values = {'poster_title': poster_title,
'poster_url': poster_url,
'delete_hash': delete_hash}
monitor_db.upsert(table_name='poster_urls', key_dict=keys, value_dict=values)
monitor_db.upsert(table_name=table, key_dict=keys, value_dict=values)
def delete_poster_url(self, rating_key=''):
monitor_db = database.MonitorDatabase()

View file

@ -22,12 +22,14 @@ import os
import time
import plexpy
import common
import database
import helpers
import libraries
import logger
import notification_handler
import pmsconnect
from notification_handler import PILLOW, get_poster_info
from notifiers import send_notification, EMAIL
@ -242,6 +244,7 @@ class Newsletter(object):
_DEFAULT_EMAIL_CONFIG['from_name'] = 'Tautulli Newsletter'
_DEFAULT_EMAIL_CONFIG['notifier'] = 0
_DEFAULT_EMAIL_CONFIG['subject'] = 'Tautulli Newsletter'
_TEMPLATE_MASTER = ''
_TEMPLATE = ''
def __init__(self, config=None, email_config=None):
@ -250,6 +253,7 @@ class Newsletter(object):
self.parameters = {'server_name': plexpy.CONFIG.PMS_NAME}
self.is_preview = False
self.master_template = False
def set_config(self, config=None, default=None):
return self._validate_config(config=config, default=default)
@ -268,26 +272,31 @@ class Newsletter(object):
return new_config
def _render_template(self, **kwargs):
if self.master_template:
template = self._TEMPLATE_MASTER
else:
template = self._TEMPLATE
return serve_template(
templatename=self._TEMPLATE,
templatename=template,
title=self.NAME,
parameters=self.parameters,
**kwargs
)
def _format_subject(self, subject):
subject = subject or self._default_email_config['subject']
subject = subject or self._DEFAULT_EMAIL_CONFIG['subject']
try:
subject = unicode(subject).format(**self.parameters)
except LookupError as e:
logger.error(
u"Tautulli Newsletter :: Unable to parse parameter %s in newsletter subject. Using fallback." % e)
subject = unicode(self._default_email_config['subject']).format(**self.parameters)
subject = unicode(self._DEFAULT_EMAIL_CONFIG['subject']).format(**self.parameters)
except Exception as e:
logger.error(
u"Tautulli Newsletter :: Unable to parse custom newsletter subject: %s. Using fallback." % e)
subject = unicode(self._default_email_config['subject']).format(**self.parameters)
subject = unicode(self._DEFAULT_EMAIL_CONFIG['subject']).format(**self.parameters)
return subject
@ -297,7 +306,10 @@ class Newsletter(object):
def generate_newsletter(self):
pass
def preview(self):
def preview(self, master=False):
self.is_preview = True
if master:
self.master_template = True
self.retrieve_data()
return self.generate_newsletter()
@ -337,6 +349,7 @@ class RecentlyAdded(Newsletter):
_DEFAULT_CONFIG = {'last_days': 7,
'incl_libraries': None
}
_TEMPLATE_MASTER = 'recently_added_master.html'
_TEMPLATE = 'recently_added.html'
def __init__(self, config=None, email_config=None):
@ -490,12 +503,38 @@ class RecentlyAdded(Newsletter):
if media_type not in self.recently_added:
self.recently_added[media_type] = self._get_recently_added(media_type)
if not self.is_preview:
# Upload posters and art to Imgur
movies = self.recently_added.get('movie', [])
shows = self.recently_added.get('show', [])
artists = self.recently_added.get('artist', [])
albums = [a for artist in artists for a in artist['album']]
for item in movies + shows + albums:
poster_info = get_poster_info(poster_thumb=item['thumb'],
poster_key=item['rating_key'],
poster_title=item['title'])
if poster_info:
item['poster_url'] = poster_info['poster_url'] or common.ONLINE_POSTER_THUMB
art_info = {}
if PILLOW:
art_info = get_poster_info(poster_thumb=item['art'],
poster_key=item['rating_key'],
poster_title=item['title'],
art=True,
width='500',
height='280',
blur=True)
item['art_url'] = art_info.get('blur_art_url', '')
return self.recently_added
def generate_newsletter(self):
return self._render_template(
recently_added=self.recently_added,
plexpy_config=self.plexpy_config
plexpy_config=self.plexpy_config,
preview=self.is_preview
)
def _get_sections(self):

View file

@ -26,6 +26,12 @@ from string import Formatter
import threading
import time
try:
from PIL import Image, ImageFilter
PILLOW = True
except ImportError:
PILLOW = False
import plexpy
import activity_processor
import common
@ -1065,45 +1071,76 @@ def format_group_index(group_keys):
return ','.join(num) or '0', ','.join(num00) or '00'
def get_poster_info(poster_thumb, poster_key, poster_title):
def get_poster_info(poster_thumb='', poster_key='', poster_title='', art=False, width='', height='', blur=False):
default_poster_info = {'poster_title': '', 'poster_url': ''}
default_art_info = {'art_title': '', 'art_url': ''}
# Try to retrieve poster info from the database
data_factory = datafactory.DataFactory()
poster_info = data_factory.get_poster_info(rating_key=poster_key)
poster_info = data_factory.get_poster_info(rating_key=poster_key, art=art)
# If no previous poster info
if not poster_info and poster_thumb:
try:
thread_name = str(threading.current_thread().ident)
poster_file = os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster-%s' % thread_name)
poster_file = os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-image-%s.jpg' % thread_name)
# Retrieve the poster from Plex and cache to file
pms_connect = pmsconnect.PmsConnect()
result = pms_connect.get_image(img=poster_thumb)
result = pms_connect.get_image(img=poster_thumb, width=width, height=height)
if result and result[0]:
with open(poster_file, 'wb') as f:
f.write(result[0])
else:
raise Exception(u'PMS image request failed')
if blur and PILLOW:
img = Image.open(poster_file)
img = img.convert("RGBA")
img = img.filter(ImageFilter.GaussianBlur(3)) # 3px blur
img.putalpha(102) # 40% opacity
# Save as a png
poster_file_blur = os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-image-%s.png' % thread_name)
img.save(poster_file_blur)
# Upload poster_thumb to Imgur and get link
poster_url, delete_hash = helpers.upload_to_imgur(poster_file, poster_title)
if blur:
poster_url, delete_hash = helpers.uploadToImgur(poster_file_blur, poster_title)
else:
poster_url, delete_hash = helpers.uploadToImgur(poster_file, poster_title)
if poster_url:
# Create poster info
poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
if art:
poster_info = {'art_title': poster_title}
if blur:
poster_info['blur_art_url'] = poster_url
else:
poster_info['art_url'] = poster_url
else:
poster_info = {'poster_title': poster_title, 'poster_url': poster_url}
# Save the poster url in the database
data_factory.set_poster_url(rating_key=poster_key,
poster_title=poster_title,
poster_url=poster_url,
delete_hash=delete_hash)
delete_hash=delete_hash,
art=art,
blur=blur)
# Delete the cached poster
os.remove(poster_file)
if blur:
os.remove(poster_file_blur)
except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to retrieve poster for rating_key %s: %s." % (str(metadata['rating_key']), e))
logger.error(u"Tautulli NotificationHandler :: Unable to retrieve poster for rating_key %s: %s."
% (poster_key, e))
return poster_info
if art:
return poster_info or default_art_info
else:
return poster_info or default_poster_info
def lookup_tvmaze_by_id(rating_key=None, thetvdb_id=None, imdb_id=None):

View file

@ -2436,15 +2436,17 @@ class PmsConnect(object):
Output: array
"""
width = width or '1000'
height = height or '1500'
if img:
if clip:
params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))}
else:
params = {'url': 'http://127.0.0.1:32400%s?%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))}
if width.isdigit() and height.isdigit():
params['width'] = width
params['height'] = height
params['width'] = width
params['height'] = height
uri = '/photo/:/transcode?%s' % urllib.urlencode(params)
result = self.request_handler.make_request(uri=uri,

View file

@ -5514,11 +5514,11 @@ class WebInterface(object):
@cherrypy.expose
@requireAuth(member_of("admin"))
def preview_newsletter(self, newsletter_id=None, **kwargs):
def preview_newsletter(self, newsletter_id=None, master=False, **kwargs):
if newsletter_id:
newsletter = newsletters.get_newsletter_config(newsletter_id=newsletter_id)
newsletter_agent = newsletters.get_agent_class(agent_id=newsletter['agent_id'], config=newsletter['config'])
if newsletter_agent:
return newsletter_agent.preview()
return newsletter_agent.preview(master=master)
return