blob: c66bd933867cf43ccf44b3eb5ba5ddff90da0ad3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
|