forked from FlashpointProject/fpcurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpcurator.py
2410 lines (2034 loc) · 112 KB
/
fpcurator.py
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
#!/usr/bin/env python3
# Best way of hiding the console window
# This should be imported first to get the right console window and hide it early
try:
from ctypes import windll
CONSOLE = windll.kernel32.GetConsoleWindow()
except:
CONSOLE = None
windll = None
CONSOLE_OPEN = True
def toggle_console():
if CONSOLE and windll:
global CONSOLE_OPEN
if CONSOLE_OPEN:
windll.user32.ShowWindow(CONSOLE, 0)
CONSOLE_OPEN = False
else:
windll.user32.ShowWindow(CONSOLE, 1)
CONSOLE_OPEN = True
toggle_console()
try:
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog as tkfd
import tkinter.messagebox as tkm
import tkinterweb as tkw
import fpclib
import deviantart # pyright: ignore [reportUnusedImport] # To make sure it's included in builds
import os, sys, time
import re, json
import bs4 # pyright: ignore [reportUnusedImport] # To make sure it's included in builds
import argparse
import codecs
import base64 # pyright: ignore [reportUnusedImport] # To make sure it's included in builds?
import datetime
import functools
import pyperclip
import pathlib
import googletrans # pyright: ignore [reportUnusedImport] # To make sure it's included in builds
import qfile # pyright: ignore [reportUnusedImport] # To make sure it's included in builds
import glob
import importlib
import sqlite3
import threading
import traceback
import urllib # pyright: ignore [reportUnusedImport] # To make sure it's included in builds?
import uuid
import webbrowser
import zipfile # pyright: ignore [reportUnusedImport] # To make sure it's included in builds?
finally:
toggle_console()
import difflib
try: import Levenshtein
except: pass
HELP_HTML = """<!doctype html>
<html><body>
<h1><center>Help</center></h1>
<p>fpcurator is a collection of tools for performing certain curation tasks easier. There are four sub-tools available. Note that the tool may freeze while performing any task. All debug info on any task is printed to the console that can be shown by clicking "Toggle Log".</p>
<h2>Auto Curator</h2>
<p>The Auto Curator tool generates a bunch of partial curations based upon a list of urls containing the games to curate. The list of curatable websites is limited the site definitions in the "sites" folder next to the program. To reload all site definitions, press "Reload". To redownload your site definitions, press "Redownload".<br>
<b>NOTE: Auto curated games should ALWAYS be tested in Flashpoint Core before being submitted.</b>
<br>Here are a list of options:
<ul>
<li><b>Save</b> - When checked, the auto curator will save it's progress so if it fails from an error, the tool will resume where it left off given the same urls.</li>
<li><b>Use Titles</b> - When checked, the auto curator will use the titles of curated games instead of randomly generated UUIDs as the names of the folders the curations are put into.</li>
<li><b>Clear Done URLs</b> - When checked, the auto curator will clear any urls in the list when they are curated. Errored urls will remain in the list.</li>
<li><b>Notify When Done</b> - When checked, the auto curator will show a message box when it is done curating.</li>
</ul>
Here are some basic usage steps:
<ol>
<li>Select the options you want, specified by the list above, and set the output directory of these partial curations.</li>
<li>Paste the urls you want to curate into the text box, one per line.</li>
<li>Press the "Curate" button to start the curation process.</li>
</ol>
</p>
<h2>Download URLs</h2>
<p>The Download URLs tool downloads and formats a list of files from a list of urls into a collection of organized folders inside the directory specified by "Output Folder". It works in a similar way to cURLsDownloader, but is powered by fpclib. Put all the urls you want to download into the textbox and press "Download".<br>
<br>Here are a list of options:
<ul>
<li><b>Rename "web.archive.org"</b> - When checked, the downloader will put all urls downloaded from the web archive back into their original domains.</li>
<li><b>Keep URLVars</b> - When checked, the downloader will append url vars present on links being downloaded to the end of the html file. This is only necessary when you have two links to the same webpage that generate different html due to the url vars.</li>
<li><b>Clear Done URLs</b> - When checked, the downloader will clear any urls in the list when they are downloaded. Errored urls will remain in the list.</li>
<li><b>Notify When Done</b> - When checked, the downloader will show a message box when it is done downloading.</li>
<li><b>Spoof Referrer</b> - When checked, the downloader will spoof the referrer of the urls to be the url itself.</li>
</ul>
Here are some basic usage steps:
<ol>
<li>Select the options you want, specified by the list above, and set the output directory of the downloaded folders and files.</li>
<li>Paste the urls you want to download into the text box, one per line.</li>
<li>Press the "Download" button to start the download process.</li>
</ol>
</p>
<h2>Game Finder</h2>
<p>The Game Finder is an extension of the default searching feature present in Flashpoint already. Type a search query into the "Query" box and press "Search" or Enter to search for those entries within the Flashpoint database of your choice. Make sure you pick the Infinity or Ultimate database ("FlashpointFolder/Data/flashpoint.sqlite") rather than the Core one.<br>
<br>
There are buttons available to export values you have selected in the list (use Ctrl+Click or Shift+Click to select multiple) into a playlist or to just copy their titles/uuids.
<br>
Overall, the search feature works in exactly the way the default Flashpoint Search Bar does, with a few changes:
<ul>
<li>String search parts now require internal quotes to be escaped: <code>""game""</code> is wrong, but <code>"\\"game\\""</code> is right.</li>
<li>Instead of using the ":" comparison operator, you may also use the "=" or "~" operators in it's place. The "=" sign checks for an exact match to the provided text (which may be in quotes) while the "~" checks for an like match to an SQL LIKE string. These operators may also be used on keywords alone: <code>="Game"</code> and <code>=Game</code> do the same thing (check that the name of a game is exactly "Game"), but the first can accept spaces inside it.</li>
<li>Queries can be separated by an <code>OR</code> keyword that does exactly what you think it does. e.g., find all action or adventure games: <code>#Action OR #Adventure</code>. If you want to search for the text "or" exactly, just use lowercase letters as the search is case-insensitive.</li>
<li><code>AND</code> is now a keyword that basically does nothing, since two search terms right next to each other are assumed to be "AND" joined unless there's an "OR" between them. Note that you cannot group AND and OR conditions with parentheses. If you want to search for the text "and" exactly, just use lowercase letters as the search is case-insensitive.</li>
<li>The @ prefix now matches any of developer, publisher, or source instead of just developer. This means you'll get more results that you're looking for.</li>
<li>If you don't provide a field to match, the program will automatically assume you are searching for a title keyword. This will also search through alternate titles. You can also use <code>title:"thing here"</code> instead of <code>thing here</code> to exclude alternate title searching.</li>
<li>The prefixes "alt", "tags", "genre", "genres", "ser", "dev", "pub", "src", "url", "tech", "mode", "ver", "v", "date", "lang", "desc", "app", and "cmd" are available to be used in place of their longer counterparts like launchCommand and applicationPath to make searching easier.</li>
</ul>
</p>
<h2>Curation DeDuper</h2>
<p>When pointed to a folder containing a bunch of curations, the curation deduper will show you (generally) how likely it is that each of them individually is in Flashpoint. Make sure the database is set to the Infinity/Ultimate database and not the Core one. The deduper first checks to see if the launch command is already in Flashpoint, then it checks the source url, and finally it checks the title. Only launch command and source url matches are confirmed duplicates. If any of your curations are from the same exact source as a game in Flashpoint, they will be marked as duplicates; turn off this feature with the checkbox if you are curating games from a disk or someplace that has multiple games per the same source (should not happen with normal games, which ought to use the webpage url)
<br>Here are some basic usage steps:
<ol>
<li>Set the database to your Infinity/Ultimate database.</li>
<li>Set the curations folder to your Curations/Working folder, wherever that may be (hopefully it's in Core).</li>
<li>Select whether or not to check sources.</li>
<li>Press the check button to check for duplicates.</li>
<li>Select the items you want to delete and delete them, or copy their titles so you can search in Flashpoint or fpcurator for duplicates.</li>
</ol>
</p>
<h2>Bulk Search Titles</h2>
<p>The Bulk Search Titles tool can take a list of titles and a list of urls for those titles and bulk check how likely it is those entries are in Flashpoint. You will need to load the Flashpoint database for it to check through, in addition to providing regexes that will be used to check if entries in Flashpoint have the right Source, Publisher, or Developer that would match a title in the list. Note that this will cache the database for later use, so if you want to reload it you'll need to either delete the file "search/database.tsv" or press "Load" on the database again.<br>
<br>Here are a list of options:
<ul>
<li><b>Priorities</b> - When checked, the searcher will generate a list of numeric priorities and print them into a file named "priorities.txt" next to the program. This is mainly used for copying into a spreadsheet.</li>
<li><b>Log</b> - When checked, the searcher will generate a more human readable log displaying how likely each it is those games are in Flashpoint.</li>
<li><b>Strip Subtitles</b> - When checked, titles will be stripped of subtitles when searching for them in Flashpoint.</li>
<li><b>Exact Url Matches</b> - When unchecked, the searcher will skip checking for exact url matches for a game match in Flashpoint. Normally an exact url match is a very good indicator if a game is curated, but this is optional in case multiple games are on the same url.</li>
<li><b>Use difflib</b> - When checked, the searcher will use the default python difflib instead of the fast and efficient python-Levenshtein.</li>
</ul>
Here are some basic usage steps:
<ol>
<li>Select the Flashpoint database, located in your Flashpoint folder under "/Data/flashpoint.sqlite".</li>
<li>Select the options you want, specified by the list above.</li>
<li>Type in a source regex that would match the source of any game in Flashpoint that comes from the same location as those in the list. The regex match is case-insensitive.</li>
<li>Type in a developer/publisher regex that would match the developer/publisher of any game in Flashpoint that comes from the same location as those in the list. Note that developers/publishers are stripped of all non-alphanumeric characters (except semicolons) and are set to lowercase ("Cool-Math-Games.com" becomes "coolmathgamescom"), so the match is case-insensitive.</li>
<li>Copy and paste the <b>TITLES</b> of entries to search with in the <b>LEFT</b> box, one per line.</li>
<li>Copy and paste the <b>URLS</b> of entries to search with in the <b>RIGHT</b> box, one per line.</li>
<li>Press the "Search" button to initiate the search. When the search is done the generated "log.txt" and/or "priorities.txt" files will be automatically opened if you chose to generate them.</li>
</ol>
Here's what each of the priorities mean:
<ul>
<table>
<tr><td><b> -1 </b></td><td>Duplicate</td></tr>
<tr><td><b> 5 </b></td><td>Exact url matches with the source of a game in Flashpoint</td></tr>
<tr><td><b> 4.9 </b></td><td>Exact url matches ignoring protocol and extra source data (like Via. Wayback)</td></tr>
<tr><td><b> 4.8 </b></td><td>Title matches with a game that is from the same source/developer/publisher</td></tr>
<tr><td><b> 4.3 </b></td><td>Title starts the title of a game from the same source/developer/publisher (and is >10 characters long)</td></tr>
<tr><td><b> 4.0 </b></td><td>Title matches with a game in Flashpoint (may not be accurate for common names of games like Chess)</td></tr>
<tr><td><b> 3.9 </b></td><td>Title starts the title of a game in Flashpoint (and is >10 characters long)</td></tr>
<tr><td><b> 3.8 </b></td><td>Title is in the title of a game in Flashpoint (and is >10 characters long)</td></tr>
<tr><td><b> 3.6-3.8 </b></td><td>This game has a very high (>95%) metric, meaning it matches with another title that probably has 1 or 2 letters different.</td></tr>
<tr><td><b> 3-3.6 </b></td><td>This game has a medium to high metric (85-95%), meaning it kind of matches with games in Flashpoint but not really.</td></tr>
<tr><td><b> 1-3 </b></td><td>Basically every other metric (60-85%). 60% is the highest match of garbage letters.</td></tr>
</table>
</ul>
</p>
<h2>Wiki Data</h2>
<p>The Wiki Data tool provides you with the ability to get a list of all Tags, Platforms, Games, or Animations in Flashpoint. Just select the given page you want the data of and press "Find".</p>
</body></html>"""
HEADINGS = ['TABLE OF CONTENTS', 'SUMMARY', 'DUPLICATE NAMES', 'DEFINITELY IN FLASHPOINT', 'PROBABLY IN FLASHPOINT', 'MAYBE IN FLASHPOINT', 'PROBABLY NOT IN FLASHPOINT', 'DEFINITELY NOT IN FLASHPOINT']
TEXTS = {
'header': 'Search performed on %s\nDISCLAIMER: ALWAYS CHECK THE MASTER LIST AND DISCORD CHANNEL BEFORE CURATING, EVEN IF SOMETHING IS LISTED HERE AS NOT CURATED\n\n',
'divider': '--------------- %s ---------------\n',
'line': '-----------------------------------\n',
'tbc.note': 'Note: use CTRL+F to find these sections quickly.\n\n',
'info.numerics': ' (%d - %.3f%%)',
'sum.totalgames': '%d Games Total',
'sum.titlematch': '%d games match titles',
'sum.sourcematch': '%d games are from the same source/developer/publisher as the list',
'sum.either': '%d games match either query',
'sum.lowmetric': '%d games have a very low similarity metric',
'sum.priority': '%d games (%.3f%%) probably need curating',
'sum.priority2': '%d games (%.3f%%) definitely need curating',
'dup.note': 'These are a list of games that have been omitted from the search because they share the same name with another game in the list',
'p5.exacturl': 'Exact url matches',
'p5.partialurl': 'Exact url matches ignoring protocol and extra source data (like Via. Wayback)',
'p5.titleandsdp': 'Title matches with a game that is from the same source/developer/publisher',
'p4.titlestartsandssdp': 'Title starts the title of a game from the same source/developer/publisher (and is >10 characters long)',
'p4.titleonly': 'Title matches',
'p4.titlestartstitle': 'Title is in the title of a game in Flashpoint (and is >10 characters long)',
'p4.titleintitle': 'Title is in the title of a game in Flashpoint (and is >10 characters long)',
'p4.highmetric': 'Has a high similarity metric (>95%)',
'p3.leftovers': 'Leftovers',
'p3.leftovers2': 'These are the games that didn\'t match any query',
'p2.lowmetric': 'Has a low similarity metric (<85%)',
'p1.verylowmetric': 'Has a very low similarity metric (<75%)'
}
FIELDS = {
"alt": "alternateTitles",
"#": "tags",
"tag": "tags",
"genre": "tags",
"genres": "tags",
"ser": "series",
"dev": "developer",
"pub": "publisher",
"src": "source",
"url": "source",
"!": "platform",
"tech": "platform",
"mode": "playMode",
"ver": "version",
"v": "version",
"date": "releaseDate",
"lang": "language",
"desc": "description",
"app": "applicationPath",
"cmd": "launchCommand"
}
# This uuid uniquely defines fpcurator. (there is a 0 on the end after the text)
UUID = '51be8a01-3307-4103-8913-c2f70e64d83'
TITLE = "fpcurator v1.7.2"
ABOUT = "Created by Zach K - v1.7.2"
VER = 7
SITES_FOLDER = "sites"
fpclib.DEBUG_LEVEL = 4
AM_PATTERN = re.compile(r'[\W_]+')
AMS_PATTERN = re.compile(r'([^\w;]|_)+')
INV = re.compile(r'[^\w ]+')
QPARSER = re.compile(r'\s*(-)?(?:(@|#|!)(:|=|~)?|(\w*)(:|=|~))?(?:"([^"\\]+|\\\\|\\.)*"|([^\s]+))')
SPACES = re.compile(r'\s+')
MAINFRAME = None
DEFS_GOTTEN = False
def set_entry(entry, data):
entry.delete(0, "end")
entry.insert(0, data)
def printfl(data):
print(data, end="", flush=True)
frozen_ui = False
def freeze(subtitle):
global frozen_ui
frozen_ui = True
MAINFRAME.freeze(subtitle)
def unfreeze():
global frozen_ui
frozen_ui = False
def edit_file(file):
webbrowser.open(file)
def print_err(pre="", start=1, e=None):
if e:
tb_lines = traceback.format_exception(e.__class__, e, e.__traceback__)
else:
tb_lines = traceback.format_exception(*sys.exc_info())
lines = []
for tb_line in tb_lines[start:]:
for line in tb_line.split("\n"):
if line:
if line[0] == " ": lines.append(line[2:])
else: lines.append(line)
for line in lines:
print(pre + line)
class Mainframe(tk.Tk):
def __init__(self):
# Create window
super().__init__()
self.minsize(695, 650)
self.title(TITLE)
try:
filepath = pathlib.Path(__file__)
icons = [*filepath.parent.glob("**/icon.png")]
if len(icons) > 0:
self.iconphoto(True, tk.PhotoImage(file=icons[0]))
else:
self.iconphoto(True, tk.PhotoImage(file="icon.png"))
except Exception:
fpclib.debug('Could not find fpcurator icon', 1, pre='[ERR] ')
self.protocol("WM_DELETE_WINDOW", self.exit_window)
# Cross-window variables
self.database = tk.StringVar()
# Add tabs
self.tabs = ttk.Notebook(self)
self.tabs.pack(expand=True, fill="both", padx=5, pady=5)
self.tabs.bind("<<NotebookTabChanged>>", self.tab_change)
self.autocurator = AutoCurator(self)
self.downloader = Downloader(self)
self.searcher = Searcher(self)
self.ssearcher = SingleSearcher(self)
self.deduper = DeDuper(self)
self.lister = Lister(self)
self.tabs.add(self.autocurator, text="Auto Curator")
self.tabs.add(self.downloader, text="Download URLs")
self.tabs.add(self.ssearcher, text="Game Finder")
self.tabs.add(self.deduper, text="Curation DeDuper")
self.tabs.add(self.searcher, text="Bulk Search Titles")
self.tabs.add(self.lister, text="Wiki Data")
# Add help and about label
bframe = tk.Frame(self)
bframe.pack(expand=False, padx=5, pady=(0, 5))
label = ttk.Label(bframe, text=ABOUT)
label.pack(side="left")
help_button = ttk.Button(bframe, text="Help", command=self.show_help)
help_button.pack(side="left", padx=5)
log_button = ttk.Button(bframe, text="Toggle Log", command=toggle_console)
log_button.pack(side="left")
# Add debug level entry
self.debug_level = tk.StringVar()
self.debug_level.set(str(fpclib.DEBUG_LEVEL))
self.debug_level.trace("w", self.set_debug_level)
dlabel = ttk.Label(bframe, text=" Debug Level: ")
dlabel.pack(side="left")
debug_level = ttk.Entry(bframe, textvariable=self.debug_level)
debug_level.pack(side="left")
# Exists to prevent more than one of a window from opening at a time
self.help = None
# Load GUI state from last close
self.load()
self.save()
# Get autocurator site definitions
self.autocurator.reload()
# Setup timer for unfreeze events
self.frozen = False
self.after(100, self.check_freeze)
def tab_change(self, _event):
tab = self.tabs.select()
if tab == ".!autocurator":
self.autocurator.stxt.txt.focus_set()
elif tab == ".!downloader":
self.downloader.stxt.txt.focus_set()
elif tab == ".!searcher":
self.searcher.stxta.txt.focus_set()
elif tab == ".!singlesearcher":
self.ssearcher.queryx.focus_set()
elif tab == ".!deduper":
self.focus_set()
self.save()
def check_freeze(self):
if self.frozen and not frozen_ui: self.unfreeze()
self.after(100, self.check_freeze)
def freeze(self, subtitle):
self.autocurator.curate_btn["state"] = "disabled"
self.autocurator.reload_btn["state"] = "disabled"
self.downloader.download_btn["state"] = "disabled"
self.searcher.load_btn["state"] = "disabled"
self.searcher.search_btn["state"] = "disabled"
self.ssearcher.search_btn["state"] = "disabled"
self.deduper.search_btn["state"] = "disabled"
self.lister.find_btn["state"] = "disabled"
#self.lister.stxt.txt["state"] = "disabled"
if self.ssearcher.lbox: self.ssearcher.lbox.search_btn["state"] = "disabled"
self.ssearcher.export_btn["state"] = "disabled"
self.ssearcher.export_all_btn["state"] = "disabled"
self.title(TITLE + " - " + subtitle)
self.frozen = True
def unfreeze(self):
self.autocurator.curate_btn["state"] = "normal"
self.autocurator.reload_btn["state"] = "normal"
self.downloader.download_btn["state"] = "normal"
self.searcher.load_btn["state"] = "normal"
self.searcher.search_btn["state"] = "normal"
self.ssearcher.search_btn["state"] = "normal"
self.deduper.search_btn["state"] = "normal"
self.lister.find_btn["state"] = "normal"
#self.lister.stxt.txt["state"] = "normal"
if self.ssearcher.lbox: self.ssearcher.lbox.search_btn["state"] = "normal"
self.ssearcher.export_btn["state"] = "normal"
self.ssearcher.export_all_btn["state"] = "normal"
self.title(TITLE)
self.frozen = False
def show_help(self):
if not self.help:
self.help = Help(self)
def set_debug_level(self, _name, _index, _mode):
dl = self.debug_level.get()
try:
fpclib.DEBUG_LEVEL = int(dl)
except ValueError:
fpclib.DEBUG_LEVEL = -1
def exit_window(self):
if not frozen_ui:
# TODO: Python can't stop a thread easily, so make sure nothing is running before closing.
if not CONSOLE_OPEN: toggle_console()
if self.ssearcher.lbox: self.ssearcher.lbox.exit_window()
self.save()
self.destroy()
def save(self):
autocurator = {}
downloader = {}
searcher = {}
ssearcher = {}
deduper = {}
data = {"autocurator": autocurator, "downloader": downloader, "searcher": searcher, "ssearcher": ssearcher, "deduper": deduper, "debug_level": self.debug_level.get(), "tab": self.tabs.select(), "database": self.database.get()}
# Save autocurator data
autocurator["output"] = self.autocurator.output.get()
autocurator["save"] = self.autocurator.save.get()
autocurator["silent"] = self.autocurator.silent.get()
autocurator["titles"] = self.autocurator.titles.get()
autocurator["clear"] = self.autocurator.clear.get()
autocurator["show_done"] = self.autocurator.show_done.get()
autocurator["urls"] = self.autocurator.stxt.txt.get("0.0", "end").strip()
# Save downloader data
downloader["output"] = self.downloader.output.get()
downloader["original"] = self.downloader.original.get()
downloader["keep_vars"] = self.downloader.keep_vars.get()
downloader["clear"] = self.downloader.clear.get()
downloader["show_done"] = self.downloader.show_done.get()
downloader["spoof"] = self.downloader.spoof.get()
downloader["urls"] = self.downloader.stxt.txt.get("0.0", "end").strip()
# Save searcher data
searcher["sources"] = self.searcher.sources.get()
searcher["devpubs"] = self.searcher.devpubs.get()
searcher["priorities"] = self.searcher.priorities.get()
searcher["log"] = self.searcher.log.get()
searcher["strip"] = self.searcher.strip.get()
searcher["exact_url"] = self.searcher.exact_url.get()
searcher["difflib"] = self.searcher.difflib.get()
searcher["titles"] = self.searcher.stxta.txt.get("0.0", "end").strip()
searcher["urls"] = self.searcher.stxtb.txt.get("0.0", "end").strip()
# Save ssearcher data
ssearcher["lib"] = self.ssearcher.library.get()
ssearcher["query"] = self.ssearcher.query.get()
ssearcher["lquery"] = self.ssearcher.lquery.get().strip()
ssearcher["rdata"] = self.ssearcher.rdata
# Save deduper data
deduper["src_chk"] = self.deduper.src_chk.get()
deduper["curations"] = self.deduper.curations.get()
deduper["rdata"] = self.deduper.rdata
with open("data.json", "w") as file: json.dump(data, file)
def load(self):
try:
with open("data.json", "r") as file: data = json.load(file)
# Set basic data
self.debug_level.set(data["debug_level"])
self.tabs.select(data["tab"])
self.database.set(data["database"])
autocurator = data["autocurator"]
downloader = data["downloader"]
searcher = data["searcher"]
ssearcher = data["ssearcher"]
deduper = data["deduper"]
# Load autocurator data
set_entry(self.autocurator.output, autocurator["output"])
self.autocurator.save.set(autocurator["save"])
self.autocurator.silent.set(autocurator["silent"])
self.autocurator.titles.set(autocurator["titles"])
self.autocurator.clear.set(autocurator["clear"])
self.autocurator.show_done.set(autocurator["show_done"])
txt = self.autocurator.stxt.txt
txt.delete("0.0", "end")
txt.insert("1.0", autocurator["urls"])
# Load downloader data
set_entry(self.downloader.output, downloader["output"])
self.downloader.original.set(downloader["original"])
self.downloader.keep_vars.set(downloader["keep_vars"])
self.downloader.clear.set(downloader["clear"])
self.downloader.show_done.set(downloader["show_done"])
self.downloader.spoof.set(downloader["spoof"])
txt = self.downloader.stxt.txt
txt.delete("0.0", "end")
txt.insert("1.0", downloader["urls"])
# Load searcher data
set_entry(self.searcher.sources, searcher["sources"])
set_entry(self.searcher.devpubs, searcher["devpubs"])
self.searcher.priorities.set(searcher["priorities"])
self.searcher.log.set(searcher["log"])
self.searcher.strip.set(searcher["strip"])
self.searcher.exact_url.set(searcher["exact_url"])
self.searcher.difflib.set(searcher["difflib"])
txt = self.searcher.stxta.txt
txt.delete("0.0", "end")
txt.insert("1.0", searcher["titles"])
txt = self.searcher.stxtb.txt
txt.delete("0.0", "end")
txt.insert("1.0", searcher["urls"])
# Load ssearcher data
self.ssearcher.library.set(ssearcher["lib"])
self.ssearcher.query.set(ssearcher["query"])
self.ssearcher.lquery.set(ssearcher["lquery"])
self.ssearcher.set_results(ssearcher["rdata"])
# Load deduper data
self.deduper.src_chk.set(deduper["src_chk"])
set_entry(self.deduper.curations, deduper["curations"])
self.deduper.set_results(deduper["rdata"])
except (FileNotFoundError, KeyError):
# On first launch, check if in Flashpoint "Utilities" folder and set default data if so
dirs = [d for d in os.getcwd().replace("\\", "/").split("/") if d]
try:
if dirs[-2].lower() == "utilities" and "flashpoint" in dirs[-3].lower():
#self.database.set("../Data/flashpoint.sqlite")
set_entry(self.autocurator.output, "../../Curations/Working")
set_entry(self.deduper.curations, "../../Curations/Working")
except:
pass
class Help(tk.Toplevel):
def __init__(self, parent):
# Create window
super().__init__(bg="white")
self.title(TITLE + " - Help")
self.minsize(445, 400)
self.geometry("745x700")
self.protocol("WM_DELETE_WINDOW", self.exit_window)
self.parent = parent
# Create htmlframe for displaying help information
txt = tkw.HtmlFrame(self, messages_enabled=False)
txt.load_html(HELP_HTML)
txt.pack(expand=True, fill="both")
def exit_window(self):
self.parent.help = None
self.destroy()
class AutoCurator(tk.Frame):
def __init__(self, parent):
# Create panel
super().__init__(bg="white")
tframe = tk.Frame(self, bg="white")
tframe.pack(fill="x", padx=5, pady=5)
# Create output folder and curate button
olabel = tk.Label(tframe, bg="white", text="Output Folder:")
olabel.pack(side="left", padx=5)
self.output = ttk.Entry(tframe)
self.output.insert(0, "output")
self.output.pack(side="left", fill="x", expand=True)
folder = ttk.Button(tframe, text="...", width=3, command=self.folder)
folder.pack(side="left")
self.curate_btn = ttk.Button(tframe, text="Curate", command=self.curate)
self.curate_btn.pack(side="left", padx=5)
# Create checkboxes
cframe = tk.Frame(self, bg="white")
cframe.pack(padx=5)
self.save = tk.BooleanVar()
self.save.set(True)
self.silent = tk.BooleanVar()
self.silent.set(True)
self.titles = tk.BooleanVar()
self.titles.set(True)
self.clear = tk.BooleanVar()
self.clear.set(True)
self.show_done = tk.BooleanVar()
self.show_done.set(True)
save = tk.Checkbutton(cframe, bg="white", text='Save', var=self.save) # pyright: ignore [reportCallIssue] # tkinter does have "var"
save.pack(side="left", padx=5)
#silent = tk.Checkbutton(cframe, bg="white", text="Silent", var=self.silent)
#silent.pack(side="left", padx=5)
titles = tk.Checkbutton(cframe, bg="white", text="Use Titles", var=self.titles) # pyright: ignore [reportCallIssue] # tkinter does have "var"
titles.pack(side="left")
clear = tk.Checkbutton(cframe, bg="white", text="Clear Done URLs", var=self.clear) # pyright: ignore [reportCallIssue] # tkinter does have "var"
clear.pack(side="left", padx=5)
show_done = tk.Checkbutton(cframe, bg="white", text='Notify When Done', var=self.show_done) # pyright: ignore [reportCallIssue] # tkinter does have "var"
show_done.pack(side="left")
Tooltip(save, text="When checked, the auto curator will save it's progress so if it fails from an error, the tool will resume where it left off given the same urls.")
#Tooltip(silent, text="")
Tooltip(titles, text="When checked, the auto curator will use the titles of curated games instead of randomly generated UUIDs as the names of the folders the curations are put into.")
Tooltip(clear, text="When checked, the auto curator will clear any urls in the list when they are curated. Errored urls will remain in the list.")
Tooltip(show_done, text="When checked, the auto curator will show a message box when it is done curating.")
# Create site definition display
dframe = tk.Frame(self, bg="white")
dframe.pack()
self.defcount = tk.StringVar()
self.defcount.set("0 site definitions found")
defcount = tk.Label(dframe, bg="white", textvariable=self.defcount)
defcount.pack(side="left")
self.reload_btn = ttk.Button(dframe, text="Reload", command=self.reload)
self.reload_btn.pack(side="left", padx=5)
self.update_btn = ttk.Button(dframe, text="Redownload", command=self.update_online)
self.update_btn.pack(side="left")
# Create panel for inputting urls
lbl = tk.Label(self, bg="white", text=" Put URLs to curate in this box:")
lbl.pack(fill="x")
self.stxt = ScrolledText(self, width=10, height=10, wrap="none")
self.stxt.pack(expand=True, fill="both", padx=5, pady=5)
def folder(self):
# For changing the output folder
folder = tkfd.askdirectory()
if folder:
self.output.delete(0, "end")
self.output.insert(0, folder)
@staticmethod
def download_defs(data: str, silent=False):
print("[INFO] Downloading site definitions from online")
global DEFS_GOTTEN
DEFS_GOTTEN = True
# Delete sites folder if it exists
fpclib.delete(SITES_FOLDER)
# Get defs.txt
fpclib.write(SITES_FOLDER+"/defs.txt", data)
# Get definition file names from url
files = data.replace("\r\n", "\n").replace("\r", "\n").split("\n")[1:]
# Compile file names into urls to download
urls = ["https://github.com/FlashpointProject/fpcurator/raw/main/sites/" + f for f in files]
# Download urls
for i in range(len(urls)):
fpclib.write(SITES_FOLDER+"/"+files[i], fpclib.read_url(urls[i]))
# Tell the user to restart the program (because python doesn't like to load newly created python files as modules)
if not silent:
tkm.showinfo(message="Definitions downloaded. Restart the program to load them. The program will now exit.")
sys.exit(0)
@staticmethod
def get_defs(silent=False):
# Query to download site definitions from online.
global DEFS_GOTTEN
if not silent and not DEFS_GOTTEN:
DEFS_GOTTEN = True
local_timestamp, online_timestamp = 0, 1
try:
data = fpclib.read_url("https://github.com/FlashpointProject/fpcurator/raw/main/sites/defs.txt")
online_timestamp = float(data.splitlines()[0])
local_timestamp = float(fpclib.read(SITES_FOLDER+"/defs.txt").splitlines()[0])
except: pass
try:
if local_timestamp < online_timestamp and tkm.askyesno(message="The Auto Curator's site definitions are out of date, would you like to redownload them from online? (you won't be able to use the Auto Curator fully without them)"):
AutoCurator.download_defs(data, silent)
except Exception:
pass
defs = []
priorities = {}
# Parse for site definitions
fpclib.debug('Parsing for site definitions', 1)
fpclib.TABULATION += 1
sys.path.insert(0, SITES_FOLDER)
for py_file in glob.glob(os.path.join(SITES_FOLDER, '*.py')):
try:
name = py_file[py_file.replace('\\', '/').rfind('/')+1:-3]
m = importlib.import_module(name)
importlib.reload(m)
priorities[name] = m.priority if hasattr(m, "priority") else 0
if getattr(m, "ver", VER) <= VER:
defs.append((m.regex, getattr(m, name)))
fpclib.debug('Found definition "{}"', 1, name)
else:
fpclib.debug('Definition "{}" is not supported. Update fpcurator!', 1, name)
except:
fpclib.debug('Skipping definition "{}", error:', 1, name)
print_err(" " * fpclib.TABULATION + " ", 2)
sys.path.pop(0)
fpclib.TABULATION -= 1
# Print count of site definitions
if defs: defs.sort(key=lambda x: priorities[x[1].__name__], reverse=True)
else:
if not silent:
fpclib.debug('No valid site-definitions were found', 1)
return defs
def reload(self):
# Initialize defs and priorities
self.defs = AutoCurator.get_defs()
self.defcount.set(f"{len(self.defs)} site defintitions found")
def update_online(self):
# Get defs and download
data = fpclib.read_url("https://github.com/FlashpointProject/fpcurator/raw/main/sites/defs.txt")
AutoCurator.download_defs(data, False)
@staticmethod
def s_curate(output, defs, urls, titles, save, ignore_errs):
cwd = os.getcwd()
fpclib.make_dir(output, True)
errs = fpclib.curate_regex(urls, defs, use_title=titles, save=save, ignore_errs=ignore_errs, config="clients.txt", config_paths=[os.path.dirname(__file__)])
os.chdir(cwd)
# Print errors
if errs:
print("[ERR] These urls failed to be curated:")
for url, e, _ in errs:
print(f" {url}:")
print_err(" ", 3, e)
return errs
def i_curate(self):
try:
txt = self.stxt.txt
# Get urls and curate them with all site definitions
urls = [i.strip() for i in txt.get("0.0", "end").replace("\r\n", "\n").replace("\r", "\n").split("\n") if i.strip()]
if len(urls) < 1:
tkm.showerror(message="No urls provided to curate!")
unfreeze()
return
errs = AutoCurator.s_curate(self.output.get(), self.defs, urls, self.titles.get(), self.save.get(), self.silent.get())
if self.show_done.get():
if errs:
if len(errs) == len(urls):
tkm.showerror(message=f"All {len(errs)} urls could not be curated.")
else:
tkm.showinfo(message=f"Successfully curated {len(urls)-len(errs)}/{len(urls)} urls.\n\n{len(errs)} urls could not be downloaded.")
else:
tkm.showinfo(message=f"Successfully curated {len(urls)} urls.")
if self.clear.get():
txt.delete("0.0", "end")
if errs: txt.insert("1.0", "\n".join([i for i, e, s in errs]))
finally:
unfreeze()
def curate(self):
freeze("AutoCurating URLs")
threading.Thread(target=self.i_curate, daemon=True).start()
class Downloader(tk.Frame):
def __init__(self, parent):
# Create panel
super().__init__(bg="white")
tframe = tk.Frame(self, bg="white")
tframe.pack(fill="x", padx=5, pady=5)
# Create output folder and curate button
olabel = tk.Label(tframe, bg="white", text="Output Folder:")
olabel.pack(side="left", padx=5)
self.output = ttk.Entry(tframe)
self.output.insert(0, "output")
self.output.pack(side="left", fill="x", expand=True)
folder = ttk.Button(tframe, text="...", width=3, command=self.folder)
folder.pack(side="left")
self.download_btn = ttk.Button(tframe, text="Download", command=self.download)
self.download_btn.pack(side="left", padx=5)
# Create checkboxes
cframe = tk.Frame(self, bg="white")
cframe.pack(padx=5)
#c2frame = tk.Frame(self, bg="white")
#c2frame.pack(padx=5, pady=5)
self.keep_vars = tk.BooleanVar()
self.clear = tk.BooleanVar()
self.clear.set(True)
self.show_done = tk.BooleanVar()
self.show_done.set(True)
self.original = tk.BooleanVar()
self.original.set(True)
self.replace_https = tk.BooleanVar()
self.replace_https.set(True)
self.spoof = tk.BooleanVar()
self.spoof.set(True)
original = tk.Checkbutton(cframe, bg="white", text='Rename "web.archive.org"', var=self.original) # pyright: ignore [reportCallIssue] # tkinter does have "var"
original.pack(side="left")
keep_vars = tk.Checkbutton(cframe, bg="white", text="Keep URLVars", var=self.keep_vars) # pyright: ignore [reportCallIssue] # tkinter does have "var"
keep_vars.pack(side="left", padx=5)
clear = tk.Checkbutton(cframe, bg="white", text="Clear Done URLs", var=self.clear) # pyright: ignore [reportCallIssue] # tkinter does have "var"
clear.pack(side="left")
show_done = tk.Checkbutton(cframe, bg="white", text='Notify When Done', var=self.show_done) # pyright: ignore [reportCallIssue] # tkinter does have "var"
show_done.pack(side="left", padx=5)
spoof = tk.Checkbutton(cframe, bg="white", text='Spoof Referrer', var=self.spoof) # pyright: ignore [reportCallIssue] # tkinter does have "var"
spoof.pack(side="left")
Tooltip(original, text="When checked, the downloader will put all urls downloaded from the web archive back into their original domains.")
Tooltip(keep_vars, text="When checked, the downloader will append url vars present on links being downloaded to the end of the html file. This is only necessary when you have two links to the same webpage that generate different html due to the url vars.")
Tooltip(clear, text="When checked, the downloader will clear any urls in the list when they are downloaded. Errored urls will remain in the list.")
Tooltip(show_done, text="When checked, the downloader will show a message box when it is done downloading.")
Tooltip(spoof, text="When checked, the downloader will spoof the referrer of the urls to be the url itself.")
# Panels
lbl = tk.Label(self, bg="white", text="Put URLs to download at the top and headers at the bottom.")
lbl.pack(fill="x")
txts = tk.Frame(self, bg="white")
txts.pack(expand=True, fill="both", padx=5, pady=(0, 5))
self.stxt = ScrolledText(txts, width=10, height=10, wrap="none")
self.stxt.pack(side="top", expand=True, fill="both")
self.stxt_headers = ScrolledText(txts, width=10, height=10, wrap="none")
self.stxt_headers.pack(side="top", expand=False, fill="both")
def folder(self):
# For changing the output directory
folder = tkfd.askdirectory()
if folder:
self.output.delete(0, "end")
self.output.insert(0, folder)
def i_download(self):
txt = self.stxt.txt
htxt = self.stxt_headers.txt
try:
headers = {}
for key, value in [i.strip().split("=", 1) for i in htxt.get("0.0", "end").replace("\r\n", "\n").replace("\r", "\n").split("\n") if i.strip()]:
headers[key.strip()] = value.strip()
links = [i.strip() for i in txt.get("0.0", "end").replace("\r\n", "\n").replace("\r", "\n").split("\n") if i.strip()]
if links:
errs = fpclib.download_all(links, self.output.get() or "output", not self.original.get(), self.keep_vars.get(), True, spoof=self.spoof.get(), headers=headers)
if self.show_done.get():
if errs:
if len(errs) == len(links):
tkm.showerror(message=f"All {len(errs)} urls could not be downloaded.")
else:
tkm.showinfo(message=f"Successfully downloaded {len(links)-len(errs)}/{len(links)} files.\n\n{len(errs)} urls could not be downloaded.")
else:
tkm.showinfo(message=f"Successfully downloaded {len(links)} files.")
if self.clear.get():
txt.delete("0.0", "end")
if errs:
txt.insert("1.0", "\n".join([i for i, e in errs]))
else:
tkm.showinfo(message="You must specify at least one url to download.")
except Exception as e:
print("[ERR] Failed to download urls, err ")
print_err(" ")
tkm.showerror(message=f"Failed to download urls.\n{e.__class__.__name__}: {str(e)}")
unfreeze()
def download(self):
freeze("Downloading URLs")
threading.Thread(target=self.i_download, daemon=True).start()
class Searcher(tk.Frame):
def __init__(self, parent):
# Create panel
super().__init__(bg="white")
tframe = tk.Frame(self, bg="white")
tframe.pack(fill="x", padx=5, pady=5)
self.parent = parent
# Create options for locating the Flashpoint database
dlabel = tk.Label(tframe, bg="white", text="Database:")
dlabel.pack(side="left", padx=5)
self.database = ttk.Entry(tframe, textvariable=parent.database)
self.database.pack(side="left", fill="x", expand=True)
db = ttk.Button(tframe, text="...", width=3, command=self.get_database)
db.pack(side="left", padx=(0, 5))
self.load_btn = ttk.Button(tframe, text="Load", command=self.load)
self.load_btn.pack(side="left")
self.search_btn = ttk.Button(tframe, text="Search", command=self.search)
self.search_btn.pack(side="left", padx=5)
# Create entries for regexs
rframe = tk.Frame(self, bg="white")
rframe.pack(fill="x", padx=5)
slabel = tk.Label(rframe, bg="white", text="Source Regex:")
slabel.pack(side="left", padx=5)
self.sources = ttk.Entry(rframe)
self.sources.pack(side="left", expand=True, fill="x")
dplabel = tk.Label(rframe, bg="white", text="Dev/Pub Regex:")
dplabel.pack(side="left", padx=5)
self.devpubs = ttk.Entry(rframe)
self.devpubs.pack(side="left", expand=True, fill="x", padx=(0, 5))
# Create checkboxes
cframe = tk.Frame(self, bg="white")
cframe.pack(padx=5)
self.priorities = tk.BooleanVar()
self.priorities.set(True)
self.log = tk.BooleanVar()
self.log.set(True)
self.strip = tk.BooleanVar()
self.exact_url = tk.BooleanVar()
self.exact_url.set(True)
self.difflib = tk.BooleanVar()
priorities = tk.Checkbutton(cframe, bg="white", text="Priorities", var=self.priorities) # pyright: ignore [reportCallIssue] # tkinter does have "var"
priorities.pack(side="left")
log = tk.Checkbutton(cframe, bg="white", text="Log", var=self.log) # pyright: ignore [reportCallIssue] # tkinter does have "var"
log.pack(side="left", padx=5)
strip = tk.Checkbutton(cframe, bg="white", text="Strip Subtitles", var=self.strip) # pyright: ignore [reportCallIssue] # tkinter does have "var"
strip.pack(side="left")
exact_url = tk.Checkbutton(cframe, bg="white", text="Exact Url Matches", var=self.exact_url) # pyright: ignore [reportCallIssue] # tkinter does have "var"
exact_url.pack(side="left", padx=5)
difflib = tk.Checkbutton(cframe, bg="white", text="Use difflib", var=self.difflib) # pyright: ignore [reportCallIssue] # tkinter does have "var"
difflib.pack(side="left")
Tooltip(priorities, text='When checked, the searcher will generate a list of numeric priorities and print them into a file named "priorities.txt" next to the program. This is mainly used for copying into a spreadsheet.')
Tooltip(log, text="When checked, the searcher will generate a more human readable log displaying how likely each it is those games are in Flashpoint.")
Tooltip(strip, text="When checked, titles will be stripped of subtitles when searching for them in Flashpoint.")
Tooltip(exact_url, text='When unchecked, the searcher will skip checking for exact url matches for a game match in Flashpoint. Normally an exact url match is a very good indicator if a game is curated, but this is optional in case multiple games are on the same url.')
Tooltip(difflib, text="When checked, the searcher will use the default python library difflib instead of the fast and efficient python-Levenshtein.")
# Panels
lbl = tk.Label(self, bg="white", text="Put TITLES in the LEFT box and URLS in the RIGHT.")
lbl.pack(fill="x")
txts = tk.Frame(self, bg="white")
txts.pack(expand=True, fill="both", padx=5, pady=(0, 5))
self.stxta = ScrolledText(txts, width=10, height=10, wrap="none")
self.stxta.pack(side="left", expand=True, fill="both")
self.stxtb = ScrolledText(txts, width=10, height=10, wrap="none")
self.stxtb.pack(side="left", expand=True, fill="both")
def get_database(self):
# For changing the flashpoint database location
db = tkfd.askopenfilename(filetypes=[("SQLite Database", "*.sqlite")])
if db: self.parent.database.set(db)
@staticmethod
def s_load(dbloc, silent=False):
try:
# Acquire the database!
db = sqlite3.connect(dbloc)
c = db.cursor()
# Next, get all required data through a query
c.execute("select id, lower(title), lower(platform), lower(alternateTitles), lower(developer), lower(publisher), source, language, title from game")
data = c.fetchall()
db.close()
# Then format the data
for i in range(len(data)):
datal = data[i]