Template the stream modal

Template the history table
Add history history to metadata info screens
Fix some more datatables stuff
More webserve housekeeping
This commit is contained in:
Tim
2015-06-19 22:27:50 +02:00
parent 58a1442fe9
commit c4504d8be0
8 changed files with 564 additions and 301 deletions

View File

@@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
from plexpy import logger, helpers, request, datatables, config
from plexpy import logger, helpers, request, datatables, config, db
from xml.dom import minidom
import plexpy
@@ -104,7 +104,7 @@ class PlexWatch(object):
return dict
def get_history(self, start='', length='', kwargs=None):
def get_history(self, start='', length='', kwargs=None, custom_where=''):
data_tables = datatables.DataTables()
start = int(start)
@@ -152,7 +152,7 @@ class PlexWatch(object):
order_dir=order_dir,
search_value=search_value,
search_regex=search_regex,
custom_where='',
custom_where=custom_where,
group_by='',
kwargs=kwargs)
@@ -216,3 +216,112 @@ class PlexWatch(object):
}
return dict
def get_stream_details(self, id=0):
myDB = db.DBConnection()
query = 'SELECT xml from %s where id = %s' % (self.get_history_table_name(), id)
xml = myDB.select_single(query)
try:
dict_data = helpers.convert_xml_to_dict(helpers.latinToAscii(xml))
except IOError, e:
logger.warn("Error parsing XML in PlexWatch db: %s" % e)
dict = {'id': id,
'data': dict_data}
return dict
"""
Validate xml keys to make sure they exist and return their attribute value, return blank value is none found
"""
@staticmethod
def get_xml_attr(xml_key, attribute, return_bool=False, default_return=''):
if xml_key.getAttribute(attribute):
if return_bool:
return True
else:
return xml_key.getAttribute(attribute)
else:
if return_bool:
return False
else:
return default_return
def get_stream_details(self, row_id=None):
myDB = db.DBConnection()
if row_id:
query = 'SELECT xml from %s where id = %s' % (self.get_history_table_name(), row_id)
xml = myDB.select_single(query)
xml_data = helpers.latinToAscii(xml)
else:
return None
try:
xml_parse = minidom.parseString(xml_data)
except:
logger.warn("Error parsing XML for Plex stream data.")
return None
xml_head = xml_parse.getElementsByTagName('opt')
if not xml_head:
logger.warn("Error parsing XML for Plex stream data.")
return None
stream_output = {}
for a in xml_head:
media_type = self.get_xml_attr(a, 'type')
title = self.get_xml_attr(a, 'title')
grandparent_title = self.get_xml_attr(a, 'grandparentTitle')
if a.getElementsByTagName('TranscodeSession'):
transcode_data = a.getElementsByTagName('TranscodeSession')
for transcode_session in transcode_data:
transcode_video_dec = self.get_xml_attr(transcode_session, 'videoDecision')
transcode_video_codec = self.get_xml_attr(transcode_session, 'videoCodec')
transcode_height = self.get_xml_attr(transcode_session, 'height')
transcode_width = self.get_xml_attr(transcode_session, 'width')
transcode_audio_dec = self.get_xml_attr(transcode_session, 'audioDecision')
transcode_audio_codec = self.get_xml_attr(transcode_session, 'audioCodec')
transcode_audio_channels = self.get_xml_attr(transcode_session, 'audioChannels')
else:
transcode_data = a.getElementsByTagName('Media')
for transcode_session in transcode_data:
transcode_video_dec = 'direct play'
transcode_video_codec = self.get_xml_attr(transcode_session, 'videoCodec')
transcode_height = self.get_xml_attr(transcode_session, 'height')
transcode_width = self.get_xml_attr(transcode_session, 'width')
transcode_audio_dec = 'direct play'
transcode_audio_codec = self.get_xml_attr(transcode_session, 'audioCodec')
transcode_audio_channels = self.get_xml_attr(transcode_session, 'audioChannels')
if a.getElementsByTagName('Media'):
stream_data = a.getElementsByTagName('Media')
for stream_item in stream_data:
stream_output = {'container': self.get_xml_attr(stream_item, 'container'),
'bitrate': self.get_xml_attr(stream_item, 'bitrate'),
'video_resolution': self.get_xml_attr(stream_item, 'videoResolution'),
'width': self.get_xml_attr(stream_item, 'width'),
'height': self.get_xml_attr(stream_item, 'height'),
'aspect_ratio': self.get_xml_attr(stream_item, 'aspectRatio'),
'video_framerate': self.get_xml_attr(stream_item, 'videoFrameRate'),
'video_codec': self.get_xml_attr(stream_item, 'videoCodec'),
'audio_codec': self.get_xml_attr(stream_item, 'audioCodec'),
'audio_channels': self.get_xml_attr(stream_item, 'audioChannels'),
'transcode_video_dec': transcode_video_dec,
'transcode_video_codec': transcode_video_codec,
'transcode_height': transcode_height,
'transcode_width': transcode_width,
'transcode_audio_dec': transcode_audio_dec,
'transcode_audio_codec': transcode_audio_codec,
'transcode_audio_channels': transcode_audio_channels,
'media_type': media_type,
'title': title,
'grandparent_title': grandparent_title
}
return stream_output