-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdlnmpv
executable file
·143 lines (119 loc) · 3.46 KB
/
pdlnmpv
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
PLAYLISTFLDR=~/.local/share/Playlist.d
PLAYLISTFILE=~/.local/share/playlist
PLAYLISTFILEbkp=/tmp/playlist-bkp
YTDLCONC='--ytdl-raw-options=concurrent-fragments=50'
# shellcheck disable=SC2089
YTDLQLTY='--ytdl-format="bestvideo[height<=1080]+bestaudio/best[height<=1080]"'
DM_OPTIONS='check-playlist
full-playlist
send-to-playlist
edit-playlist-file
get-playlist-bkp
primary-to-clipboard
stop-ytb-or-clean
torrent
ytdl
ytdl-mix'
# The options on the initial dmenu prompt
CHOICE=$(dmenu -i <<<"$DM_OPTIONS")
# If no DM_OPTIONS/CHOICE was selected, exits
[[ -z $CHOICE ]] && exit
# The clipboard content
CLIP=$(xclip -selection clipboard -o 2>/dev/null)
getPlaylistLine() {
# shellcheck disable=SC2317
sed -e 1$'{w/dev/stdout\n;d}' -i~ "$1" |
tee -a "$PLAYLISTFILEbkp" |
awk '{print $NF}'
}
ytbNotify() {
youtube-dl -f "${YTDLQLTY:15:-1}" "--${YTDLCONC:19}" \
--match-filter !is_live \
--add-chapters --embed-metadata --embed-thumbnail \
--newline --no-playlist "$1" 2>&1 |
send2notify -p
}
exec_mpv() {
xterm -g 76x5-1-1 -class XTerm-float -e mpv "${YTDLQLTY:1:-1}" "$@" --fs
}
case "$CHOICE" in
"full-playlist")
if [[ -f $PLAYLISTFILE ]]; then
# if playlist exists and is not empty
PLAYLIST_LIST="$(awk '{printf "%s ", $NF}' <$PLAYLISTFILE)"
# shellcheck disable=SC2086
exec_mpv $PLAYLIST_LIST
cat $PLAYLISTFILE >>$PLAYLISTFILEbkp
rm $PLAYLISTFILE
else
notify-send "Local playlist is probably Empty" && exit 1
fi
;;
"check-playlist")
if [[ -s $PLAYLISTFILE ]]; then
# If the playlist file has anything in it
PLAYLIST_CHOICE="$(dmenu -i -l 10 <"$PLAYLISTFILE")"
else
notify-send 'Stream and Local Playlists Empty' && exit 1
fi
if [[ -n "$PLAYLIST_CHOICE" ]]; then
CHOICE_URL="$(awk '{print $NF}' <<<"$PLAYLIST_CHOICE")"
exec_mpv "$CHOICE_URL"
echo "$PLAYLIST_CHOICE" >>$PLAYLISTFILEbkp
sed -i "/$(sed -e 's/\//\\\//g' <<<"$CHOICE_URL")/d" $PLAYLISTFILE
else
pdlnmpv
fi
;;
"send-to-playlist")
send2notify -s "$CLIP"
;;
"edit-playlist-file")
# Needs a conditional because vim doesn't care if the file exits or not
if [[ -s $PLAYLISTFILE ]]; then
$TERMINAL -e nvim $PLAYLISTFILE
else
notify-send 'Playlist file is empty'
fi
pdlnmpv
;;
"get-playlist-bkp")
if [[ -s $PLAYLISTFILEbkp ]]; then
# Gets the backup line
TO_GET="$(dmenu -i -l 10 <$PLAYLISTFILEbkp)"
[[ -z $TO_GET ]] && exit
# Saves it to the PLAYLISTFILE
echo "$TO_GET" >>$PLAYLISTFILE
# Removes the line from the playlist-bkp
sed -i "/$(sed -e 's/\//\\\//g' <<<"$TO_GET")/d" $PLAYLISTFILEbkp
else
notify-send 'Playlist Backup not found'
fi
pdlnmpv
;;
"primary-to-clipboard")
xclip -o | xclip -selection clipboard
notify-send 'Sent from Primary to Clipboard'
;;
"stop-ytb-or-clean")
killall yt-dlp
rm $PLAYLISTFLDR/{*.part*,*.f251.*,*.f303.*,*.ytdl}
;;
"torrent")
tadd "$CLIP"
;;
"ytdl")
ytbNotify "$CLIP"
;;
"ytdl-mix")
cd ~/Media/Videos/Mixes/jMIX || exit 1
ytbNotify "$CLIP"
;;
esac
# if the content of the clipboard wasn't a url and some of the option tried to
# use it, send the error to notify-send
if [[ "$?" == 1 && $CHOICE =~ (send-to-playlist|torrent) ]]; then
notify-send "Invalid or Not an URL" && exit 1
fi
exit