diff options
| author | Fuwn <[email protected]> | 2023-07-15 22:01:34 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-07-15 22:01:34 -0700 |
| commit | 9c3068e61d4b4dd6543d793442dcda97f7a34a66 (patch) | |
| tree | 2379b105e62dae97b481401291f5d5e98454d732 /src/x_command.sh | |
| download | kaguya-9c3068e61d4b4dd6543d793442dcda97f7a34a66.tar.xz kaguya-9c3068e61d4b4dd6543d793442dcda97f7a34a66.zip | |
feat: initial release
Diffstat (limited to 'src/x_command.sh')
| -rw-r--r-- | src/x_command.sh | 28 |
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 |