Add user new device notification setting for initial stream only

This commit is contained in:
JonnyWong16 2020-11-08 13:16:49 -08:00
parent dfb60de6d2
commit 89ab665923
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 26 additions and 3 deletions

View file

@ -997,6 +997,15 @@
</div>
<p class="help-block">The number of concurrent streams by a single user for Tautulli to trigger a notification. Minimum 2.</p>
</div>
<div class="checkbox advanced-setting">
<label>
<input type="checkbox" name="notify_new_device_initial_only" id="notify_new_device_initial_only" value="1" ${config['notify_new_device_initial_only']}> User New Device Notification First Time Only
</label>
<p class="help-block">
Enable to only send a new device notification the first time a user streams from a new device.
Disable to send a new device notification everytime a user streams from the device until it is recorded in history (i.e. exceeds the ignore interval).
</p>
</div>
<div class="form-group advanced-setting">
<label for="notify_concurrent_threshold">Continued Session Threshold</label>
<div class="row">

View file

@ -167,6 +167,7 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_REMOTE_ACCESS_THRESHOLD': (int, 'Monitoring', 60),
'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0),
'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2),
'NOTIFY_NEW_DEVICE_INITIAL_ONLY': (int, 'Monitoring', 1),
'PLEXPY_AUTO_UPDATE': (int, 'General', 0),
'REFRESH_LIBRARIES_INTERVAL': (int, 'Monitoring', 12),
'REFRESH_LIBRARIES_ON_STARTUP': (int, 'Monitoring', 1),

View file

@ -1841,12 +1841,22 @@ class DataFactory(object):
logger.warn("Tautulli DataFactory :: Unable to execute database query for delete_newsletter_log: %s." % e)
return False
def get_user_devices(self, user_id=''):
def get_user_devices(self, user_id='', history_only=True):
monitor_db = database.MonitorDatabase()
if user_id:
if history_only:
query = 'SELECT machine_id FROM session_history ' \
'WHERE user_id = ? ' \
'GROUP BY machine_id'
else:
query = 'SELECT * FROM (' \
'SELECT user_id, machine_id FROM session_history ' \
'UNION SELECT user_id, machine_id from sessions_continued) ' \
'WHERE user_id = ? ' \
'GROUP BY machine_id'
try:
query = 'SELECT machine_id FROM session_history WHERE user_id = ? GROUP BY machine_id'
result = monitor_db.select(query=query, args=[user_id])
except Exception as e:
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_user_devices: %s." % e)

View file

@ -193,7 +193,8 @@ def notify_conditions(notify_action=None, stream_data=None, timeline_data=None):
elif notify_action == 'on_newdevice':
data_factory = datafactory.DataFactory()
user_devices = data_factory.get_user_devices(user_id=stream_data['user_id'])
user_devices = data_factory.get_user_devices(user_id=stream_data['user_id'],
history_only=not plexpy.CONFIG.NOTIFY_NEW_DEVICE_INITIAL_ONLY)
evaluated = stream_data['machine_id'] not in user_devices
elif stream_data['media_type'] in ('movie', 'episode', 'clip'):

View file

@ -3136,6 +3136,7 @@ class WebInterface(object):
"notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP),
"notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD,
"notify_continued_session_threshold": plexpy.CONFIG.NOTIFY_CONTINUED_SESSION_THRESHOLD,
"notify_new_device_initial_only": checked(plexpy.CONFIG.NOTIFY_NEW_DEVICE_INITIAL_ONLY),
"home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS),
"home_stats_cards": json.dumps(plexpy.CONFIG.HOME_STATS_CARDS),
"home_library_cards": json.dumps(plexpy.CONFIG.HOME_LIBRARY_CARDS),
@ -3199,6 +3200,7 @@ class WebInterface(object):
"refresh_libraries_on_startup", "refresh_users_on_startup",
"notify_consecutive", "notify_recently_added_upgrade",
"notify_group_recently_added_grandparent", "notify_group_recently_added_parent",
"notify_new_device_initial_only",
"monitor_pms_updates", "get_file_sizes", "log_blacklist", "http_hash_password",
"allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip",
"history_table_activity", "plexpy_auto_update",