forked from Nemris/getcover
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcover.sh
More file actions
153 lines (136 loc) · 4.26 KB
/
getcover.sh
File metadata and controls
153 lines (136 loc) · 4.26 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
checkdeps() {
local deps
# on windows git bash must download:
# CRC32: http://esrg.sourceforge.net/utils_win_up/md5sum/crc32.exe to "C:\Program Files\Git\usr\bin"
# WGET: https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
deps="awk wget xxd crc32 sed"
unameOut="$(uname -s)"
case "${unameOut}" in
CYGWIN* | MINGW*)
OS=Windows
;;
esac
for dep in $deps; do
if [ -z "$(command -v "$dep")" ]; then
echo "Fatal: the required dependency \"$dep\" is missing."
exit 1
fi
done
}
searchcover() {
local baseurl
local lid
local langs
baseurl="https://art.gametdb.com/ds/coverS"
if [ "$romtype" = "nds" ]; then
lid="EN"
langs=(US JA DE FR KO)
if ! getcover "$baseurl/$lid/$1.png"; then
for i in "${langs[@]}"; do
lid="$i"
getcover "$baseurl/$lid/$1.png"
status=$?
# exits for loop on first success preventing failed message per array language
if [ "${status:-0}" -eq 0 ]; then
break
fi
done
fi
else
# baseurl="http://hakchicloud.com/Hakchi_Themes/dsart"
baseurl="https://github.com/DefKorns/rom-cover-generator/raw/master/boxart/"
getcover "$baseurl/$tid.png"
fi
# file not found or no connection available
# "${status:-0}" fix [: -ne: unary operator expected and [: : integer expression expected
if [ "${status:-0}" -ne 0 ]; then
echo "$1: cover download failed." 1>&2
fi
}
gettid() {
if [ -f "$1" ]; then
xxd -s 12 -l 4 "$1" | awk '{print $4}'
fi
}
getcover() {
# '-nc' ||'--no-clobber', overwrites the file instead of creating multiple files if they already exits
if [ "$romtype" = "nds" ]; then
wget -q -nc --compression=auto "$1"
else
if [ $romtype = "md" ]; then
romtype="gen"
fi
wget -q -nc --compression=auto "$1" -O "$title.$romtype.png"
fi
}
rename() {
if [ -f "$1" ]; then
mv "$1" "$2"
fi
}
help() {
echo ""
echo "Usage:
./$(basename "$0") titleID | ndsfile [titleID] | ndsfile | files | [options]..."
echo ""
echo "Files:
Rom files of type: \"*.nes\", \"*.snes\", \"*.gb\", \"*.gbc\", \"*.sms\", \"*.gen\", \"*.gg\""
echo ""
echo "Options:
-?, -h, -help This information screen
game_name.nds Downloads boxart for a expecific NDS game
titleID Same as above
*.* Downloads boxart to all roms on the directory
*.(extension) Downloads boxart for supported roms on the directory"
echo ""
echo "Examples:
./$(basename "$0") *.nds Downloads boxart for all NDS games
./$(basename "$0") Mario Bros.nds Downloads boxart by game title
./$(basename "$0") AMCE Download boxart by titleID (this case \"Mario Kart DS\")
./$(basename "$0") *.nes Downloads boxart for NES roms on the directory
./$(basename "$0") *.snes Downloads boxart for SNES roms on the directory
./$(basename "$0") *.md Downloads boxart for Mega Drive and also converts the roms to *.gen
./$(basename "$0") -? Display help info"
echo ""
exit 1
}
checkdeps
if [ $# -lt 1 ]; then
help
fi
for i in "$@"; do
case $i in
*.nds)
romtype="nds"
tid=$(gettid "$i")
if [ -z "$tid" ]; then
echo "$i: not a .nds file"
continue
fi
;;
*.nes | *.gbc | *.snes | *.gb | *.sms | *.gen | *.gg | *.md)
fulltitle=$(basename -- "$i")
romtype="${fulltitle##*.}"
title="${fulltitle%.*}"
if [[ "$i" == *.md ]]; then
rename "$i" "$title.gen"
i="$title.gen"
fi
tid=$(crc32 "$i")
if [ $OS = "Windows" ]; then
tid=$(crc32 "$i" | sed -e 's/^0x\(.\{8\}\).*/\1/')
fi
;;
*.*)
romfamily=(*.nes *.gbc *.snes *.gb *.sms *.gen *.gg *.md)
for ext in "${romfamily[@]}"; do
i="$ext"
done
;;
'-?' | -h | -help)
help
;;
esac
searchcover "$tid"
done