Exporter check rating key first

This commit is contained in:
JonnyWong16 2020-08-04 10:45:46 -07:00
parent 14bb377794
commit 28c6163a31
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 21 additions and 18 deletions

View file

@ -512,7 +512,7 @@ DOCUMENTATION :: END
% endif % endif
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal" <button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal"
data-id="${data['rating_key']}"> data-section_id="${data['section_id']}" data-rating_key="${data['rating_key']}">
<i class="fa fa-file-export"></i> Export Metadata <i class="fa fa-file-export"></i> Export Metadata
</button> </button>
</div> </div>
@ -844,7 +844,10 @@ DOCUMENTATION :: END
$("#toggle-export-modal").click(function() { $("#toggle-export-modal").click(function() {
$.ajax({ $.ajax({
url: 'export_metadata_modal', url: 'export_metadata_modal',
data: { rating_key: $(this).data('id') }, data: {
section_id: $(this).data('section_id'),
rating_key: $(this).data('rating_key')
},
cache: false, cache: false,
async: true, async: true,
complete: function(xhr, status) { complete: function(xhr, status) {

View file

@ -322,7 +322,7 @@ DOCUMENTATION :: END
% if _session['user_group'] == 'admin': % if _session['user_group'] == 'admin':
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal" <button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal"
data-id="${data['section_id']}"> data-section_id="${data['section_id']}">
<i class="fa fa-file-export"></i> Export Metadata <i class="fa fa-file-export"></i> Export Metadata
</button> </button>
</div> </div>
@ -563,7 +563,7 @@ DOCUMENTATION :: END
$("#toggle-export-modal").click(function() { $("#toggle-export-modal").click(function() {
$.ajax({ $.ajax({
url: 'export_metadata_modal', url: 'export_metadata_modal',
data: { section_id: $(this).data('id') }, data: { section_id: $(this).data('section_id') },
cache: false, cache: false,
async: true, async: true,
complete: function(xhr, status) { complete: function(xhr, status) {

View file

@ -853,29 +853,19 @@ def export(section_id=None, rating_key=None, file_format='json'):
if not section_id and not rating_key: if not section_id and not rating_key:
logger.error("Tautulli Exporter :: Export called but no section_id or rating_key provided.") logger.error("Tautulli Exporter :: Export called but no section_id or rating_key provided.")
return return
elif section_id and not str(section_id).isdigit():
logger.error("Tautulli Exporter :: Export called with invalid section_id '%s'.", section_id)
return
elif rating_key and not str(rating_key).isdigit(): elif rating_key and not str(rating_key).isdigit():
logger.error("Tautulli Exporter :: Export called with invalid rating_key '%s'.", rating_key) logger.error("Tautulli Exporter :: Export called with invalid rating_key '%s'.", rating_key)
return return
elif section_id and not str(section_id).isdigit():
logger.error("Tautulli Exporter :: Export called with invalid section_id '%s'.", section_id)
return
elif file_format not in ('json', 'csv'): elif file_format not in ('json', 'csv'):
logger.error("Tautulli Exporter :: Export called but invalid file_format '%s' provided.", file_format) logger.error("Tautulli Exporter :: Export called but invalid file_format '%s' provided.", file_format)
return return
plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN) plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN)
if section_id: if rating_key:
logger.debug("Tautulli Exporter :: Export called with section_id %s", section_id)
library = plex.get_library(section_id)
media_type = library.type
library_title = library.title
filename = 'Library - {} [{}].{}.{}'.format(
library_title, section_id, helpers.timestamp_to_YMDHMS(timestamp), file_format)
items = library.all()
elif rating_key:
logger.debug("Tautulli Exporter :: Export called with rating_key %s", rating_key) logger.debug("Tautulli Exporter :: Export called with rating_key %s", rating_key)
item = plex.get_item(helpers.cast_to_int(rating_key)) item = plex.get_item(helpers.cast_to_int(rating_key))
@ -897,6 +887,16 @@ def export(section_id=None, rating_key=None, file_format='json'):
items = [item] items = [item]
elif section_id:
logger.debug("Tautulli Exporter :: Export called with section_id %s", section_id)
library = plex.get_library(section_id)
media_type = library.type
library_title = library.title
filename = 'Library - {} [{}].{}.{}'.format(
library_title, section_id, helpers.timestamp_to_YMDHMS(timestamp), file_format)
items = library.all()
else: else:
return return