The branch, dharma has been updated
via 8961e1c427b9a26a3b9fb874f717de566d8a29a3 (commit)
from fec565d8f7ef245d0badf777fa86ac9d956786c1 (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=8961e1c427b9a26a3b9fb874f717de566d8a29a3
commit 8961e1c427b9a26a3b9fb874f717de566d8a29a3
Author: amet <[email protected]>
Date: Sun Jan 16 11:46:06 2011 +0400
[script.filecleaner] -v 1.3.5
Version 1.3.5
===============
- Bug fixes
Version 1.2.0
===============
- Added option to delete based on movie/episode rating
- Added option to movie to holding folder instead of deleting
- Code cleanup
diff --git a/script.filecleaner/README b/script.filecleaner/README
index e2da4a7..0517dc6 100644
--- a/script.filecleaner/README
+++ b/script.filecleaner/README
@@ -3,10 +3,15 @@ __ _____ __ __ ___ ___ _ _ ___ _
> <| _ \ |\/| | (__ | _|| | / -_) | (__| / -_) _` | ' \/ -_) '_|
/_/\_\___/_| |_|\___| |_| |_|_\___| \___|_\___\__,_|_||_\___|_|
-DISCLAIMER
+DANGER WILL ROBINSON!!!
=====================================
-Service is disabled in options by default, please make sure that you fully
understand what this plugin is intended to do and that you've configured the
options to your requirements before enabling. Once enabled, please run once to
intialize the service. I will not be held responsible for loss of data due to
user error.
+This script has the potential to wipe your entire video collection! Please
make sure you understand exactly what this script is designed to do before
running. I will not be held responsible for loss of data due to user error.
DESCRIPTION
=====================================
-This plugin will automatically scan your library for watched TV shows and
Movies and delete them from the file system and from the library. By default
only TV episodes are deleted and files will only be deleted if the hard disk is
running out of space and the file has previously been watched over 14 days ago.
All these options and more can be configured via add-on settings (right click
addon or press C for context menu and select 'Add-on Settings'). Also make
sure you set the disk usage path before enabling if you store your videos on a
secondary drive (e.g, /media/external or D:\ etc).
+This plugin will automatically scan your library for watched TV shows and
Movies and delete them from the file system based on numerous critia such as
age, rating, disk free space etc. All these options and more can be configured
via add-on settings (right click addon or press C for context menu and select
'Add-on Settings'). Also make sure you set the disk usage path before enabling
if you store your videos on a secondary drive (e.g, /media/external or D:\ etc).
+
+QUESTIONS/COMMENTS/SUGGESTIONS
+=====================================
+web: http://drewzh.com
+email: [email protected]
diff --git a/script.filecleaner/addon.xml b/script.filecleaner/addon.xml
index 80e1580..9bc0504 100644
--- a/script.filecleaner/addon.xml
+++ b/script.filecleaner/addon.xml
@@ -1,28 +1,28 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="script.filecleaner"
- name="XBMC File Cleaner" version="1.1.2" provider-name="drewzh">
- <requires>
- <import addon="xbmc.python" version="1.0"/>
- </requires>
- <extension point="xbmc.python.script" library="default.py">
- <provides>executable</provides>
- </extension>
- <extension point="xbmc.addon.metadata">
- <summary lang="en">Regularly deletes old movie and tv files</summary>
- <description lang="en">DISCLAIMER
-=====================================
-Service is disabled in options by default, please make sure that you fully
understand what this plugin is intended to do and that you've configured the
options to your requirements before enabling. Once enabled, please run once to
intialize the service. I will not be held responsible for loss of data due to
user error.
-
-DESCRIPTION
-=====================================
-This plugin will automatically scan your library for watched TV shows and
Movies and delete them from the file system and from the library. By default
only TV episodes are deleted and files will only be deleted if the hard disk is
running out of space and the file has previously been watched over 14 days ago.
All these options and more can be configured via add-on settings (right click
addon or press C for context menu and select 'Add-on Settings'). Also make
sure you set the disk usage path before enabling if you store your videos on a
secondary drive (e.g, /media/external or D:\ etc).
-
-QUESTIONS/COMMENTS/SUGGESTIONS
-=====================================
-email: [email protected]
-twitter: drewzh
- </description>
- <platform>all</platform>
- </extension>
-</addon>
-
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<addon id="script.filecleaner"
+ name="XBMC File Cleaner" version="1.3.5" provider-name="drewzh">
+ <requires>
+ <import addon="xbmc.python" version="1.0"/>
+ </requires>
+ <extension point="xbmc.python.script" library="default.py">
+ <provides>executable</provides>
+ </extension>
+ <extension point="xbmc.addon.metadata">
+ <summary lang="en">Regularly deletes old movie and tv files</summary>
+ <description lang="en">DANGER WILL ROBINSON!!!
+=====================================
+This script has the potential to wipe your entire video collection! Please
make sure you understand exactly what this script is designed to do before
running. I will not be held responsible for loss of data due to user error.
+
+DESCRIPTION
+=====================================
+This plugin will automatically scan your library for watched TV shows and
Movies and delete them from the file system based on numerous critia such as
age, rating, disk free space etc. All these options and more can be configured
via add-on settings (right click addon or press C for context menu and select
'Add-on Settings'). Also make sure you set the disk usage path before enabling
if you store your videos on a secondary drive (e.g, /media/external or D:\ etc).
+
+QUESTIONS/COMMENTS/SUGGESTIONS
+=====================================
+web: http://drewzh.com
+email: [email protected]
+ </description>
+ <platform>all</platform>
+ </extension>
+</addon>
+
diff --git a/script.filecleaner/changelog.txt b/script.filecleaner/changelog.txt
index be15d60..d747804 100644
--- a/script.filecleaner/changelog.txt
+++ b/script.filecleaner/changelog.txt
@@ -1,3 +1,13 @@
+Version 1.3.5
+===============
+- Bug fixes
+
+Version 1.2.0
+===============
+- Added option to delete based on movie/episode rating
+- Added option to movie to holding folder instead of deleting
+- Code cleanup
+
Version 1.1.2
===============
- Fixed file naming conventions
diff --git a/script.filecleaner/default.py b/script.filecleaner/default.py
index 4ebb7d7..930391d 100644
--- a/script.filecleaner/default.py
+++ b/script.filecleaner/default.py
@@ -1,79 +1,120 @@
-import xbmc, xbmcgui, xbmcaddon, os, math, time
+import xbmc, xbmcgui, xbmcaddon, os, shutil, math, time
from pysqlite2 import dbapi2 as sqlite
-# Addon info
+""" Addon info """
__title__ = 'XBMC File Cleaner'
__author__ = 'Andrew Higginson <[email protected]>'
-__addonID__ = "script.filecleaner"
+__addonID__ = "script.filecleaner"
__settings__ = xbmcaddon.Addon(__addonID__)
-# Autoexec info
+""" Autoexec info """
AUTOEXEC_PATH = xbmc.translatePath('special://home/userdata/autoexec.py')
AUTOEXEC_FOLDER_PATH = xbmc.translatePath('special://home/userdata/')
AUTOEXEC_SCRIPT = '\nimport
time;time.sleep(5);xbmc.executebuiltin("XBMC.RunScript(special://home/addons/script.filecleaner/default.py,-startup)")\n'
class Main:
def __init__(self):
- # Refreh settings
- self.refreshSettings()
+ """ Refreh settings """
+ self.refresh_settings()
if self.serviceEnabled:
- # Monitoring library
+ """ Monitoring library """
self.notify(__settings__.getLocalizedString(30013))
- # Main service loop
- while self.refreshSettings() and self.serviceEnabled:
+ """ Main service loop """
+ while self.refresh_settings() and self.serviceEnabled:
self.cleanup()
time.sleep(60)
- # Service disabled
+ """ Service disabled """
self.notify(__settings__.getLocalizedString(30015))
- # Run cleanup routine
+
+ """ Run cleanup routine """
def cleanup(self):
- self.log(__settings__.getLocalizedString(30009))
- if not self.deleteOnDiskLow or (self.deleteOnDiskLow and
self.isDiskSpaceLow()):
+ self.debug(__settings__.getLocalizedString(30009))
+ if not self.deleteOnDiskLow or (self.deleteOnDiskLow and
self.disk_space_low()):
doClean = False
- # Delete any expired movies
+ """ Delete any expired movies """
if self.deleteMovies:
- movies = self.getExpired('movie')
+ movies = self.get_expired('movie')
if movies:
- doClean = True
- for file in movies:
- self.deleteFile(file)
+ for file, path in movies:
+ if os.path.exists(path):
+ doClean = True
+ if self.enableHolding:
+ self.debug("Moving %s to %s..." % (file,
self.holdingFolder))
+ self.move_file(path, self.holdingFolder)
+ else:
+ self.debug("Deleting %s..." % (file))
+ self.delete_file(path)
- # Delete any expired TV shows
+ """ Delete any expired TV shows """
if self.deleteTVShows:
- episodes = self.getExpired('episode')
+ episodes = self.get_expired('episode')
if episodes:
- doClean = True
- for file in episodes:
- self.deleteFile(file)
+ for file, path in episodes:
+ if os.path.exists(path):
+ doClean = True
+ if self.enableHolding:
+ self.debug("Moving %s to %s..." % (file,
self.holdingFolder))
+ self.move_file(path, self.holdingFolder)
+ else:
+ self.debug("Deleting %s..." % (file))
+ self.delete_file(path)
- # Finally clean the library to account for any deleted videos
+ """ Finally clean the library to account for any deleted videos """
if doClean and self.cleanLibrary:
xbmc.executebuiltin("XBMC.CleanLibrary(video)")
- # Get all expired videos from the library database
- def getExpired(self, option):
+
+ """ Get all expired videos from the library database """
+ def get_expired(self, option):
try:
con =
sqlite.connect(xbmc.translatePath('special://database/MyVideos34.db'))
cur = con.cursor()
- sql = "SELECT path.strPath || files.strFilename FROM files, path,
%s WHERE %s.idFile = files.idFile AND files.idPath = path.idPath AND
files.lastPlayed < datetime('now', '-%d days') AND playCount > 0" % (option,
option, self.expireAfter)
+ if option == 'movie':
+ sql = "SELECT files.strFilename as filename,\
+ path.strPath || files.strFilename as full_path\
+ FROM files, path, %s\
+ WHERE %s.idFile = files.idFile\
+ AND files.idPath = path.idPath\
+ AND files.lastPlayed < datetime('now', '-%f days')\
+ AND playCount > 0" % (option, option,
self.expireAfter)
+ if self.deleteLowRating:
+ sql += ' AND c05+0 < %f' % (self.lowRatingFigure)
+ if self.ignoreNoRating:
+ sql += ' AND c05 > 0'
+
+ elif option == 'episode':
+ sql = "SELECT files.strFilename as filename,\
+ path.strPath || files.strFilename as full_path\
+ FROM files, path, %s\
+ WHERE %s.idFile = files.idFile\
+ AND files.idPath = path.idPath\
+ AND files.lastPlayed < datetime('now', '-%f days')\
+ AND playCount > 0" % (option, option,
self.expireAfter)
+ if self.deleteLowRating:
+ sql += ' AND c03+0 < %f' % (self.lowRatingFigure)
+ if self.ignoreNoRating:
+ sql += ' AND c03 > 0'
+ self.debug('Executing ' + str(sql))
+
cur.execute(sql)
- # Return list of files to delete
- return [element[0] for element in cur.fetchall()]
+ """ Return list of files to delete """
+ return cur.fetchall()
except:
- # Error opening video library database
+ """ Error opening video library database """
self.notify(__settings__.getLocalizedString(30012))
raise
- # Refreshes current settings
- def refreshSettings(self):
+
+ """ Refreshes current settings """
+ def refresh_settings(self):
__settings__ = xbmcaddon.Addon(__addonID__)
self.serviceEnabled = bool(__settings__.getSetting('service_enabled')
== "true")
@@ -81,63 +122,83 @@ class Main:
self.expireAfter = float(__settings__.getSetting('expire_after'))
self.deleteOnDiskLow =
bool(__settings__.getSetting('delete_on_low_disk') == "true")
self.lowDiskPercentage =
float(__settings__.getSetting('low_disk_percentage'))
- self.lowDiskPath = __settings__.getSetting('low_disk_path')
+ self.lowDiskPath =
xbmc.translatePath(__settings__.getSetting('low_disk_path'))
self.cleanLibrary = bool(__settings__.getSetting('clean_library') ==
"true")
self.deleteMovies = bool(__settings__.getSetting('delete_movies') ==
"true")
self.deleteTVShows = bool(__settings__.getSetting('delete_tvshows') ==
"true")
- # Set or remove autoexec.py line
- self.autoStart(self.serviceEnabled)
+ self.deleteLowRating =
bool(__settings__.getSetting('delete_low_rating') == "true")
+ self.lowRatingFigure =
float(__settings__.getSetting('low_rating_figure'))
+ self.ignoreNoRating = bool(__settings__.getSetting('ignore_no_rating')
== "true")
+ self.enableHolding = bool(__settings__.getSetting('enable_holding') ==
"true")
+ self.holdingFolder =
xbmc.translatePath(__settings__.getSetting('holding_folder'))
+ #self.holdingExpire = int(__settings__.getSetting('holding_expire'))
+ self.enableDebug =
bool(xbmc.translatePath(__settings__.getSetting('enable_debug')) == "true")
+
+ """ Set or remove autoexec.py line """
+ self.toggle_auto_start(self.serviceEnabled)
return True
- # Returns true if running out of disk space
- def isDiskSpaceLow(self):
- diskStats = os.statvfs(xbmc.translatePath(self.lowDiskPath))
+
+ """ Returns true if running out of disk space """
+ def disk_space_low(self):
+ diskStats = os.statvfs(self.lowDiskPath)
diskCapacity = diskStats.f_frsize * diskStats.f_blocks
diskFree = diskStats.f_frsize * diskStats.f_bavail
diskFreePercent = math.ceil(float(100) / float(diskCapacity) *
float(diskFree))
return (float(diskFreePercent) < float(self.lowDiskPercentage))
- # Delete file from the OS
- def deleteFile(self, file):
+
+ """ Delete file from the OS """
+ def delete_file(self, file):
if os.path.exists(file):
os.remove(file)
- # Deleted
+ """ Deleted """
self.notify(__settings__.getLocalizedString(30014) + ' ' + file)
- # Display notification on screen and send to log
+ """ Move file """
+ def move_file(self, file, destination):
+ if os.path.exists(file):
+ shutil.move(file, destination)
+ """ Deleted """
+ self.notify(__settings__.getLocalizedString(30025) % (file))
+
+ """ Display notification on screen and send to log """
def notify(self, message):
- self.log(message)
+ self.debug(message)
if self.showNotifications:
xbmc.executebuiltin('XBMC.Notification(%s, %s)' % (__title__,
message))
- # Log message
- def log(self, message):
- xbmc.log('::' + __title__ + '::' + message)
+
+ """ Log debug message """
+ def debug(self, message):
+ if self.enableDebug:
+ xbmc.log('::' + __title__ + '::' + message)
+
- # Sets or removes autostart line in special://home/userdata/autoexec.py
- def autoStart(self, option):
- # See if the autoexec.py file exists
+ """ Sets or removes auto start line in special://home/userdata/autoexec.py
"""
+ def toggle_auto_start(self, option):
+ """ See if the autoexec.py file exists """
if (os.path.exists(AUTOEXEC_PATH)):
- # Var to check if we're in autoexec.py
+ """ Var to check if we're in autoexec.py """
found = False
autoexecfile = file(AUTOEXEC_PATH, 'r')
filecontents = autoexecfile.readlines()
autoexecfile.close()
- # Check if we're in it
+ """ Check if we're in it """
for line in filecontents:
if line.find(__addonID__) > 0:
found = True
- # If the autoexec.py file is found and we're not in it,
+ """ If the autoexec.py file is found and we're not in it """
if (not found and option):
autoexecfile = file(AUTOEXEC_PATH, 'w')
filecontents.append(AUTOEXEC_SCRIPT)
autoexecfile.writelines(filecontents)
autoexecfile.close()
- # Found that we're in it and it's time to remove ourselves
+ """ Found that we're in it and it's time to remove ourselves """
if (found and not option):
autoexecfile = file(AUTOEXEC_PATH, 'w')
for line in filecontents:
diff --git a/script.filecleaner/resources/language/English/strings.xml
b/script.filecleaner/resources/language/English/strings.xml
index 41ce413..0994cc2 100644
--- a/script.filecleaner/resources/language/English/strings.xml
+++ b/script.filecleaner/resources/language/English/strings.xml
@@ -1,17 +1,26 @@
-<strings>
- <string id="30001">Enable service</string>
- <string id="30003">Clean library when finished</string>
- <string id="30004">Show notifications</string>
- <string id="30006">Only delete videos if low on disk space</string>
- <string id="30007">Low disk space percentage</string>
- <string id="30008">Service</string>
- <string id="30009">Running clearup</string>
- <string id="30010">Days after which a video is classed as expired</string>
- <string id="30011">Path to check for low disk usage</string>
- <string id="30012">Error opening video library database</string>
- <string id="30013">Monitoring library</string>
- <string id="30014">Deleted</string>
- <string id="30015">Service Disabled</string>
- <string id="30016">Delete movies</string>
- <string id="30017">Delete TV shows</string>
-</strings>
+<strings>
+ <string id="30001">Enable service</string>
+ <string id="30003">Clean library when finished</string>
+ <string id="30004">Show notifications</string>
+ <string id="30004">Delete video when watched X days ago</string>
+ <string id="30006">Only delete videos if low on disk space</string>
+ <string id="30007">Low disk space percentage</string>
+ <string id="30008">Service</string>
+ <string id="30009">Running clearup</string>
+ <string id="30010">Days after which a video is classed as expired</string>
+ <string id="30011">Path to check for low disk usage</string>
+ <string id="30012">Error opening video library database</string>
+ <string id="30013">Monitoring library</string>
+ <string id="30014">Deleted</string>
+ <string id="30015">Service Disabled</string>
+ <string id="30016">Delete movies</string>
+ <string id="30017">Delete TV shows</string>
+ <string id="30018">Only delete when rating has a low rating</string>
+ <string id="30019">Delete when rating lower than</string>
+ <string id="30020">Ignore files with no rating</string>
+ <string id="30021">Enable holding folder</string>
+ <string id="30022">Holding folder location</string>
+ <string id="30023">How many days to hold files before deletion</string>
+ <string id="30024">Enable debug messages</string>
+ <string id="30025">Moved %s to holding folder</string>
+</strings>
diff --git a/script.filecleaner/resources/settings.xml
b/script.filecleaner/resources/settings.xml
index 83cfaca..d1df3ff 100644
--- a/script.filecleaner/resources/settings.xml
+++ b/script.filecleaner/resources/settings.xml
@@ -1,13 +1,21 @@
-<settings>
- <category label="00008">
- <setting id="service_enabled" type="bool" label="30001"
default="false"/>
- <setting id="show_notifications" type="bool" label="30004"
default="true" />
- <setting id="delete_movies" type="bool" label="30016" default="false"
/>
- <setting id="delete_tvshows" type="bool" label="30017" default="true"
/>
- <setting id="clean_library" type="bool" label="30003" default="true"/>
- <setting id="expire_after" type="text" label="30010" default="14"/>
- <setting id="delete_on_low_disk" type="bool" label="30006"
default="true"/>
- <setting id="low_disk_percentage" type="text" label="30007"
default="10"/>
- <setting id="low_disk_path" type="text" label="30011"
default="special://home"/>
- </category>
-</settings>
+<settings>
+ <category label="00008">
+ <setting id="service_enabled" type="bool" label="30001"
default="false"/>
+ <setting id="show_notifications" type="bool" label="30004"
default="true" visible="eq(-1,true)" />
+ <setting id="delete_movies" type="bool" label="30016" default="false"
visible="eq(-2,true)" />
+ <setting id="delete_tvshows" type="bool" label="30017" default="true"
visible="eq(-3,true)" />
+ <setting id="clean_library" type="bool" label="30003" default="true"
visible="eq(-4,true)" />
+ <setting id="enable_expire" type="bool" label="30004" default="true"
visible="eq(-5,true)" />
+ <setting id="expire_after" type="labelenum" label="30010"
values="0|1|2|3|4|5|7|14|21|28" default="7" visible="eq(-6,true)" />
+ <setting id="delete_low_rating" type="bool" label="30018"
default="true" visible="eq(-7,true)" />
+ <setting id="low_rating_figure" type="labelenum" label="30019"
values="1|2|3|4|5|6|7|8|9|10" default="7" visible="eq(-8,true) + eq(-1,true)" />
+ <setting id="ignore_no_rating" type="bool" label="30020"
default="true" visible="eq(-9,true) + eq(-2,true)" />
+ <setting id="delete_on_low_disk" type="bool" label="30006"
default="true" visible="eq(-10,true)" />
+ <setting id="low_disk_percentage" type="labelenum" label="30007"
values="10|20|30|40|50|60|70|80" default="0" visible="eq(-11,true) +
eq(-1,true)" />
+ <setting id="low_disk_path" type="folder" label="30011"
default="special://home" visible="eq(-12,true) + eq(-2,true)" />
+ <setting id="enable_holding" type="bool" label="30021" default="false"
visible="eq(-13,true)" />
+ <setting id="holding_folder" type="folder" label="30022"
default="special://temp" visible="eq(-14,true) + eq(-1,true)" />
+ <setting id="holding_expire" type="labelenum" label="30023"
values="1|2|3|4|5|7|14|21|28" default="5" enable="false" visible="eq(-15,true)
+ eq(-2,true)" />
+ <setting id="enable_debug" type="bool" label="30024" default="false"
visible="eq(-16,true)" />
+ </category>
+</settings>
-----------------------------------------------------------------------
Summary of changes:
script.filecleaner/README | 11 +-
script.filecleaner/addon.xml | 56 ++++----
script.filecleaner/changelog.txt | 10 ++
script.filecleaner/default.py | 167 +++++++++++++------
.../resources/language/English/strings.xml | 43 +++--
script.filecleaner/resources/settings.xml | 34 +++--
6 files changed, 207 insertions(+), 114 deletions(-)
hooks/post-receive
--
Scripts
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons