diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-15 03:00:25 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-15 03:00:25 +0200 |
commit | 4914b43f642e2772a140a8f9b1f26b4e555ed88b (patch) | |
tree | fa665e469f8daa1f150d13411d0f8537a93e5355 /bin/common | |
parent | ad05cb18f03f3a97a918e090c38ba760147a0bb6 (diff) | |
parent | 2a9d0908651ac236855fa515e14a83bada3ad7f9 (diff) |
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin/common')
-rwxr-xr-x | bin/common/ytlink | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/bin/common/ytlink b/bin/common/ytlink index 48be9cf..215c164 100755 --- a/bin/common/ytlink +++ b/bin/common/ytlink @@ -2,15 +2,21 @@ # convert to youtube.com/path url # works for: -# - 'youtu.be/watch?v=xxxxxx' +# - 'youtu.be/xxxxxx' # - 'https://piped.video/watch?v=xxxxx' +# - https://youtube.com/watch?v=xxxx -inp="$1" -[ "${inp:=$(clipo)}" ] || inp="$(cat /dev/stdin)" +# get from $1 or clipboard if empty +vid="${1:-$(clipo)}" +# The following subsitutions will try to grab the video id # if link is http://127.0.0.1:9010/https://www.youtube.com/watch?v=7KpxsqwNF0o -inp="${inp#*/https://}" +vid="${vid#*/https://}" # remove util scheme -inp="${inp#*//}" -inp="https://youtube.com/${inp#*/}" -printf "%s" "$inp" +vid="${vid#*//}" +# remove domain +vid="${vid#*/}" +# remove query string +vid="${vid#watch?v=}" + +printf "https://youtube.com/watch?v=%s\n" "$vid" |