-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_song
executable file
·38 lines (30 loc) · 1.13 KB
/
play_song
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
#!/usr/bin/env bash
# Takes song name - format: Artist (arg 1) and Title (arg 2) - and attempts to locate and play a matching local file.
artist="$1"
title="$2"
underscore_artist="$(echo "$artist" | sed 's/ /_/g')"
underscore_title="$(echo "$title" | sed 's/ /_/g')"
echo -e '\nFiles matching that song title:'
counter=0
readarray files < <(find ~/music/collection/ -ipath "*$artist*$title*.mp3" \
-o -ipath "*$artist*$title*.flac" \
-o -ipath "*$underscore_artist*$underscore_title*.mp3" \
-o -ipath "*$underscore_artist*$underscore_title*.flac")
for file in "${files[@]}"
do
echo -e "\n$counter)" $(basename "${file}")
(( counter=$counter + 1 ))
done
echo
if [ $counter = 0 ]; then
echo -e 'No matching files found\n'
exit 0
fi
if [ $counter = 1 ]; then
selected_file=${files[0]}
else
echo -e 'Select which file you want to play:'
read chosen_index
selected_file=${files["$chosen_index"]}
fi
echo "$selected_file" | mpv --no-audio-display --playlist=-