forked from tokee/juxta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_kb.sh
executable file
·105 lines (92 loc) · 3.29 KB
/
demo_kb.sh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Creates collage of public available images from kb.dk
# API described on https://github.com/Det-Kongelige-Bibliotek/access-digital-objects
pushd ${BASH_SOURCE%/*} > /dev/null
: ${DOWNLOAD_SCRIPT:="$(pwd)/download_kb.sh"}
popd > /dev/null
# Valid values are 'none', 'intensity' and 'rainbow'
: ${IMAGE_SORT:="none"}
: ${ALLOW_UPSCALE:=true}
: ${RAW_MODE:=automax}
: ${BACKGROUND:=000000}
: ${TEMPLATE:=demo_kb.template.html}
: ${MAX_IMAGES:="1000000000"} # 1b
: ${MAX_IMAGES_PER_COLLECTION:="$MAX_IMAGES"}
# TODO: Extract the title of the collection and show it on the generated page
# TODO: Better guessing of description text based on md:note fields
# TODO: Get full images: http://kb-images.kb.dk/online_master_arkiv_6/non-archival/Images/BILLED/2008/Billede/dk_eksp_album_191/kbb_alb_2_191_friis_011/full/full/0/native.jpg
# TODO: Trim titles to max X chars
usage() {
echo "Usage:"
echo "./demo_kb.sh list"
echo " Shows available collections"
echo "./demo_kb.sh create collection*"
echo " Creates a page for the given collection IDs"
exit $1
}
COMMAND="$1"
if [ "list" != "$COMMAND" -a "create" != "$COMMAND" ]; then
if [ "." == ".$COMMAND" ]; then
echo "Please provide a command"
usage
fi
>&2 echo "Error: Unknown command '$COMMAND'"
usage 1
fi
shift
export COLLECTIONS="$@"
if [ "create" == "$COMMAND" -a "." == ".$COLLECTIONS" ]; then
>&2 echo "Error: A collection must be provided"
usage 2
fi
# Multi-collection handling
ALLC=$(tr ' ' '_' <<< "$COLLECTIONS" | sed 's/_$//')
: ${DEST:="$ALLC"}
# https://github.com/Det-Kongelige-Bibliotek/access-digital-objects
# http://www.kb.dk/cop/syndication/images/billed/2010/okt/billeder/subject2109/
list_collections() {
echo "Not implemented yet. Go to"
echo "http://www.kb.dk/images/billed/2010/okt/billeder/subject2109/en/"
echo "And browse to a collection (not an individual image)."
echo "In the URL the subject can be located, such as 'subject3795'."
}
if [ "list" == "$COMMAND" ]; then
list_collections
exit
fi
mkdir -p downloads/$DEST
rm -r downloads/$DEST/sources.dat
if [[ "$MAX_IMAGES" -lt "$MAX_IMAGES_PER_COLLECTION" ]]; then
MAX_IMAGES_PER_COLLECTION=$MAX_IMAGES
fi
OLD_MI=$MAX_IMAGES
MAX_IMAGES=$MAX_IMAGES_PER_COLLECTION
for COLLECTION in $COLLECTIONS; do
echo "Downloading collection $COLLECTION"
. $DOWNLOAD_SCRIPT "$COLLECTION"
#cat downloads/$COLLECTION/sources.dat >> downloads/$DEST/sources.dat
done
MAX_IMAGES=$OLD_MI
COLLECTION="$DEST"
if [ "intensity" == "$IMAGE_SORT" ]; then
DAT=downloads/$DEST/sources_intensity_${MAX_IMAGES}.dat
if [ -s "$DAT" ]; then
echo "- Skipping sort by intensity as $DAT already exists"
else
echo "- Sorting images by intensity"
./intensity_sort.sh downloads/$COLLECTION/sources.dat $DAT
fi
SORTED_SOURCE="$DAT"
elif [ "rainbow" == "$IMAGE_SORT" ]; then
DAT=downloads/$COLLECTION/sources_rainbow_${MAX_IMAGES}.dat
if [ -s $DAT ]; then
echo "Skipping sort in rainbow order as $DAT already exists"
else
echo "- Sorting images in rainbow order"
./rainbow_sort.sh downloads/$COLLECTION/sources.dat $DAT
fi
SORTED_SOURCE="$DAT"
else
SORTED_SOURCE="downloads/$COLLECTION/sources.dat"
fi
. ./juxta.sh $SORTED_SOURCE $DEST