Add buttons to delete all 3rd party metadata lookup info in the settings

This commit is contained in:
JonnyWong16 2020-03-14 14:00:17 -07:00
parent ccdd410eda
commit 90374bb46f
4 changed files with 47 additions and 10 deletions

View file

@ -860,10 +860,10 @@ DOCUMENTATION :: END
% if data.get('tvmaze_id') or data.get('themoviedb_id') or data.get('musicbrainz_id'): % if data.get('tvmaze_id') or data.get('themoviedb_id') or data.get('musicbrainz_id'):
<script> <script>
$('#delete-lookup-info').on('click', function () { $('#delete-lookup-info').on('click', function () {
var msg = 'Are you sure you want to delete the 3rd party API lookup for <strong>' + $(this).data('title') + '</strong>?<br><br>' + var msg = 'Are you sure you want to delete all the metadata lookup info for <strong>' + $(this).data('title') + '</strong>?' +
'The info will be looked up again the next time a notification is sent.'; '<br /><br />Tautulli will lookup the metadata info again the next time a notification is sent.';
var url = 'delete_lookup_info'; var url = 'delete_lookup_info';
var data = { rating_key: $(this).data('id'), title: $(this).data('title') }; var data = { rating_key: $(this).data('id') };
var callback = function () { var callback = function () {
$('#delete-lookup-info').closest('.btn-group').remove(); $('#delete-lookup-info').closest('.btn-group').remove();
}; };

View file

@ -1239,6 +1239,19 @@
</label> </label>
<p class="help-block">Enable to lookup links to MusicBrainz for music when available.</p> <p class="help-block">Enable to lookup links to MusicBrainz for music when available.</p>
</div> </div>
<div class="form-group">
<label for="maxmind_license_key">Delete Lookup Info</label>
<p class="help-block">Delete all cached metadata lookup info in Tautulli.</p>
<div class="row">
<div class="col-md-9">
<div class="btn-group">
<button class="btn btn-form delete_all_lookups" type="button" data-service="themoviedb">TheMovieDB</button>
<button class="btn btn-form delete_all_lookups" type="button" data-service="tvmaze">TVmaze</button>
<button class="btn btn-form delete_all_lookups" type="button" data-service="musicbrainz">MusicBrainz</button>
</div>
</div>
</div>
</div>
<div class="padded-header"> <div class="padded-header">
<h3>Geolocation Database</h3> <h3>Geolocation Database</h3>
@ -2806,12 +2819,23 @@ $(document).ready(function() {
var name = image_hosting_option.text(); var name = image_hosting_option.text();
var msg = 'Are you sure you want to delete all uploaded images on <strong>' + name + '</strong>?' + var msg = 'Are you sure you want to delete all uploaded images on <strong>' + name + '</strong>?' +
'<br />All previous links to the images will no longer work. This cannot be undone!'; '<br /><br />All previous links to the images will no longer work. This cannot be undone!';
var url = 'delete_hosted_images'; var url = 'delete_hosted_images';
var data = { service: name, delete_all: true }; var data = { service: name, delete_all: true };
confirmAjaxCall(url, msg, data, false); confirmAjaxCall(url, msg, data, false);
}); });
$('body').on('click', '.delete_all_lookups', function () {
var service = $(this).data('service');
var name = $(this).text();
var msg = 'Are you sure you want to delete all the metadata lookup info from <strong>' + name + '</strong>?' +
'<br /><br />Tautulli will lookup the metadata info again the next time a notification is sent.';
var url = 'delete_lookup_info';
var data = { service: service, delete_all: true };
confirmAjaxCall(url, msg, data, false);
});
function baseURLSet() { function baseURLSet() {
if ($('#http_base_url').val()) { if ($('#http_base_url').val()) {
$('.base-url-warning').hide(); $('.base-url-warning').hide();

View file

@ -1406,16 +1406,29 @@ class DataFactory(object):
return lookup_info return lookup_info
def delete_lookup_info(self, rating_key='', title=''): def delete_lookup_info(self, rating_key='', service='', delete_all=False):
if not rating_key and not delete_all:
logger.error(u"Tautulli DataFactory :: Unable to delete lookup info: rating_key not provided.")
return False
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
if rating_key: if rating_key:
logger.info(u"Tautulli DataFactory :: Deleting lookup info for '%s' (rating_key %s) from the database." logger.info(u"Tautulli DataFactory :: Deleting lookup info for rating_key %s from the database."
% (title, rating_key)) % (title, rating_key))
result_tvmaze = monitor_db.action('DELETE FROM tvmaze_lookup WHERE rating_key = ?', [rating_key])
result_themoviedb = monitor_db.action('DELETE FROM themoviedb_lookup WHERE rating_key = ?', [rating_key]) result_themoviedb = monitor_db.action('DELETE FROM themoviedb_lookup WHERE rating_key = ?', [rating_key])
result_tvmaze = monitor_db.action('DELETE FROM tvmaze_lookup WHERE rating_key = ?', [rating_key])
result_musicbrainz = monitor_db.action('DELETE FROM musicbrainz_lookup WHERE rating_key = ?', [rating_key]) result_musicbrainz = monitor_db.action('DELETE FROM musicbrainz_lookup WHERE rating_key = ?', [rating_key])
return True if (result_tvmaze or result_themoviedb or result_musicbrainz) else False return bool(result_themoviedb or result_tvmaze or result_musicbrainz)
elif service and delete_all:
if service.lower() in ('themoviedb', 'tvmaze', 'musicbrainz'):
logger.info(u"Tautulli DataFactory :: Deleting all lookup info for '%s' from the database."
% service)
result = monitor_db.action('DELETE FROM %s_lookup' % service.lower())
return bool(result)
else:
logger.error(u"Tautulli DataFactory :: Unable to delete lookup info: invalid service '%s' provided."
% service)
def get_search_query(self, rating_key=''): def get_search_query(self, rating_key=''):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()

View file

@ -4345,7 +4345,7 @@ class WebInterface(object):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth(member_of("admin")) @requireAuth(member_of("admin"))
@addtoapi() @addtoapi()
def delete_lookup_info(self, rating_key='', title='', **kwargs): def delete_lookup_info(self, rating_key='', service='', delete_all=False, **kwargs):
""" Delete the 3rd party API lookup info. """ Delete the 3rd party API lookup info.
``` ```
@ -4363,7 +4363,7 @@ class WebInterface(object):
""" """
data_factory = datafactory.DataFactory() data_factory = datafactory.DataFactory()
result = data_factory.delete_lookup_info(rating_key=rating_key, title=title) result = data_factory.delete_lookup_info(rating_key=rating_key, service=service, delete_all=delete_all)
if result: if result:
return {'result': 'success', 'message': 'Deleted lookup info.'} return {'result': 'success', 'message': 'Deleted lookup info.'}