How anthirian/script.service.janitor works
Project type and purpose
• This is a Kodi/XBMC addon written in Python.
• It runs as a background “cleaner” service (service.py) and provides a simple UI (default.py with accompanying XML skin files).
• Its purpose is to scan watched media files on local or network disks, apply user‑configured criteria (age, rating, free disk space, exclusions), delete matching files, and expose a log viewer in Kodi’s interface.
File structure
• Top‑level files:
• addon.xml – metadata and entrypoints for Kodi
• default.py – UI entrypoint script (invoked when user opens the addon)
• service.py – background service script (runs on Kodi startup or schedule)
• README, LICENSE, changelog – docs
• resources/
• skins/Default – XML layouts for the log viewer UI and Estuary artwork
• language/…/strings.po – localization files
• settings.xml – addon settings schema
• util/
• addon_info.py – reads metadata from addon.xml
• settings.py – loads and validates user settings
• disk.py – disk‑scanning and free‑space checks
• exclusions.py – resolves user‑configured exclusion patterns
• logging/Janitor & kodi.py – write logs both to file and Kodi’s log API
README for additional insights
• Describes configuration options (age, rating, free disk space, exclusions)
• Warns about the destructive power of the addon
• Mentions reuse of Estuary artwork under CC BY‑SA 4.0
a. Main components
• Kodi Host Application
• Addon Container (addon.xml defines two entrypoints)
– Service Module (service.py)
– UI Module (default.py + XML skins)
• Utility Library (util/…)
– Settings Loader
– Disk Scanner
– Exclusion Engine
– Logging Subsystem
• Persistent Storage
– File System(s) (local drives, network shares)
– Kodi’s settings storage (where settings.xml is persisted)
b. Relationships & interactions
– Kodi Host loads the addon at startup → service.py begins scheduled scans
– service.py calls util/settings to fetch user criteria
– service.py invokes util/disk to enumerate media files & check free space
– util/exclusions filters out paths/patterns user has excluded
– service.py deletes files via disk module
– util/logging writes actions to both a log file and Kodi’s log
– User opens the addon in Kodi UI → default.py reads log via util/logging & renders it with XML skins
c. Architectural patterns/design principles
– Plugin architecture: addon entrypoints registered in addon.xml
– Separation of concerns: background service vs. interactive UI vs. pure logic in util modules
– Event/schedule‑based design: service triggers periodically or at startup
– Layered design: UI layer, service layer, utilities layer, filesystem
d. Key technologies/frameworks
– Python 3 with Kodi Addon API
– Kodi’s XML‑based skinning engine
– gettext (.po files) for localization
– Standard filesystem and OS libraries for disk operations