Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ their database.
Users can also choose (via the add-on settings) to retain or remove old
PVR information and to retain or remove bookmarks. As of V0.5.5 all the different
settings are documented in the file **docs.txt** which is included with the add-on
and can be found in the add-on's directory.
and can be found in the add-on's directory and will be displayed upon the first run.
There is a setting that can re-enable display of the documentation.

When run, the script will prompt with a summary window containing a list
of the paths to retain in the database. Users are encouraged to check that
Expand All @@ -24,7 +25,7 @@ are also displayed, along with the contents of any 'excludes.xml' file.
The name of the currently connected database is also displayed.
If you are using MySQL, there will also be a warning to back up your database
manually. You have the option to either abort the script, or to clean the database.
Clicking on 'DO IT !!' will run the cleaner, clicking on 'ABORT' will exit the script
Clicking on 'Clean' will run the cleaner, clicking on 'ABORT' will exit the script
with no changes made to the database.

Once users are happy that the script is working correctly, this summary can
Expand Down
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.database.cleaner"
name="Video Database Cleaner"
version="0.6.1"
version="0.6.3"
provider-name="black_eagle, BatterPudding.">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Vesrion 0.6.3 07/07/19
[Add] Ability to display log file before cleaning

Version 0.6.2 06/07/19
[Add] Display documentation on first run

Version 0.6.1 01/07/19
[Fix] Sql error when no sources are spcified or found and no other settings are enabled

Expand Down
70 changes: 70 additions & 0 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,45 @@
ACTION_MOUSE_LEFT_CLICK = 100
flag = 0
WINDOW = xbmcgui.Window(10000)
global flag

class displayDocs(xbmcgui.WindowXMLDialog):
def __init__( self, *args, **kwargs ):
self.MAIN_TEXT_BOX = 10

def onInit( self ):
log(userdata_path)
content_path = xbmc.translatePath('special://home/addons/script.database.cleaner/docs.txt').decode('utf-8')
if flag == 2: # display log file rather than docs
content_path = xbmc.translatePath('special://temp/database-cleaner.log').decode('utf-8')
dbglog(content_path)
docfile = xbmcvfs.File(content_path)
contents = docfile.read()
docfile.close()
log('docs file read OK')
self.docbox = self.getControl(self.MAIN_TEXT_BOX)
self.docbox.setText(contents)

def onAction(self, action):

dbglog('Got an action %s' % action.getId())
if ( action == ACTION_PREVIOUS_MENU ) or ( action == ACTION_NAV_BACK ):
self.close()
if (action == ACTION_SELECT_ITEM) or ( action == ACTION_MOUSE_LEFT_CLICK ):
try:
btn = self.getFocus()
btn_id = btn.getId()

except:
btn_id = None
if btn_id == 1:
dbglog('you pressed exit')
flag = 0
self.close()
elif btn_id == 2:
dbglog('you pressed settings')
flag = 1
self.close()

class MyClass(xbmcgui.WindowXMLDialog):
def __init__( self, *args, **kwargs ): pass
Expand Down Expand Up @@ -168,6 +206,10 @@ def onAction(self, action):
dbglog('you pressed clean')
flag = 1
self.close()
elif btn_id == 3:
dbglog('Show cleaner log')
flag = 2
self.close()

# Set some variables ###

Expand All @@ -183,6 +225,12 @@ def onAction(self, action):
userdata_path = xbmc.translatePath('special://userdata').decode('utf-8')
bp_logfile_path = xbmc.translatePath('special://temp/bp-debuglog.log').decode('utf-8')
type_of_log =''
show_docs = addon.getSetting('showdocs')
if show_docs == 'true':
show_docs = True
addon.setSetting('showdocs','false')
else:
show_docs = False
is_pvr = addon.getSetting('pvr')
autoclean = addon.getSetting('autoclean')
bookmarks = addon.getSetting('bookmark')
Expand Down Expand Up @@ -363,6 +411,15 @@ def cleaner_log_file(our_select, cleaning):
xbmcgui.Dialog().notification(addonname, 'Starting Up', xbmcgui.NOTIFICATION_INFO, 2000)
xbmc.sleep(2000)

log('userdata path [%s] ' %userdata_path)
if show_docs:
WINDOW.setProperty('database-cleaner','docs')
mydisplay = displayDocs('cleaner-docs.xml', addonpath, 'Default', '1080i')
mydisplay.doModal()
del mydisplay
if flag:
addon.openSettings(addonname)

if xbmcvfs.exists(advanced_file):
dbglog('Found advancedsettings.xml')
found = True
Expand Down Expand Up @@ -690,6 +747,19 @@ def cleaner_log_file(our_select, cleaning):
del mydisplay
if flag == 1:
i = True
elif flag == 2:
while flag == 2:
WINDOW.setProperty('database-cleaner','log-file')
mydisplay = displayDocs('cleaner-docs.xml', addonpath, 'Default', '1080i')
mydisplay.doModal()
del mydisplay
mydisplay = MyClass('cleaner-window.xml', addonpath, 'Default', '1080i')
mydisplay.doModal()
del mydisplay
if flag == 1:
i = True
else:
i = False
else:
i = False

Expand Down
99 changes: 47 additions & 52 deletions docs.txt
Original file line number Diff line number Diff line change
@@ -1,146 +1,142 @@
Video.database.cleaner documentation
====================================

About
-----
[B][COLOR yellow]ABOUT[/COLOR][/B]

Kodi's video database accumulates un-needed and un-wanted file links over time.

This add-on was written to help users to clean all the rubbish out and make the
built in 'clean library' more efficient as well as much faster.

Settings
--------
[B][COLOR yellow]SETTINGS[/COLOR][/B]

General settings
++++++++++++++++
[B]General Settings[/B]

A) Keep any pvr information
[B]A) Keep any pvr information[/B]

When enabled the add-on will not delete any references to files recorded with a
live-tv backend.
When enabled the add-on will not delete any references to files recorded with a
live-tv backend.

B) Keep bookmarked files
[B]B) Keep bookmarked files[/B]

When enabled, any files that have bookmarks will not be deleted, even if they are
in a path that would have been deleted otherwise.

C) Automatically trigger clean library
[B]C) Automatically trigger clean library[/B]

When enabled, the add-on will call Kodi's built in 'clean library' routine after it
When enabled, the add-on will call Kodi's built in 'clean library' routine after it
has finished it's own cleaning. This cleans the other tables in the database that the
add-on doesn't touch. It is recommended that this setting is left enabled at all times.

D) Back-up local database before cleaning
[B]D) Back-up local database before cleaning[/B]

When enabled, the database will be backed up to a sub-directory in Kodi's Database directory.
The back-up is time and date stamped in case a user wishes/needs to revert to an older database.
Optionally, it is also possible to specify a name for the back-up. NOTE - It is not possible
for the add-on to back up a MySQL shared database. Users with MySQL databases should use their
tool of choice to manually back-up their database. phpMyAdmin is one such tool used by the authors.

E) Show summary window
[B]E) Show summary window[/B]

When enabled, a pop-up window will list various settings and paths, depending upon the options
chosen in the add-on settings. It is possible to abort the add-on run at this point which will
leave the database un-touched, or to select the 'Do It !!' button which will run the cleaning
leave the database un-touched, or to select the 'Clean' button which will run the cleaning
routine with the chosen settings. If this setting is disabled, the add-on will run without user
intervention although any logs will still be created.

Debug and log settings
++++++++++++++++++++++
[B]F) Show documentation at start-up[/B]

A) Log paths to database-cleaner.log
Shows this documentation window when database cleaner starts up. As this could get annoying,
the setting will turn itself OFF after the documentation window is closed. To re-show this
document, turn this setting back on in the addon's settings.

If enabled the add-on will create a logfile in Kodi's 'temp' directory that records all the
[B][COLOR yellow]Debug and log settings[/COLOR][/B]

[B]A) Log paths to database-cleaner.log[/B]

If enabled the add-on will create a logfile in Kodi's 'temp' directory that records all the
paths that the add-on will delete. If 'show summary window' is enabled it is possible to stop
the add-on by pressing the 'abort' button. The logfile will still be created so that users can
the add-on by pressing the 'abort' button. The logfile will still be created so that users can
see what will be deleted before actually doing so. When the add-on cleans the video database, any
existing log will be backed-up to 'database-cleaner.old.log'.

B) Log creation style
[B]B) Log creation style[/B]

Two options are available - create new log each run or add to log each run. If the first option
is chosen, any existing log will be deleted and replaced with a fresh log. If the second option
is chosen, the logfile will be added to on each run. Logfiles are still backed-up on cleaning,
regardless of this setting.

C) Enable debugging to Kodi debug log
[B]C) Enable debugging to Kodi debug log[/B]

In normal use, the add-on writes very little to the Kodi logfile. In the event of an error or an
issue with using this add-on, users should first enable the systemwide Kodi debug log and enable
this setting to produce a debug log that the authors can use to determine the cause of the error or issue.

Sources
+++++++
[B][COLOR yellow]Sources[/COLOR][/B]

A) Use sources.xml to determine files to keep
[B]A) Use sources.xml to determine files to keep[/B]

When a user scans a video source into Kodi, the path is stored in a 'sources.xml' file. Enabling
this setting tells the add-on that any files that have been added into the video library by
this method should not be deleted. NOTE - Kodi should delete any files when a user removes a source
but if this has not happened, the add-on will remove them automatically.

B) Use sources.xml on this machine
[B]B) Use sources.xml on this machine[/B]

Generally, this setting should be enabled. Users of MySQL databases do not need to have a 'sources.xml' on each
machine that their database is shared with, because the paths are contained within the shared database.
Such users can disable this setting and can then set the path to a 'sources.xml' on a different networked
machine. This means MySQL users can run the add-on on any of their machines whilst only having a
machine. This means MySQL users can run the add-on on any of their machines whilst only having a
'sources.xml' on one machine.

Advanced
++++++++
[B][COLOR red]Advanced[/COLOR][/B]

A) Force database name
[B]A) Force database name[/B]

If enabled, makes the add-on connect to the specified database rather than the automatically detected one.
Useful for testing purposes to see what effect the add-on will have on a database. NOTE - This setting
does not alter the database that Kodi's built in 'clean library' cleans. This setting should be
disabled unless the user understands the implications of enabling it.

B) Remove specific path from database
[B]B) Remove specific path from database[/B]

If enabled the user must enter a path to be deleted from the database. NOTE - A wildcard will be
appended to the end of the supplied path. The add-on will remove the path from the files table
in the database. This setting will revert to disabled once the add-on has removed the path from
the database. It is however possible, by using the summary window, to generate a logfile showing
the details of paths to be removed by aborting the add-on at this point and viewing the log file
that it has created. The setting will not revert until either the summary window is disabled OR
the 'do it !!' button is pressed.
the 'Clean' button is pressed.

C) Replace path in database
[B]C) Replace path in database[/B]

If enabled the user must specify an existing path and a new path. Any paths containing the
specified existing path will be renamed to the new path. This is useful if you move a
If enabled the user must specify an existing path and a new path. Any paths containing the
specified existing path will be renamed to the new path. This is useful if you move a
directory on disk but do not want to remove and re-scan the source in Kodi. The add-on
generates the list of paths by appending a wildcard to the supplied 'old path'. This means that
a supplied path of 'nfs://OLD_SERVER' will include 'nfs://OLD_SERVER/Movies' and any other
directories in the tree. If the new path were 'nfs://NEW_SERVER' then every path starting with
directories in the tree. If the new path were 'nfs://NEW_SERVER' then every path starting with
'nfs://OLD_SERVER' will become 'nfs://NEW_SERVER' eg with the Movies directory above, the path
would become 'nfs://NEW_SERVER/Movies'. Renaming a path automatically turns off once the path
has been renamed. Again, it is possible by aborting the add-on in the summary window to generate a
has been renamed. Again, it is possible by aborting the add-on in the summary window to generate a
logfile showing the original path and the new path to aid users in determining if everything is correct.
Clicking on the 'Do it !' button or turning off the summary window will rename the path(s) and turn this setting off.
Clicking on the 'Clean' button or turning off the summary window will rename the path(s) and turn this setting off.

NOTE - Paths should NOT end with a terminating slash (either '\' or '/' depending on your OS) as this will lead to
[B][COLOR red]NOTE[/COLOR][/B] - Paths should [B]NOT[/B] end with a terminating slash (either '\' or '/' depending on your OS) as this will lead to
double slashes being inserted into the database.

USAGE
=====
[B][COLOR yellow]USAGE[/COLOR][/B]

To quickly remove any streaming links from your database, turn OFF 'Use sources.xml to determine files to keep'
in the add-on's 'sources' settings. This will remove only streaming links from your database when the add-on is
run. No other cleaning will be done however.

To run the add-on silently as a scheduled task, turn OFF 'Show summary window' in general settings.

To remove old links, streaming info and general rubbish accumulated in the database, ensure that
To remove old links, streaming info and general rubbish accumulated in the database, ensure that
'use sources.xml to determine files to keep' is turned ON. If you have a PVR backend, turn on
'keep any pvr information' otherwise all information relating to your recordings will be deleted.

ADVANCED USAGE
==============
[B][COLOR red]ADVANCED USAGE[/COLOR][/B]

The add-on can exclude user defined paths (including plugins) from the clean. This is done by
creating a file called 'excludes.xml' in the add-ons 'addon_data' directory. This is located
Expand All @@ -152,8 +148,8 @@ however does not exist by default, it must be created by the user.
The format of the 'excludes.xml' file is simple. EG

<excludes>
<exclude>plugin://plugin.video.youtube</exclude>
<exclude>plugin://plugin.video.itunes_trailers</exclude>
<exclude>plugin://plugin.video.youtube</exclude>
<exclude>plugin://plugin.video.itunes_trailers</exclude>
</excludes>

The excludes.xml file must start with the <excludes> tag and end with </excludes>
Expand All @@ -169,10 +165,9 @@ Users can be as precise or as vague as they require. EG
the itunes_trailers plugin has played. Useful if you want to maintain watched status
for your trailers.

<exclude>plugin://plugin.video.itunes_trailers/trailer/play/http%3A%2F%2Fmovietrailers.apple.com%2Fmovies%2Fdisney%2Fzootopia%2Fzootopia-tlr1_h720p.mov</exclude>
<exclude>plugin://plugin.video.itunes_trailers/trailer/play/http%3A%2F%2Fmovietrailers.apple.com
%2Fmovies%2Fdisney%2Fzootopia%2Fzootopia-tlr1_h720p.mov</exclude>
keeps just that one trailer and deletes all the others.

NOTE - It is possible to specify any valid path or part of a path in the <exclude> tag
[B]NOTE[/B] - It is possible to specify any valid path or part of a path in the <exclude> tag
This allows very fine control over what is removed or kept.


4 changes: 4 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ msgctxt "#32007"
msgid "Show summary window"
msgstr ""

msgctxt "#32008"
msgid "Show documentation at startup"
msgstr ""

msgctxt "#32010"
msgid "Sources"
msgstr ""
Expand Down
Loading