aboutsummaryrefslogtreecommitdiff
path: root/src/x_command.sh
blob: 25d162201128607cb4e851289a1e9ce725f9a41a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Default to anime, permit manga
if [ "${args[--manga]}" = 1 ]; then
	FORMAT="manga"
	TYPE="manga"
	FILTER="format"
elif [ "${args[--novel]}" = 1 ]; then
	FORMAT="novel"
	TYPE="manga"
	FILTER="format"
elif [ "${args['--any-manga']}" = 1 ]; then
	FORMAT="manga"
	TYPE="manga"
	FILTER="type"
else
	FORMAT="tv"
	TYPE="anime"
	FILTER="format"
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}\\\", \
    ${FILTER}: $(echo ${FORMAT} | 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