Add file size to export table

This commit is contained in:
JonnyWong16 2020-08-03 21:28:13 -07:00
parent a27a5b023b
commit 40fbc55ab3
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
4 changed files with 39 additions and 22 deletions

View file

@ -61,22 +61,11 @@ export_table_options = {
$(td).html('<a href="' + page('info', rowData['rating_key']) + '">' + cellData + '</a>');
}
},
"width": "8%",
"width": "6%",
"className": "no-wrap"
},
{
"targets": [3],
"data": "file_format",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') {
$(td).html(cellData);
}
},
"width": "8%",
"className": "no-wrap"
},
{
"targets": [4],
"data": "filename",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') {
@ -86,8 +75,30 @@ export_table_options = {
"width": "50%",
"className": "no-wrap"
},
{
"targets": [4],
"data": "file_format",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') {
$(td).html(cellData);
}
},
"width": "6%",
"className": "no-wrap"
},
{
"targets": [5],
"data": "file_size",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '' && cellData !== null) {
$(td).html(humanFileSize(cellData));
}
},
"width": "6%",
"className": "no-wrap"
},
{
"targets": [6],
"data": "complete",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData === 1 && rowData['exists']) {
@ -100,11 +111,11 @@ export_table_options = {
$(td).html('<span class="btn btn-xs btn-dark pull-left" data-id="' + rowData['row_id'] + '" disabled><i class="fa fa-question-circle fa-fw"></i> Not Found</span>');
}
},
"width": "8%",
"width": "7%",
"className": "export_download"
},
{
"targets": [6],
"targets": [7],
"data": null,
"createdCell": function (td, cellData, rowData, row, col) {
if (rowData['complete'] !== 0) {
@ -113,7 +124,7 @@ export_table_options = {
$(td).html('<span class="btn btn-xs btn-danger pull-left" data-id="' + rowData['row_id'] + '" disabled><i class="fa fa-trash-o fa-fw"></i> Delete</span>');
}
},
"width": "8%",
"width": "7%",
"className": "export_delete"
}
],

View file

@ -342,8 +342,9 @@ DOCUMENTATION :: END
<th align="left" id="timestamp">Exported At</th>
<th align="left" id="media_type_title">Media Type</th>
<th align="left" id="rating_key">Rating Key</th>
<th align="left" id="file_format">Format</th>
<th align="left" id="filename">Filename</th>
<th align="left" id="file_format">File Format</th>
<th align="left" id="file_size">File Size</th>
<th align="left" id="complete">Download</th>
<th align="left" id="delete">Delete</th>
</tr>

View file

@ -794,7 +794,7 @@ def dbcheck():
c_db.execute(
'CREATE TABLE IF NOT EXISTS exports (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'timestamp INTEGER, section_id INTEGER, rating_key INTEGER, media_type TEXT, '
'file_format TEXT, filename TEXT, complete INTEGER DEFAULT 0)'
'filename TEXT, file_format TEXT, file_size INTEGER DEFAULT 0, complete INTEGER DEFAULT 0)'
)
# Upgrade sessions table from earlier versions

View file

@ -962,6 +962,8 @@ def _real_export(export_id, items, attrs, file_format, filename):
writer.writeheader()
writer.writerows(flatten_result)
file_size = os.path.getsize(filepath)
except Exception as e:
import traceback
traceback.print_exc()
@ -976,7 +978,7 @@ def _real_export(export_id, items, attrs, file_format, filename):
if not success:
return
set_export_state(export_id=export_id)
set_export_state(export_id=export_id, file_size=file_size)
logger.info("Tautulli Exporter :: Successfully exported to '%s'", filepath)
@ -1010,14 +1012,15 @@ def add_export(timestamp, section_id, rating_key, media_type, file_format, filen
return False
def set_export_state(export_id, success=True):
def set_export_state(export_id, file_size=None, success=True):
if success:
complete = 1
else:
complete = -1
keys = {'id': export_id}
values = {'complete': complete}
values = {'complete': complete,
'file_size': file_size}
db = database.MonitorDatabase()
db.upsert(table_name='exports', key_dict=keys, value_dict=values)
@ -1083,8 +1086,9 @@ def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
'exports.section_id',
'exports.rating_key',
'exports.media_type',
'exports.file_format',
'exports.filename',
'exports.file_format',
'exports.file_size',
'exports.complete'
]
try:
@ -1113,8 +1117,9 @@ def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
'rating_key': item['rating_key'],
'media_type': item['media_type'],
'media_type_title': media_type_title,
'file_format': item['file_format'],
'filename': item['filename'],
'file_format': item['file_format'],
'file_size': item['file_size'],
'complete': item['complete'],
'exists': exists
}