-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscrap.sh
executable file
·1043 lines (947 loc) · 30.8 KB
/
scrap.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
touch ~/storage/shared/scrap.log &> /dev/null
echo "" > ~/storage/shared/scrap.log &> /dev/null
useInternalStorage=false
FILE=~/dragoonDoriseTools/.storageInternal
if [ -f "$FILE" ]; then
useInternalStorage=true
storageLocation="shared/roms"
else
useInternalStorage=false
storageLocation="external-1"
fi
get_sc_id(){
#SS ID systems
case $1 in
genesis)
ssID="1";;
genesiswide)
ssID="1";;
mastersystem)
ssID="2";;
nes)
ssID="3";;
snes)
ssID="4";;
gb)
ssID="9";;
gbc)
ssID="10";;
virtualboy)
ssID="11";;
gba)
ssID="12";;
gc)
ssID="13";;
n64)
ssID="14";;
nds)
ssID="15";;
wii)
ssID="16";;
3ds)
ssID="17";;
sega32x)
ssID="19";;
segacd)
ssID="20";;
gamegear)
ssID="21";;
saturn)
ssID="22";;
dreamcast)
ssID="23";;
ngp)
ssID="25";;
atari2600)
ssID="26";;
jaguar)
ssID="27";;
lynx)
ssID="28";;
3do)
ssID="29";;
pcengine)
ssID="31";;
bbcmicro)
ssID="37";;
atari5200)
ssID="40";;
atari7800)
ssID="41";;
atarist)
ssID="42";;
atari800)
ssID="43";;
wswan)
ssID="45";;
wswanc)
ssID="46";;
colecovision)
ssID="48";;
pcengine)
ssID="50";;
gw)
ssID="52";;
psx)
ssID="57";;
ps2)
ssID="58";;
psp)
ssID="61";;
amiga600)
ssID="64";;
amstradcpc)
ssID="65";;
c64)
ssID="66";;
scv)
ssID="67";;
neogeocd)
ssID="70";;
pcfx)
ssID="72";;
vic20)
ssID="73";;
zxspectrum)
ssID="76";;
zx81)
ssID="77";;
x68000)
ssID="79";;
channelf)
ssID="80";;
ngpc)
ssID="82";;
apple2)
ssID="86";;
gx4000)
ssID="87";;
dragon)
ssID="91";;
bk)
ssID="93";;
vectrex)
ssID="102";;
supergrafx)
ssID="105";;
fds)
ssID="106";;
satellaview)
ssID="107";;
sufami)
ssID="108";;
sg1000)
ssID="109";;
amiga1200)
ssID="111";;
msx)
ssID="113";;
pcenginecd)
ssID="114";;
intellivision)
ssID="115";;
msx2)
ssID="116";;
msxturbor)
ssID="118";;
64dd)
ssID="122";;
scummvm)
ssID="123";;
gb)
ssID="127";;
gb)
ssID="128";;
amigacdtv)
ssID="129";;
amigacd32)
ssID="130";;
oricatmos)
ssID="131";;
amiga)
ssID="134";;
dos)
ssID="135";;
prboom)
ssID="135";;
amigacd32)
ssID="139";;
thomson)
ssID="141";;
neogeo)
ssID="142";;
psp)
ssID="172";;
snes)
ssID="202";;
sneswide)
ssID="202";;
megadrive)
ssID="203";;
ti994a)
ssID="205";;
lutro)
ssID="206";;
supervision)
ssID="207";;
pc98)
ssID="208";;
pokemini)
ssID="211";;
samcoupe)
ssID="213";;
openbor)
ssID="214";;
uzebox)
ssID="216";;
apple2gs)
ssID="217";;
spectravideo)
ssID="218";;
palm)
ssID="219";;
x1)
ssID="220";;
pc88)
ssID="221";;
tic80)
ssID="222";;
solarus)
ssID="223";;
mame)
ssID="230";;
easyrpg)
ssID="231";;
pico8)
ssID="234";;
pcv2)
ssID="237";;
pet)
ssID="240";;
lowresnx)
ssID="244";;
*)
echo -n "unknown"
;;
esac
}
get_ra_alias(){
case $1 in
atari2600)
remoteSystem="Atari - 2600"
;;
atari5200)
remoteSystem="Atari - 5200"
;;
atari7800)
remoteSystem="Atari - 7800"
;;
lynx)
remoteSystem="Atari - Lynx"
;;
doom)
remoteSystem="DOOM"
;;
dos)
remoteSystem="DOS"
;;
fbneo)
remoteSystem="FBNeo - Arcade Games"
;;
pcengine)
remoteSystem="NEC - PC Engine - TurboGrafx 16"
;;
pcenginecd)
remoteSystem="NEC - PC Engine CD - TurboGrafx-CD"
;;
gb)
remoteSystem="Nintendo - Game Boy"
;;
gba)
remoteSystem="Nintendo - Game Boy Advance"
;;
gbc)
remoteSystem="Nintendo - Game Boy Color"
;;
gc)
remoteSystem="Nintendo - GameCube"
;;
3ds)
remoteSystem="Nintendo - Nintendo 3DS"
;;
n64)
remoteSystem="Nintendo - Nintendo 64"
;;
nds)
remoteSystem="Nintendo - Nintendo DS"
;;
nes)
remoteSystem="Nintendo - Nintendo Entertainment System"
;;
pokemini)
remoteSystem="Nintendo - Pokemon Mini"
;;
snes)
remoteSystem="Nintendo - Super Nintendo Entertainment System"
;;
wii)
remoteSystem="Nintendo - Wii"
;;
neogeo)
remoteSystem="SNK - Neo Geo"
;;
neogeocd)
remoteSystem="SNK - Neo Geo CD"
;;
ngp)
remoteSystem="SNK - Neo Geo Pocket"
;;
ngpc)
remoteSystem="SNK - Neo Geo Pocket Color"
;;
scummvm)
remoteSystem="ScummVM"
;;
sega32x)
remoteSystem="Sega - 32X"
;;
dreamcast)
remoteSystem="Sega - Dreamcast"
;;
gamegear)
remoteSystem="Sega - Game Gear"
;;
mastersystem)
remoteSystem="Sega - Master System - Mark III"
;;
genesis)
remoteSystem="Sega - Mega Drive - Genesis"
;;
genesiswide)
remoteSystem="Sega - Mega Drive - Genesis"
;;
segacd)
remoteSystem="Sega - Mega-CD - Sega CD"
;;
saturn)
remoteSystem="Sega - Saturn"
;;
psx)
remoteSystem="Sony - PlayStation"
;;
ps2)
remoteSystem="Sony - PlayStation 2"
;;
psp)
remoteSystem="Sony - PlayStation Portable"
;;
3d0)
remoteSystem="The 3DO Company - 3DO"
;;
amstradcpc)
remoteSystem="Amstrad - CPC"
;;
atarist)
remoteSystem="Atari - ST"
;;
colecovision)
remoteSystem="Coleco - ColecoVision"
;;
intellivision)
remoteSystem="Mattel - Intellivision"
;;
lutro)
remoteSystem="Lutro"
;;
msx)
remoteSystem="Microsoft - MSX"
;;
tic80)
remoteSystem="TIC-80"
;;
vectrex)
remoteSystem="GCE - Vectrex"
;;
zxspectrum)
remoteSystem="Sinclair - ZX Spectrum"
;;
*)
echo -n "unknown"
;;
esac
}
scrap_ss () {
urlMedia=$1
urlSave=$2
media=$3
echo -e "${BOLD}Scraping: $media.${NONE}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
echo -ne "${BOLD}Searching World Region..."
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo -ne "${BOLD}Searching US Region..."
firstString="$urlMedia"
secondString="(us)"
urlMedia="${firstString/(wor)/"$secondString"}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo -ne "${BOLD}Searching EU Region..."
firstString="$urlMedia"
secondString="(eu)"
urlMedia="${firstString/(us)/"$secondString"}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo -ne "${BOLD}Searching USA Region..."
firstString="$urlMedia"
secondString="(usa)"
urlMedia="${firstString/(eu)/"$secondString"}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo -ne "${BOLD}Searching Custom Region..."
firstString="$urlMedia"
secondString="(cus)"
urlMedia="${firstString/(usa)/"$secondString"}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo -ne "${BOLD}Searching No Region..."
firstString="$urlMedia"
secondString=""
urlMedia="${firstString/(cus)/"$secondString"}"
StatusString=$(wget --spider "$urlMedia" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "$urlMedia" -O "$urlSave" &> /dev/null
echo -e "${GREEN}Found it!${NONE}"
else
echo $urlMedia >> ~/storage/shared/scrap.log &> /dev/null
echo -e "${RED}NO IMG FOUND${NONE}"
fi
fi
fi
fi
fi
fi
}
NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
BLINK='\x1b[5m'
clear
cat ~/dragoonDoriseTools/pegasus-android-metadata/logo.ans
$selected_device_descriptions = "ALL"
selected_device_descriptions_all="atari2600 atari5200 atari7800 lynx doom dos fbneo pcengine pcenginecd gb gba gbc gc 3ds n64 nds nes pokemini snes sneswide wii neogeo neogeocd ngp ngpc scummvm sega32x dreamcast gamegear mastersystem genesis genesiswide segacd saturn psx ps2 psp 3do amstradcpc atarist colecovision intellivision lutro msx tic80 vectrex zxspectrum"
mapfile -t selected_device_names <<< $selected_device_descriptions_all
clear
scrapers_names=$(whiptail --title "Choose your Scrape Engine - We recomend to choose all of them" \
--checklist "Move using your DPAD and select your options with the Y button. Press the A button to select." 10 80 4 \
"RETROARCH" "Retroarch Thumbs - Fast but only works on No Intro Romsets" ON \
"LAUNCHBOX" "Launchbox GamesDB - Fast - Still on beta" ON \
"SCREENSCRAPER" "ScreenScraper - Really really slow but more reliable" ON \
3>&1 1<&2 2>&3)
clear
mapfile -t scrapers <<< $scrapers_names
for scraper in ${scrapers[@]};
do
if [[ $scraper == *"RETROARCH"* ]]; then
clear
echo -e "Using Retroarch Thumbnails..."
for device_name in ${selected_device_names[@]};
do
message=$device_name
system="${message//'"'/}"
#ls ~/storage/$storageLocation/$system
mkdir ~/storage/$storageLocation/$system/media &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/screenshot &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/box2dfront &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/wheel &> /dev/null
#Retroarch system folder name
get_ra_alias $system
echo ""
echo -e "Scraping $system..."
echo ""
#Roms loop
for entry in ~/storage/$storageLocation/$system/*
do
#Cleaning up names
firstString=$entry
secondString=""
romName="${firstString/"/data/data/com.termux/files/home/storage/$storageLocation/$system/"/"$secondString"}"
romNameNoExtension=${romName%.*}
startcapture=true
#.txt validation
STR=$romName
SUB='.txt'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#.sav validation
STR=$romName
SUB='.sav'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#.srm validation
STR=$romName
SUB='.srm'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#Directory Validation
DIR=~/storage/$storageLocation/$system/$romName
if [ -d "$DIR" ]; then
startcapture=false
fi
#Blanks cleaning up, TODO: DRY
firstString=$romNameNoExtension
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString="%20"
romNameNoExtensionNoSpace="${firstString/" "/"$secondString"}"
if [ $system == "mame" ]; then
startcapture=false
fi
if [ $startcapture == true ]; then
#First Scan: Retroarch
FILE=~/storage/$storageLocation/$system/media/screenshot/$romNameNoExtension.png
if [ -f "$FILE" ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
StatusString=$(wget --spider "http://thumbnails.libretro.com/$remoteSystem/Named_Snaps/$romNameNoExtension.png" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "http://thumbnails.libretro.com/$remoteSystem/Named_Snaps/$romNameNoExtension.png" -P ~/storage/$storageLocation/$system/media/screenshot/
else
echo -e "Image not found: $romNameNoExtension screenshot..."
fi
fi
FILE=~/storage/$storageLocation/$system/media/box2dfront/$romNameNoExtension.png
if [ -f "$FILE" ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
StatusString=$(wget --spider "http://thumbnails.libretro.com/$remoteSystem/Named_Boxarts/$romNameNoExtension.png" 2>&1)
if [[ $StatusString == *"image/png"* ]] || [[ $StatusString == *"image/jpeg"* ]] || [[ $StatusString == *"image/jpg"* ]]; then
wget -q --show-progress "http://thumbnails.libretro.com/$remoteSystem/Named_Boxarts/$romNameNoExtension.png" -P ~/storage/$storageLocation/$system/media/box2dfront/
echo -e ""
else
echo -e "Image not found: $romNameNoExtension box2dfront..."
fi
fi
fi
done
done
echo -e "${GREEN}completed${NONE}"
fi
if [[ $scraper == *"LAUNCHBOX"* ]]; then
clear
echo -e "Using Launchbox GamesDB..."
for device_name in ${selected_device_names[@]};
do
message=$device_name
system="${message//'"'/}"
#ls ~/storage/$storageLocation/$system
mkdir ~/storage/$storageLocation/$system/media &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/screenshot &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/box2dfront &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/wheel &> /dev/null
#Roms loop
for entry in ~/storage/$storageLocation/$system/*
do
#Cleaning up names
firstString=$entry
secondString=""
romName="${firstString/"/data/data/com.termux/files/home/storage/$storageLocation/$system/"/"$secondString"}"
romNameNoExtension=${romName%.*}
startcapture=true
#.txt validation
STR=$romName
SUB='.txt'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#.sav validation
STR=$romName
SUB='.sav'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#.srm validation
STR=$romName
SUB='.srm'
if grep -q "$SUB" <<< "$STR"; then
startcapture=false
fi
#Directory Validation
DIR=~/storage/$storageLocation/$system/$romName
if [ -d "$DIR" ]; then
startcapture=false
fi
#Blanks cleaning up, TODO: DRY
firstString=$romNameNoExtension
secondString=""
romNameNoExtensionNoDisc="${firstString/"Disc "/""}"
firstString=$romNameNoExtensionNoDisc
romNameNoExtensionNoRev="${firstString/"Rev "/""}"
firstString=$romNameNoExtensionNoRev
romNameNoExtensionTrimmed=$(echo $firstString | sed -r "s/(.[()].*)//g")
firstString=$romNameNoExtensionTrimmed
romNameNoExtensionNoAnd="${firstString/"&"/"$secondString"}"
firstString=$romNameNoExtensionNoAnd
secondString="%20"
romNameNoExtensionNoDash="${firstString/" - "/"$secondString"}"
firstString=$romNameNoExtensionNoDash
romNameNoExtensionNoDash="${firstString/"-"/"$secondString"}"
firstString=$romNameNoExtensionNoDash
romNameNoExtensionNoSpace="${firstString//" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString=""
romNameNoExtensionNoNkit="${firstString/".nkit"/"$secondString"}"
firstString=$romNameNoExtensionNoNkit
romNameNoExtensionNoSpace="${firstString/"!"/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
STR=$romNameNoExtensionTrimmed
SUB=', The'
if [[ "$STR" == *"$SUB"* ]]; then
firstString=$romNameNoExtensionTrimmed
secondString=""
romNameNoExtensionNoThe="${firstString/", The"/"$secondString"}"
romNameNoExtensionForLaunchbox="The $romNameNoExtensionNoThe"
else
romNameNoExtensionForLaunchbox=$romNameNoExtensionTrimmed
fi
romNameNoExtensionForLaunchbox=$(echo $romNameNoExtensionForLaunchbox | sed -r "s/,//g")
if [ $startcapture == true ]; then
hasWheel=false
hasSs=false
hasBox=false
FILE=~/storage/$storageLocation/$system/media/wheel/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasWheel=true
fi
FILE=~/storage/$storageLocation/$system/media/screenshot/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasSs=true
fi
FILE=~/storage/$storageLocation/$system/media/box2dfront/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasBox=true
fi
#We only search games with no art
if [ $hasWheel == false ] || [ $hasSs == false ] || [ $hasBox == false ]; then
content=$(cat ~/dragoonDoriseTools/pegasus-android-metadata/metadata.json)
urlMediaWheel=$( jq -r ".platform.$system.games.\"$romNameNoExtensionForLaunchbox\".medias.wheel" <<< "${content}" )
urlMediaSs=$( jq -r ".platform.$system.games.\"$romNameNoExtensionForLaunchbox\".medias.screenshot" <<< "${content}" )
urlMediaBox=$( jq -r ".platform.$system.games.\"$romNameNoExtensionForLaunchbox\".medias.box2dfront" <<< "${content}" )
wheelSavePath="./storage/$storageLocation/$system/media/wheel/$romNameNoExtension.png"
ssSavePath="./storage/$storageLocation/$system/media/screenshot/$romNameNoExtension.png"
box2dfrontSavePath="./storage/$storageLocation/$system/media/box2dfront/$romNameNoExtension.png"
echo -e "Searching Images for $romNameNoExtension"
if [[ $urlMediaWheel != null ]]; then
if [ $hasWheel == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
wget -q --show-progress "$urlMediaWheel" -O "$wheelSavePath"
fi
fi
if [[ $urlMediaSs != null ]]; then
if [ $hasSs == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
wget -q --show-progress "$urlMediaSs" -O "$ssSavePath"
fi
fi
if [[ $urlMediaBox != null ]]; then
if [ $hasBox == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
wget -q --show-progress "$urlMediaBox" -O "$box2dfrontSavePath"
fi
fi
else
echo -e "Game already scraped" &> /dev/null
fi
fi
done
done
echo -e "${GREEN}completed${NONE}"
fi
if [[ $scraper == *"SCREENSCRAPER"* ]]; then
if (whiptail --title "Scrape metadata" --yesno "Would you like to scrape metadata for individual games?" 8 78); then
saveMetadata=true
else
saveMetadata=false
fi
clear
echo -e "Using ScreenScraper..."
#We check for existing credentials
userStored=false
FILE=~/dragoonDoriseTools/.screenScraperUser
if [ -f "$FILE" ]; then
userStored=true
userSS=$(cat ~/dragoonDoriseTools/.screenScraperUser)
passSS=$(cat ~/dragoonDoriseTools/.screenScraperPass)
fi
if [ $userStored == false ]; then
if (whiptail --title "Screen Scraper" --yesno "Do you have an account on www.screenscraper.fr? If you don't we will open your browser so you can create one. Come back afterwards" 8 78); then
find ~/storage/shared/RetroArch/config/ -type f -name "*.cfg" -exec sed -i -e 's/input_overlay_enable = "false"/input_overlay_enable = "true"/g' {} \;
else
termux-open "https://www.screenscraper.fr/membreinscription.php"
clear
echo -e "Press the ${RED}A Button${NONE} if you already have your account created"
read pause
fi
echo -e "Now I'm going to ask for your username and password. ${BOLD}These will never be read or used outside this scraper${NONE}"
echo -e "What is your ScreenScraper user? Type it and press the ${RED}A button${NONE}"
read user
echo $user > ~/dragoonDoriseTools/.screenScraperUser
echo -e "What is your ScreenScraper password? Type it and press the ${RED}A button${NONE}"
read pass
echo $pass > ~/dragoonDoriseTools/.screenScraperPass
echo -e "${GREEN}Thanks!${NONE}"
echo -e "You can change the credentials later by opening Termux again"
echo -e "Press the ${RED}A Button${NONE} to start scraping your roms"
read pause
fi
#ScreenScraper loop
for device_name in ${selected_device_names[@]};
do
message=$device_name
system="${message//'"'/}"
mkdir ~/storage/$storageLocation/$system/media &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/screenshot &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/box2dfront &> /dev/null
mkdir ~/storage/$storageLocation/$system/media/wheel &> /dev/null
#ScreenScraper system ID
get_sc_id $system
echo ""
echo -e "Scraping $system..."
echo ""
#Check for metadata file
metadataFile=~/storage/$storageLocation/$system/metadata.pegasus.txt
if [[ -f $metadataFile ]]; then
systemMetadata=$(cat $metadataFile)
fileExtensions=$(grep -E '^extensions' $metadataFile)
extensions="${fileExtensions/"extensions: "/""}"
else
systemMetadata=""
extensions=""
fi
#Roms loop
for entry in ~/storage/$storageLocation/$system/*
do
#Cleaning up names
firstString=$entry
secondString=""
romName="${firstString/"/data/data/com.termux/files/home/storage/$storageLocation/$system/"/"$secondString"}"
romNameNoExtension=${romName%.*}
startcapture=true
#.txt validation
STR=$romName
SUB='.txt'
if grep -q "$SUB" <<< "$STR"; then
continue;
fi
#.sav validation
STR=$romName
SUB='.sav'
if grep -q "$SUB" <<< "$STR"; then
continue;
fi
#.srm validation
STR=$romName
SUB='.srm'
if grep -q "$SUB" <<< "$STR"; then
continue;
fi
#Directory Validation
DIR=~/storage/$storageLocation/$system/$romName
if [ -d "$DIR" ]; then
continue;
fi
#Extension Validation
#"" means metadata couldn't be parsed, no extensions to check
if [[ $extensions == "" ]]; then
startcapture=true
else
if grep -q "${romName##*.}" <<< "$extensions"]; then
startcapture=true
else
continue;
fi
fi
#Blanks cleaning up, TODO: DRY
firstString=$romNameNoExtension
secondString=""
romNameNoExtensionNoDisc="${firstString/"Disc "/""}"
firstString=$romNameNoExtensionNoDisc
romNameNoExtensionNoRev="${firstString/"Rev "/""}"
firstString=$romNameNoExtensionNoRev
romNameNoExtensionTrimmed=$(echo $firstString | sed 's/ ([^()]*)//g' | sed 's/ [[A-z0-9!+]*]//g' | sed 's/([^()]*)//g' | sed 's/[[A-z0-9!+]*]//g')
firstString=$romNameNoExtensionTrimmed
romNameNoExtensionNoAnd="${firstString/"&"/"$secondString"}"
firstString=$romNameNoExtensionNoAnd
secondString="%20"
romNameNoExtensionNoDash="${firstString/" - "/"$secondString"}"
firstString=$romNameNoExtensionNoDash
romNameNoExtensionNoDash="${firstString/"-"/"$secondString"}"
firstString=$romNameNoExtensionNoDash
romNameNoExtensionNoSpace="${firstString//" "/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
secondString=""
romNameNoExtensionNoNkit="${firstString/".nkit"/"$secondString"}"
firstString=$romNameNoExtensionNoNkit
romNameNoExtensionNoSpace="${firstString/"!"/"$secondString"}"
firstString=$romNameNoExtensionNoSpace
if [ $startcapture == true ]; then
hasWheel=false
hasSs=false
hasBox=false
hasMetadata=false
FILE=~/storage/$storageLocation/$system/media/wheel/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasWheel=true
fi
FILE=~/storage/$storageLocation/$system/media/screenshot/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasSs=true
fi
FILE=~/storage/$storageLocation/$system/media/box2dfront/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasBox=true
fi
if [[ $systemMetadata == "" ]] || [[ $systemMetadata == *"game: $romNameNoExtensionTrimmed"* ]]; then
hasMetadata=true
fi
#We only search games with no art or metadata
if [ $hasWheel == false ] || [ $hasSs == false ] || [ $hasBox == false ] || ([ $hasMetadata == false ] && [ $saveMetadata == true ]); then
#Second Scan: Screenscraper
url="https://www.screenscraper.fr/api2/jeuInfos.php?devid=djrodtc&devpassword=diFay35WElL&softname=zzz&output=json&ssid=${userSS}&sspassword=${passSS}&crc=&systemeid=${ssID}&romtype=rom&romnom=${romNameNoExtensionNoSpace}.zip"
#ID Game
content=$(curl "$url")
#Don't check art if screenscraper is closed
if [[ $content == *"API closed"* ]]; then
echo -e "The Screenscraper API is currently down, please try again later."
echo -e "Press the ${RED}A button${NONE} to finish"
read pause
am startservice -a com.termux.service_stop com.termux/.app.TermuxService &> /dev/null
fi
#Don't check art after a failed curl request
if [[ $content == "" ]]; then
echo -e "Request failed to send for $romNameNoExtensionTrimmed, ${YELLOW}skipping${NONE}"
echo ""
echo "Request failed for $romNameNoExtensionTrimmed" >> ~/storage/shared/scrap.log
continue;
fi
#Don't check art if screenscraper can't find a match
if [[ $content == *"Erreur"* ]]; then
echo -e "Couldn't find a match for $romNameNoExtensionTrimmed, ${YELLOW}skipping${NONE}"
echo ""
echo "Couldn't find a match for $romNameNoExtensionTrimmed" >> ~/storage/shared/scrap.log
continue;
fi
gameIDSS=$( jq -r '.response.jeu.id' <<< "${content}" )
urlMediaWheel="https://www.screenscraper.fr/api2/mediaJeu.php?devid=djrodtc&devpassword=diFay35WElL&softname=zzz&ssid=${userSS}&sspassword=${passSS}&crc=&md5=&sha1=&systemeid=${ssID}&jeuid=${gameIDSS}&media=wheel(wor)"
urlMediaWheelHD="https://www.screenscraper.fr/api2/mediaJeu.php?devid=djrodtc&devpassword=diFay35WElL&softname=zzz&ssid=${userSS}&sspassword=${passSS}&crc=&md5=&sha1=&systemeid=${ssID}&jeuid=${gameIDSS}&media=wheel-hd(wor)"
urlMediaSs="https://www.screenscraper.fr/api2/mediaJeu.php?devid=djrodtc&devpassword=diFay35WElL&softname=zzz&ssid=${userSS}&sspassword=${passSS}&crc=&md5=&sha1=&systemeid=${ssID}&jeuid=${gameIDSS}&media=ss(wor)"
urlMediaBox="https://www.screenscraper.fr/api2/mediaJeu.php?devid=djrodtc&devpassword=diFay35WElL&softname=zzz&ssid=${userSS}&sspassword=${passSS}&crc=&md5=&sha1=&systemeid=${ssID}&jeuid=${gameIDSS}&media=box-2D(wor)"
wheelSavePath="./storage/$storageLocation/$system/media/wheel/$romNameNoExtension.png"
ssSavePath="./storage/$storageLocation/$system/media/screenshot/$romNameNoExtension.png"
box2dfrontSavePath="./storage/$storageLocation/$system/media/box2dfront/$romNameNoExtension.png"
echo -e "Downloading Images for $romNameNoExtensionTrimmed - $gameIDSS"
if [ $hasWheel == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
scrap_ss "$urlMediaWheel" "$wheelSavePath" "Wheel"
fi
if [ $hasSs == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
scrap_ss "$urlMediaSs" "$ssSavePath" "Screenshot"
fi
if [ $hasBox == true ]; then
echo -e "Image already exists, ${YELLOW}ignoring${NONE}" &> /dev/null
else
scrap_ss "$urlMediaBox" "$box2dfrontSavePath" "2D Box"
fi
#Wheel HD just in case
FILE=~/storage/$storageLocation/$system/media/wheel/$romNameNoExtension.png
if [ -f "$FILE" ]; then
hasWheel=true
fi
if [ $hasWheel == true ]; then