aboutsummaryrefslogtreecommitdiff
path: root/units/ib_post.zsh
blob: 3a86d087f905bb2e8cdaaf1ebe6673da1592f505 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (C) 2024-2026 Maria Lisina
# Copyright (C) 2024-2026 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

ib_id="$(jq -r ".[0].${ib_iid}" "${ib_file}")"
ib_created_at="$(jq -r ".[0].${ib_icreated}" "${ib_file}")"
ib_file_size="$(jq -r ".[0].${ib_isize}" "${ib_file}")"
ib_file_url="$(jq -r ".[0].${ib_ifile}" "${ib_file}")"
ib_sample_url="$(jq -r ".[0].${ib_isample}" "${ib_file}")"
ib_preview_url="$(jq -r ".[0].${ib_ipreview}" "${ib_file}")"
ib_width="$(jq -r ".[0].${ib_iwidth}" "${ib_file}")"
ib_height="$(jq -r ".[0].${ib_iheight}" "${ib_file}")"
ib_rating="$(jq -r ".[0].${ib_irating}" "${ib_file}")"
ib_parent_id="$(jq -r ".[0].${ib_iparent}" "${ib_file}")"
ib_has_children="$(jq -r ".[0].${ib_ichildren}" "${ib_file}")"
ib_md5="$(jq -r ".[0].${ib_imd5}" "${ib_file}")"
ib_source="$(jq -r ".[0].${ib_isource}" "${ib_file}" | htmlescape)"
ib_tags=($(jq -r ".[0].${ib_itags}" "${ib_file}"))

source "${units}/ib_date.zsh"
source "${units}/ib_meta.zsh"

output_text="$(printf "<b>%s</b>\n<b>ID:</b> <code>%s</code>" "${ib_name}" "${ib_id}")"

if [[ -n "${ib_date_text}" ]]
then
    output_text="$(printf "%s\n<b>Date:</b> <code>%s</code>" "${output_text}" "${ib_date_text}")"
fi

if [[ -n "${ib_resolution_text}" ]]
then
    output_text="$(printf "%s\n<b>Resolution:</b> %s" "${output_text}" "${ib_resolution_text}")"
fi

if [[ -n "${ib_size_text}" ]]
then
    output_text="$(printf "%s\n<b>Size:</b> %s" "${output_text}" "${ib_size_text}")"
fi

if [[ -n "${ib_type_text}" ]]
then
    output_text="$(printf "%s\n<b>Type:</b> %s" "${output_text}" "${ib_type_text}")"
fi

if [[ -n "${ib_rating}" && "${ib_rating}" != "null" ]]
then
    while [[ ${#ib_ratings} -ge 2 ]]
    do
        if [[ "${ib_rating}" == "${ib_ratings[1]}" ]]
        then
            output_text="$(printf "%s\n<b>Rating:</b> <code>%s</code>" "${output_text}" "${ib_ratings[2]}")"
            break
        else
            shift 2 ib_ratings
        fi
    done
fi

if [[ -n "${ib_parent_id}" && "${ib_parent_id}" != "null" && "${ib_parent_id}" != "0" ]]
then
    output_text="$(printf "%s\n<b>Parent ID:</b> <code>%s</code>" "${output_text}" "${ib_parent_id}")"
fi

if [[ "${ib_has_children}" == "true" ]]
then
    output_text="$(printf "%s\n<b>Has children:</b> yes" "${output_text}")"
fi

if [[ -n "${ib_md5}" && "${ib_md5}" != "null" ]]
then
    output_text="$(printf "%s\n<b>MD5:</b> <code>%s</code>" "${output_text}" "${ib_md5}")"
fi

if [[ -n "${ib_source}" && "${ib_source}" != "null" ]]
then
    if grep -q -e "pixiv" -e "pximg" <<< "${ib_source}"
    then
        ib_source="https://www.pixiv.net/artworks/$(cut -d "[._]" -F 1 <<< "${ib_source##*/}")"
    fi

    if [[ ${#ib_source} -le 1024 ]]
    then
        output_text="$(printf "%s\n<b>Source:</b> %s" "${output_text}" "${ib_source}")"
    fi
fi