-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddSongToFavsPlaylist.sh
More file actions
33 lines (24 loc) · 1.13 KB
/
AddSongToFavsPlaylist.sh
File metadata and controls
33 lines (24 loc) · 1.13 KB
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
#!/bin/bash
## ADD CURRENT PLAYING MPD SONG TO M3U
# Check if the argument is a valid file
if [[ -f "$1" ]]; then
PLAYLIST="$1"
else
echo "Not a valid playlist file"
echo "Provide the target playlist file as an argument"
exit 2
fi
# Get the current playing song. -f is the format option, %file% gives the file path
SONG=$(mpc -f %file% current)
# Check if the song is already in the playlist, if not append it to it
# grep -qxF -- "$SONG" "$PLAYLIST" || echo "$SONG" >> "$PLAYLIST"
# Or just add it and remove duplicates later
echo "$SONG" >> "$PLAYLIST"
# Sort alphabetically the playlist and -o output it to the second file
# The advantage over using > is that if its the same file (like this case) > leaves an empty file
# -u to remove duplicate lines
sort -uo "$PLAYLIST" "$PLAYLIST"
echo "Added $SONG to $PLAYLIST"
# One liner version of the adding only if its not in the file already
#song=$(mpc -f %file% current); grep -qxF "$song" "/playlist/dir/file.m3u" || echo "$song" >> "/playlist/dir/file.m3u"
#mpc -f %file% current | xargs -I % echo % >> "/playlist/dir/file.m3u" && sort -uo "/playlist/dir/file.m3u" "/playlist/dir/file.m3u"