-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebVideoMPV.sh
More file actions
26 lines (20 loc) · 791 Bytes
/
WebVideoMPV.sh
File metadata and controls
26 lines (20 loc) · 791 Bytes
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
#!/bin/bash
## A SCRIPT TO PLAY CLIPBOARDED URLS WITH MPV
# Get cliboard content
link=$(xclip -o -selection clipboard)
# Directory for a history of played urls
history=$HOME/.webvideompvhistory
# Save clipboard to the history
# Do this before playing so if it crashes you still have the history
echo "$link" >> "$history"
# Try to play the clipboard with mpv, and if it fails
if ! mpv "$link"; then
# Remove the last added line from history
sed -i '$d' "$history"
# Get the last item from the history
old_link=$(tail -n 1 "$history")
# Play that instead
mpv "$old_link"
fi
## One liner
# link=$(xclip -o -selection clipboard); history=$HOME/.webvideompvhistory; echo "$link" >> "$history"; mpv "$link" || sed -i '$d' "$history"; old_link=$(tail -n 1 "$history"); mpv "$old_link"