mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Ability to stop a stream using session key
This commit is contained in:
parent
c18ee81130
commit
8c0bcd0059
6 changed files with 46 additions and 12 deletions
8
API.md
8
API.md
|
@ -2624,15 +2624,15 @@ Returns:
|
||||||
|
|
||||||
|
|
||||||
### terminate_session
|
### terminate_session
|
||||||
Add a new notification agent.
|
Stop a streaming session.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
session_id (str): The id of the session to terminate
|
session_key (int): The session key of the session to terminate, OR
|
||||||
message (str): A custom message to send to the client
|
session_id (str): The session id of the session to terminate
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
None
|
message (str): A custom message to send to the client
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
|
|
|
@ -675,6 +675,7 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'terminate_session',
|
url: 'terminate_session',
|
||||||
data: {
|
data: {
|
||||||
|
session_key: key,
|
||||||
session_id: session_id,
|
session_id: session_id,
|
||||||
message: message
|
message: message
|
||||||
},
|
},
|
||||||
|
|
|
@ -518,7 +518,7 @@ def dbcheck():
|
||||||
|
|
||||||
# sessions table :: This is a temp table that logs currently active sessions
|
# sessions table :: This is a temp table that logs currently active sessions
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, session_key INTEGER, '
|
'CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, session_key INTEGER, session_id TEXT, '
|
||||||
'transcode_key TEXT, rating_key INTEGER, section_id INTEGER, media_type TEXT, started INTEGER, stopped INTEGER, '
|
'transcode_key TEXT, rating_key INTEGER, section_id INTEGER, media_type TEXT, started INTEGER, stopped INTEGER, '
|
||||||
'paused_counter INTEGER DEFAULT 0, state TEXT, user_id INTEGER, user TEXT, friendly_name TEXT, '
|
'paused_counter INTEGER DEFAULT 0, state TEXT, user_id INTEGER, user TEXT, friendly_name TEXT, '
|
||||||
'ip_address TEXT, machine_id TEXT, player TEXT, product TEXT, platform TEXT, title TEXT, parent_title TEXT, '
|
'ip_address TEXT, machine_id TEXT, player TEXT, product TEXT, platform TEXT, title TEXT, parent_title TEXT, '
|
||||||
|
@ -1081,6 +1081,15 @@ def dbcheck():
|
||||||
'ALTER TABLE sessions ADD COLUMN live_uuid TEXT'
|
'ALTER TABLE sessions ADD COLUMN live_uuid TEXT'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade sessions table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT session_id FROM sessions')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table sessions.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE sessions ADD COLUMN session_id TEXT'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade sessions table from earlier versions
|
# Upgrade sessions table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT original_title FROM sessions')
|
c_db.execute('SELECT original_title FROM sessions')
|
||||||
|
|
|
@ -34,6 +34,7 @@ class ActivityProcessor(object):
|
||||||
def write_session(self, session=None, notify=True):
|
def write_session(self, session=None, notify=True):
|
||||||
if session:
|
if session:
|
||||||
values = {'session_key': session.get('session_key', ''),
|
values = {'session_key': session.get('session_key', ''),
|
||||||
|
'session_id': session.get('session_id', ''),
|
||||||
'transcode_key': session.get('transcode_key', ''),
|
'transcode_key': session.get('transcode_key', ''),
|
||||||
'section_id': session.get('section_id', ''),
|
'section_id': session.get('section_id', ''),
|
||||||
'rating_key': session.get('rating_key', ''),
|
'rating_key': session.get('rating_key', ''),
|
||||||
|
@ -466,6 +467,16 @@ class ActivityProcessor(object):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_session_by_id(self, session_id=None):
|
||||||
|
if session_id:
|
||||||
|
session = self.db.select_single('SELECT * FROM sessions '
|
||||||
|
'WHERE session_id = ? ',
|
||||||
|
args=[session_id])
|
||||||
|
if session:
|
||||||
|
return session
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def set_session_state(self, session_key=None, state=None, **kwargs):
|
def set_session_state(self, session_key=None, state=None, **kwargs):
|
||||||
if str(session_key).isdigit():
|
if str(session_key).isdigit():
|
||||||
values = {}
|
values = {}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import time
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
|
import activity_processor
|
||||||
import common
|
import common
|
||||||
import helpers
|
import helpers
|
||||||
import http_handler
|
import http_handler
|
||||||
|
@ -1919,7 +1920,7 @@ class PmsConnect(object):
|
||||||
|
|
||||||
return session_output
|
return session_output
|
||||||
|
|
||||||
def terminate_session(self, session_id='', message=''):
|
def terminate_session(self, session_key='', session_id='', message=''):
|
||||||
"""
|
"""
|
||||||
Terminates a streaming session.
|
Terminates a streaming session.
|
||||||
|
|
||||||
|
@ -1927,10 +1928,22 @@ class PmsConnect(object):
|
||||||
"""
|
"""
|
||||||
message = message or 'The server owner has ended the stream.'
|
message = message or 'The server owner has ended the stream.'
|
||||||
|
|
||||||
|
if session_key and not session_id:
|
||||||
|
ap = activity_processor.ActivityProcessor()
|
||||||
|
session = ap.get_session_by_key(session_key=session_key)
|
||||||
|
session_id = session['session_id']
|
||||||
|
|
||||||
|
elif session_id and not session_key:
|
||||||
|
ap = activity_processor.ActivityProcessor()
|
||||||
|
session = ap.get_session_by_id(session_id=session_id)
|
||||||
|
session_key = session['session_key']
|
||||||
|
|
||||||
if session_id:
|
if session_id:
|
||||||
|
logger.info(u"Tautulli Pmsconnect :: Terminating session %s (session_id %s)." % (session_key, session_id))
|
||||||
result = self.get_sessions_terminate(session_id=session_id, reason=urllib.quote_plus(message))
|
result = self.get_sessions_terminate(session_id=session_id, reason=urllib.quote_plus(message))
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
|
logger.warn(u"Tautulli Pmsconnect :: Failed to terminate session %s. Missing session_id." % session_key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_item_children(self, rating_key='', get_grandchildren=False):
|
def get_item_children(self, rating_key='', get_grandchildren=False):
|
||||||
|
|
|
@ -248,23 +248,23 @@ class WebInterface(object):
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def terminate_session(self, session_id=None, message=None, **kwargs):
|
def terminate_session(self, session_key=None, session_id=None, message=None, **kwargs):
|
||||||
""" Add a new notification agent.
|
""" Stop a streaming session.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
session_id (str): The id of the session to terminate
|
session_key (int): The session key of the session to terminate, OR
|
||||||
message (str): A custom message to send to the client
|
session_id (str): The session id of the session to terminate
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
None
|
message (str): A custom message to send to the client
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
result = pms_connect.terminate_session(session_id=session_id, message=message)
|
result = pms_connect.terminate_session(session_key=session_key, session_id=session_id, message=message)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return {'result': 'success', 'message': 'Session terminated.'}
|
return {'result': 'success', 'message': 'Session terminated.'}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue