VERY EXPERIMENTAL CHANGES!

History logging is now under the hood. Disabled by default.
Write new database tables and upgrade old ones.
Provide more detail to get_activity.
This commit is contained in:
Tim 2015-07-11 22:10:45 +02:00
commit 9152fa01af
9 changed files with 596 additions and 89 deletions

View file

@ -367,11 +367,58 @@ def dbcheck():
conn_db = sqlite3.connect(DB_FILE)
c_db = conn_db.cursor()
# sessions table :: This is a temp table that logs currently active sessions
c_db.execute(
'CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'session_key INTEGER, rating_key INTEGER, media_type TEXT, started INTEGER, '
'paused_counter INTEGER, state TEXT, user_id INTEGER, user TEXT, friendly_name TEXT, '
'machine_id TEXT, player TEXT, title TEXT, parent_title TEXT, grandparent_title TEXT)'
'paused_counter INTEGER, state TEXT, user_id INTEGER, user TEXT, friendly_name TEXT, ip_address TEXT, '
'machine_id TEXT, player TEXT, platform TEXT, title TEXT, parent_title TEXT, '
'grandparent_title TEXT, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
'view_offset INTEGER DEFAULT 0, duration INTEGER, video_decision TEXT, audio_decision TEXT, '
'width INTEGER, height INTEGER, container TEXT, video_codec TEXT, audio_codec TEXT, '
'bitrate INTEGER, video_resolution TEXT, video_framerate TEXT, aspect_ratio TEXT, '
'audio_channels INTEGER, transcode_protocol TEXT, transcode_container TEXT, '
'transcode_video_codec TEXT, transcode_audio_codec TEXT, transcode_audio_channels INTEGER,'
'transcode_width INTEGER, transcode_height INTEGER)'
)
# session_history table :: This is a history table which logs essential stream details
c_db.execute(
'CREATE TABLE IF NOT EXISTS session_history (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'started INTEGER, stopped INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
'ip_address TEXT, paused_counter INTEGER, player TEXT, platform TEXT, machine_id TEXT, '
'parent_rating_key INTEGER, grandparent_rating_key INTEGER, media_type TEXT, view_offset INTEGER)'
)
# session_history_media_info table :: This is a table which logs each session's media info
c_db.execute(
'CREATE TABLE IF NOT EXISTS session_history_media_info (id INTEGER PRIMARY KEY, '
'rating_key INTEGER, video_decision TEXT, audio_decision TEXT, duration INTEGER, width INTEGER, '
'height INTEGER, container TEXT, video_codec TEXT, audio_codec TEXT, bitrate INTEGER, video_resolution TEXT, '
'video_framerate TEXT, aspect_ratio TEXT, audio_channels INTEGER, transcode_protocol TEXT, '
'transcode_container TEXT, transcode_video_codec TEXT, transcode_audio_codec TEXT, '
'transcode_audio_channels INTEGER, transcode_width INTEGER, transcode_height INTEGER)'
)
# session_history_metadata table :: This is a table which logs each session's media metadata
c_db.execute(
'CREATE TABLE IF NOT EXISTS session_history_metadata (id INTEGER PRIMARY KEY, '
'rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, '
'title TEXT, parent_title TEXT, grandparent_title TEXT, media_index INTEGER, parent_media_index INTEGER, '
'thumb TEXT, parent_thumb TEXT, grandparent_thumb TEXT, art TEXT, media_type TEXT, '
'year INTEGER, originally_available_at TEXT, added_at INTEGER, updated_at INTEGER, last_viewed_at INTEGER, '
'content_rating TEXT, summary TEXT, rating TEXT, duration INTEGER, guid TEXT, '
'directors TEXT, writers TEXT, actors TEXT, genres TEXT, studio TEXT)'
''
)
# users table :: This table keeps record of the friends list
c_db.execute(
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, '
'is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL)'
)
# Upgrade sessions table from earlier versions
@ -419,6 +466,87 @@ def dbcheck():
'ALTER TABLE sessions ADD COLUMN user_id INTEGER'
)
# Upgrade sessions table from earlier versions
try:
c_db.execute('SELECT ip_address from sessions')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table sessions.")
c_db.execute(
'ALTER TABLE sessions ADD COLUMN ip_address TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN platform TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN parent_rating_key INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN grandparent_rating_key INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN view_offset INTEGER DEFAULT 0'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN duration INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN video_decision TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN audio_decision TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN width INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN height INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN container TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN video_codec TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN audio_codec TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN bitrate INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN video_resolution TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN video_framerate TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN aspect_ratio TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN audio_channels INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_protocol TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_container TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_video_codec TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_audio_codec TEXT'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_audio_channels INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_width INTEGER'
)
c_db.execute(
'ALTER TABLE sessions ADD COLUMN transcode_height INTEGER'
)
conn_db.commit()
c_db.close()

View file

@ -73,6 +73,7 @@ _CONFIG_DEFINITIONS = {
'JOURNAL_MODE': (str, 'Advanced', 'wal'),
'LAUNCH_BROWSER': (int, 'General', 1),
'LOG_DIR': (str, 'General', ''),
'LOGGING_IGNORE_INTERVAL': (int, 'Monitoring', 120),
'MOVIE_NOTIFY_ENABLE': (int, 'Monitoring', 0),
'MOVIE_NOTIFY_ON_START': (int, 'Monitoring', 1),
'MOVIE_NOTIFY_ON_STOP': (int, 'Monitoring', 0),
@ -81,6 +82,7 @@ _CONFIG_DEFINITIONS = {
'MUSIC_NOTIFY_ON_START': (int, 'Monitoring', 1),
'MUSIC_NOTIFY_ON_STOP': (int, 'Monitoring', 0),
'MUSIC_NOTIFY_ON_PAUSE': (int, 'Monitoring', 0),
'MUSIC_LOGGING_ENABLE': (int, 'Monitoring', 0),
'MONITORING_INTERVAL': (int, 'Monitoring', 60),
'NMA_APIKEY': (str, 'NMA', ''),
'NMA_ENABLED': (int, 'NMA', 0),
@ -115,6 +117,7 @@ _CONFIG_DEFINITIONS = {
'TWITTER_USERNAME': (str, 'Twitter', ''),
'UPDATE_DB_INTERVAL': (int, 'General', 24),
'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1),
'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 0),
'XBMC_ENABLED': (int, 'XBMC', 0),
'XBMC_HOST': (str, 'XBMC', ''),
'XBMC_PASSWORD': (str, 'XBMC', ''),

View file

@ -41,21 +41,55 @@ def check_active_sessions():
media_container = session_list['sessions']
# Check our temp table for what we must do with the new streams
db_streams = monitor_db.select('SELECT session_key, rating_key, media_type, title, parent_title, '
'grandparent_title, user, friendly_name, player, state '
db_streams = monitor_db.select('SELECT started, session_key, rating_key, media_type, title, parent_title, '
'grandparent_title, user_id, user, friendly_name, ip_address, player, '
'platform, machine_id, parent_rating_key, grandparent_rating_key, state, '
'view_offset, duration, video_decision, audio_decision, width, height, '
'container, video_codec, audio_codec, bitrate, video_resolution, '
'video_framerate, aspect_ratio, audio_channels, transcode_protocol, '
'transcode_container, transcode_video_codec, transcode_audio_codec, '
'transcode_audio_channels, transcode_width, transcode_height '
'FROM sessions')
for result in db_streams:
# Build a result dictionary for easier referencing
stream = {'session_key': result[0],
'rating_key': result[1],
'media_type': result[2],
'title': result[3],
'parent_title': result[4],
'grandparent_title': result[5],
'user': result[6],
'friendly_name': result[7],
'player': result[8],
'state': result[9]
stream = {'started': result[0],
'session_key': result[1],
'rating_key': result[2],
'media_type': result[3],
'title': result[4],
'parent_title': result[5],
'grandparent_title': result[6],
'user_id': result[7],
'user': result[8],
'friendly_name': result[9],
'ip_address': result[10],
'player': result[11],
'platform': result[12],
'machine_id': result[13],
'parent_rating_key': result[14],
'grandparent_rating_key': result[15],
'state': result[16],
'view_offset': result[17],
'duration': result[18],
'video_decision': result[19],
'audio_decision': result[20],
'width': result[21],
'height': result[22],
'container': result[23],
'video_codec': result[24],
'audio_codec': result[25],
'bitrate': result[26],
'video_resolution': result[27],
'video_framerate': result[28],
'aspect_ratio': result[29],
'audio_channels': result[30],
'transcode_protocol': result[31],
'transcode_container': result[32],
'transcode_video_codec': result[33],
'transcode_audio_codec': result[34],
'transcode_audio_channels': result[35],
'transcode_width': result[36],
'transcode_height': result[37]
}
if any(d['session_key'] == str(stream['session_key']) for d in media_container):
@ -70,15 +104,20 @@ def check_active_sessions():
notify(stream_data=stream, notify_action='pause')
else:
# The user has stopped playing a stream
logger.debug(u"Removing sessionKey %s ratingKey %s from session queue"
% (stream['session_key'], stream['rating_key']))
monitor_db.action('DELETE FROM sessions WHERE session_key = ? AND rating_key = ?',
[stream['session_key'], stream['rating_key']])
# Push any notifications
notify(stream_data=stream, notify_action='stop')
monitor_process.write_session_history(session=stream)
else:
# The user's session is no longer active
logger.debug(u"Removing sessionKey %s from session queue" % stream['session_key'])
monitor_db.action('DELETE FROM sessions WHERE session_key = ?', [stream['session_key']])
# Push any notifications
notify(stream_data=stream, notify_action='stop')
monitor_process.write_session_history(session=stream)
# Process the newly received session data
for session in media_container:
@ -151,6 +190,15 @@ class MonitorDatabase(object):
return sql_results
def select_single(self, query, args=None):
sql_results = self.action(query, args).fetchone()[0]
if sql_results is None or sql_results == "":
return ""
return sql_results
def upsert(self, table_name, value_dict, key_dict):
trans_type = 'update'
@ -188,33 +236,149 @@ class MonitorProcessing(object):
values = {'rating_key': session['rating_key'],
'media_type': session['type'],
'state': session['state'],
'user_id': session['user_id'],
'user': session['user'],
'machine_id': session['machine_id'],
'title': session['title'],
'parent_title': session['parent_title'],
'grandparent_title': session['grandparent_title'],
'friendly_name': session['friendly_name'],
'player': session['player']
'player': session['player'],
'platform': session['platform'],
'parent_rating_key': session['parent_rating_key'],
'grandparent_rating_key': session['grandparent_rating_key'],
'view_offset': session['progress'],
'duration': session['duration'],
'video_decision': session['video_decision'],
'audio_decision': session['audio_decision'],
'width': session['width'],
'height': session['height'],
'container': session['container'],
'video_codec': session['video_codec'],
'audio_codec': session['audio_codec'],
'bitrate': session['bitrate'],
'video_resolution': session['video_resolution'],
'video_framerate': session['video_framerate'],
'aspect_ratio': session['aspect_ratio'],
'audio_channels': session['audio_channels'],
'transcode_protocol': session['transcode_protocol'],
'transcode_container': session['transcode_container'],
'transcode_video_codec': session['transcode_video_codec'],
'transcode_audio_codec': session['transcode_audio_codec'],
'transcode_audio_channels': session['transcode_audio_channels'],
'transcode_width': session['transcode_width'],
'transcode_height': session['transcode_height']
}
timestamp = {'started': int(time.time())}
keys = {'session_key': session['session_key'],
'rating_key': session['rating_key']}
result = self.db.upsert('sessions', values, keys)
if result == 'insert':
# If it's our first write then time stamp it.
self.db.upsert('sessions', timestamp, keys)
# Push any notifications
notify(stream_data=values, notify_action='play')
started = int(time.time())
# Try and grab IP address from logs
if plexpy.CONFIG.IP_LOGGING_ENABLE and plexpy.CONFIG.PMS_LOGS_FOLDER:
ip_address = self.find_session_ip(rating_key=session['rating_key'],
machine_id=session['machine_id'])
else:
ip_address = None
timestamp = {'started': started,
'ip_address': ip_address}
# If it's our first write then time stamp it.
self.db.upsert('sessions', timestamp, keys)
def write_session_history(self, session=None):
if session:
logging_enabled = False
if plexpy.CONFIG.VIDEO_LOGGING_ENABLE and \
(session['media_type'] == 'movie' or session['media_type'] == 'episode'):
logging_enabled = True
if plexpy.CONFIG.MUSIC_LOGGING_ENABLE and \
session['media_type'] == 'track':
logging_enabled = True
if plexpy.CONFIG.LOGGING_IGNORE_INTERVAL:
if (session['media_type'] == 'movie' or session['media_type'] == 'episode') and \
(int(time.time()) - session['started'] < plexpy.CONFIG.LOGGING_IGNORE_INTERVAL):
logging_enabled = False
logger.debug(u"Item played for %s seconds which is less than %s seconds, so we're not logging it." %
(str(int(time.time()) - session['started']), plexpy.CONFIG.LOGGING_IGNORE_INTERVAL))
if logging_enabled:
logger.debug(u"PlexPy Monitor :: Attempting to write to session_history table...")
query = 'INSERT INTO session_history (started, stopped, rating_key, parent_rating_key, grandparent_rating_key, ' \
'media_type, user_id, user, ip_address, player, platform, machine_id, view_offset) VALUES ' \
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
args = [session['started'], int(time.time()), session['rating_key'], session['parent_rating_key'],
session['grandparent_rating_key'], session['media_type'], session['user_id'], session['user'],
session['ip_address'], session['player'], session['platform'], session['machine_id'],
session['view_offset']]
logger.debug(u"Writing session_history transaction...")
self.db.action(query=query, args=args)
# Get the id for the last transaction
last_id = self.db.select_single('SELECT max(id) FROM session_history')
logger.debug(u"Successfully written history item, last id for session_history is %s" % last_id)
logger.debug(u"PlexPy Monitor :: Attempting to write to session_history_media_info table...")
query = 'INSERT INTO session_history_media_info (id, rating_key, video_decision, audio_decision, ' \
'duration, width, height, container, video_codec, audio_codec, bitrate, video_resolution, ' \
'video_framerate, aspect_ratio, audio_channels, transcode_protocol, transcode_container, ' \
'transcode_video_codec, transcode_audio_codec, transcode_audio_channels, transcode_width, ' \
'transcode_height) VALUES ' \
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
args = [last_id, session['rating_key'], session['video_decision'], session['audio_decision'],
session['duration'], session['width'], session['height'], session['container'],
session['video_codec'], session['audio_codec'], session['bitrate'],
session['video_resolution'], session['video_framerate'], session['aspect_ratio'],
session['audio_channels'], session['transcode_protocol'], session['transcode_container'],
session['transcode_video_codec'], session['transcode_audio_codec'],
session['transcode_audio_channels'], session['transcode_width'], session['transcode_height']]
logger.debug(u"Writing session_history_media_info transaction...")
self.db.action(query=query, args=args)
logger.debug(u"PlexPy Monitor :: Fetching metadata for item ratingKey %s" % session['rating_key'])
pms_connect = pmsconnect.PmsConnect()
result = pms_connect.get_metadata_details(rating_key=str(session['rating_key']))
metadata = result['metadata']
directors = ";".join(metadata['directors'])
writers = ";".join(metadata['writers'])
actors = ";".join(metadata['actors'])
genres = ";".join(metadata['genres'])
logger.debug(u"PlexPy Monitor :: Attempting to write to session_history_metadata table...")
query = 'INSERT INTO session_history_metadata (id, rating_key, parent_rating_key, ' \
'grandparent_rating_key, title, parent_title, grandparent_title, media_index, ' \
'parent_media_index, thumb, parent_thumb, grandparent_thumb, art, media_type, year, ' \
'originally_available_at, added_at, updated_at, last_viewed_at, content_rating, summary, ' \
'rating, duration, guid, directors, writers, actors, genres, studio) VALUES ' \
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
args = [last_id, session['rating_key'], session['parent_rating_key'], session['grandparent_rating_key'],
session['title'], session['parent_title'], session['grandparent_title'], metadata['index'],
metadata['parent_index'], metadata['thumb'], metadata['parent_thumb'],
metadata['grandparent_thumb'], metadata['art'], session['media_type'], metadata['year'],
metadata['originally_available_at'], metadata['added_at'], metadata['updated_at'],
metadata['last_viewed_at'], metadata['content_rating'], metadata['summary'], metadata['rating'],
metadata['duration'], metadata['guid'], directors, writers, actors, genres, metadata['studio']]
logger.debug(u"Writing session_history_metadata transaction...")
self.db.action(query=query, args=args)
def find_session_ip(self, rating_key=None, machine_id=None):

View file

@ -263,6 +263,9 @@ class PmsConnect(object):
elif a.getElementsByTagName('Video'):
metadata_main = a.getElementsByTagName('Video')[0]
metadata_type = helpers.get_xml_attr(metadata_main, 'type')
elif a.getElementsByTagName('Track'):
metadata_main = a.getElementsByTagName('Track')[0]
metadata_type = helpers.get_xml_attr(metadata_main, 'type')
else:
logger.debug(u"Metadata failed")
@ -299,12 +302,17 @@ class PmsConnect(object):
'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'),
'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'duration': helpers.convert_milliseconds_to_minutes(helpers.get_xml_attr(metadata_main, 'duration')),
'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'),
'originally_available_at': helpers.get_xml_attr(metadata_main, 'originallyAvailableAt'),
'added_at': helpers.get_xml_attr(metadata_main, 'addedAt'),
'updated_at': helpers.get_xml_attr(metadata_main, 'updatedAt'),
'last_viewed_at': helpers.get_xml_attr(metadata_main, 'lastViewedAt'),
'guid': helpers.get_xml_attr(metadata_main, 'guid'),
'writers': writers,
'directors': directors,
'genres': genres,
@ -323,12 +331,17 @@ class PmsConnect(object):
'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'),
'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'duration': helpers.convert_milliseconds_to_minutes(helpers.get_xml_attr(metadata_main, 'duration')),
'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'),
'originally_available_at': helpers.get_xml_attr(metadata_main, 'originallyAvailableAt'),
'added_at': helpers.get_xml_attr(metadata_main, 'addedAt'),
'updated_at': helpers.get_xml_attr(metadata_main, 'updatedAt'),
'last_viewed_at': helpers.get_xml_attr(metadata_main, 'lastViewedAt'),
'guid': helpers.get_xml_attr(metadata_main, 'guid'),
'writers': writers,
'directors': directors,
'genres': genres,
@ -347,12 +360,17 @@ class PmsConnect(object):
'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'),
'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'duration': helpers.convert_milliseconds_to_minutes(helpers.get_xml_attr(metadata_main, 'duration')),
'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'),
'originally_available_at': helpers.get_xml_attr(metadata_main, 'originallyAvailableAt'),
'added_at': helpers.get_xml_attr(metadata_main, 'addedAt'),
'updated_at': helpers.get_xml_attr(metadata_main, 'updatedAt'),
'last_viewed_at': helpers.get_xml_attr(metadata_main, 'lastViewedAt'),
'guid': helpers.get_xml_attr(metadata_main, 'guid'),
'genres': genres,
'actors': actors,
'writers': writers,
@ -377,8 +395,42 @@ class PmsConnect(object):
'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'),
'originally_available_at': helpers.get_xml_attr(metadata_main, 'originallyAvailableAt'),
'added_at': helpers.get_xml_attr(metadata_main, 'addedAt'),
'updated_at': helpers.get_xml_attr(metadata_main, 'updatedAt'),
'last_viewed_at': helpers.get_xml_attr(metadata_main, 'lastViewedAt'),
'guid': helpers.get_xml_attr(metadata_main, 'guid'),
'genres': genres,
'actors': actors,
'writers': writers,
'directors': directors
}
metadata_list = {'metadata': metadata}
elif metadata_type == 'track':
metadata = {'type': metadata_type,
'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'),
'grandparent_title': helpers.get_xml_attr(metadata_main, 'grandparentTitle'),
'parent_index': helpers.get_xml_attr(metadata_main, 'parentIndex'),
'parent_title': helpers.get_xml_attr(metadata_main, 'parentTitle'),
'index': helpers.get_xml_attr(metadata_main, 'index'),
'studio': helpers.get_xml_attr(metadata_main, 'studio'),
'title': helpers.get_xml_attr(metadata_main, 'title'),
'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'),
'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'),
'originally_available_at': helpers.get_xml_attr(metadata_main, 'originallyAvailableAt'),
'added_at': helpers.get_xml_attr(metadata_main, 'addedAt'),
'updated_at': helpers.get_xml_attr(metadata_main, 'updatedAt'),
'last_viewed_at': helpers.get_xml_attr(metadata_main, 'lastViewedAt'),
'guid': helpers.get_xml_attr(metadata_main, 'guid'),
'genres': genres,
'actors': actors,
'writers': writers,
@ -445,20 +497,29 @@ class PmsConnect(object):
session_output = None
plex_watch = plexwatch.PlexWatch()
if stream_type == 'track':
media_info = session.getElementsByTagName('Media')[0]
audio_decision = 'direct play'
audio_channels = helpers.get_xml_attr(media_info, 'audioChannels')
audio_codec = helpers.get_xml_attr(media_info, 'audioCodec')
container = helpers.get_xml_attr(media_info, 'container')
bitrate = helpers.get_xml_attr(media_info, 'bitrate')
duration = helpers.get_xml_attr(media_info, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
if session.getElementsByTagName('TranscodeSession'):
transcode_session = session.getElementsByTagName('TranscodeSession')[0]
audio_decision = helpers.get_xml_attr(transcode_session, 'audioDecision')
audio_channels = helpers.get_xml_attr(transcode_session, 'audioChannels')
audio_codec = helpers.get_xml_attr(transcode_session, 'audioCodec')
transcode_audio_channels = helpers.get_xml_attr(transcode_session, 'audioChannels')
transcode_audio_codec = helpers.get_xml_attr(transcode_session, 'audioCodec')
transcode_container = helpers.get_xml_attr(transcode_session, 'container')
transcode_protocol = helpers.get_xml_attr(transcode_session, 'protocol')
duration = helpers.get_xml_attr(transcode_session, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
else:
media_info = session.getElementsByTagName('Media')[0]
audio_decision = 'direct play'
audio_channels = helpers.get_xml_attr(media_info, 'audioChannels')
audio_codec = helpers.get_xml_attr(media_info, 'audioCodec')
duration = helpers.get_xml_attr(media_info, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
transcode_audio_channels = ''
transcode_audio_codec = ''
transcode_container = ''
transcode_protocol = ''
user_details = plex_watch.get_user_details(
user=helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'))
@ -471,7 +532,9 @@ class PmsConnect(object):
session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'),
'art': helpers.get_xml_attr(session, 'art'),
'parent_thumb': helpers.get_xml_attr(session, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(session, 'grandparentThumb'),
'thumb': helpers.get_xml_attr(session, 'thumb'),
'bif_thumb': '',
'user': helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'),
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
@ -483,6 +546,8 @@ class PmsConnect(object):
'parent_title': helpers.get_xml_attr(session, 'parentTitle'),
'title': helpers.get_xml_attr(session, 'title'),
'rating_key': helpers.get_xml_attr(session, 'ratingKey'),
'parent_rating_key': helpers.get_xml_attr(session, 'parentRatingKey'),
'grandparent_rating_key': helpers.get_xml_attr(session, 'grandparentRatingKey'),
'audio_decision': audio_decision,
'audio_channels': audio_channels,
'audio_codec': audio_codec,
@ -490,6 +555,18 @@ class PmsConnect(object):
'video_codec': '',
'height': '',
'width': '',
'container': container,
'bitrate': bitrate,
'video_resolution': '',
'video_framerate': '',
'aspect_ratio': '',
'transcode_audio_channels': transcode_audio_channels,
'transcode_audio_codec': transcode_audio_codec,
'transcode_video_codec': '',
'transcode_width': '',
'transcode_height': '',
'transcode_container': transcode_container,
'transcode_protocol': transcode_protocol,
'duration': duration,
'progress': progress,
'progress_percent': str(helpers.get_percent(progress, duration)),
@ -497,28 +574,41 @@ class PmsConnect(object):
'indexes': 0
}
elif stream_type == 'video':
media_info = session.getElementsByTagName('Media')[0]
audio_decision = 'direct play'
audio_channels = helpers.get_xml_attr(media_info, 'audioChannels')
audio_codec = helpers.get_xml_attr(media_info, 'audioCodec')
video_decision = 'direct play'
video_codec = helpers.get_xml_attr(media_info, 'videoCodec')
container = helpers.get_xml_attr(media_info, 'container')
bitrate = helpers.get_xml_attr(media_info, 'bitrate')
video_resolution = helpers.get_xml_attr(media_info, 'videoResolution')
video_framerate = helpers.get_xml_attr(media_info, 'videoFrameRate')
aspect_ratio = helpers.get_xml_attr(media_info, 'aspectRatio')
width = helpers.get_xml_attr(media_info, 'width')
height = helpers.get_xml_attr(media_info, 'height')
duration = helpers.get_xml_attr(media_info, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
if session.getElementsByTagName('TranscodeSession'):
transcode_session = session.getElementsByTagName('TranscodeSession')[0]
audio_decision = helpers.get_xml_attr(transcode_session, 'audioDecision')
audio_channels = helpers.get_xml_attr(transcode_session, 'audioChannels')
audio_codec = helpers.get_xml_attr(transcode_session, 'audioCodec')
transcode_audio_channels = helpers.get_xml_attr(transcode_session, 'audioChannels')
transcode_audio_codec = helpers.get_xml_attr(transcode_session, 'audioCodec')
video_decision = helpers.get_xml_attr(transcode_session, 'videoDecision')
video_codec = helpers.get_xml_attr(transcode_session, 'videoCodec')
width = helpers.get_xml_attr(transcode_session, 'width')
height = helpers.get_xml_attr(transcode_session, 'height')
duration = helpers.get_xml_attr(session, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
transcode_video_codec = helpers.get_xml_attr(transcode_session, 'videoCodec')
transcode_width = helpers.get_xml_attr(transcode_session, 'width')
transcode_height = helpers.get_xml_attr(transcode_session, 'height')
transcode_container = helpers.get_xml_attr(transcode_session, 'container')
transcode_protocol = helpers.get_xml_attr(transcode_session, 'protocol')
else:
media_info = session.getElementsByTagName('Media')[0]
audio_decision = 'direct play'
audio_channels = helpers.get_xml_attr(media_info, 'audioChannels')
audio_codec = helpers.get_xml_attr(media_info, 'audioCodec')
video_decision = 'direct play'
video_codec = helpers.get_xml_attr(media_info, 'videoCodec')
width = helpers.get_xml_attr(media_info, 'width')
height = helpers.get_xml_attr(media_info, 'height')
duration = helpers.get_xml_attr(media_info, 'duration')
progress = helpers.get_xml_attr(session, 'viewOffset')
transcode_audio_channels = ''
transcode_audio_codec = ''
transcode_video_codec = ''
transcode_width = ''
transcode_height = ''
transcode_container = ''
transcode_protocol = ''
media_info = session.getElementsByTagName('Media')[0]
if media_info.getElementsByTagName('Part'):
@ -533,10 +623,8 @@ class PmsConnect(object):
bif_thumb = ''
if plexpy.CONFIG.PMS_USE_BIF and indexes == 'sd':
thumb = bif_thumb
use_indexes = 1
else:
thumb = helpers.get_xml_attr(session, 'thumb')
use_indexes = 0
user_details = plex_watch.get_user_details(
@ -551,7 +639,9 @@ class PmsConnect(object):
session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'),
'art': helpers.get_xml_attr(session, 'art'),
'parent_thumb': helpers.get_xml_attr(session, 'parentThumb'),
'thumb': thumb,
'grandparent_thumb': helpers.get_xml_attr(session, 'grandparentThumb'),
'thumb': helpers.get_xml_attr(session, 'thumb'),
'bif_thumb': bif_thumb,
'user': helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'),
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
@ -563,6 +653,8 @@ class PmsConnect(object):
'parent_title': helpers.get_xml_attr(session, 'parentTitle'),
'title': helpers.get_xml_attr(session, 'title'),
'rating_key': helpers.get_xml_attr(session, 'ratingKey'),
'parent_rating_key': helpers.get_xml_attr(session, 'parentRatingKey'),
'grandparent_rating_key': helpers.get_xml_attr(session, 'grandparentRatingKey'),
'audio_decision': audio_decision,
'audio_channels': audio_channels,
'audio_codec': audio_codec,
@ -570,6 +662,18 @@ class PmsConnect(object):
'video_codec': video_codec,
'height': height,
'width': width,
'container': container,
'bitrate': bitrate,
'video_resolution': video_resolution,
'video_framerate': video_framerate,
'aspect_ratio': aspect_ratio,
'transcode_audio_channels': transcode_audio_channels,
'transcode_audio_codec': transcode_audio_codec,
'transcode_video_codec': transcode_video_codec,
'transcode_width': transcode_width,
'transcode_height': transcode_height,
'transcode_container': transcode_container,
'transcode_protocol': transcode_protocol,
'duration': duration,
'progress': progress,
'progress_percent': str(helpers.get_percent(progress, duration)),
@ -579,8 +683,10 @@ class PmsConnect(object):
elif helpers.get_xml_attr(session, 'type') == 'movie':
session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'),
'art': helpers.get_xml_attr(session, 'art'),
'thumb': thumb,
'thumb': helpers.get_xml_attr(session, 'thumb'),
'bif_thumb': bif_thumb,
'parent_thumb': helpers.get_xml_attr(session, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(session, 'grandparentThumb'),
'user': helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'),
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
@ -592,6 +698,8 @@ class PmsConnect(object):
'parent_title': helpers.get_xml_attr(session, 'parentTitle'),
'title': helpers.get_xml_attr(session, 'title'),
'rating_key': helpers.get_xml_attr(session, 'ratingKey'),
'parent_rating_key': helpers.get_xml_attr(session, 'parentRatingKey'),
'grandparent_rating_key': helpers.get_xml_attr(session, 'grandparentRatingKey'),
'audio_decision': audio_decision,
'audio_channels': audio_channels,
'audio_codec': audio_codec,
@ -599,6 +707,18 @@ class PmsConnect(object):
'video_codec': video_codec,
'height': height,
'width': width,
'container': container,
'bitrate': bitrate,
'video_resolution': video_resolution,
'video_framerate': video_framerate,
'aspect_ratio': aspect_ratio,
'transcode_audio_channels': transcode_audio_channels,
'transcode_audio_codec': transcode_audio_codec,
'transcode_video_codec': transcode_video_codec,
'transcode_width': transcode_width,
'transcode_height': transcode_height,
'transcode_container': transcode_container,
'transcode_protocol': transcode_protocol,
'duration': duration,
'progress': progress,
'progress_percent': str(helpers.get_percent(progress, duration)),
@ -608,8 +728,10 @@ class PmsConnect(object):
elif helpers.get_xml_attr(session, 'type') == 'clip':
session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'),
'art': helpers.get_xml_attr(session, 'art'),
'thumb': thumb,
'thumb': helpers.get_xml_attr(session, 'thumb'),
'bif_thumb': bif_thumb,
'parent_thumb': helpers.get_xml_attr(session, 'parentThumb'),
'grandparent_thumb': helpers.get_xml_attr(session, 'grandparentThumb'),
'user': helpers.get_xml_attr(session.getElementsByTagName('User')[0], 'title'),
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
@ -621,6 +743,8 @@ class PmsConnect(object):
'parent_title': helpers.get_xml_attr(session, 'parentTitle'),
'title': helpers.get_xml_attr(session, 'title'),
'rating_key': helpers.get_xml_attr(session, 'ratingKey'),
'parent_rating_key': helpers.get_xml_attr(session, 'parentRatingKey'),
'grandparent_rating_key': helpers.get_xml_attr(session, 'grandparentRatingKey'),
'audio_decision': audio_decision,
'audio_channels': audio_channels,
'audio_codec': audio_codec,
@ -628,6 +752,18 @@ class PmsConnect(object):
'video_codec': video_codec,
'height': height,
'width': width,
'container': container,
'bitrate': bitrate,
'video_resolution': video_resolution,
'video_framerate': video_framerate,
'aspect_ratio': aspect_ratio,
'transcode_audio_channels': transcode_audio_channels,
'transcode_audio_codec': transcode_audio_codec,
'transcode_video_codec': transcode_video_codec,
'transcode_width': transcode_width,
'transcode_height': transcode_height,
'transcode_container': transcode_container,
'transcode_protocol': transcode_protocol,
'duration': duration,
'progress': progress,
'progress_percent': str(helpers.get_percent(progress, duration)),

View file

@ -345,7 +345,10 @@ class WebInterface(object):
"monitoring_interval": plexpy.CONFIG.MONITORING_INTERVAL,
"refresh_users_interval": plexpy.CONFIG.REFRESH_USERS_INTERVAL,
"refresh_users_on_startup": checked(plexpy.CONFIG.REFRESH_USERS_ON_STARTUP),
"ip_logging_enable": checked(plexpy.CONFIG.IP_LOGGING_ENABLE)
"ip_logging_enable": checked(plexpy.CONFIG.IP_LOGGING_ENABLE),
"video_logging_enable": checked(plexpy.CONFIG.VIDEO_LOGGING_ENABLE),
"music_logging_enable": checked(plexpy.CONFIG.MUSIC_LOGGING_ENABLE),
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL
}
return serve_template(templatename="config.html", title="Settings", config=config)
@ -366,7 +369,7 @@ class WebInterface(object):
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
"ip_logging_enable"
"ip_logging_enable", "video_logging_enable", "music_logging_enable"
]
for checked_config in checked_configs:
if checked_config not in kwargs: