summaryrefslogtreecommitdiff
path: root/bin/common/ytclipo
blob: 959ee21fbbe841a3207f435fd6658af102350b3d (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
#!/bin/sh

# argument ($1) -> clipboard -> stdin
if [ "$WAYLAND_DISPLAY" ]
then paste() { wl-paste; }
elif [ "$TERMUX_VERSION" ]
then paste() { termux-clipboard-get; }
else paste() { xclip -o -sel c; }
fi

inp="$1"
[ "${inp:=$(paste)}" ] || inp="$(cat /dev/stdin)"

# remove util scheme
inp="${inp#*//}"
# convert to youtube.com/path url
# works for:
# - 'youtu.be/watch?v=xxxxxx'
# - 'https://piped.video/watch?v=xxxxx'
inp="https://youtube.com/${inp#*/}"
>&2 printf "inp: %s\n" "$inp"
notify-send "ytclipo" "downloading <i>$inp</i>" || :

yt-dlp "$inp" \
	--restrict-filenames \
	--embed-chapters \
	-f "b" \
	-S "res:1080" \
	-P "$HOME/vids/youtube/" \
	-o "%(channel)s/%(title)s.%(ext)s"
notify-send "ytclipo" "finished downloading." || :