diff options
| author | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-06-02 06:08:21 +0500 |
|---|---|---|
| committer | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-06-02 06:08:21 +0500 |
| commit | a3474e2b7ef1005675bede0494c31b9a8b809f39 (patch) | |
| tree | de95470e53b12bf186663ef047e481752a92fdc5 | |
| parent | 98e3f4749f319be42dc2c519ada73fa3ef751ada (diff) | |
bot: Move Image Board configuration and authorization out
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
| -rw-r--r-- | auth/donmai.zsh | 59 | ||||
| -rw-r--r-- | auth/gelbooru.zsh | 7 | ||||
| -rw-r--r-- | auth/idolcomplex.zsh | 124 | ||||
| -rw-r--r-- | auth/moebooru.zsh | 40 | ||||
| -rw-r--r-- | auth/sankakuchannel.zsh | 55 | ||||
| -rwxr-xr-x | bot.zsh | 1 | ||||
| -rw-r--r-- | config/donmai.zsh | 84 | ||||
| -rw-r--r-- | config/donmai_auth.zsh | 18 | ||||
| -rw-r--r-- | config/gelbooru.zsh | 71 | ||||
| -rw-r--r-- | config/gelbooru_auth.zsh | 9 | ||||
| -rw-r--r-- | config/idolcomplex.zsh | 76 | ||||
| -rw-r--r-- | config/idolcomplex_auth.zsh | 11 | ||||
| -rw-r--r-- | config/moebooru.zsh | 77 | ||||
| -rw-r--r-- | config/moebooru_auth.zsh | 17 | ||||
| -rw-r--r-- | config/sankakuchannel.zsh | 72 | ||||
| -rw-r--r-- | config/sankakuchannel_auth.zsh | 11 | ||||
| -rw-r--r-- | units/ib_auth.zsh | 277 | ||||
| -rw-r--r-- | units/ib_authconfig.zsh | 51 | ||||
| -rw-r--r-- | units/ib_config.zsh | 365 |
19 files changed, 753 insertions, 672 deletions
diff --git a/auth/donmai.zsh b/auth/donmai.zsh new file mode 100644 index 0000000..8bc04a8 --- /dev/null +++ b/auth/donmai.zsh @@ -0,0 +1,59 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth_file="${cache}/${update_id}_profile.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user "${ib_login}:${ib_key}" \ + --user-agent "${useragent}" \ + "${ib_auth}/profile.json" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.success' "${ib_auth_file}")" = "false" ]] +then + output_text="Error: <code>$(jq -r '.message' "${ib_auth_file}" | htmlescape)</code>" + log_text="ib_auth (${update_id}): Error: $(jq -r '.message' "${ib_auth_file}")" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]] +then + output_text="Failed to verify user authorization" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +printf "%s" "${ib_login}:${ib_key}" | base64 > "${token_file}" diff --git a/auth/gelbooru.zsh b/auth/gelbooru.zsh new file mode 100644 index 0000000..8adb436 --- /dev/null +++ b/auth/gelbooru.zsh @@ -0,0 +1,7 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +printf '%s="%s"\n%s="%s"\n' \ + "ib_dfield5" "user_id=${ib_login}" \ + "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" diff --git a/auth/idolcomplex.zsh b/auth/idolcomplex.zsh new file mode 100644 index 0000000..3112514 --- /dev/null +++ b/auth/idolcomplex.zsh @@ -0,0 +1,124 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_cookies="${cookies_file}" +ib_auth_file="${cache}/${update_id}_login.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie-jar "${ib_cookies}" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/users/login" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_action="$(xq -a "action" -q "form" "${ib_auth_file}")" +ib_token="$(xq -a "value" -q "form>input[name=authenticity_token]" "${ib_auth_file}")" + +if [[ -z "${ib_action}" || -z "${ib_token}" ]] +then + output_text="Failed to get authorization data" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_auth_file="${cache}/${update_id}_authenticate.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie "${ib_cookies}" \ + --cookie-jar "${ib_cookies}" \ + --data-urlencode "authenticity_token=${ib_token}" \ + --data-urlencode "user[name]=${ib_login}" \ + --data-urlencode "user[password]=${ib_key}" \ + --data-urlencode "commit=Login" \ + --header "Referer: ${ib_auth}/users/login" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request POST \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}${ib_action}" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ -s "${ib_auth_file}" ]] +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_auth_file="${cache}/${update_id}_home.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie "${ib_cookies}" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/users/home" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_notice="$(xq -q "div[id=notice]" "${ib_auth_file}")" + +if [[ -n "${ib_notice}" && "${ib_notice}" != "You are now logged in" ]] +then + output_text="$(printf "%s" "${ib_notice}" | htmlescape)" + log_text="ib_auth (${update_id}): ${ib_notice}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ -z "${ib_notice}" ]] +then + output_text="Failed to verify user authorization" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +strftime %s > "${timestamp_file}" diff --git a/auth/moebooru.zsh b/auth/moebooru.zsh new file mode 100644 index 0000000..c3a893d --- /dev/null +++ b/auth/moebooru.zsh @@ -0,0 +1,40 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth_file="${cache}/${update_id}_user.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --data-urlencode "username=${ib_login}" \ + --data-urlencode "api_key=${ib_key}" \ + --get \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/user.json" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="Invalid username or API key" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +printf '%s="%s"\n%s="%s"\n' \ + "ib_dfield5" "username=${ib_login}" \ + "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" diff --git a/auth/sankakuchannel.zsh b/auth/sankakuchannel.zsh new file mode 100644 index 0000000..86f076a --- /dev/null +++ b/auth/sankakuchannel.zsh @@ -0,0 +1,55 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_login_data="$(jq --null-input --compact-output \ + --arg login "${ib_login}" \ + --arg password "${ib_key}" \ + '{"login": $login, "password": $password}')" + +ib_auth_file="${cache}/${update_id}_token.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --data "${ib_login_data}" \ + --header "Content-Type: application/json" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request POST \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/auth/token" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]] +then + output_text="Error: <code>$(jq -r '.error' "${ib_auth_file}" | htmlescape)</code>" + log_text="ib_auth (${update_id}): Error: $(jq -r '.error' "${ib_auth_file}")" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +jq -r '.access_token' "${ib_auth_file}" > "${token_file}" +strftime %s > "${timestamp_file}" @@ -17,6 +17,7 @@ local_address="127.0.0.1:8081" default_address="https://api.telegram.org" dir="${0%/*}" +auth="${dir}/auth" cache="${dir}/cache/${$}" config="${dir}/config" dumps="${dir}/dumps/${$}" diff --git a/config/donmai.zsh b/config/donmai.zsh new file mode 100644 index 0000000..eeba644 --- /dev/null +++ b/config/donmai.zsh @@ -0,0 +1,84 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +case "${ib_board}" in + (a) + ib_name="Safebooru" + ib_config="safebooru" + ib_api="https://safebooru.donmai.us" + ib_url="https://safebooru.donmai.us" + ;; + (d) + ib_name="Danbooru" + ib_config="danbooru" + ib_api="https://danbooru.donmai.us" + ib_url="https://danbooru.donmai.us" + ;; +esac + +ib_ratings=( + g general + s sensitive + q questionable + e explicit +) + +ib_groups=( + tag_string_artist Artist + tag_string_copyright Copyright + tag_string_character Character + tag_string_general General + tag_string_meta Meta +) + +case "${ib_mode}" in + (l) + ib_data_url="${ib_api}/pools.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="search[name_matches]" + ib_iid="id" + ib_icreated="created_at" + ib_ipool="name" + ib_icount="post_count" + ib_idate="%Y-%m-%dT%X" + ib_ispace="_" + ib_iorder="order:created_at_asc" + ib_url="${ib_url}/pools/" + ;; + (p) + ib_data_url="${ib_api}/posts.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="tags" + ib_iid="id" + ib_icreated="created_at" + ib_isize="file_size" + ib_ifile="file_url" + ib_isample="large_file_url" + ib_ipreview="preview_file_url" + ib_iwidth="image_width" + ib_iheight="image_height" + ib_irating="rating" + ib_iparent="parent_id" + ib_ichildren="has_children" + ib_imd5="md5" + ib_isource="source" + ib_itags="tag_string" + ib_idate="%Y-%m-%dT%X" + ib_ifilename="cut -d '/' -f 7" + ib_url="${ib_url}/posts/" + ;; + (t) + ib_data_url="${ib_api}/tags.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="search[name_matches]" + ib_iid="id" + ib_itag="name" + ib_icount="post_count" + ib_irecode="HTML" + ib_url="${ib_url}/wiki_pages/" + ;; +esac diff --git a/config/donmai_auth.zsh b/config/donmai_auth.zsh new file mode 100644 index 0000000..dfd3581 --- /dev/null +++ b/config/donmai_auth.zsh @@ -0,0 +1,18 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +case "${ib_board}" in + (a) + ib_auth="https://safebooru.donmai.us" + ;; + (d) + ib_auth="https://danbooru.donmai.us" + ;; +esac + +ib_header="Authorization: Baisc" +ib_login_file="login" +ib_key_file="api_key" +ib_login_word="login" +ib_key_word="API key" diff --git a/config/gelbooru.zsh b/config/gelbooru.zsh new file mode 100644 index 0000000..87eb035 --- /dev/null +++ b/config/gelbooru.zsh @@ -0,0 +1,71 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_name="Gelbooru" +ib_config="gelbooru" +ib_api="https://gelbooru.com" +ib_url="https://gelbooru.com" + +ib_ratings=( + safe safe + general general + sensitive sensitive + questionable questionable + explicit explicit +) + +ib_groups=( + tags Tags +) + +case "${ib_mode}" in + (p) + ib_data_url="${ib_api}/index.php" + ib_dfield1="page=dapi" + ib_dfield2="s=post" + ib_dfield3="q=index" + ib_dfield4="json=1" + ib_dlimit="limit" + ib_dpage="pid" + ib_dquery="tags" + ib_iarray="post" + ib_iid="id" + ib_icreated="created_at" + ib_isize="deprecated" + ib_ifile="file_url" + ib_isample="sample_url" + ib_ipreview="preview_url" + ib_iwidth="width" + ib_iheight="height" + ib_irating="rating" + ib_iparent="parent_id" + ib_ichildren="has_children" + ib_imd5="md5" + ib_isource="source" + ib_itags="tags" + ib_ioffset=-1 + ib_itzfield="-4,6-" + ib_idate="%a %b %d %X %Y" + ib_ifilename="cut -d '/' -f 7" + ib_url="${ib_url}/index.php?page=post&s=view&id=" + ;; + (t) + ib_data_url="${ib_api}/index.php" + ib_dfield1="page=dapi" + ib_dfield2="s=tag" + ib_dfield3="q=index" + ib_dfield4="json=1" + ib_dlimit="limit" + ib_dpage="pid" + ib_dquery="name_pattern" + ib_iarray="tag" + ib_iid="id" + ib_itag="name" + ib_icount="count" + ib_iwildcard="%" + ib_ioffset=-1 + ib_irecode="HTML" + ib_url="${ib_url}/index.php?page=wiki&s=list&search=" + ;; +esac diff --git a/config/gelbooru_auth.zsh b/config/gelbooru_auth.zsh new file mode 100644 index 0000000..9638211 --- /dev/null +++ b/config/gelbooru_auth.zsh @@ -0,0 +1,9 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth=0 +ib_login_file="user_id" +ib_key_file="api_key" +ib_login_word="user ID" +ib_key_word="API key" diff --git a/config/idolcomplex.zsh b/config/idolcomplex.zsh new file mode 100644 index 0000000..bd283c7 --- /dev/null +++ b/config/idolcomplex.zsh @@ -0,0 +1,76 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_name="Idol Complex" +ib_config="idolcomplex" +ib_api="https://idol.sankakucomplex.com" +ib_url="https://idol.sankakucomplex.com" + +ib_ratings=( + s safe + q questionable + e explicit +) + +ib_groups=( + "tags[]|select(.type==1)|.name" Idol + "tags[]|select(.type==2)|.name" Studio + "tags[]|select(.type==3)|.name" Copyright + "tags[]|select(.type==4)|.name" Character + "tags[]|select(.type==6)|.name" Genre + "tags[]|select(.type==5)|.name" Set + "tags[]|select(.type==0)|.name" General + "tags[]|select(.type==8)|.name" Medium + "tags[]|select(.type==9)|.name" Meta +) + +case "${ib_mode}" in + (l) + ib_data_url="${ib_api}/pools.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="name" + ib_iid="id" + ib_icreated="created_at" + ib_ipool="name" + ib_icount="post_count" + ib_idate="%Y-%m-%d %H:%M" + ib_ispace="_" + ib_url="${ib_url}/pools/" + ;; + (p) + ib_data_url="${ib_api}/posts.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="tags" + ib_iid="id" + ib_icreated="created_at" + ib_isize="file_size" + ib_ifile="file_url" + ib_isample="sample_url" + ib_ipreview="preview_url" + ib_iwidth="width" + ib_iheight="height" + ib_irating="rating" + ib_iparent="parent_id" + ib_ichildren="has_children" + ib_imd5="md5" + ib_isource="deprecated" + ib_itags="tags[].name" + ib_idate="%Y-%m-%dT%X" + ib_ifilename="cut -d '?' -f 1 | cut -d '/' -f 7" + ib_url="${ib_url}/posts/" + ;; + (t) + ib_data_url="${ib_api}/tags.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="name" + ib_iid="id" + ib_itag="name" + ib_icount="count" + ib_irecode="UTF-8" + ib_url="${ib_url}/wiki/" + ;; +esac diff --git a/config/idolcomplex_auth.zsh b/config/idolcomplex_auth.zsh new file mode 100644 index 0000000..c4a89cb --- /dev/null +++ b/config/idolcomplex_auth.zsh @@ -0,0 +1,11 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth="https://idol.sankakucomplex.com" +ib_cookie="_idolcomplex_session" +ib_expire=86400 +ib_login_file="username" +ib_key_file="password" +ib_login_word="email or username" +ib_key_word="password" diff --git a/config/moebooru.zsh b/config/moebooru.zsh new file mode 100644 index 0000000..5aed454 --- /dev/null +++ b/config/moebooru.zsh @@ -0,0 +1,77 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +case "${ib_board}" in + (k) + ib_name="Konachan.com" + ib_config="konachan" + ib_api="https://konachan.com" + ib_url="https://konachan.com" + ;; + (y) + ib_name="yande.re" + ib_config="yandere" + ib_api="https://yande.re" + ib_url="https://yande.re" + ;; +esac + +ib_ratings=( + s safe + q questionable + e explicit +) + +ib_groups=( + tags Tags +) + +case "${ib_mode}" in + (l) + ib_data_url="${ib_api}/pool.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="query" + ib_iid="id" + ib_icreated="created_at" + ib_ipool="name" + ib_icount="post_count" + ib_idate="%Y-%m-%dT%X" + ib_ispace="_" + ib_url="${ib_url}/pool/show/" + ;; + (p) + ib_data_url="${ib_api}/post.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="tags" + ib_iid="id" + ib_icreated="created_at" + ib_isize="file_size" + ib_ifile="file_url" + ib_isample="sample_url" + ib_ipreview="preview_url" + ib_iwidth="width" + ib_iheight="height" + ib_irating="rating" + ib_iparent="parent_id" + ib_ichildren="has_children" + ib_imd5="md5" + ib_isource="source" + ib_itags="tags" + ib_ifilename="sed 's/\/${ib_name}.*\./\./' | cut -d '/' -f 5" + ib_url="${ib_url}/post/show/" + ;; + (t) + ib_data_url="${ib_api}/tag.json" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="name" + ib_iid="id" + ib_itag="name" + ib_icount="count" + ib_irecode="UTF-8" + ib_url="${ib_url}/wiki/show?title=" + ;; +esac diff --git a/config/moebooru_auth.zsh b/config/moebooru_auth.zsh new file mode 100644 index 0000000..b1e70e9 --- /dev/null +++ b/config/moebooru_auth.zsh @@ -0,0 +1,17 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +case "${ib_board}" in + (k) + ib_auth="https://konachan.com" + ;; + (y) + ib_auth="https://yande.re" + ;; +esac + +ib_login_file="username" +ib_key_file="api_key" +ib_login_word="username" +ib_key_word="API key" diff --git a/config/sankakuchannel.zsh b/config/sankakuchannel.zsh new file mode 100644 index 0000000..c3a621a --- /dev/null +++ b/config/sankakuchannel.zsh @@ -0,0 +1,72 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_name="Sankaku Channel" +ib_config="sankakuchannel" +ib_api="https://sankakuapi.com" +ib_url="https://chan.sankakucomplex.com" + +ib_ratings=( + s safe + q questionable + e explicit +) + +ib_groups=( + "tags[]|select(.type==1)|.tagName" Artist + "tags[]|select(.type==2)|.tagName" Studio + "tags[]|select(.type==3)|.tagName" Copyright + "tags[]|select(.type==4)|.tagName" Character + "tags[]|select(.type==5)|.tagName" Genre + "tags[]|select(.type==0)|.tagName" General + "tags[]|select(.type==8)|.tagName" Medium + "tags[]|select(.type==9)|.tagName" Meta +) + +case "${ib_mode}" in + (l) + ib_data_url="${ib_api}/pools" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="name" + ib_iid="id" + ib_icreated="created_at" + ib_ipool="name" + ib_icount="post_count" + ib_idate="%Y-%m-%d %H:%M" + ib_url="${ib_url}/pools/" + ;; + (p) + ib_data_url="${ib_api}/posts" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="tags" + ib_iid="id" + ib_icreated="created_at.s" + ib_isize="file_size" + ib_ifile="file_url" + ib_isample="sample_url" + ib_ipreview="preview_url" + ib_iwidth="width" + ib_iheight="height" + ib_irating="rating" + ib_iparent="parent_id" + ib_ichildren="has_children" + ib_imd5="md5" + ib_isource="deprecated" + ib_itags="tags[].tagName" + ib_ifilename="cut -d '?' -f 1 | cut -d '/' -f 7" + ib_url="${ib_url}/posts/" + ;; + (t) + ib_data_url="${ib_api}/tags" + ib_dlimit="limit" + ib_dpage="page" + ib_dquery="name" + ib_iid="id" + ib_itag="tagName" + ib_icount="post_count" + ib_url="${ib_url}/wiki/" + ;; +esac diff --git a/config/sankakuchannel_auth.zsh b/config/sankakuchannel_auth.zsh new file mode 100644 index 0000000..196538f --- /dev/null +++ b/config/sankakuchannel_auth.zsh @@ -0,0 +1,11 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth="https://sankakuapi.com" +ib_header="Authorization: Bearer" +ib_expire=86400 +ib_login_file="login" +ib_key_file="password" +ib_login_word="login" +ib_key_word="password" diff --git a/units/ib_auth.zsh b/units/ib_auth.zsh index 6a70167..4c81a93 100644 --- a/units/ib_auth.zsh +++ b/units/ib_auth.zsh @@ -34,282 +34,27 @@ then fi case "${ib_board}" in - (d) - ib_auth_file="${cache}/${update_id}_profile.json" - dump+=(${ib_auth_file##*/}) - - if ! curl --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request GET \ - --silent \ - --user "${ib_login}:${ib_key}" \ - --user-agent "${useragent}" \ - "${ib_auth}/profile.json" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if ! jq -e '.' "${ib_auth_file}" > /dev/null - then - output_text="An unknown error occurred" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if [[ "$(jq -r '.success' "${ib_auth_file}")" = "false" ]] - then - output_text="Error: <code>$(jq -r '.message' "${ib_auth_file}" | htmlescape)</code>" - log_text="ib_auth (${update_id}): Error: $(jq -r '.message' "${ib_auth_file}")" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if [[ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]] - then - output_text="Failed to verify user authorization" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - printf "%s" "${ib_login}:${ib_key}" | base64 > "${token_file}" + (a|d) + . "${auth}/donmai.zsh" ;; (g) - printf '%s="%s"\n%s="%s"\n' \ - "ib_dfield5" "user_id=${ib_login}" \ - "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" + . "${auth}/gelbooru.zsh" ;; (i) - ib_cookies="${cookies_file}" - ib_auth_file="${cache}/${update_id}_login.html" - dump+=(${ib_auth_file##*/}) - - if ! curl --cookie-jar "${ib_cookies}" \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request GET \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/users/login" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - ib_action="$(xq -a "action" -q "form" "${ib_auth_file}")" - ib_token="$(xq -a "value" -q "form>input[name=authenticity_token]" "${ib_auth_file}")" - - if [[ -z "${ib_action}" || -z "${ib_token}" ]] - then - output_text="Failed to get authorization data" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - ib_auth_file="${cache}/${update_id}_authenticate.html" - dump+=(${ib_auth_file##*/}) - - if ! curl --cookie "${ib_cookies}" \ - --cookie-jar "${ib_cookies}" \ - --data-urlencode "authenticity_token=${ib_token}" \ - --data-urlencode "user[name]=${ib_login}" \ - --data-urlencode "user[password]=${ib_key}" \ - --data-urlencode "commit=Login" \ - --header "Referer: ${ib_auth}/users/login" \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request POST \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}${ib_action}" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if [[ -s "${ib_auth_file}" ]] - then - output_text="An unknown error occurred" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - ib_auth_file="${cache}/${update_id}_home.html" - dump+=(${ib_auth_file##*/}) - - if ! curl --cookie "${ib_cookies}" \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request GET \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/users/home" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - ib_notice="$(xq -q "div[id=notice]" "${ib_auth_file}")" - - if [[ -n "${ib_notice}" && "${ib_notice}" != "You are now logged in" ]] - then - output_text="$(printf "%s" "${ib_notice}" | htmlescape)" - log_text="ib_auth (${update_id}): ${ib_notice}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if [[ -z "${ib_notice}" ]] - then - output_text="Failed to verify user authorization" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - strftime %s > "${timestamp_file}" + . "${auth}/idolcomplex.zsh" ;; (s) - ib_login_data="$(jq --null-input --compact-output \ - --arg login "${ib_login}" \ - --arg password "${ib_key}" \ - '{"login": $login, "password": $password}')" - - ib_auth_file="${cache}/${update_id}_token.json" - dump+=(${ib_auth_file##*/}) - - if ! curl --data "${ib_login_data}" \ - --header "Content-Type: application/json" \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --request POST \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/auth/token" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if ! jq -e '.' "${ib_auth_file}" > /dev/null - then - output_text="An unknown error occurred" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if [[ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]] - then - output_text="Error: <code>$(jq -r '.error' "${ib_auth_file}" | htmlescape)</code>" - log_text="ib_auth (${update_id}): Error: $(jq -r '.error' "${ib_auth_file}")" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - jq -r '.access_token' "${ib_auth_file}" > "${token_file}" - strftime %s > "${timestamp_file}" + . "${auth}/sankakuchannel.zsh" ;; (k|y) - ib_auth_file="${cache}/${update_id}_user.json" - dump+=(${ib_auth_file##*/}) - - if ! curl --data-urlencode "username=${ib_login}" \ - --data-urlencode "api_key=${ib_key}" \ - --get \ - --max-time ${external_timeout} \ - --output "${ib_auth_file}" \ - --proxy "${external_proxy}" \ - --silent \ - --user-agent "${useragent}" \ - "${ib_auth}/user.json" - then - output_text="Failed to access ${ib_name} API" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - if ! jq -e '.' "${ib_auth_file}" > /dev/null - then - output_text="Invalid username or API key" - log_text="ib_auth (${update_id}): ${output_text}" - - . "${units}/log.zsh" - . "${units}/dump.zsh" - - return 0 - fi - - printf '%s="%s"\n%s="%s"\n' \ - "ib_dfield5" "username=${ib_login}" \ - "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" + . "${auth}/moebooru.zsh" ;; esac +if [[ -n "${output_text}" ]] +then + return 0 +fi + printf "%s\n" "${ib_login}" > "${login_file}" printf "%s\n" "${ib_key}" > "${key_file}" diff --git a/units/ib_authconfig.zsh b/units/ib_authconfig.zsh index f6b57cd..1edb6cf 100644 --- a/units/ib_authconfig.zsh +++ b/units/ib_authconfig.zsh @@ -9,59 +9,18 @@ token_file="${user_config}/${ib_config}/token" case "${ib_board}" in (a|d) - case "${ib_board}" in - (a) - ib_auth="https://safebooru.donmai.us" - ;; - (d) - ib_auth="https://danbooru.donmai.us" - ;; - esac - - ib_header="Authorization: Baisc" - ib_login_file="login" - ib_key_file="api_key" - ib_login_word="login" - ib_key_word="API key" + . "${config}/donmai_auth.zsh" ;; (g) - ib_auth=0 - ib_login_file="user_id" - ib_key_file="api_key" - ib_login_word="user ID" - ib_key_word="API key" + . "${config}/gelbooru_auth.zsh" ;; (i) - ib_auth="https://idol.sankakucomplex.com" - ib_cookie="_idolcomplex_session" - ib_expire=86400 - ib_login_file="username" - ib_key_file="password" - ib_login_word="email or username" - ib_key_word="password" + . "${config}/idolcomplex_auth.zsh" ;; (s) - ib_auth="https://sankakuapi.com" - ib_header="Authorization: Bearer" - ib_expire=86400 - ib_login_file="login" - ib_key_file="password" - ib_login_word="login" - ib_key_word="password" + . "${config}/sankakuchannel_auth.zsh" ;; (k|y) - case "${ib_board}" in - (k) - ib_auth="https://konachan.com" - ;; - (y) - ib_auth="https://yande.re" - ;; - esac - - ib_login_file="username" - ib_key_file="api_key" - ib_login_word="username" - ib_key_word="API key" + . "${config}/moebooru_auth.zsh" ;; esac diff --git a/units/ib_config.zsh b/units/ib_config.zsh index 80b3c17..c99a6c8 100644 --- a/units/ib_config.zsh +++ b/units/ib_config.zsh @@ -8,373 +8,18 @@ ib_error_height=516 case "${ib_board}" in (a|d) - case "${ib_board}" in - (a) - ib_name="Safebooru" - ib_config="safebooru" - ib_api="https://safebooru.donmai.us" - ib_url="https://safebooru.donmai.us" - ;; - (d) - ib_name="Danbooru" - ib_config="danbooru" - ib_api="https://danbooru.donmai.us" - ib_url="https://danbooru.donmai.us" - ;; - esac - - ib_ratings=( - g general - s sensitive - q questionable - e explicit - ) - - ib_groups=( - tag_string_artist Artist - tag_string_copyright Copyright - tag_string_character Character - tag_string_general General - tag_string_meta Meta - ) - - case "${ib_mode}" in - (l) - ib_data_url="${ib_api}/pools.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="search[name_matches]" - ib_iid="id" - ib_icreated="created_at" - ib_ipool="name" - ib_icount="post_count" - ib_idate="%Y-%m-%dT%X" - ib_ispace="_" - ib_iorder="order:created_at_asc" - ib_url="${ib_url}/pools/" - ;; - (p) - ib_data_url="${ib_api}/posts.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="tags" - ib_iid="id" - ib_icreated="created_at" - ib_isize="file_size" - ib_ifile="file_url" - ib_isample="large_file_url" - ib_ipreview="preview_file_url" - ib_iwidth="image_width" - ib_iheight="image_height" - ib_irating="rating" - ib_iparent="parent_id" - ib_ichildren="has_children" - ib_imd5="md5" - ib_isource="source" - ib_itags="tag_string" - ib_idate="%Y-%m-%dT%X" - ib_ifilename="cut -d '/' -f 7" - ib_url="${ib_url}/posts/" - ;; - (t) - ib_data_url="${ib_api}/tags.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="search[name_matches]" - ib_iid="id" - ib_itag="name" - ib_icount="post_count" - ib_irecode="HTML" - ib_url="${ib_url}/wiki_pages/" - ;; - esac + . "${config}/donmai.zsh" ;; (g) - ib_name="Gelbooru" - ib_config="gelbooru" - ib_api="https://gelbooru.com" - ib_url="https://gelbooru.com" - - ib_ratings=( - safe safe - general general - sensitive sensitive - questionable questionable - explicit explicit - ) - - ib_groups=( - tags Tags - ) - - case "${ib_mode}" in - (p) - ib_data_url="${ib_api}/index.php" - ib_dfield1="page=dapi" - ib_dfield2="s=post" - ib_dfield3="q=index" - ib_dfield4="json=1" - ib_dlimit="limit" - ib_dpage="pid" - ib_dquery="tags" - ib_iarray="post" - ib_iid="id" - ib_icreated="created_at" - ib_isize="deprecated" - ib_ifile="file_url" - ib_isample="sample_url" - ib_ipreview="preview_url" - ib_iwidth="width" - ib_iheight="height" - ib_irating="rating" - ib_iparent="parent_id" - ib_ichildren="has_children" - ib_imd5="md5" - ib_isource="source" - ib_itags="tags" - ib_ioffset=-1 - ib_itzfield="-4,6-" - ib_idate="%a %b %d %X %Y" - ib_ifilename="cut -d '/' -f 7" - ib_url="${ib_url}/index.php?page=post&s=view&id=" - ;; - (t) - ib_data_url="${ib_api}/index.php" - ib_dfield1="page=dapi" - ib_dfield2="s=tag" - ib_dfield3="q=index" - ib_dfield4="json=1" - ib_dlimit="limit" - ib_dpage="pid" - ib_dquery="name_pattern" - ib_iarray="tag" - ib_iid="id" - ib_itag="name" - ib_icount="count" - ib_iwildcard="%" - ib_ioffset=-1 - ib_irecode="HTML" - ib_url="${ib_url}/index.php?page=wiki&s=list&search=" - ;; - esac + . "${config}/gelbooru.zsh" ;; (i) - ib_name="Idol Complex" - ib_config="idolcomplex" - ib_api="https://idol.sankakucomplex.com" - ib_url="https://idol.sankakucomplex.com" - - ib_ratings=( - s safe - q questionable - e explicit - ) - - ib_groups=( - "tags[]|select(.type==1)|.name" Idol - "tags[]|select(.type==2)|.name" Studio - "tags[]|select(.type==3)|.name" Copyright - "tags[]|select(.type==4)|.name" Character - "tags[]|select(.type==6)|.name" Genre - "tags[]|select(.type==5)|.name" Set - "tags[]|select(.type==0)|.name" General - "tags[]|select(.type==8)|.name" Medium - "tags[]|select(.type==9)|.name" Meta - ) - - case "${ib_mode}" in - (l) - ib_data_url="${ib_api}/pools.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="name" - ib_iid="id" - ib_icreated="created_at" - ib_ipool="name" - ib_icount="post_count" - ib_idate="%Y-%m-%d %H:%M" - ib_ispace="_" - ib_url="${ib_url}/pools/" - ;; - (p) - ib_data_url="${ib_api}/posts.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="tags" - ib_iid="id" - ib_icreated="created_at" - ib_isize="file_size" - ib_ifile="file_url" - ib_isample="sample_url" - ib_ipreview="preview_url" - ib_iwidth="width" - ib_iheight="height" - ib_irating="rating" - ib_iparent="parent_id" - ib_ichildren="has_children" - ib_imd5="md5" - ib_isource="deprecated" - ib_itags="tags[].name" - ib_idate="%Y-%m-%dT%X" - ib_ifilename="cut -d '?' -f 1 | cut -d '/' -f 7" - ib_url="${ib_url}/posts/" - ;; - (t) - ib_data_url="${ib_api}/tags.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="name" - ib_iid="id" - ib_itag="name" - ib_icount="count" - ib_irecode="UTF-8" - ib_url="${ib_url}/wiki/" - ;; - esac + . "${config}/idolcomplex.zsh" ;; (s) - ib_name="Sankaku Channel" - ib_config="sankakuchannel" - ib_api="https://sankakuapi.com" - ib_url="https://chan.sankakucomplex.com" - - ib_ratings=( - s safe - q questionable - e explicit - ) - - ib_groups=( - "tags[]|select(.type==1)|.tagName" Artist - "tags[]|select(.type==2)|.tagName" Studio - "tags[]|select(.type==3)|.tagName" Copyright - "tags[]|select(.type==4)|.tagName" Character - "tags[]|select(.type==5)|.tagName" Genre - "tags[]|select(.type==0)|.tagName" General - "tags[]|select(.type==8)|.tagName" Medium - "tags[]|select(.type==9)|.tagName" Meta - ) - - case "${ib_mode}" in - (l) - ib_data_url="${ib_api}/pools" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="name" - ib_iid="id" - ib_icreated="created_at" - ib_ipool="name" - ib_icount="post_count" - ib_idate="%Y-%m-%d %H:%M" - ib_url="${ib_url}/pools/" - ;; - (p) - ib_data_url="${ib_api}/posts" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="tags" - ib_iid="id" - ib_icreated="created_at.s" - ib_isize="file_size" - ib_ifile="file_url" - ib_isample="sample_url" - ib_ipreview="preview_url" - ib_iwidth="width" - ib_iheight="height" - ib_irating="rating" - ib_iparent="parent_id" - ib_ichildren="has_children" - ib_imd5="md5" - ib_isource="deprecated" - ib_itags="tags[].tagName" - ib_ifilename="cut -d '?' -f 1 | cut -d '/' -f 7" - ib_url="${ib_url}/posts/" - ;; - (t) - ib_data_url="${ib_api}/tags" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="name" - ib_iid="id" - ib_itag="tagName" - ib_icount="post_count" - ib_url="${ib_url}/wiki/" - ;; - esac + . "${config}/sankakuchannel.zsh" ;; (k|y) - case "${ib_board}" in - (k) - ib_name="Konachan.com" - ib_config="konachan" - ib_api="https://konachan.com" - ib_url="https://konachan.com" - ;; - (y) - ib_name="yande.re" - ib_config="yandere" - ib_api="https://yande.re" - ib_url="https://yande.re" - ;; - esac - - ib_ratings=( - s safe - q questionable - e explicit - ) - - ib_groups=( - tags Tags - ) - - case "${ib_mode}" in - (l) - ib_data_url="${ib_api}/pool.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="query" - ib_iid="id" - ib_icreated="created_at" - ib_ipool="name" - ib_icount="post_count" - ib_idate="%Y-%m-%dT%X" - ib_ispace="_" - ib_url="${ib_url}/pool/show/" - ;; - (p) - ib_data_url="${ib_api}/post.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="tags" - ib_iid="id" - ib_icreated="created_at" - ib_isize="file_size" - ib_ifile="file_url" - ib_isample="sample_url" - ib_ipreview="preview_url" - ib_iwidth="width" - ib_iheight="height" - ib_irating="rating" - ib_iparent="parent_id" - ib_ichildren="has_children" - ib_imd5="md5" - ib_isource="source" - ib_itags="tags" - ib_ifilename="sed 's/\/${ib_name}.*\./\./' | cut -d '/' -f 5" - ib_url="${ib_url}/post/show/" - ;; - (t) - ib_data_url="${ib_api}/tag.json" - ib_dlimit="limit" - ib_dpage="page" - ib_dquery="name" - ib_iid="id" - ib_itag="name" - ib_icount="count" - ib_irecode="UTF-8" - ib_url="${ib_url}/wiki/show?title=" - ;; - esac + . "${config}/moebooru.zsh" ;; esac |
