Last active
February 28, 2020 21:13
-
-
Save Phate6660/eae1f8d2001f32a033b1143e3d9fd3a2 to your computer and use it in GitHub Desktop.
Convert YouTube/invidio video urls to a locally proxied invidio urls, then copy/play/echo the url.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### This is a script used to convert YouTube and invidio video URLs to locally proxied invidio URLs. | |
main() { | |
clear | |
echo "Please input an invidio or YouTube video url." | |
read -r base | |
ID="$(echo "$base" | sed -n -e 's/^.*=//p')" | |
new="https://invidio.us/watch?v=$ID&local=true" | |
echo -e "\nWould you like to play or copy the new url? (Input nothing (just press enter) to echo the url instead.)" | |
read -r action | |
case $action in | |
"copy") | |
clear | |
if command -v xclip >/dev/null 2>&1; then | |
echo "\"$new\"" | xclip | |
exit 0 | |
else | |
echo "xclip is not installed, echoing instead." | |
echo "$new" | |
exit 0 | |
fi | |
;; | |
"play") | |
clear | |
if command -v mpv >/dev/null 2>&1; then | |
mpv "$new" | |
exit 0 | |
else | |
echo "mpv is not instaled, echoing instead." | |
echo "$new" | |
exit 0 | |
fi | |
;; | |
*) | |
clear | |
echo "$new" | |
exit 0 | |
;; | |
esac | |
} | |
search() { | |
clear | |
echo "Input what you would like to search for." | |
read -r video | |
video=${video// /+} | |
ID="$(youtube-dl --get-id ytsearch:"$video")" | |
new="https://invidio.us/watch?v=$ID&local=true" | |
echo -e "\nWould you like to play or copy the new url? (Input nothing (just press enter) to echo the url instead.)" | |
read -r action | |
case $action in | |
"copy") | |
clear | |
if command -v xclip >/dev/null 2>&1; then | |
echo "\"$new\"" | xclip | |
exit 0 | |
else | |
echo "xclip is not installed, echoing instead." | |
echo "$new" | |
exit 0 | |
fi | |
;; | |
"play") | |
clear | |
if command -v mpv >/dev/null 2>&1; then | |
mpv "$new" | |
exit 0 | |
else | |
echo "mpv is not instaled, echoing instead." | |
echo "$new" | |
exit 0 | |
fi | |
;; | |
*) | |
clear | |
echo "$new" | |
exit 0 | |
;; | |
esac | |
} | |
start() { | |
clear | |
echo "Youtube to invidio proxy" | |
echo "------------------------" | |
prompt="Pick an option:" | |
options=("I have a url." "Search for a video.") | |
PS3="$prompt " | |
select opt in "${options[@]}" "Quit"; do | |
case "$REPLY" in | |
1 ) main;; | |
2 ) search;; | |
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;; | |
*) echo "Invalid option. Try another one.";continue;; | |
esac | |
done | |
} | |
start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment