mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
Rework notification logic to only build parameters once per action
* Instead of rebuilding for each notification agent * Change season/episode to use season poster * Change album/track to use album art
This commit is contained in:
parent
f45bd49421
commit
ffdd9c9cbf
7 changed files with 199 additions and 181 deletions
|
@ -88,9 +88,6 @@ class ActivityHandler(object):
|
|||
# Write the new session to our temp session table
|
||||
self.update_db_session(session=session)
|
||||
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': session, 'notify_action': 'on_concurrent'})
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': session, 'notify_action': 'on_newdevice'})
|
||||
|
||||
def on_stop(self, force_stop=False):
|
||||
if self.is_valid_session():
|
||||
logger.debug(u"PlexPy ActivityHandler :: Session %s stopped." % str(self.get_session_key()))
|
||||
|
|
|
@ -47,7 +47,7 @@ def check_active_sessions(ws_request=False):
|
|||
media_container = session_list['sessions']
|
||||
|
||||
# Check our temp table for what we must do with the new streams
|
||||
db_streams = monitor_db.select('SELECT * FROM sessions')
|
||||
db_streams = monitor_process.get_sessions()
|
||||
for stream in db_streams:
|
||||
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
|
||||
for d in media_container):
|
||||
|
|
|
@ -106,10 +106,6 @@ class ActivityProcessor(object):
|
|||
timestamp = {'started': started}
|
||||
self.db.upsert('sessions', timestamp, keys)
|
||||
|
||||
if notify:
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': values, 'notify_action': 'on_concurrent'})
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': values, 'notify_action': 'on_newdevice'})
|
||||
|
||||
return True
|
||||
|
||||
def write_session_history(self, session=None, import_metadata=None, is_import=False, import_ignore_interval=0):
|
||||
|
@ -456,14 +452,20 @@ class ActivityProcessor(object):
|
|||
|
||||
return None
|
||||
|
||||
def get_session_by_user_id(self, user_id=None, ip_address=None):
|
||||
sessions = []
|
||||
def get_sessions(self):
|
||||
sessions = self.db.select('SELECT * FROM sessions')
|
||||
return sessions
|
||||
|
||||
def get_sessions(self, user_id=None, ip_address=None):
|
||||
query = 'SELECT * FROM sessions'
|
||||
args = []
|
||||
|
||||
if str(user_id).isdigit():
|
||||
ip = 'GROUP BY ip_address' if ip_address else ''
|
||||
sessions = self.db.select('SELECT * '
|
||||
'FROM sessions '
|
||||
'WHERE user_id = ? %s' % ip,
|
||||
[user_id])
|
||||
ip = ' GROUP BY ip_address' if ip_address else ''
|
||||
query += ' WHERE user_id = ?' + ip
|
||||
args.append(user_id)
|
||||
|
||||
sessions = self.db.select(query, args)
|
||||
return sessions
|
||||
|
||||
def set_temp_stopped(self):
|
||||
|
|
|
@ -1018,25 +1018,27 @@ class DataFactory(object):
|
|||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
poster_url = ''
|
||||
poster_key = ''
|
||||
poster_key = []
|
||||
|
||||
if rating_key:
|
||||
poster_key = rating_key
|
||||
where_key = 'WHERE rating_key = ? OR parent_rating_key = ? OR grandparent_rating_key = ?'
|
||||
poster_key = [rating_key, rating_key, rating_key]
|
||||
elif metadata:
|
||||
if metadata['media_type'] == 'movie' or metadata['media_type'] == 'show' or \
|
||||
metadata['media_type'] == 'artist' or metadata['media_type'] == 'album':
|
||||
poster_key = metadata['rating_key']
|
||||
elif metadata['media_type'] == 'episode':
|
||||
poster_key = metadata['grandparent_rating_key']
|
||||
elif metadata['media_type'] == 'season' or metadata['media_type'] == 'track':
|
||||
poster_key = metadata['parent_rating_key']
|
||||
if metadata['media_type'] in ('movie', 'show', 'artist'):
|
||||
where_key = 'WHERE rating_key = ?'
|
||||
poster_key = [metadata['rating_key']]
|
||||
elif metadata['media_type'] in ('season', 'album'):
|
||||
where_key = 'WHERE parent_rating_key = ?'
|
||||
poster_key = [metadata['rating_key']]
|
||||
elif metadata['media_type'] in ('episode', 'track'):
|
||||
where_key = 'WHERE parent_rating_key = ?'
|
||||
poster_key = [metadata['parent_rating_key']]
|
||||
|
||||
if poster_key:
|
||||
try:
|
||||
query = 'SELECT id, poster_url FROM notify_log ' \
|
||||
'WHERE rating_key = %d OR parent_rating_key = %d OR grandparent_rating_key = %d ' \
|
||||
'ORDER BY id DESC LIMIT 1' % (int(poster_key), int(poster_key), int(poster_key))
|
||||
result = monitor_db.select(query)
|
||||
query = 'SELECT id, poster_url FROM notify_log %s ' \
|
||||
'ORDER BY id DESC LIMIT 1' % where_key
|
||||
result = monitor_db.select(query, args=poster_key)
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy DataFactory :: Unable to execute database query for get_poster_url: %s." % e)
|
||||
return poster_url
|
||||
|
|
|
@ -36,6 +36,7 @@ import plextv
|
|||
import pmsconnect
|
||||
import users
|
||||
|
||||
|
||||
def process_queue():
|
||||
queue = plexpy.NOTIFY_QUEUE
|
||||
while True:
|
||||
|
@ -64,20 +65,51 @@ def add_notifier_each(notify_action=None, stream_data=None, timeline_data=None,
|
|||
# Check if any notification agents have notifications enabled for the action
|
||||
notifiers_enabled = notifiers.get_notifiers(notify_action=notify_action)
|
||||
|
||||
# Check on_watched for each notifier
|
||||
if notifiers_enabled and notify_action == 'on_watched':
|
||||
for n, notifier in enumerate(notifiers_enabled):
|
||||
if any(d['agent_id'] == notifier['agent_id'] and d['notify_action'] == notify_action
|
||||
for d in get_notify_state(session=stream_data)):
|
||||
# Already notified on_watched, remove from notifier
|
||||
notifiers_enabled.pop(n)
|
||||
|
||||
if notifiers_enabled:
|
||||
# Check if notification conditions are satisfied
|
||||
conditions = notify_conditions(notify_action=notify_action,
|
||||
stream_data=stream_data,
|
||||
timeline_data=timeline_data)
|
||||
|
||||
if notifiers_enabled and conditions:
|
||||
if stream_data or timeline_data:
|
||||
# Build the notification parameters
|
||||
parameters = build_media_notify_params(notify_action=notify_action,
|
||||
session=stream_data,
|
||||
timeline=timeline_data,
|
||||
**kwargs)
|
||||
else:
|
||||
# Build the notification parameters
|
||||
parameters = build_server_notify_params(notify_action=notify_action,
|
||||
**kwargs)
|
||||
|
||||
if not parameters:
|
||||
logger.error(u"PlexPy NotificationHandler :: Failed to build notification parameters.")
|
||||
return
|
||||
|
||||
# Add each notifier to the queue
|
||||
for notifier in notifiers_enabled:
|
||||
# Check if notification conditions are satisfied
|
||||
conditions = notify_conditions(notifier=notifier,
|
||||
notify_action=notify_action,
|
||||
stream_data=stream_data,
|
||||
timeline_data=timeline_data)
|
||||
if conditions:
|
||||
data = {'notifier_id': notifier['id'],
|
||||
'notify_action': notify_action,
|
||||
'stream_data': stream_data,
|
||||
'timeline_data': timeline_data}
|
||||
data.update(kwargs)
|
||||
plexpy.NOTIFY_QUEUE.put(data)
|
||||
data = {'notifier_id': notifier['id'],
|
||||
'notify_action': notify_action,
|
||||
'stream_data': stream_data,
|
||||
'timeline_data': timeline_data,
|
||||
'parameters': parameters}
|
||||
data.update(kwargs)
|
||||
plexpy.NOTIFY_QUEUE.put(data)
|
||||
|
||||
# Add on_concurrent and on_newdevice to queue if action is on_play
|
||||
if notify_action == 'on_play':
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': stream_data, 'notify_action': 'on_concurrent'})
|
||||
plexpy.NOTIFY_QUEUE.put({'stream_data': stream_data, 'notify_action': 'on_newdevice'})
|
||||
|
||||
|
||||
def notify_conditions(notifier=None, notify_action=None, stream_data=None, timeline_data=None):
|
||||
if stream_data:
|
||||
|
@ -100,13 +132,9 @@ def notify_conditions(notifier=None, notify_action=None, stream_data=None, timel
|
|||
|
||||
progress_percent = helpers.get_percent(stream_data['view_offset'], stream_data['duration'])
|
||||
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
current_activity = pms_connect.get_current_activity()
|
||||
sessions = current_activity.get('sessions', [])
|
||||
user_stream_count = [d for d in sessions if d['user_id'] == stream_data['user_id']]
|
||||
if plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP:
|
||||
user_stream_count = set(d['ip_address'] for d in user_stream_count)
|
||||
ap = activity_processor.ActivityProcessor()
|
||||
user_sessions = ap.get_sessions(user_id=stream_data['user_id'],
|
||||
ip_address=plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP)
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
user_devices = data_factory.get_user_devices(user_id=stream_data['user_id'])
|
||||
|
@ -114,9 +142,7 @@ def notify_conditions(notifier=None, notify_action=None, stream_data=None, timel
|
|||
conditions = \
|
||||
{'on_stop': plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT,
|
||||
'on_resume': plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99,
|
||||
'on_watched': not any(d['agent_id'] == notifier['agent_id'] and d['notify_action'] == notify_action
|
||||
for d in get_notify_state(session=stream_data)),
|
||||
'on_concurrent': len(user_stream_count) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD,
|
||||
'on_concurrent': len(user_sessions) >= plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD,
|
||||
'on_newdevice': stream_data['machine_id'] not in user_devices
|
||||
}
|
||||
|
||||
|
@ -127,36 +153,17 @@ def notify_conditions(notifier=None, notify_action=None, stream_data=None, timel
|
|||
else:
|
||||
return False
|
||||
elif timeline_data:
|
||||
|
||||
conditions = \
|
||||
{'on_created': True}
|
||||
|
||||
return conditions.get(notify_action, True)
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data=None, **kwargs):
|
||||
def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data=None, parameters=None, **kwargs):
|
||||
notifier_config = notifiers.get_notifier_config(notifier_id=notifier_id)
|
||||
|
||||
if not notifier_config:
|
||||
return
|
||||
|
||||
if stream_data or timeline_data:
|
||||
# Build the notification parameters
|
||||
parameters, metadata = build_media_notify_params(notify_action=notify_action,
|
||||
session=stream_data,
|
||||
timeline=timeline_data,
|
||||
**kwargs)
|
||||
else:
|
||||
# Build the notification parameters
|
||||
parameters, metadata = build_server_notify_params(notify_action=notify_action,
|
||||
**kwargs)
|
||||
|
||||
if not parameters:
|
||||
logger.error(u"PlexPy NotificationHandler :: Failed to build notification parameters.")
|
||||
return
|
||||
|
||||
# Get the subject and body strings
|
||||
subject_string = notifier_config['notify_text'][notify_action]['subject']
|
||||
body_string = notifier_config['notify_text'][notify_action]['body']
|
||||
|
@ -173,7 +180,7 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
|||
subject=subject,
|
||||
body=body,
|
||||
notify_action=notify_action,
|
||||
metadata=metadata)
|
||||
parameters=parameters)
|
||||
|
||||
# Set the notification state in the db
|
||||
set_notify_state(session=stream_data or timeline_data,
|
||||
|
@ -181,7 +188,7 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
|||
notifier=notifier_config,
|
||||
subject=subject,
|
||||
body=body,
|
||||
metadata=metadata)
|
||||
parameters=parameters)
|
||||
|
||||
|
||||
def get_notify_state(session):
|
||||
|
@ -203,13 +210,13 @@ def get_notify_state(session):
|
|||
return notify_states
|
||||
|
||||
|
||||
def set_notify_state(notify_action, notifier, subject, body, session=None, metadata=None):
|
||||
def set_notify_state(notify_action, notifier, subject, body, session=None, parameters=None):
|
||||
|
||||
if notify_action and notifier:
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
session = session or {}
|
||||
metadata = metadata or {}
|
||||
parameters = parameters or {}
|
||||
|
||||
keys = {'timestamp': int(time.time()),
|
||||
'session_key': session.get('session_key', None),
|
||||
|
@ -225,7 +232,7 @@ def set_notify_state(notify_action, notifier, subject, body, session=None, metad
|
|||
'agent_name': notifier['agent_name'],
|
||||
'subject_text': subject,
|
||||
'body_text': body,
|
||||
'poster_url': metadata.get('poster_url', None)}
|
||||
'poster_url': parameters.get('poster_url', None)}
|
||||
|
||||
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
||||
else:
|
||||
|
@ -252,7 +259,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
|||
logger.error(u"PlexPy NotificationHandler :: Unable to retrieve server uptime.")
|
||||
server_uptime = 'N/A'
|
||||
|
||||
# Get metadata feed for item
|
||||
# Get metadata for the item
|
||||
if session:
|
||||
rating_key = session['rating_key']
|
||||
elif timeline:
|
||||
|
@ -263,7 +270,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
|||
|
||||
if not metadata:
|
||||
logger.error(u"PlexPy NotificationHandler :: Unable to retrieve metadata for rating_key %s" % str(rating_key))
|
||||
return None, None
|
||||
return None
|
||||
|
||||
child_metadata = grandchild_metadata = []
|
||||
for key in kwargs.pop('child_keys', []):
|
||||
|
@ -271,24 +278,14 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
|||
for key in kwargs.pop('grandchild_keys', []):
|
||||
grandchild_metadata.append(pms_connect.get_metadata_details(rating_key=key))
|
||||
|
||||
current_activity = pms_connect.get_current_activity()
|
||||
sessions = current_activity.get('sessions', [])
|
||||
stream_count = current_activity.get('stream_count', '')
|
||||
user_stream_count = sum(1 for d in sessions if d['user_id'] == session['user_id']) if session else ''
|
||||
|
||||
# Create a title
|
||||
if metadata['media_type'] == 'episode' or metadata['media_type'] == 'track':
|
||||
full_title = '%s - %s' % (metadata['grandparent_title'],
|
||||
metadata['title'])
|
||||
elif metadata['media_type'] == 'season' or metadata['media_type'] == 'album':
|
||||
full_title = '%s - %s' % (metadata['parent_title'],
|
||||
metadata['title'])
|
||||
else:
|
||||
full_title = metadata['title']
|
||||
ap = activity_processor.ActivityProcessor()
|
||||
sessions = ap.get_sessions()
|
||||
stream_count = len(sessions)
|
||||
user_sessions = ap.get_sessions(user_id=session['user_id'])
|
||||
user_stream_count = len(user_sessions)
|
||||
|
||||
# Session values
|
||||
if session is None:
|
||||
session = {}
|
||||
session = session or {}
|
||||
|
||||
# Generate a combined transcode decision value
|
||||
if session.get('video_decision','') == 'transcode' or session.get('audio_decision','') == 'transcode':
|
||||
|
@ -345,49 +342,18 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
|||
metadata['lastfm_id'] = metadata['guid'].split('lastfm://')[1].rsplit('/', 1)[0]
|
||||
metadata['lastfm_url'] = 'https://www.last.fm/music/' + metadata['lastfm_id']
|
||||
|
||||
if metadata['media_type'] == 'movie' or metadata['media_type'] == 'show' or metadata['media_type'] == 'artist':
|
||||
thumb = metadata['thumb']
|
||||
poster_key = metadata['rating_key']
|
||||
poster_title = metadata['title']
|
||||
elif metadata['media_type'] == 'episode':
|
||||
thumb = metadata['grandparent_thumb']
|
||||
poster_key = metadata['grandparent_rating_key']
|
||||
poster_title = metadata['grandparent_title']
|
||||
elif metadata['media_type'] == 'track':
|
||||
thumb = metadata['parent_thumb']
|
||||
poster_key = metadata['parent_rating_key']
|
||||
poster_title = metadata['parent_title']
|
||||
if plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS:
|
||||
metadata['poster_url'] = upload_poster(metadata=metadata)
|
||||
|
||||
# Create a title
|
||||
if metadata['media_type'] == 'episode' or metadata['media_type'] == 'track':
|
||||
full_title = '%s - %s' % (metadata['grandparent_title'],
|
||||
metadata['title'])
|
||||
elif metadata['media_type'] == 'season' or metadata['media_type'] == 'album':
|
||||
full_title = '%s - %s' % (metadata['parent_title'],
|
||||
metadata['title'])
|
||||
else:
|
||||
thumb = None
|
||||
|
||||
if plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS and thumb:
|
||||
# Try to retrieve a poster_url from the database
|
||||
data_factory = datafactory.DataFactory()
|
||||
poster_url = data_factory.get_poster_url(rating_key=poster_key)
|
||||
|
||||
# If no previous poster_url
|
||||
if not poster_url and plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS:
|
||||
try:
|
||||
thread_name = str(threading.current_thread().ident)
|
||||
poster_file = os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster-%s' % thread_name)
|
||||
|
||||
# Retrieve the poster from Plex and cache to file
|
||||
result = pms_connect.get_image(img=thumb)
|
||||
if result and result[0]:
|
||||
with open(poster_file, 'wb') as f:
|
||||
f.write(result[0])
|
||||
else:
|
||||
raise Exception(u'PMS image request failed')
|
||||
|
||||
# Upload thumb to Imgur and get link
|
||||
poster_url = helpers.uploadToImgur(poster_file, poster_title)
|
||||
|
||||
# Delete the cached poster
|
||||
os.remove(poster_file)
|
||||
except Exception as e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to retrieve poster for rating_key %s: %s." % (str(rating_key), e))
|
||||
|
||||
metadata['poster_url'] = poster_url
|
||||
full_title = metadata['title']
|
||||
|
||||
# Fix metadata params for grouped recently added
|
||||
show_name = metadata['grandparent_title']
|
||||
|
@ -551,7 +517,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
|||
'grandparent_rating_key': metadata['grandparent_rating_key']
|
||||
}
|
||||
|
||||
return available_params, metadata
|
||||
return available_params
|
||||
|
||||
|
||||
def build_server_notify_params(notify_action=None, **kwargs):
|
||||
|
@ -608,7 +574,7 @@ def build_server_notify_params(notify_action=None, **kwargs):
|
|||
'plexpy_update_changelog': plexpy_download_info.get('body', '')
|
||||
}
|
||||
|
||||
return available_params, None
|
||||
return available_params
|
||||
|
||||
|
||||
def build_notify_text(subject='', body='', notify_action=None, parameters=None, agent_id=None):
|
||||
|
@ -714,3 +680,54 @@ def format_group_index(group_keys):
|
|||
num00.append(str(group[0]).zfill(2))
|
||||
|
||||
return ','.join(sorted(num)) or '0', ','.join(sorted(num00)) or '00'
|
||||
|
||||
|
||||
def upload_poster(metadata):
|
||||
if metadata['media_type'] in ('movie', 'show', 'season', 'artist', 'album'):
|
||||
thumb = metadata['thumb']
|
||||
poster_key = metadata['rating_key']
|
||||
poster_title = metadata['title']
|
||||
elif metadata['media_type'] in ('season', 'album'):
|
||||
thumb = metadata['thumb']
|
||||
poster_key = metadata['rating_key']
|
||||
poster_title = '%s - %s' % (metadata['parent_title'],
|
||||
metadata['title'])
|
||||
elif metadata['media_type'] in ('episode', 'track'):
|
||||
thumb = metadata['parent_thumb']
|
||||
poster_key = metadata['parent_rating_key']
|
||||
poster_title = '%s - %s' % (metadata['grandparent_title'],
|
||||
metadata['parent_title'])
|
||||
else:
|
||||
thumb = None
|
||||
|
||||
poster_url = ''
|
||||
|
||||
if thumb:
|
||||
# Try to retrieve a poster_url from the database
|
||||
data_factory = datafactory.DataFactory()
|
||||
poster_url = data_factory.get_poster_url(rating_key=poster_key)
|
||||
|
||||
# If no previous poster_url
|
||||
if not poster_url:
|
||||
try:
|
||||
thread_name = str(threading.current_thread().ident)
|
||||
poster_file = os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster-%s' % thread_name)
|
||||
|
||||
# Retrieve the poster from Plex and cache to file
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_image(img=thumb)
|
||||
if result and result[0]:
|
||||
with open(poster_file, 'wb') as f:
|
||||
f.write(result[0])
|
||||
else:
|
||||
raise Exception(u'PMS image request failed')
|
||||
|
||||
# Upload thumb to Imgur and get link
|
||||
poster_url = helpers.uploadToImgur(poster_file, poster_title)
|
||||
|
||||
# Delete the cached poster
|
||||
os.remove(poster_file)
|
||||
except Exception as e:
|
||||
logger.error(u"PlexPy Notifier :: Unable to retrieve poster for rating_key %s: %s." % (str(rating_key), e))
|
||||
|
||||
return poster_url
|
||||
|
|
|
@ -504,12 +504,12 @@ def send_notification(notifier_id=None, subject='', body='', notify_action='', *
|
|||
|
||||
|
||||
class PrettyMetadata(object):
|
||||
def __init__(self, metadata):
|
||||
self.metadata = metadata
|
||||
self.media_type = metadata['media_type']
|
||||
def __init__(self, parameters):
|
||||
self.parameters = parameters
|
||||
self.media_type = parameters['media_type']
|
||||
|
||||
def get_poster_url(self):
|
||||
self.poster_url = self.metadata.get('poster_url','')
|
||||
self.poster_url = self.parameters['poster_url']
|
||||
if not self.poster_url:
|
||||
if self.media_type in ('artist', 'album', 'track'):
|
||||
self.poster_url = 'https://raw.githubusercontent.com/%s/plexpy/master/data/interfaces/default/images/cover.png' % plexpy.CONFIG.GIT_USER
|
||||
|
@ -519,59 +519,59 @@ class PrettyMetadata(object):
|
|||
|
||||
def get_poster_link(self):
|
||||
self.poster_link = ''
|
||||
if self.metadata.get('thetvdb_url',''):
|
||||
self.poster_link = self.metadata.get('thetvdb_url', '')
|
||||
elif self.metadata.get('themoviedb_url',''):
|
||||
self.poster_link = self.metadata.get('themoviedb_url', '')
|
||||
elif self.metadata.get('imdb_url',''):
|
||||
self.poster_link = self.metadata.get('imdb_url', '')
|
||||
elif self.metadata.get('lastfm_url',''):
|
||||
self.poster_link = self.metadata.get('lastfm_url', '')
|
||||
if self.parameters['thetvdb_url']:
|
||||
self.poster_link = self.parameters['thetvdb_url']
|
||||
elif self.parameters['themoviedb_url']:
|
||||
self.poster_link = self.parameters['themoviedb_url']
|
||||
elif self.parameters['imdb_url']:
|
||||
self.poster_link = self.parameters['imdb_url']
|
||||
elif self.parameters['lastfm_url']:
|
||||
self.poster_link = self.parameters['lastfm_url']
|
||||
return self.poster_link
|
||||
|
||||
def get_caption(self):
|
||||
self.caption = ''
|
||||
if self.metadata.get('thetvdb_url',''):
|
||||
if self.parameters['thetvdb_url']:
|
||||
self.caption = 'View on TheTVDB'
|
||||
elif self.metadata.get('themoviedb_url',''):
|
||||
elif self.parameters['themoviedb_url']:
|
||||
self.caption = 'View on The Movie Database'
|
||||
elif self.metadata.get('imdb_url',''):
|
||||
elif self.parameters['imdb_url']:
|
||||
self.caption = 'View on IMDB'
|
||||
elif self.metadata.get('lastfm_url',''):
|
||||
elif self.parameters['lastfm_url']:
|
||||
self.caption = 'View on Last.fm'
|
||||
return self.caption
|
||||
|
||||
def get_title(self, divider = '-'):
|
||||
self.title = ''
|
||||
if self.media_type == 'movie':
|
||||
self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year'])
|
||||
self.title = '%s (%s)' % (self.parameters['title'], self.parameters['year'])
|
||||
elif self.media_type == 'show':
|
||||
self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year'])
|
||||
self.title = '%s (%s)' % (self.parameters['show_name'], self.parameters['year'])
|
||||
elif self.media_type == 'season':
|
||||
self.title = '%s - %s' % (self.metadata['parent_title'], self.metadata['title'])
|
||||
self.title = '%s - Season %s' % (self.parameters['show_name'], self.parameters['season_num'])
|
||||
elif self.media_type == 'episode':
|
||||
self.title = '%s - %s (S%s %s E%s)' % (self.metadata['grandparent_title'],
|
||||
self.metadata['title'],
|
||||
self.metadata['parent_media_index'],
|
||||
self.title = '%s - %s (S%s %s E%s)' % (self.parameters['show_name'],
|
||||
self.parameters['episode_name'],
|
||||
self.parameters['season_num'],
|
||||
divider,
|
||||
self.metadata['media_index'])
|
||||
self.parameters['episode_num'])
|
||||
elif self.media_type == 'artist':
|
||||
self.title = self.metadata['title']
|
||||
self.title = self.parameters['artist_name']
|
||||
elif self.media_type == 'album':
|
||||
self.title = '%s - %s' % (self.metadata['parent_title'], self.metadata['title'])
|
||||
self.title = '%s - %s' % (self.parameters['artist_name'], self.parameters['album_name'])
|
||||
elif self.media_type == 'track':
|
||||
self.title = '%s - %s' % (self.metadata['grandparent_title'], self.metadata['title'])
|
||||
self.title = '%s - %s' % (self.parameters['artist_name'], self.parameters['track_name'])
|
||||
return self.title.encode("utf-8")
|
||||
|
||||
def get_subtitle(self):
|
||||
if self.media_type == 'track':
|
||||
self.subtitle = self.metadata['parent_title']
|
||||
self.subtitle = self.parameters['album_name']
|
||||
else:
|
||||
self.subtitle = self.metadata['summary']
|
||||
self.subtitle = self.parameters['summary']
|
||||
return self.subtitle.encode("utf-8")
|
||||
|
||||
def get_plex_url(self):
|
||||
self.plex_url = self.metadata['plex_url']
|
||||
self.plex_url = self.parameters['plex_url']
|
||||
return self.plex_url
|
||||
|
||||
|
||||
|
@ -777,9 +777,9 @@ class DISCORD(Notifier):
|
|||
#if self.config['tts']:
|
||||
# data['tts'] = True
|
||||
|
||||
if self.config['incl_poster'] and 'metadata' in kwargs:
|
||||
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||
# Grab formatted metadata
|
||||
pretty_metadata = PrettyMetadata(kwargs['metadata'])
|
||||
pretty_metadata = PrettyMetadata(kwargs['parameters'])
|
||||
poster_url = pretty_metadata.get_poster_url()
|
||||
plex_url = pretty_metadata.get_plex_url()
|
||||
poster_link = pretty_metadata.get_poster_link()
|
||||
|
@ -1075,9 +1075,9 @@ class FACEBOOK(Notifier):
|
|||
|
||||
attachment = {}
|
||||
|
||||
if self.config['incl_poster'] and 'metadata' in kwargs:
|
||||
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||
# Grab formatted metadata
|
||||
pretty_metadata = PrettyMetadata(kwargs['metadata'])
|
||||
pretty_metadata = PrettyMetadata(kwargs['parameters'])
|
||||
poster_url = pretty_metadata.get_poster_url()
|
||||
plex_url = pretty_metadata.get_plex_url()
|
||||
poster_link = pretty_metadata.get_poster_link()
|
||||
|
@ -2261,7 +2261,7 @@ class SCRIPTS(Notifier):
|
|||
|
||||
# Allow overrides for shitty systems
|
||||
if prefix and script_args:
|
||||
if script_args[0] in ['python2', 'python', 'pythonw', 'php', 'ruby', 'perl']:
|
||||
if script_args[0] in ('python2', 'python', 'pythonw', 'php', 'ruby', 'perl'):
|
||||
script[0] = script_args[0]
|
||||
del script_args[0]
|
||||
|
||||
|
@ -2337,9 +2337,9 @@ class SLACK(Notifier):
|
|||
else:
|
||||
data['icon_url'] = self.config['icon_emoji']
|
||||
|
||||
if self.config['incl_poster'] and 'metadata' in kwargs:
|
||||
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||
# Grab formatted metadata
|
||||
pretty_metadata = PrettyMetadata(kwargs['metadata'])
|
||||
pretty_metadata = PrettyMetadata(kwargs['parameters'])
|
||||
poster_url = pretty_metadata.get_poster_url()
|
||||
plex_url = pretty_metadata.get_plex_url()
|
||||
poster_link = pretty_metadata.get_poster_link()
|
||||
|
@ -2461,12 +2461,12 @@ class TELEGRAM(Notifier):
|
|||
else:
|
||||
text = body.encode('utf-8')
|
||||
|
||||
if self.config['incl_poster'] and 'metadata' in kwargs:
|
||||
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||
poster_data = {'chat_id': self.config['chat_id'],
|
||||
'disable_notification': True}
|
||||
|
||||
metadata = kwargs['metadata']
|
||||
poster_url = metadata.get('poster_url','')
|
||||
parameters = kwargs['parameters']
|
||||
poster_url = parameters.get('poster_url','')
|
||||
|
||||
if poster_url:
|
||||
files = {'photo': (poster_url, urllib.urlopen(poster_url).read())}
|
||||
|
@ -2595,9 +2595,9 @@ class TWITTER(Notifier):
|
|||
return
|
||||
|
||||
poster_url = ''
|
||||
if self.config['incl_poster'] and 'metadata' in kwargs:
|
||||
metadata = kwargs['metadata']
|
||||
poster_url = metadata.get('poster_url','')
|
||||
if self.config['incl_poster'] and kwargs.get('parameters'):
|
||||
parameters = kwargs['parameters']
|
||||
poster_url = parameters.get('poster_url','')
|
||||
|
||||
if self.config['incl_subject']:
|
||||
return self._send_tweet(subject + '\r\n' + body, attachment=poster_url)
|
||||
|
|
|
@ -728,7 +728,7 @@ class PmsConnect(object):
|
|||
'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'),
|
||||
'grandparent_rating_key': helpers.get_xml_attr(metadata_main, 'grandparentRatingKey'),
|
||||
'title': helpers.get_xml_attr(metadata_main, 'title'),
|
||||
'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'),
|
||||
'parent_title': 'Season %s' % helpers.get_xml_attr(metadata_main, 'parentIndex'),
|
||||
'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'),
|
||||
'media_index': helpers.get_xml_attr(metadata_main, 'index'),
|
||||
'parent_media_index': helpers.get_xml_attr(metadata_main, 'parentIndex'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue