Update {invid,yt}-conv.

This commit is contained in:
2026-03-11 16:22:36 +01:00
parent beb012d569
commit 3871339237
2 changed files with 99 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
# Copyright (C) 2025 Nicolás Ortega Froysa <nicolas@ortegas.org> All rights reserved.
# Author: Nicolás Ortega Froysa <nicolas@ortegas.org>
#
@@ -22,25 +24,64 @@
# 3. This notice may not be removed or altered from any source
# distribution.
YT_URL="$1"
INVID_BASE="${INVID_BASE:-https://inv.nadeko.net}"
CLIP=0
if [ $# -ne 1 ]
if [ $# -lt 1 ]
then
>&2 echo "Usage: $0 <url>"
>&2 echo "Usage: $0 [-c] <url>"
exit 1
elif [ "$1" = "-h" ]
then
echo "Usage: $0 <url>"
exit 0
fi
if [[ $YT_URL == *"youtu.be"* ]]
for arg in "$@"
do
case "$arg" in
-c|--clip)
CLIP=1
;;
-h|--help)
echo "Usage: $0 <url>"
exit 0
;;
*)
YT_URL="$arg"
;;
esac
done
if [ -z "${YT_URL:-}" ]
then
>&2 echo "No URL provided"
exit 1
elif [[ $YT_URL == *"youtu.be"* ]]
then
INVID_URL="${INVID_BASE}/watch?v=${YT_URL##*/}"
elif [[ $YT_URL == *"www.youtube.com"* ]]
then
INVID_URL="${INVID_BASE}/${YT_URL##*/}"
else
>&2 echo "Invalid URL: $YT_URL"
exit 1
fi
echo "$INVID_URL"
if [ $CLIP -eq 0 ]
then
echo "$INVID_URL"
else
if [ "$XDG_SESSION_TYPE" = "wayland" ]
then
if ! command -v wl-copy &> /dev/null
then
echo "wl-copy not found, cannot copy to clipboard"
exit 1
fi
echo "$INVID_URL" | wl-copy
else
if ! command -v xclip &> /dev/null
then
echo "xclip not found, cannot copy to clipboard"
exit 1
fi
echo "$INVID_URL" | xclip -sel clip
fi
fi

55
yt-conv
View File

@@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
# Copyright (C) 2025 Nicolás Ortega Froysa <nicolas@ortegas.org> All rights reserved.
# Author: Nicolás Ortega Froysa <nicolas@ortegas.org>
#
@@ -22,16 +24,57 @@
# 3. This notice may not be removed or altered from any source
# distribution.
CLIP=0
if [ $# -ne 1 ]
then
>&2 echo "Usage: $0 <url>"
exit 1
elif [ "$1" = "-h" ]
then
echo "Usage: $0 <url>"
exit 0
fi
URL="$1"
for arg in "$@"
do
case "$arg" in
-c|--clip)
CLIP=1
;;
-h|--help)
echo "Usage: $0 [-c] <url>"
exit 0
;;
*)
URL="$arg"
;;
esac
done
if [ -z "${URL:-}" ]
then
>&2 echo "No URL provided"
exit 1
fi
YT_URL="${URL//https:\/\/*\//https:\/\/www.youtube.com\/}"
echo "$YT_URL"
if [ $CLIP -eq 0 ]
then
echo "$YT_URL"
else
if [ "$XDG_SESSION_TYPE" = "wayland" ]
then
if ! command -v wl-copy &> /dev/null
then
>&2 echo "wl-copy not found, cannot copy to clipboard"
exit 1
fi
echo "$YT_URL" | wl-copy
else
if ! command -v xclip &> /dev/null
then
>&2 echo "xclip not found, cannot copy to clipboard"
exit 1
fi
echo "$YT_URL" | xclip -sel clip
fi
fi