Add setting to enable calculating total file sizes

* Setting is disabled by default
This commit is contained in:
JonnyWong16 2016-01-17 16:15:28 -08:00
parent 0d7e261bd1
commit 1809b95e2d
9 changed files with 71 additions and 43 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -10,7 +10,6 @@ $.ajax({
} }
}); });
var get_file_sizes = false;
var refresh_child_tables = false; var refresh_child_tables = false;
media_info_table_options = { media_info_table_options = {
@ -24,7 +23,7 @@ media_info_table_options = {
"emptyTable": "No data in table" "emptyTable": "No data in table"
}, },
"pagingType": "bootstrap", "pagingType": "bootstrap",
"stateSave": true, "stateSave": false,
"processing": false, "processing": false,
"serverSide": true, "serverSide": true,
"pageLength": 25, "pageLength": 25,
@ -102,7 +101,7 @@ media_info_table_options = {
} }
} }
}, },
"width": "24%" "width": "20%"
}, },
{ {
"targets": [2], "targets": [2],
@ -112,7 +111,7 @@ media_info_table_options = {
$(td).html(cellData); $(td).html(cellData);
} }
}, },
"width": "5%", "width": "6%",
"className": "no-wrap hidden-sm hidden-xs" "className": "no-wrap hidden-sm hidden-xs"
}, },
{ {
@ -123,7 +122,7 @@ media_info_table_options = {
$(td).html(cellData + ' kbps'); $(td).html(cellData + ' kbps');
} }
}, },
"width": "5%", "width": "6%",
"className": "no-wrap hidden-md hidden-sm hidden-xs", "className": "no-wrap hidden-md hidden-sm hidden-xs",
"searchable": false "searchable": false
}, },
@ -189,7 +188,9 @@ media_info_table_options = {
if (cellData !== null && cellData !== '') { if (cellData !== null && cellData !== '') {
$(td).html(Math.round(cellData / Math.pow(1024, 2)).toString() + ' MiB'); $(td).html(Math.round(cellData / Math.pow(1024, 2)).toString() + ' MiB');
} else { } else {
if (rowData['section_type'] != 'photo') { get_file_sizes = true; } if (rowData['section_type'] != 'photo' && get_file_sizes != null) {
get_file_sizes = true;
}
} }
}, },
"width": "7%", "width": "7%",
@ -375,6 +376,7 @@ function childTableOptionsMedia(rowData) {
createChildTableMedia(this, childrowData) createChildTableMedia(this, childrowData)
} }
}); });
}
if (get_file_sizes) { if (get_file_sizes) {
$('#refresh-media-info-table').prop('disabled', true); $('#refresh-media-info-table').prop('disabled', true);
@ -395,7 +397,6 @@ function childTableOptionsMedia(rowData) {
}); });
get_file_sizes = false; get_file_sizes = false;
} }
}
$(this).closest('div.slider').slideDown(); $(this).closest('div.slider').slideDown();
} }

View file

@ -196,7 +196,7 @@ DOCUMENTATION :: END
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
% if data['section_id'] in config['get_file_sizes']['section_ids']: % if config['get_file_sizes'] and data['section_id'] in config['get_file_sizes_hold']['section_ids']:
<div id="get_file_sizes_message" style="text-align: center; margin-top: 20px;"> <div id="get_file_sizes_message" style="text-align: center; margin-top: 20px;">
% else: % else:
<div id="get_file_sizes_message" style="text-align: center; margin-top: 20px; display: none;"> <div id="get_file_sizes_message" style="text-align: center; margin-top: 20px; display: none;">
@ -214,7 +214,7 @@ DOCUMENTATION :: END
</span> </span>
</div> </div>
<div class="button-bar"> <div class="button-bar">
% if data['section_id'] in config['get_file_sizes']['section_ids']: % if config['get_file_sizes'] and data['section_id'] in config['get_file_sizes_hold']['section_ids']:
<button class="btn btn-dark refresh-media-info-table-button" id="refresh-media-info-table" style="margin-right: 5px;" disabled> <button class="btn btn-dark refresh-media-info-table-button" id="refresh-media-info-table" style="margin-right: 5px;" disabled>
<i class="fa fa-refresh"></i> Refresh media info <i class="fa fa-refresh"></i> Refresh media info
</button> </button>
@ -316,6 +316,12 @@ DOCUMENTATION :: END
% endif % endif
var section_name = '${data['section_name'].replace("'", "\\'")}'; var section_name = '${data['section_name'].replace("'", "\\'")}';
var refresh_table = false; var refresh_table = false;
% if config['get_file_sizes']:
var get_file_sizes = false;
% else:
var get_file_sizes = null;
% endif
</script> </script>
<script src="interfaces/default/js/moment-with-locale.js"></script> <script src="interfaces/default/js/moment-with-locale.js"></script>
<script src="interfaces/default/js/tables/history_table.js"></script> <script src="interfaces/default/js/tables/history_table.js"></script>

View file

@ -89,5 +89,5 @@ DOCUMENTATION :: END
% endfor % endfor
</ul> </ul>
% else: % else:
<div class="text-muted">No stats to show for the selected period.</div><br> <div class="text-muted">No stats to show.</div><br>
% endif % endif

View file

@ -453,6 +453,13 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</label> </label>
<p class="help-block">If you have media indexing enabled on your server, use these on the activity pane.</p> <p class="help-block">If you have media indexing enabled on your server, use these on the activity pane.</p>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" id="get_file_sizes" name="get_file_sizes" value="1" ${config['get_file_sizes']}> Calculate Total File Sizes [experimental]
</label>
<p class="help-block">Enable if you want PlexPy to calculate the total file size for TV Shows/Seasons and Artists/Albums on the media info tables.<br />
This is currently experimental.</p>
</div>
<div class="padded-header"> <div class="padded-header">
<h3>PlexWatch Import Tool</h3> <h3>PlexWatch Import Tool</h3>
@ -478,9 +485,10 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" class="monitor-settings" id="monitoring_use_websocket" name="monitoring_use_websocket" value="1" ${config['monitoring_use_websocket']}> Use Websocket (requires restart) <input type="checkbox" class="monitor-settings" id="monitoring_use_websocket" name="monitoring_use_websocket" value="1" ${config['monitoring_use_websocket']}> Use Websocket (requires restart) [experimental]
</label> </label>
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental. Encrypted websocket is not currently supported.</p> <p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens.<br />
This is currently experimental. Encrypted websocket is not currently supported.</p>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>

View file

@ -97,7 +97,8 @@ _CONFIG_DEFINITIONS = {
'FACEBOOK_ON_INTUP': (int, 'Facebook', 0), 'FACEBOOK_ON_INTUP': (int, 'Facebook', 0),
'FIRST_RUN_COMPLETE': (int, 'General', 0), 'FIRST_RUN_COMPLETE': (int, 'General', 0),
'FREEZE_DB': (int, 'General', 0), 'FREEZE_DB': (int, 'General', 0),
'GET_FILE_SIZES': (dict, 'General', {'section_ids': [], 'rating_keys': []}), 'GET_FILE_SIZES': (int, 'General', 0),
'GET_FILE_SIZES_HOLD': (dict, 'General', {'section_ids': [], 'rating_keys': []}),
'GIT_BRANCH': (str, 'General', 'master'), 'GIT_BRANCH': (str, 'General', 'master'),
'GIT_PATH': (str, 'General', ''), 'GIT_PATH': (str, 'General', ''),
'GIT_USER': (str, 'General', 'drzoidberg33'), 'GIT_USER': (str, 'General', 'drzoidberg33'),

View file

@ -242,7 +242,7 @@ class Libraries(object):
# Import media info cache from json file # Import media info cache from json file
if rating_key: if rating_key:
try: try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key)) inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
with open(inFilePath, 'r') as inFile: with open(inFilePath, 'r') as inFile:
rows = json.load(inFile) rows = json.load(inFile)
library_count = len(rows) library_count = len(rows)
@ -252,7 +252,7 @@ class Libraries(object):
pass pass
elif section_id: elif section_id:
try: try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id) inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
with open(inFilePath, 'r') as inFile: with open(inFilePath, 'r') as inFile:
rows = json.load(inFile) rows = json.load(inFile)
library_count = len(rows) library_count = len(rows)
@ -314,13 +314,19 @@ class Libraries(object):
# Cache the media info to a json file # Cache the media info to a json file
if rating_key: if rating_key:
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key)) try:
with open(outFilePath, 'w') as outFile: outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
json.dump(rows, outFile) with open(outFilePath, 'w') as outFile:
json.dump(rows, outFile)
except IOError as e:
logger.debug(u"PlexPy Libraries :: Unable to create cache file for rating_key %s." % rating_key)
elif section_id: elif section_id:
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id) try:
with open(outFilePath, 'w') as outFile: outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
json.dump(rows, outFile) with open(outFilePath, 'w') as outFile:
json.dump(rows, outFile)
except IOError as e:
logger.debug(u"PlexPy Libraries :: Unable to create cache file for section_id %s." % section_id)
# Update the last_watched and play_count # Update the last_watched and play_count
for item in rows: for item in rows:
@ -407,7 +413,7 @@ class Libraries(object):
if rating_key: if rating_key:
#logger.debug(u"PlexPy Libraries :: Getting file sizes for rating_key %s." % rating_key) #logger.debug(u"PlexPy Libraries :: Getting file sizes for rating_key %s." % rating_key)
try: try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key)) inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
with open(inFilePath, 'r') as inFile: with open(inFilePath, 'r') as inFile:
rows = json.load(inFile) rows = json.load(inFile)
except IOError as e: except IOError as e:
@ -417,7 +423,7 @@ class Libraries(object):
elif section_id: elif section_id:
logger.debug(u"PlexPy Libraries :: Getting file sizes for section_id %s." % section_id) logger.debug(u"PlexPy Libraries :: Getting file sizes for section_id %s." % section_id)
try: try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id) inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
with open(inFilePath, 'r') as inFile: with open(inFilePath, 'r') as inFile:
rows = json.load(inFile) rows = json.load(inFile)
except IOError as e: except IOError as e:
@ -426,32 +432,37 @@ class Libraries(object):
pass pass
# Get the total file size for each item # Get the total file size for each item
pms_connect = pmsconnect.PmsConnect()
for item in rows: for item in rows:
if item['rating_key'] and not item['file_size']: if item['rating_key'] and not item['file_size']:
file_size = 0 file_size = 0
pms_connect = pmsconnect.PmsConnect()
child_metadata = pms_connect.get_metadata_children_details(rating_key=item['rating_key'], child_metadata = pms_connect.get_metadata_children_details(rating_key=item['rating_key'],
get_children=True, get_children=True,
get_media_info=True) get_media_info=True)
metadata_list = child_metadata['metadata'] metadata_list = child_metadata['metadata']
for child_metadata in metadata_list: for child_metadata in metadata_list:
child_file_size = helpers.cast_to_int(child_metadata.get('file_size', 0)) file_size += helpers.cast_to_int(child_metadata.get('file_size', 0))
if child_file_size > 0:
file_size += child_file_size
item['file_size'] = file_size item['file_size'] = file_size
# Cache the media info to a json file # Cache the media info to a json file
if rating_key: if rating_key:
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key)) try:
with open(outFilePath, 'w') as outFile: outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s-%s.json' % (section_id, rating_key))
json.dump(rows, outFile) with open(outFilePath, 'w') as outFile:
json.dump(rows, outFile)
except IOError as e:
logger.debug(u"PlexPy Libraries :: Unable to create cache file with file sizes for rating_key %s." % rating_key)
elif section_id: elif section_id:
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id) try:
with open(outFilePath, 'w') as outFile: outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info_%s.json' % section_id)
json.dump(rows, outFile) with open(outFilePath, 'w') as outFile:
json.dump(rows, outFile)
except IOError as e:
logger.debug(u"PlexPy Libraries :: Unable to create cache file with file sizes for section_id %s." % section_id)
if rating_key: if rating_key:
#logger.debug(u"PlexPy Libraries :: File sizes updated for rating_key %s." % rating_key) #logger.debug(u"PlexPy Libraries :: File sizes updated for rating_key %s." % rating_key)
@ -460,7 +471,6 @@ class Libraries(object):
logger.debug(u"PlexPy Libraries :: File sizes updated for section_id %s." % section_id) logger.debug(u"PlexPy Libraries :: File sizes updated for section_id %s." % section_id)
return True return True
def set_config(self, section_id=None, custom_thumb='', do_notify=1, keep_history=1, do_notify_created=1): def set_config(self, section_id=None, custom_thumb='', do_notify=1, keep_history=1, do_notify_created=1):
if section_id: if section_id:

View file

@ -258,7 +258,8 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
def library(self, section_id=None): def library(self, section_id=None):
config = { config = {
"get_file_sizes": plexpy.CONFIG.GET_FILE_SIZES "get_file_sizes": plexpy.CONFIG.GET_FILE_SIZES,
"get_file_sizes_hold": plexpy.CONFIG.GET_FILE_SIZES_HOLD
} }
library_data = libraries.Libraries() library_data = libraries.Libraries()
@ -376,16 +377,16 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
def get_media_info_file_sizes(self, section_id=None, rating_key=None): def get_media_info_file_sizes(self, section_id=None, rating_key=None):
get_file_sizes = plexpy.CONFIG.GET_FILE_SIZES get_file_sizes_hold = plexpy.CONFIG.GET_FILE_SIZES_HOLD
section_ids = set(get_file_sizes['section_ids']) section_ids = set(get_file_sizes_hold['section_ids'])
rating_keys = set(get_file_sizes['rating_keys']) rating_keys = set(get_file_sizes_hold['rating_keys'])
if (section_id and section_id not in section_ids) or (rating_key and rating_key not in rating_keys): if (section_id and section_id not in section_ids) or (rating_key and rating_key not in rating_keys):
if section_id: if section_id:
section_ids.add(section_id) section_ids.add(section_id)
elif rating_key: elif rating_key:
rating_keys.add(rating_key) rating_keys.add(rating_key)
plexpy.CONFIG.GET_FILE_SIZES = {'section_ids': list(section_ids), 'rating_keys': list(rating_keys)} plexpy.CONFIG.GET_FILE_SIZES_HOLD = {'section_ids': list(section_ids), 'rating_keys': list(rating_keys)}
library_data = libraries.Libraries() library_data = libraries.Libraries()
result = library_data.get_media_info_file_sizes(section_id=section_id, result = library_data.get_media_info_file_sizes(section_id=section_id,
@ -395,7 +396,7 @@ class WebInterface(object):
section_ids.remove(section_id) section_ids.remove(section_id)
elif rating_key: elif rating_key:
rating_keys.remove(rating_key) rating_keys.remove(rating_key)
plexpy.CONFIG.GET_FILE_SIZES = {'section_ids': list(section_ids), 'rating_keys': list(rating_keys)} plexpy.CONFIG.GET_FILE_SIZES_HOLD = {'section_ids': list(section_ids), 'rating_keys': list(rating_keys)}
else: else:
result = False result = False
@ -476,8 +477,8 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
def delete_datatable_media_info_cache(self, section_id, **kwargs): def delete_datatable_media_info_cache(self, section_id, **kwargs):
get_file_sizes = plexpy.CONFIG.GET_FILE_SIZES get_file_sizes_hold = plexpy.CONFIG.GET_FILE_SIZES_HOLD
section_ids = set(get_file_sizes['section_ids']) section_ids = set(get_file_sizes_hold['section_ids'])
if section_id not in section_ids: if section_id not in section_ids:
if section_id: if section_id:
@ -1049,6 +1050,7 @@ class WebInterface(object):
"pms_uuid": plexpy.CONFIG.PMS_UUID, "pms_uuid": plexpy.CONFIG.PMS_UUID,
"date_format": plexpy.CONFIG.DATE_FORMAT, "date_format": plexpy.CONFIG.DATE_FORMAT,
"time_format": plexpy.CONFIG.TIME_FORMAT, "time_format": plexpy.CONFIG.TIME_FORMAT,
"get_file_sizes": checked(plexpy.CONFIG.GET_FILE_SIZES),
"grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY), "grouping_global_history": checked(plexpy.CONFIG.GROUPING_GLOBAL_HISTORY),
"grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY), "grouping_user_history": checked(plexpy.CONFIG.GROUPING_USER_HISTORY),
"grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS), "grouping_charts": checked(plexpy.CONFIG.GROUPING_CHARTS),
@ -1122,7 +1124,7 @@ class WebInterface(object):
# Handle the variable config options. Note - keys with False values aren't getting passed # Handle the variable config options. Note - keys with False values aren't getting passed
checked_configs = [ checked_configs = [
"launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github", "launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github", "get_file_sizes",
"grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif", "pms_ssl", "grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif", "pms_ssl",
"movie_notify_enable", "tv_notify_enable", "music_notify_enable", "monitoring_use_websocket", "movie_notify_enable", "tv_notify_enable", "music_notify_enable", "monitoring_use_websocket",
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start", "tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",