summaryrefslogtreecommitdiff
path: root/.local/bin/web/fpl
blob: 03987705fc1c6ffcb4b69ce1bcbe954970f51ed4 (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
#!/bin/sh

# You can pass any text file containing a list of video titles.
# An fzf prompt will shown to select a video title.
# The script will then try to find a video file whose name fuzzy matches the
# selected title.

[ -z "$1" ] && { echo "fzf-playlist: browse a list of video titles
USAGE: fpl <PLAYLIST_FILE>" >&2; exit 1; }

if [ "$OPENFLAG" = 1 ]; then

	if [ -z "$OPENWITH" ]; then
		files="$(find "${PWD%/*}")"
	else
		files="$(find "${PWD%/*}" -name '*.webm' -or -name '*.mkv' -or -name '*.mp4' -or \
			-name '*.mp3' -or -name '*.ogg')"
	fi

	if [ -z "$OPENWITH" ]; then
		for title in "$@"; do echo "$files" |
			fzf --filter "$(printf '%s\n' "$title" | sed 's/[^A-Za-z0-9]*//g')"
			echo; done
	else
		for title in "$@"; do $OPENWITH "$(echo "$files" |
			fzf --filter "$(printf '%s\n' "$title" | sed 's/[^A-Za-z0-9]*//g')" |
			head -1)"; echo; done
	fi

	exit
fi

file="$(readlink -f "$1")"
cd "${file%/*}" || exit
fzf --multi --reverse \
	--header="Playlist: ${file##*/}" --header-first \
	--bind 'enter:become(OPENFLAG=1 fpl {+})' \
	--bind 'ctrl-o:execute(OPENFLAG=1 OPENWITH=mpv fpl {})' < "$file"