mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 02:20:11 -08:00
feat: Enhance Plex Recent Additions script with dynamic day range and error handling
This commit is contained in:
@@ -39,6 +39,26 @@
|
|||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
# 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
|
# 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"
|
PLEX_DB="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"
|
||||||
|
|
||||||
@@ -48,21 +68,21 @@ if [ ! -f "$PLEX_DB" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Query the database for items added in the last 7 days
|
# Query the database for items added in the specified number of days
|
||||||
sqlite3 "$PLEX_DB" <<EOF
|
sqlite3 "$PLEX_DB" <<EOF
|
||||||
.headers on
|
.headers on
|
||||||
.mode column
|
.mode column
|
||||||
SELECT
|
SELECT
|
||||||
datetime(meta.added_at, 'unixepoch', 'localtime') AS "added_at"
|
date(meta.added_at, 'unixepoch', 'localtime') AS "added_at"
|
||||||
, meta.title
|
|
||||||
, meta.year
|
|
||||||
, lib.section_type AS "library_section_type"
|
|
||||||
, lib.name as "library_name"
|
, lib.name as "library_name"
|
||||||
|
, meta.year
|
||||||
|
, meta.title
|
||||||
|
, meta.original_title
|
||||||
FROM
|
FROM
|
||||||
metadata_items meta
|
metadata_items meta
|
||||||
left join library_sections lib on meta.library_section_id = lib.id
|
join library_sections lib on meta.library_section_id = lib.id
|
||||||
WHERE
|
WHERE
|
||||||
meta.added_at >= strftime('%s', 'now', '-7 days')
|
meta.added_at >= strftime('%s', 'now', '-$DAYS days')
|
||||||
|
and meta.title is null
|
||||||
ORDER BY meta.added_at DESC;
|
ORDER BY meta.added_at DESC;
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user