aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-09-06 16:34:56 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-09-06 16:34:56 -0300
commitb99e56674492cde24483f9415bfd2e66bd0acce7 (patch)
tree2c80f65fd8b60bc29be7117f3d6dd50df16e6429
parent71a5bbdbed854416ac84846474a242e39cd66b51 (diff)
downloadplaylister-b99e56674492cde24483f9415bfd2e66bd0acce7.tar.gz
playlister-b99e56674492cde24483f9415bfd2e66bd0acce7.tar.bz2
Adds playlist-orphans
-rw-r--r--README.md3
-rwxr-xr-xplaylist-orphans74
2 files changed, 75 insertions, 2 deletions
diff --git a/README.md b/README.md
index a486f52..797bf99 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-Playlister
-==========
+# Playlister
Playlister is a simple music playlist manager based on git-annex to share audio
files between devices.
diff --git a/playlist-orphans b/playlist-orphans
new file mode 100755
index 0000000..c66bd93
--- /dev/null
+++ b/playlist-orphans
@@ -0,0 +1,74 @@
+#!/bin/bash
+#
+# Check for files not on any playlist.
+#
+# This script lists music files that aren't on any playlist (useful for
+# removing dangling files etc).
+#
+
+# Parameters
+BASENAME="`basename $0`"
+ITEM="$1"
+MEDIA="/var/cache/media/noise"
+PLAYLISTS="$MEDIA/playlists"
+
+# Check orphaned files
+function playlist_orphan {
+ local file="`echo "$*" | sed -e 's|^./||' -e "s|^$MEDIA/||"`"
+
+ # Ignore playlist files
+ if [ "`basename "$file"`" != "`basename "$file" .m3u`" ]; then
+ return
+ fi
+
+ # Check if a file is not in any playlist
+ if ! grep -q "$file" $PLAYLISTS/*m3u; then
+ #echo "Orphan: $file"
+ echo "$file"
+ #else
+ # echo "Not orphan: $file"
+ fi
+}
+
+# Process a path
+function playlist_orphans {
+ local cwd="`pwd`"
+
+ cd $MEDIA
+
+ if [ ! -z "$FILE" ]; then
+ playlist_orphan $FILE
+ else
+ # We're not keeping a list of specific file extensions to search, because
+ # it would need to be maintained, which we can't do right now.
+ find $FOLDER -not -type d | while read entry; do
+ playlist_orphan $entry
+ done
+ fi
+
+ cd $cwd
+}
+
+# Basic syntax check
+if [ "$ITEM" == "--help" ]; then
+ echo "Usage: $BASENAME [file|folder]"
+
+ exit 1
+fi
+
+# Determine items
+if [ ! -z "$ITEM" ]; then
+ if [ -d "$MEDIA/$ITEM" ]; then
+ FOLDER="$MEDIA/$ITEM"
+ elif [ -e "$MEDIA/$ITEM" ] || [ -L "$MEDIA/$ITEM" ]; then
+ FILE="$MEDIA/$ITEM"
+ else
+ echo "$BASENAME: error: item not found: $MEDIA/$ITEM"
+ exit 1
+ fi
+else
+ FOLDER="."
+fi
+
+# Dispatch
+playlist_orphans