Commit | Line | Data |
---|---|---|
1de93811 ML |
1 | #!/bin/bash |
2 | ||
3 | # default values | |
4 | PROGNAME=$(basename $0) | |
5 | ||
6 | # defaut values | |
7 | id=0 | |
8 | ||
9 | # get last values | |
10 | [ -f .$PROGNAME ] && source .$PROGNAME | |
11 | ||
12 | # init | |
13 | file="$1" | |
14 | ||
15 | # get serial | |
16 | serial=$(isoinfo -f -i "$file" | \ | |
17 | grep "^/[A-Z][A-Z][A-Z][A-Z]_[0-9][0-9][0-9]\.[0-9][0-9];" | \ | |
18 | sed 's,[/.],,g;s,_,-,;s,;.*,,') | |
19 | [ "$serial" ] || { serial=$(printf "PS2U-1%04d" $id); let id++; } | |
20 | CID=${serial/-} | |
21 | ||
22 | # store last value | |
23 | echo > .$PROGNAME | |
24 | echo "id=$id" >> .$PROGNAME | |
25 | ||
26 | # get name | |
27 | function getname () { | |
28 | [ -f jlist2.html ] || wget https://psxdatacenter.com/psx2/jlist2.html | |
29 | [ -f plist2.html ] || wget https://psxdatacenter.com/psx2/plist2.html | |
30 | [ -f ulist2.html ] || wget https://psxdatacenter.com/psx2/ulist2.html | |
31 | awk '/>'$1'</ { | |
32 | getline; gsub(/<[^<]*>/, "") | |
33 | sub(/ /, " ") | |
34 | gsub(/^[ \t]*/, "") | |
35 | gsub(/[ \t]*$/, "") | |
36 | ||
37 | }' [jpu]list2.html | |
38 | } | |
39 | ||
40 | # get game title | |
41 | [ -f PS2-GAMEID-TITLE-MASTER.csv ] || wget https://raw.githubusercontent.com/VTSTech/PS2-OPL-CFG/master/test/PS2-GAMEID-TITLE-MASTER.csv | |
42 | title=$(awk -F\; '"'$serial'" == $1 {print $2}' PS2-GAMEID-TITLE-MASTER.csv) | |
43 | [ "$title" ] || title=$(basename "$file" | sed 's/ *(.*//') | |
44 | ||
45 | # main process | |
46 | echo "File: '$file'" | |
47 | echo "Serial: $serial" | |
48 | echo "Title: '$title'" | |
49 | ||
50 | # skeleton | |
51 | mkdir $serial | |
52 | tar -C $serial -xzf skeleton.tgz | |
53 | ||
54 | ||
55 | # images: | |
56 | # - ICON0.PNG 320x176 | |
57 | # - PIC0.PNG 1000x560 | |
58 | # - PIC1.PNG 1920x1080 | |
59 | ||
60 | # cover | |
61 | wget https://psxdatacenter.com/psx2/images2/covers/$serial.jpg | |
62 | if [ -f $serial.jpg ]; then | |
63 | convert $serial.jpg tmp.png | |
64 | mogrify -resize 320x176 tmp.png | |
65 | mogrify -background transparent -gravity center -extent 320x176 tmp.png | |
66 | mv tmp.png $serial/ICON0.PNG | |
67 | rm $serial.jpg | |
68 | fi | |
69 | ||
70 | # screenshot | |
71 | touch .touch | |
72 | find $HOME/.config/PCSX2/snaps/ -type f | xargs rm .touch | |
73 | #pcsx2 "$file" | |
74 | capture=$(find $HOME/.config/PCSX2/snaps/ -type f | sort) | |
75 | if [ "$capture" ]; then | |
76 | cp "$capture" tmp.png | |
77 | mogrify -scale 1000x560 tmp.png | |
78 | mogrify -background transparent -gravity center -extent 1000x560 tmp.png | |
79 | mv tmp.png $serial/PIC0.PNG | |
80 | fi | |
81 | ||
82 | # parameters | |
83 | # - file: PARAM.SFO | |
84 | # 0x108: title | |
85 | # 0x188: CID | |
86 | # - file: USRDIR/ISO.BIN.EDAT | |
87 | # 0x017: CID | |
88 | echo -n $title | xxd | xxd -r -s 0x108 - $serial/PARAM.SFO | |
89 | echo -n $CID | xxd | xxd -r -s 0x188 - $serial/PARAM.SFO | |
90 | echo -n $CID | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT | |
91 | ||
92 | # convert | |
93 | ps2classic e cex ps2.key "$1" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC 2P0001-${CID}_00-0000111122223333 |