aboutsummaryrefslogtreecommitdiff
path: root/src/x_command.sh
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-07-15 22:01:34 -0700
committerFuwn <[email protected]>2023-07-15 22:01:34 -0700
commit9c3068e61d4b4dd6543d793442dcda97f7a34a66 (patch)
tree2379b105e62dae97b481401291f5d5e98454d732 /src/x_command.sh
downloadkaguya-9c3068e61d4b4dd6543d793442dcda97f7a34a66.tar.xz
kaguya-9c3068e61d4b4dd6543d793442dcda97f7a34a66.zip
feat: initial release
Diffstat (limited to 'src/x_command.sh')
-rw-r--r--src/x_command.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/x_command.sh b/src/x_command.sh
new file mode 100644
index 0000000..4150cdb
--- /dev/null
+++ b/src/x_command.sh
@@ -0,0 +1,28 @@
+# Default to anime, permit manga
+if [ "${args[--manga]}" = 1 ]; then
+ TYPE="manga"
+else
+ TYPE="anime"
+fi
+
+TITLE=$(array_to_string "${args[title]}")
+
+# Obtain media IDs from AniList
+ID=$(curl 'https://graphql.anilist.co/' \
+ --silent \
+ --request POST \
+ --header 'Content-Type: application/json' \
+ --header 'Accept: application/json' \
+ --data "{ \"query\": \"{ Media(search: \\\"${TITLE}\\\", \
+ type: $(echo ${TYPE} | tr '[:lower:]' '[:upper:]')) { id idMal } }\" }")
+
+# Open the anime or manga in AniList by default, permit MyAnimeList
+if [ "${args[--mal]}" = 1 ]; then
+ xdg-open https://myanimelist.net/${TYPE}/"$(echo "${ID}" | jq '.data.Media.idMal')"
+else
+ if [ "${args[--social]}" = 1 ]; then
+ xdg-open https://anilist.co/${TYPE}/"$(echo "${ID}" | jq '.data.Media.id')"/social
+ else
+ xdg-open https://anilist.co/${TYPE}/"$(echo "${ID}" | jq '.data.Media.id')"
+ fi
+fi