-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube
executable file
·77 lines (69 loc) · 1.71 KB
/
youtube
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
VLC="cvlc"
YOUTUBEDL="yt-dlp"
vlc_opts="--play-and-exit"
yt_opts=""
yt_post_opts=""
link=""
listen=true
out=$(mktemp -d)
for arg in "$@"; do
case $arg in
--save)
out=$2
[[ -z $out ]] && out="."
listen=false
shift
shift
;;
--audio) yt_opts="--extract-audio --audio-quality 0" ;;
--time)
offset=$(echo $2 | cut -d "," -f 1)
duration=$(echo $2 | cut -d "," -f 2)
((duration++))
shift
shift
;;
--loop) vlc_opts="${vlc_opts} --loop" ;;
--random) vlc_opts="${vlc_opts} --random" ;;
*) link=`echo $arg | grep "youtube.com\|youtu.be"` ;;
esac
shift
done
if [[ "${OSTYPE}" =~ "darwin" ]]; then
VLC="vlc"
[[ -z $link ]] && link=`pbpaste`
else
[[ -z $link ]] && link=`xclip -selection clipboard -out`
fi
link=`echo "$link" | grep "youtube.com\|youtu.be"`
if [ -z "$link" ]; then
echo "A youtube link was not found."
exit
fi
if [[ $listen == true ]]; then
listen="${VLC} $vlc_opts --quiet"
else
listen="echo"
fi
if [[ $link =~ list= ]]; then
yt_opts="${yt_opts} --ignore-errors"
directory=`${YOUTUBEDL} --playlist-items 1 --get-filename \
--output "%(playlist_id)s" "$link"`
out="${out}/${directory}"
mkdir -p ${out}
${YOUTUBEDL} $yt_opts --no-part --output "${out}/%(id)s.%(ext)s" \
"$link" && \
${listen} $out/* &
else
file=`${YOUTUBEDL} $yt_opts --get-filename --output "%(id)s.%(ext)s" "$link"`
out="${out}/${file}"
if [[ -z $offset ]]; then
${YOUTUBEDL} $yt_opts --output "$out" \
--exec "${listen} {} &" "$link"
else
${YOUTUBEDL} $yt_opts --output "$out" \
--postprocessor-args "-ss $offset -t $duration" \
--exec "${listen} --quiet {} &" "$link"
fi
fi