urlscan
urlscan copied to clipboard
adding quotes (") around youtube links on standard output
Url scan opens youtube links well in the browser but I want to write a script that detects the youtube url and opens it in mpv. I believe my script works but zsh cannot handle special characters like question mark (?). Is there a way I can have urlscan add quotes before pushing to standard output so that mpv can properly source the link?
Can you share your script so I can test and figure out exactly what's going on? Thanks!
hmmm i mean the script is really quite simple, it just takes in the url from urlscan and places that as the argument for mpv.
I guess if I must show the script I'll include it below, please note I'm only really focusing the part of the case statement that opens the link with mpv
Thanks in advance!
`#!/bin/sh
if [ -z "$1" ]; then url="$(xclip -o)" else url=""$1"" fi
case "$url" in *mkv|*webm|*mp4|youtube.com/watch|youtube.com/playlist|youtube.com/shorts|youtu.be|hooktube.com|bitchute.com|videos.lukesmith.xyz|odysee.com) setsid -f mpv -quiet "$url" >/dev/null 2>&1 ;; #echo "$url" ;; *png|*jpg|*jpe|*jpeg|gif|webp) curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" && pqiv -a "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" >/dev/null 2>&1 & ;; *pdf|cbz|cbr) curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" >/dev/null 2>&1 & ;; *mp3|*flac|*opus|mp3?source) qndl "$url" 'curl -LO' >/dev/null 2>&1 ;; *) [ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1 esac`
Well, I'm not seeing the same behavior. I tried your script (slightly edited) in zsh with a list of youtube links and it worked just fine.
# ./launch.sh
#!/bin/sh
if [ -z "$1" ]; then
url="$(wl-paste)"
else
url="$1"
fi
case "$url" in
*youtube.com/watch*)
mpv -quiet "$url"
echo "yes" ;;
*png|*jpg|*jpe|*jpeg|gif|webp)
curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" && pqiv -a "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" >/dev/null 2>&1 & ;;
*pdf|cbz|cbr)
curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.///;s/%20/ /g")" >/dev/null 2>&1 & ;;
*mp3|*flac|*opus|mp3?source)
qndl "$url" 'curl -LO' >/dev/null 2>&1 ;;
*)
[ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1
esac
# links
https://www.youtube.com/watch?v=4qTt4rc1vmE
https://www.youtube.com/watch?v=4xc4TERZR8w
https://www.youtube.com/watch?v=7NB1Auof7_8
# Command in both zsh and bash
urlscan -r "./launch.sh {}" links
Are you doing anything else different?
Okay so I'm almost there but not quite:
I think having you specify the command urlscan -r "./launch.sh {}" helped since I was just using the -r flag and then my script I also noticed that in my script I used "" as an escape character to add quotes in the $url variable which doesn't help.
So i'm able to get the following script to work
#!/bin/sh
if [ -z "$1" ]; then read -r url else url="$1" fi
echo $url setsid -f mpv -quiet "$url" >/dev/null 2>&1
however, when i make the adjustments into my original script with the case statements it doesn't quite work anymore.
I'll troubleshoot some more and see if I can find a solution but if you or anyone has any ideas, would appreciate the suggestions
hmmm actually I have no idea why, maybe there was some bug in my script but I tried it again and now it works! Thanks for your help, i think you providing the command syntax was the key!