mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 05:31:15 -07:00
Add function to download exported files
This commit is contained in:
parent
6334ffa197
commit
deb49d7ff9
3 changed files with 72 additions and 4 deletions
|
@ -116,3 +116,12 @@ export_table_options = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$('.export_table').on('click', '> tbody > tr > td > button.btn-download', function (e) {
|
||||||
|
var tr = $(this).closest('tr');
|
||||||
|
var row = export_table.row(tr);
|
||||||
|
var rowData = row.data();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = 'download_export?row_id=' + rowData['row_id'];
|
||||||
|
});
|
||||||
|
|
|
@ -897,7 +897,7 @@ def export(section_id=None, rating_key=None, file_format='json'):
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = helpers.clean_filename(filename)
|
filename = helpers.clean_filename(filename)
|
||||||
filepath = os.path.join(plexpy.CONFIG.EXPORT_DIR, filename)
|
filepath = get_export_filepath(filename)
|
||||||
logger.info("Tautulli Exporter :: Starting export for '%s'...", filename)
|
logger.info("Tautulli Exporter :: Starting export for '%s'...", filename)
|
||||||
|
|
||||||
export_id = set_export_state(timestamp=timestamp,
|
export_id = set_export_state(timestamp=timestamp,
|
||||||
|
@ -932,6 +932,18 @@ def export(section_id=None, rating_key=None, file_format='json'):
|
||||||
logger.info("Tautulli Exporter :: Successfully exported to '%s'", filepath)
|
logger.info("Tautulli Exporter :: Successfully exported to '%s'", filepath)
|
||||||
|
|
||||||
|
|
||||||
|
def get_export(export_id):
|
||||||
|
db = database.MonitorDatabase()
|
||||||
|
result = db.select_single('SELECT filename, complete '
|
||||||
|
'FROM exports WHERE id = ?',
|
||||||
|
[export_id])
|
||||||
|
|
||||||
|
if result:
|
||||||
|
result['exists'] = check_export_exists(result['filename'])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def set_export_state(timestamp, section_id, rating_key, media_type, file_format, filename):
|
def set_export_state(timestamp, section_id, rating_key, media_type, file_format, filename):
|
||||||
keys = {'timestamp': timestamp,
|
keys = {'timestamp': timestamp,
|
||||||
'section_id': section_id,
|
'section_id': section_id,
|
||||||
|
@ -1000,8 +1012,7 @@ def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
|
||||||
rows = []
|
rows = []
|
||||||
for item in result:
|
for item in result:
|
||||||
media_type_title = item['media_type'].title()
|
media_type_title = item['media_type'].title()
|
||||||
filepath = os.path.join(plexpy.CONFIG.EXPORT_DIR, item['filename'])
|
exists = helpers.cast_to_int(check_export_exists(item['filename']))
|
||||||
exists = helpers.cast_to_int(os.path.isfile(filepath))
|
|
||||||
|
|
||||||
row = {'row_id': item['row_id'],
|
row = {'row_id': item['row_id'],
|
||||||
'timestamp': item['timestamp'],
|
'timestamp': item['timestamp'],
|
||||||
|
@ -1024,3 +1035,11 @@ def get_export_datatable(section_id=None, rating_key=None, kwargs=None):
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_export_filepath(filename):
|
||||||
|
return os.path.join(plexpy.CONFIG.EXPORT_DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
|
def check_export_exists(filename):
|
||||||
|
return os.path.isfile(get_export_filepath(filename))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# This file is part of Tautulli.
|
# This file is part of Tautulli.
|
||||||
#
|
#
|
||||||
|
@ -6482,9 +6482,49 @@ class WebInterface(object):
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def export_metadata(self, section_id=None, rating_key=None, file_format='json', **kwargs):
|
def export_metadata(self, section_id=None, rating_key=None, file_format='json', **kwargs):
|
||||||
|
""" Download the Plex log file.
|
||||||
|
|
||||||
|
```
|
||||||
|
Required parameters:
|
||||||
|
row_id (int): The row id of the exported file to download
|
||||||
|
|
||||||
|
|
||||||
|
Optional parameters:
|
||||||
|
None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
json:
|
||||||
|
{"result": "success",
|
||||||
|
"message": "Metadata export has started. Check the logs to monitor any problems."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
"""
|
||||||
threading.Thread(target=exporter.export,
|
threading.Thread(target=exporter.export,
|
||||||
kwargs={'section_id': section_id,
|
kwargs={'section_id': section_id,
|
||||||
'rating_key': rating_key,
|
'rating_key': rating_key,
|
||||||
'file_format': file_format}).start()
|
'file_format': file_format}).start()
|
||||||
return {'result': 'success',
|
return {'result': 'success',
|
||||||
'message': 'Metadata export has started. Check the logs to monitor any problems.'}
|
'message': 'Metadata export has started. Check the logs to monitor any problems.'}
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
@cherrypy.tools.json_out()
|
||||||
|
@requireAuth(member_of("admin"))
|
||||||
|
@addtoapi()
|
||||||
|
def download_export(self, row_id=None, **kwargs):
|
||||||
|
""" Download the Plex log file.
|
||||||
|
|
||||||
|
```
|
||||||
|
Required parameters:
|
||||||
|
row_id (int): The row id of the exported file to download
|
||||||
|
|
||||||
|
|
||||||
|
Optional parameters:
|
||||||
|
None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
download
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
result = exporter.get_export(export_id=row_id)
|
||||||
|
if result and result['complete'] and result['exists']:
|
||||||
|
serve_download(path=exporter.get_export_filepath(result['filename']), name=result['filename'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue