#!/bin/bash ################################################################################ # Plex Recent Additions Report Script ################################################################################ # # Author: Peter Wood # Description: Generates reports of recently added media items in Plex Media # Server by querying the library database directly. Provides # customizable time ranges and output formats. # # Features: # - Recent additions reporting (configurable time range) # - Library section filtering # - Formatted output with headers and columns # - Direct SQLite database querying # - Media type categorization # # Related Scripts: # - backup-plex.sh: Backs up the database queried by this script # - plex.sh: General Plex service management # - validate-plex-backups.sh: Validates database integrity # - monitor-plex-backup.sh: System monitoring # # Usage: # ./plex-recent-additions.sh # Show additions from last 7 days # ./plex-recent-additions.sh 30 # Show additions from last 30 days # ./plex-recent-additions.sh --help # Show usage information # # Dependencies: # - sqlite3 (for database queries) # - Plex Media Server with populated library # - Read access to Plex database files # # Exit Codes: # 0 - Success # 1 - Database not found or access denied # 2 - Query execution failure # ################################################################################ # Handle command line arguments DAYS=${1:-7} # Show help if requested if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then echo "Usage: $0 [DAYS]" echo "Show Plex media added in the last DAYS days (default: 7)" echo "" echo "Examples:" echo " $0 # Last 7 days" echo " $0 30 # Last 30 days" exit 0 fi # Validate that DAYS is a number if ! [[ "$DAYS" =~ ^[0-9]+$ ]]; then echo "Error: DAYS must be a positive integer" exit 2 fi # Define the path to the Plex database PLEX_DB="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" # Check if the database exists if [ ! -f "$PLEX_DB" ]; then echo "Plex database not found at $PLEX_DB" exit 1 fi # Query the database for items added in the specified number of days sqlite3 "$PLEX_DB" <= strftime('%s', 'now', '-$DAYS days') and meta.title is null ORDER BY meta.added_at DESC; EOF