aboutsummaryrefslogtreecommitdiff
path: root/units/ib_meta.zsh
blob: 4109759416a5e72978c3e929b8852bec8fb36aa8 (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
86
87
88
89
90
91
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

if [[ -n "${ib_file_url}" && "${ib_file_url}" != "null" ]]
then
    ib_type="$(eval ${ib_ifilename} <<< "${ib_file_url}" | cut -d '.' -f 2)"

    if [[ -z "${ib_sample_url}" || "${ib_sample_url}" == "null" ]]
    then
        ib_sample_url=${ib_file_url}
    fi

    if [[ -z "${ib_preview_url}" || "${ib_preview_url}" == "null" ]]
    then
        ib_preview_url=${ib_error_url}
    elif [[ "${ib_cname}" == "sankakucomplex" ]]
    then
        ib_preview_url="${ib_sample_url}"
    fi

    if [[ -n "${ib_width}" && "${ib_width}" != "null" && ${ib_width} -gt 0 ]]
    then
        ib_resolution_text="${ib_width}x${ib_height}"
    fi

    if [[ -n "${ib_type}" ]]
    then
        ib_type_text="$(tr '[:lower:]' '[:upper:]' <<< "${ib_type}")"
    fi

    case "${ib_type}" in
        (jpeg | jpg | png | webp)
            ib_type="photo"
        ;;
        (gif)
            source "${units}/ib_preview.zsh"
            ib_type="gif"
        ;;
        (mp4)
            source "${units}/ib_preview.zsh"
            ib_type="video"
        ;;
        (zip | webm)
            source "${units}/ib_sample.zsh"
        ;;
        (*)
            ib_sample_url="${ib_error_url}"
            ib_preview_url="${ib_error_url}"
            ib_width="${ib_error_width}"
            ib_height="${ib_error_height}"
            ib_type="photo"
        ;;
    esac
else
    ib_file_size=0
    ib_file_url="${ib_error_url}"
    ib_sample_url="${ib_error_url}"
    ib_preview_url="${ib_error_url}"
    ib_width="${ib_error_width}"
    ib_height="${ib_error_height}"
    ib_type="photo"
fi

if [[ -n "${ib_file_size}" && "${ib_file_size}" != "null" && ${ib_file_size} -gt 0 ]]
then
    if [[ ${ib_file_size} -gt 20971520 && "${ib_sample_url}" == "${ib_file_url}" ]]
    then
        source "${units}/ib_sample.zsh"
    fi

    size_offset=1.0

    for unit in B KiB MiB GiB TiB PiB
    do
        unit_offset=${size_offset}
        size_offset=$((size_offset * 1024))

        if [[ ${ib_file_size} -lt ${size_offset} ]]
        then
            break
        fi
    done

    if [[ ${ib_file_size} -ge 1024 ]]
    then
        ib_size_text="$(printf "%.2f %s" "$((ib_file_size / unit_offset))" "${unit}")"
    else
        ib_size_text="$(printf "%u %s" "${ib_file_size}" "${unit}")"
    fi
fi