add igdb script
This commit is contained in:
parent
549983ce29
commit
5f7c881d96
3 changed files with 44 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
.obsidian/wokspace.json
|
||||
.obsidian/wokspace-mobile.json
|
||||
.obsidian/wokspace-mobile.json
|
||||
.env
|
||||
|
|
|
|||
4
.obsidian/workspace.json
vendored
4
.obsidian/workspace.json
vendored
|
|
@ -158,8 +158,9 @@
|
|||
"dbfolder:Create a new database table": false
|
||||
}
|
||||
},
|
||||
"active": "772303a551e0940a",
|
||||
"active": "230c77af3893ffdd",
|
||||
"lastOpenFiles": [
|
||||
"igdb",
|
||||
"games/Castlevania symphony of the Night.md",
|
||||
"projects/games.md",
|
||||
"games/the-elder-scrolls-v-skyrim.md",
|
||||
|
|
@ -186,7 +187,6 @@
|
|||
"projects/todos-notes/Improve dev tools.md",
|
||||
"projects/todos-notes/Improve VPN setup.md",
|
||||
"projects/todos-notes/Setup notification services.md",
|
||||
"projects/todos-notes/Rewrite neovim config.md",
|
||||
"projects/homelab-notes/Untitled",
|
||||
"projects/todos-notes",
|
||||
"notes/utils",
|
||||
|
|
|
|||
40
.utils/igdb.sh
Executable file
40
.utils/igdb.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
query="$*"
|
||||
shift
|
||||
|
||||
set -e pipefile
|
||||
|
||||
if [[ -z "$query" ]]; then
|
||||
echo "No query provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "$(git rev-parse --show-toplevel)/.env"
|
||||
|
||||
# login
|
||||
if [[ -e /tmp/igdb-login.json ]]; then
|
||||
token=$(jq -r '.access_token' /tmp/igdb-login.json)
|
||||
else
|
||||
login_url="https://id.twitch.tv/oauth2/token?client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials"
|
||||
token=$(curl -s -X POST "$login_url" | tee /tmp/igdb-login.json | jq -r '.access_token')
|
||||
fi
|
||||
|
||||
if [[ "$token" == "null" ]]; then
|
||||
echo "Couldn't fetch token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fields="name, parent_game.name, franchises.name, franchises.slug, genres.name, platforms.name, release_dates.human"
|
||||
limit=50
|
||||
|
||||
preview=".[{n}] | del(.id) | walk(if type == \"array\" then map((.name // .human)?) else . end )"
|
||||
# preview=".[{n}]"
|
||||
|
||||
curl -s 'https://api.igdb.com/v4/games' \
|
||||
-H "Client-ID: $CLIENT_ID" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-H 'Accept: application/json' \
|
||||
-d "search \"$query\"; fields $fields; where category = (0, 8, 9, 11, 13); limit $limit;" | tee /tmp/igdb-query.json |
|
||||
jq -r '.[].name' |
|
||||
fzf --preview "jq --sort-keys --color-output '$preview' /tmp/igdb-query.json"
|
||||
Loading…
Add table
Add a link
Reference in a new issue