aboutsummaryrefslogtreecommitdiff
path: root/getyt
blob: 2ea3d6f92fb6e360bd064a6fcf9fbbfb771d148e (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
#!/bin/sh
FZF_PREVIEW_LINES=20
FZF_PREVIEW_COLUMNS=50


cd "$(dirname "$0")" || exit
has_chafa=0

while getopts "c" opt; do
    case "$opt" in
        c) has_chafa=1;
            break;
            ;;
        *) break;;
    esac
done

shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift

! command -v chafa >/dev/null && has_chafa=0

playlist=$1


if [ "$playlist" = "" ]; then
    item="$(sqlite3 ./youtube_stuffs.db "select rowid,* from ytlist")"
else
    item="$(sqlite3 ./youtube_stuffs.db "select rowid,* from ytlist where category='$playlist'")"
fi


if [ "$has_chafa" = "1" ]; then
    item="$( printf -- "%s" "$item" | \
        fzf --preview "./preview.sh {} | xargs chafa --clear -f sixel -s ${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" \
        | sed -- 's/|.*//g')"
else
    item="$( printf -- "%s" "$item" | \
        fzf \
        | sed -- 's/|.*//g')"
fi


url=$(sqlite3 ./youtube_stuffs.db "select id from ytlist where rowid=$item")
if [ -z "$WAYLAND_DISPLAY" ]; then
    printf -- "https://youtube.com/watch?v=%s" "$url" | xclip -selection clipboard
else
    printf -- "https://youtube.com/watch?v=%s" "$url" | wl-copy
fi