diff --git a/plexpy/libraries.py b/plexpy/libraries.py index b764077b..cbe2e33e 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -879,3 +879,21 @@ class Libraries(object): return 'Unable to delete media info table cache, section_id not valid.' except Exception as e: logger.warn(u"PlexPy Libraries :: Unable to delete media info table cache: %s." % e) + + def delete_duplicate_libraries(self): + from plexpy import plextv + + monitor_db = database.MonitorDatabase() + + # Refresh the PMS_URL to make sure the server_id is updated + plextv.get_real_pms_url() + + server_id = plexpy.CONFIG.PMS_IDENTIFIER + + try: + logger.debug(u"PlexPy Libraries :: Deleting libraries where server_id does not match %s." % server_id) + monitor_db.action('DELETE FROM library_sections WHERE server_id != ?', [server_id]) + + return 'Deleted duplicate libraries from the database.' + except Exception as e: + logger.warn(u"PlexPy Libraries :: Unable to delete duplicate libraries: %s." % e) \ No newline at end of file diff --git a/plexpy/webserve.py b/plexpy/webserve.py index a73b5576..831aaef0 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -492,7 +492,20 @@ class WebInterface(object): cherrypy.response.headers['Content-type'] = 'application/json' return json.dumps({'message': 'no data received'}) else: - return json.dumps({'message': 'Cannot refresh library while getting file sizes.'}) + return json.dumps({'message': 'Cannot refresh library while getting file sizes.'}) + + @cherrypy.expose + def delete_duplicate_libraries(self): + library_data = libraries.Libraries() + + result = library_data.delete_duplicate_libraries() + + if result: + cherrypy.response.headers['Content-type'] = 'application/json' + return json.dumps({'message': result}) + else: + cherrypy.response.headers['Content-type'] = 'application/json' + return json.dumps({'message': 'Unable to delete duplicate libraries from the database.'}) ##### Users #####