-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIMDB_ALT.ifs
More file actions
1447 lines (1294 loc) · 55.3 KB
/
IMDB_ALT.ifs
File metadata and controls
1447 lines (1294 loc) · 55.3 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
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
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Purfview | Contributors: Elman
Title=IMDB ( via API )
Description=Imports stuff from IMDb's API
Site=https://github.com/Purfview/IMDB_ALT
Language=EN
Version=3.4.0
Requires=4.2.3
Comments=Alternative IMDb script to get info from original API. Aims to be simpler, faster & reliable.
License=MIT License||Copyright (c) 2025 Purfview||Permission is hereby granted, free of charge, to any person obtaining a copy|of this software and associated documentation files (the "Software"), to deal|in the Software without restriction, including without limitation the rights|to use, copy, modify, merge, publish, distribute, sublicense, and/or sell|copies of the Software, and to permit persons to whom the Software is|furnished to do so, subject to the following conditions:||The above copyright notice and this permission notice shall be included in all|copies or substantial portions of the Software.||THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR|IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,|FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE|AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER|LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,|OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE|SOFTWARE.|
GetInfo=1
RequiresMovies=1
[Options]
BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found|2=Same as 1, but it uses the URL field if available to update movie information
PosterImageSize=3|3|0=Don't import poster|1=x200|2=x500|3=x700|4=x1100|5=x1500|6=x2000|7=Max size
MultipleValuesCategory=1|1|0=Only take first genre for Category|1=Take all genres
MultipleValuesCountry=0|0|0=Only take first country|1=Take all countries
ActorsLimit=0|0|0=5|1=10|2=25|3=50|4=250
ActorsImage=0|0|0=Don't import|1=Import
ActorsImageSize=2|2|1=x200|2=x500|3=x700|4=x1100|5=x1500|6=x2000|7=Max size
GetCharacters=0|0|0=Do nothing|1=Pair the actors with the characters
GetCharactersFormat=0|0|0=name ... character [on separate lines]|1=name (as character) [all cast on one line]
TitleSelection=1|1|1=Retrieve max 5 titles|2=Retrieve max 10 titles|3=Retrieve max 25 titles
SearchMethod=0|0|0=Normal search|1=Fuzzy search
SearchWithYear=1|1|0=Do nothing|1=Try to search with a year (a year can be included at the end of a title)
SearchYearDeviation=1|1|0=No deviation|1=deviation by 1 year|2=deviation by 3 years
Description=0|0|0=Prefer a short summary|1=Prefer a long summary (aka Storyline)
DescriptionLanguage1st=0|0|0=English|1=German|2=French (Canada)|3=French (France)|4=Spanish (Spain)|5=Spanish (Mexico)|6=Italian|7=Portuguese|8=Japanese|9=Hindi
DescriptionLanguage2nd=0|0|0=English|1=German|2=French (Canada)|3=French (France)|4=Spanish (Spain)|5=Spanish (Mexico)|6=Italian|7=Portuguese|8=Japanese|9=Hindi
Tagline=1|1|0=Do not import tagline|1=Prepend the top tagline to Description
Trivia=0|0|0=Do not import trivia|1=Append trivia to Description|2=Append trivia to Comments|3=Replace Description with trivia|4=Replace Comments with trivia
TriviaLimit=0|0|0=1|1=10|2=25|3=50|4=250
TriviaFormat=0|0|0=Separated by blank lines|1=Without blank lines, prefixed with "-"
AKAs=0|0|0=Do nothing|1=Import all AKA titles to Translated Title field.
ShortCountryName=0|0|0=Do nothing|1=Use UK/USA
ConvertToASCII=0|0|0=Do not change special characters and accents.|1=Replace special characters and accents by basic ASCII characters
RoundRating=0|0|0=Do nothing|1=Round rating to nearest integer
[Parameters]
IMDB_userID=ur00000000|ur00000000|Your IMDb userID to get "My Rating", your ratings must be set to public.
Replace_delimiter=default|default|Your delimiter to replace default in Country, Category fields.
userCountryCode=US|US|Affects Translated Title and some other stuff. (default is US)
***************************************************)
(*************** Version History *****************************************************************************
3.4.0 - (2026/05/03) - New feature: You can now select the plot language with DescriptionLanguage1st.
DescriptionLanguage2nd is fallback if a plot with 1st language is not found.
If 2nd language is not found then it falls back to English.
3.3.0 - (2026/04/17) - Regression bugfix: Version 3.1.0 broke "Actor image importing" [3.0.0] due to a Pascal syntax typo.
3.2.0 - (2026/04/12) - Bugfix: Incorrect line break in Actors field when a character name contains a comma.
3.1.0 - (2026/04/11) - Improvement: Untie actor image importing from CanSetField(fieldActors) dependency.
3.0.0 - (2026/04/09) - New feature: Actor image importing. [new options: 'ActorsImage', 'ActorsImageSize']
Change: Renamed 'ImageSize' to 'PosterImageSize'.
Change: 'ActorsLimit' rework.
2.3.0 - (2026/04/08) - New feature: New option 'GetCharactersFormat'.
New feature: New option 'RoundRating' to round IMDB ratings to nearest integer.
Useful when "Do not display decimals..." is turned on in AMC preferences.
New feature: New option 'TriviaFormat'.
2.2.0 - (2026/04/07) - New feature: New option 'Description'. Can import a long summary (aka Storyline).
New feature: New option 'Tagline'. Can be turned off.
2.1.0 - (2026/01/31) - Fixed: AKAs didn't import a primary title.
2.0.0 - (2026/01/30) - New feature: New parameter 'userCountryCode'. Affects Translated Title, Trivia, Certification...
New feature: New option 'AKAs'. [ignores dupes and the titles with unrecognized chars]
Improvement: Import a category and other stuff for Trivia.
Improvement: Added safety in dedot for the titles containing dots originally.
Improvement: Added support for a year in brackets. ['SearchWithYear']
Fixed: Attribute wasn't added if there was no character for an actor. ['GetCharacters']
1.5.1 - (2026/01/27) - Improvement: Import attributes too when GetCharacters is enabled. [voice, uncredited, ect.]
Improvement: Remove escapes from tagline.
Improvement: Replace 'null' with 'x' if authorRating is not set in a comment.
1.5.0 - (2026/01/27) - New feature: Added Replace_delimiter parameter
New feature: Added Trivia importing
1.4.0 - (2026/01/25) - Fixed: Issues passing unicode chars in query with PostPage3() [returns nothing in normal search]
Solution: Fix the titles with UTF8EncodeToUnicodeEscapes()
The title examples to test:
"Schönberg" (www.imdb.com/title/tt0100560)
"Les Misérables" (www.imdb.com/title/tt1707386) [user report, but worked for me]
1.3.0 - (2025/12/04) - Regression bugfix: 1.1.0 broke "More options for ImageSize" [1.0.9]
1.2.0 - (2025/12/03) - New feature: Added fuzzy search. [can be enabled with 'SearchMethod' option]
- Improvement: Changed default ImageSize to 3.
1.1.0 - (2025/07/06) - Improvement: Get the most helpful review instead of "featured" nonsense.
- Moved less important options to the bottom.
- Remove the escapes from Description.
1.0.9 - (2025/07/05) - Improvement: More options for ImageSize.
1.0.8 - (2025/07/05) - Improvement: Optimized some code - now the script is 4 times faster.
1.0.7 - (2025/07/04) - Improvement: If alt versions available then add all runtimes to Description.
- Fixed bug with Comments field.
1.0.6 - (2025/07/02) - Fixed rare Cloudflare/API timeout bug by changing a credits endpoint to a faster one.
- Reworked all credits.
- Renamed CreditsLimit to ActorsLimit.
- Added support to pair the actors with the characters. [GetCharacters option]
- Improvement: Adds tagline to Description.
1.0.5 - (2025/06/29) - Added support for "My ratings" field. [IMDB_userID must be set]
- Added CreditsLimit option.
- Reworked Director/Writer/Actors.
- Fixed country errors: 'West Germany','East Germany','Soviet Union','Czechoslovakia',
'Yugoslavia','Zaire','Serbia and Montenegro','Burma'.
- Fixed country names: 'Vietnam', 'Czech Republic'.
- Fixed: The title search didn't include the adult titles.
- Fixed few other bugs.
1.0.4 - (2025/06/29) - Added support for Producer & Composer fields.
- Fixed few bugs.
1.0.3 - (2025/06/27) - Fixed: BatchMode 1/2 wasn't working properly.
- Auto-remove dots from the titles as IMDb's advanced search doesn't like them
- Removed unneeded scripts from "uses".
1.0.2 - (2025/06/27) - Fixed few country names
- Remove the escapes from Comment
1.0.1 - (2025/06/27) - File changed to UTF8 [note: AMC does not support UTF8, use UTF8Decode]
- The scripts title changed to "IMDB ( via API )"
1.0.0 - (2025/06/26) - The first public release.
*************************************************************************************************************)
program IMDB_ALT;
uses
StringUtils1;
const
Query_Search_by_Title = '{ "query": "query { advancedTitleSearch( first: replace_max_titles constraints: { titleTextConstraint:{searchTerm:\"replace_search_string\"} explicitContentConstraint: { explicitContentFilter: INCLUDE_ADULT } } ) { edges { node { title { titleText { text } releaseYear { year } titleType { text } id principalCredits { category { id } credits { name { nameText { text } } } } } } } } }" }';
Query_Search_by_Title_and_Year = '{ "query": "query { advancedTitleSearch( first: replace_max_titles constraints: { titleTextConstraint:{searchTerm:\"replace_search_string\"} explicitContentConstraint: { explicitContentFilter: INCLUDE_ADULT } releaseDateConstraint: {releaseDateRange: {start:\"replace_start_year-01-01\",end:\"replace_end_year-12-31\"}} } ) { edges { node { title { titleText { text } releaseYear { year } titleType { text } id principalCredits { category { id } credits { name { nameText { text } } } } } } } } }" }';
Query_FuzzySearch_by_Title = '{ "query": "query { mainSearch(first: replace_max_titles, options: {searchTerm: \"replace_search_string\", includeAdult: true, isExactMatch: false, type: [TITLE]}) { edges { node { entity { __typename ... on Title { id titleText { text } releaseYear { year } titleType { text } principalCredits { category { id } credits { name { nameText { text } } } } } } } } } }" }';
Query_FuzzySearch_by_Title_and_Year = '{ "query": "query { mainSearch(first: replace_max_titles, options: {searchTerm: \"replace_search_string\", includeAdult: true, isExactMatch: false, type: [TITLE], titleSearchOptions: {releaseDateRange: {start: \"replace_start_year-01-01\", end: \"replace_end_year-12-31\"}}}) { edges { node { entity { __typename ... on Title { id titleText { text } releaseYear { year } titleType { text } principalCredits { category { id } credits { name { nameText { text } } } } } } } } } }" }';
Query_ID = '{ "query": "query { title(id: \"replace_imdbid\") { id titleText { text isOriginalTitle } originalTitleText { text } releaseYear { year } titleGenres { genres { genre { text } } } runtime { seconds } countriesOfOrigin { countries { id } } certificate { rating } titleType { id } taglines(first: 1) { edges { node { text } } } plots ( replace_plot_settings ) { edges { node { language { id } plotText { plainText } } } } ratingsSummary { aggregateRating } primaryImage { url } runtimes(first: 25) { edges { node { displayableProperty { value { plainText } } seconds attributes { text } country { text } } } } credits(first: 250, filter: { categories: [\"director\", \"producer\", \"writer\", \"composer\"] }) { edges { node { category { categoryId } name { nameText { text } } } } } reviews(first: 15) { edges { node { submissionDate authorRating helpfulness { score } author { nickName } summary { originalText } text { originalText { plainText } } } } } akas ( filter: EXCLUDE_IF_SAME_AS_PRIMARY, first: 250 ) { edges { node { text } } } } }" }';
Query_userRating = '{ "query": "query { title(id: \"replace_imdbid\") { userRating(userId: \"replace_userid\") { value } } }" }';
Query_actors = '{ "query": "query { title(id: \"replace_imdbid\") { credits(first: replace_max_actors, filter: { categories: [\"cast\"] }) { edges { node { name { id nameText { text } primaryImage { url } } } } } } }" }';
Query_actors_paired = '{ "query": "query { title(id: \"replace_imdbid\") { credits(first: replace_max_actors, filter: { categories: [\"cast\"] }) { edges { node { name { id nameText { text } primaryImage { url } } ... on Cast { characters { name } attributes { __typename ... on MiscellaneousCreditAttribute { text } ... on CreditedAsCreditAttribute { creditedAs text } } } } } } } }" }';
Query_trivia = '{ "query": "query { title ( id: \"replace_imdbid\" ) { trivia ( first: replace_max_trivia ) { edges { node { displayableArticle { body { plainText } } category { text } } } } } }" }';
var
MovieName: string;
//==============================================================================
// Helping functions
//==============================================================================
function ExpandCountryCode(Code: string): string;
begin
case UpperCase(Trim(Code)) of
'AD': Result := 'Andorra';
'AE': Result := 'United Arab Emirates';
'AF': Result := 'Afghanistan';
'AG': Result := 'Antigua And Barbuda';
'AI': Result := 'Anguilla';
'AL': Result := 'Albania';
'AM': Result := 'Armenia';
'AO': Result := 'Angola';
'AQ': Result := 'Antarctica';
'AR': Result := 'Argentina';
'AS': Result := 'American Samoa';
'AT': Result := 'Austria';
'AU': Result := 'Australia';
'AW': Result := 'Aruba';
'AX': Result := 'Finland';
'AZ': Result := 'Azerbaijan';
'BA': Result := 'Bosnia And Herzegovina';
'BB': Result := 'Barbados';
'BD': Result := 'Bangladesh';
'BE': Result := 'Belgium';
'BF': Result := 'Burkina Faso';
'BG': Result := 'Bulgaria';
'BH': Result := 'Bahrain';
'BI': Result := 'Burundi';
'BJ': Result := 'Benin';
'BL': Result := 'France';
'BM': Result := 'Bermuda';
'BN': Result := 'Brunei Darussalam';
'BO': Result := 'Bolivia';
'BQ': Result := 'Sint Eustatius And Saba Bonaire';
'BR': Result := 'Brazil';
'BS': Result := 'Bahamas';
'BT': Result := 'Bhutan';
'BUMM': Result := 'Burma';
'BV': Result := 'Bouvet Island';
'BW': Result := 'Botswana';
'BY': Result := 'Belarus';
'BZ': Result := 'Belize';
'CA': Result := 'Canada';
'CC': Result := 'Cocos Islands';
'CD': Result := 'Democratic Republic Of The Congo';
'CF': Result := 'Central African Republic';
'CG': Result := 'Congo';
'CH': Result := 'Switzerland';
'CI': Result := 'Ivory Coast';
'CK': Result := 'Cook Islands';
'CL': Result := 'Chile';
'CM': Result := 'Cameroon';
'CN': Result := 'China';
'CO': Result := 'Colombia';
'CR': Result := 'Costa Rica';
'CSHH': Result := 'Czechoslovakia';
'CSXX': Result := 'Serbia and Montenegro';
'CU': Result := 'Cuba';
'CV': Result := 'Cabo Verde';
'CW': Result := 'Curacao';
'CX': Result := 'Christmas Island';
'CY': Result := 'Cyprus';
'CZ': Result := 'Czech Republic';
'DDDE': Result := 'East Germany';
'DE': Result := 'Germany';
'DJ': Result := 'Djibouti';
'DK': Result := 'Denmark';
'DM': Result := 'Dominica';
'DO': Result := 'Dominican Republic';
'DZ': Result := 'Algeria';
'EC': Result := 'Ecuador';
'EE': Result := 'Estonia';
'EG': Result := 'Egypt';
'EH': Result := 'Western Sahara';
'ER': Result := 'Eritrea';
'ES': Result := 'Spain';
'ET': Result := 'Ethiopia';
'FI': Result := 'Finland';
'FJ': Result := 'Fiji';
'FK': Result := 'Falkland Islands';
'FM': Result := 'Micronesia';
'FO': Result := 'Faroe Islands';
'FR': Result := 'France';
'GA': Result := 'Gabon';
'GB':
if GetOption('ShortCountryName') = 0 then
Result := 'United Kingdom'
else
Result := 'UK';
'GD': Result := 'Grenada';
'GE': Result := 'Georgia';
'GF': Result := 'French Guiana';
'GG': Result := 'Guernsey';
'GH': Result := 'Ghana';
'GI': Result := 'Gibraltar';
'GL': Result := 'Greenland';
'GM': Result := 'Gambia';
'GN': Result := 'Guinea';
'GP': Result := 'Guadeloupe';
'GQ': Result := 'Equatorial Guinea';
'GR': Result := 'Greece';
'GS': Result := 'South Georgia And The South Sandwich Islands';
'GT': Result := 'Guatemala';
'GU': Result := 'Guam';
'GW': Result := 'Guinea-Bissau';
'GY': Result := 'Guyana';
'HK': Result := 'Hong Kong';
'HM': Result := 'Heard Island And Mcdonald Islands';
'HN': Result := 'Honduras';
'HR': Result := 'Croatia';
'HT': Result := 'Haiti';
'HU': Result := 'Hungary';
'ID': Result := 'Indonesia';
'IE': Result := 'Ireland';
'IL': Result := 'Israel';
'IM': Result := 'Isle Of Man';
'IN': Result := 'India';
'IO': Result := 'British Indian Ocean Territory';
'IQ': Result := 'Iraq';
'IR': Result := 'Iran';
'IS': Result := 'Iceland';
'IT': Result := 'Italy';
'JE': Result := 'Jersey';
'JM': Result := 'Jamaica';
'JO': Result := 'Jordan';
'JP': Result := 'Japan';
'KE': Result := 'Kenya';
'KG': Result := 'Kyrgyzstan';
'KH': Result := 'Cambodia';
'KI': Result := 'Kiribati';
'KM': Result := 'Comoros';
'KN': Result := 'Saint Kitts And Nevis';
'KP': Result := 'North Korea';
'KR': Result := 'South Korea';
'KW': Result := 'Kuwait';
'KY': Result := 'Cayman Islands';
'KZ': Result := 'Kazakhstan';
'LA': Result := 'Laos';
'LB': Result := 'Lebanon';
'LC': Result := 'Saint Lucia';
'LI': Result := 'Liechtenstein';
'LK': Result := 'Sri Lanka';
'LR': Result := 'Liberia';
'LS': Result := 'Lesotho';
'LT': Result := 'Lithuania';
'LU': Result := 'Luxembourg';
'LV': Result := 'Latvia';
'LY': Result := 'Libya';
'MA': Result := 'Morocco';
'MC': Result := 'Monaco';
'MD': Result := 'Moldova';
'ME': Result := 'Montenegro';
'MF': Result := 'Saint Martin';
'MG': Result := 'Madagascar';
'MH': Result := 'Marshall Islands';
'MK': Result := 'North Macedonia';
'ML': Result := 'Mali';
'MM': Result := 'Myanmar';
'MN': Result := 'Mongolia';
'MO': Result := 'Macao';
'MP': Result := 'Northern Mariana Islands';
'MQ': Result := 'Martinique';
'MR': Result := 'Mauritania';
'MS': Result := 'Montserrat';
'MT': Result := 'Malta';
'MU': Result := 'Mauritius';
'MV': Result := 'Maldives';
'MW': Result := 'Malawi';
'MX': Result := 'Mexico';
'MY': Result := 'Malaysia';
'MZ': Result := 'Mozambique';
'NA': Result := 'Namibia';
'NC': Result := 'New Caledonia';
'NE': Result := 'Niger';
'NF': Result := 'Norfolk Island';
'NG': Result := 'Nigeria';
'NI': Result := 'Nicaragua';
'NL': Result := 'Netherlands';
'NO': Result := 'Norway';
'NP': Result := 'Nepal';
'NR': Result := 'Nauru';
'NU': Result := 'Niue';
'NZ': Result := 'New Zealand';
'OM': Result := 'Oman';
'PA': Result := 'Panama';
'PE': Result := 'Peru';
'PF': Result := 'French Polynesia';
'PG': Result := 'Papua New Guinea';
'PH': Result := 'Philippines';
'PK': Result := 'Pakistan';
'PL': Result := 'Poland';
'PM': Result := 'Saint Pierre And Miquelon';
'PN': Result := 'Pitcairn';
'PR': Result := 'Puerto Rico';
'PS': Result := 'Palestine';
'PT': Result := 'Portugal';
'PW': Result := 'Palau';
'PY': Result := 'Paraguay';
'QA': Result := 'Qatar';
'RE': Result := 'France';
'RO': Result := 'Romania';
'RS': Result := 'Serbia';
'RU': Result := 'Russian Federation';
'RW': Result := 'Rwanda';
'SA': Result := 'Saudi Arabia';
'SB': Result := 'Solomon Islands';
'SC': Result := 'Seychelles';
'SD': Result := 'Sudan';
'SE': Result := 'Sweden';
'SG': Result := 'Singapore';
'SH': Result := 'Saint Helena';
'SI': Result := 'Slovenia';
'SJ': Result := 'Svalbard And Jan Mayen';
'SK': Result := 'Slovakia';
'SL': Result := 'Sierra Leone';
'SM': Result := 'San Marino';
'SN': Result := 'Senegal';
'SO': Result := 'Somalia';
'SR': Result := 'Suriname';
'SS': Result := 'South Sudan';
'ST': Result := 'Sao Tome And Principe';
'SUHH': Result := 'Soviet Union';
'SV': Result := 'El Salvador';
'SX': Result := 'Sint Maarten';
'SY': Result := 'Syria';
'SZ': Result := 'Eswatini';
'TC': Result := 'Turks And Caicos Islands';
'TD': Result := 'Chad';
'TF': Result := 'French Southern Territories';
'TG': Result := 'Togo';
'TH': Result := 'Thailand';
'TJ': Result := 'Tajikistan';
'TK': Result := 'Tokelau';
'TL': Result := 'Timor-Leste';
'TM': Result := 'Turkmenistan';
'TN': Result := 'Tunisia';
'TO': Result := 'Tonga';
'TR': Result := 'Turkey';
'TT': Result := 'Trinidad And Tobago';
'TV': Result := 'Tuvalu';
'TW': Result := 'Taiwan';
'TZ': Result := 'Tanzania';
'UA': Result := 'Ukraine';
'UG': Result := 'Uganda';
'UM': Result := 'United States Minor Outlying Islands';
'US':
if GetOption('ShortCountryName') = 0 then
Result := 'United States'
else
Result := 'USA';
'UY': Result := 'Uruguay';
'UZ': Result := 'Uzbekistan';
'VA': Result := 'Holy See';
'VC': Result := 'Saint Vincent And The Grenadines';
'VE': Result := 'Venezuela';
'VG': Result := 'Virgin Islands (British)';
'VI': Result := 'Virgin Islands (U.S.)';
'VN': Result := 'Vietnam';
'VU': Result := 'Vanuatu';
'WF': Result := 'Wallis And Futuna';
'WS': Result := 'Samoa';
'XWG': Result := 'West Germany';
'XYU': Result := 'Yugoslavia';
'YE': Result := 'Yemen';
'YT': Result := 'Mayotte';
'ZA': Result := 'South Africa';
'ZRCD': Result := 'Zaire';
'ZM': Result := 'Zambia';
'ZW': Result := 'Zimbabwe';
else
begin
ShowMessage('Error: Unknown country code! Please report the error.');
Result := Code;
end;
end;
end;
function GetJsonBlock(Json, SearchStr: string): string;
var
SearchPos, BlockStart, NextOpen, NextClose, CurPos, Level: Integer;
begin
Result := '';
SearchPos := Pos(SearchStr, Json);
if SearchPos = 0 then
Exit;
BlockStart := Pos('{', Copy(Json, SearchPos, Length(Json) - SearchPos + 1));
if BlockStart = 0 then
Exit;
BlockStart := BlockStart + SearchPos - 1;
CurPos := BlockStart + 1;
Level := 1;
while Level > 0 do
begin
NextOpen := Pos('{', Copy(Json, CurPos, Length(Json) - CurPos + 1));
if NextOpen > 0 then
NextOpen := NextOpen + CurPos - 1;
NextClose := Pos('}', Copy(Json, CurPos, Length(Json) - CurPos + 1));
if NextClose > 0 then
NextClose := NextClose + CurPos - 1;
if (NextOpen > 0) and ((NextOpen < NextClose) or (NextClose = 0)) then
begin
Level := Level + 1;
CurPos := NextOpen + 1;
end
else if NextClose > 0 then
begin
Level := Level - 1;
CurPos := NextClose + 1;
end
else
Exit;
end;
Result := Copy(Json, BlockStart, CurPos - BlockStart);
end;
function ConvertToASCII(AText: string): string;
begin
Result := UTF8Decode(AText);
if Result = '' then
Result := AText; // in case of a UTF8 decoding error
if GetOption('ConvertToASCII') = 1 then
Result := Cp1252ToASCII(Result);
end;
function UTF8EncodeToUnicodeEscapes(AText: string): string;
var
firstChar, restChars, outStr: string;
d1, d2, d3, d4, CharCode: Integer;
c1, c2, c3, c4: Char;
begin
outStr := '';
while RegExprSetExec('^(.)(.*)', AText) do
begin
firstChar := RegExprMatch(1);
restChars := RegExprMatch(2);
CharCode := Ord(firstChar);
d1 := (CharCode div 4096) mod 16;
d2 := (CharCode div 256) mod 16;
d3 := (CharCode div 16) mod 16;
d4 := CharCode mod 16;
if d1 < 10 then c1 := Chr(Ord('0') + d1) else c1 := Chr(55 + d1);
if d2 < 10 then c2 := Chr(Ord('0') + d2) else c2 := Chr(55 + d2);
if d3 < 10 then c3 := Chr(Ord('0') + d3) else c3 := Chr(55 + d3);
if d4 < 10 then c4 := Chr(Ord('0') + d4) else c4 := Chr(55 + d4);
if (CharCode >= 32) and (CharCode <= 127) then
outStr := outStr + firstChar
else
outStr := outStr + '\u' + c1 + c2 + c3 + c4;
AText := restChars;
end;
UTF8EncodeToUnicodeEscapes := outStr;
end;
//==============================================================================
// Select most helpful review
//==============================================================================
function GetMostHelpfulReview(Json: string): string;
var
Block, ScoreStr: string;
Score, MaxScore: double;
begin
Result := '';
MaxScore := -1;
while true do
begin
Block := GetJsonBlock(Json, '"node"');
if Block = '' then
break;
ScoreStr := TextBetween(Block, '"score":', '}');
if (ScoreStr <> '') and (AnsiCompareStr(ScoreStr, 'null') <> 0) then
begin
Score := StrToFloat(Trim(ScoreStr));
if Score > MaxScore then
begin
MaxScore := Score;
Result := Block;
end;
end;
Json := TextAfter(Json, Block);
end;
end;
//==============================================================================
// Extract the title runtimes of the alt versions
//==============================================================================
function ExtractAllRuntimes(Json: string): string;
var
RuntimesBlock, NodeBlock, PlainText, Seconds, AttributeText, CountryText, ResultText: string;
Count: Integer;
begin
ResultText := '';
RuntimesBlock := GetJsonBlock(Json, '"runtimes":{"edges"');
/////////////////// Exit if "node" is one or zero
Count := 0;
RegExprSet('"node"');
if RegExprExec(RuntimesBlock) then
begin
Count := Count + 1;
while RegExprExecNext do
Count := Count + 1;
end;
if Count < 2 then
begin
Result := '';
Exit;
end;
///////////////////
while Pos('"node":{', RuntimesBlock) > 0 do
begin
NodeBlock := GetJsonBlock(RuntimesBlock, '"node"');
PlainText := TextBetween(NodeBlock, '"plainText":"', '"');
Seconds := TextBetween(NodeBlock, '"seconds":', ',');
if (AnsiCompareStr(Seconds, 'null') <> 0) and (Seconds <> '') then
Seconds := IntToStr(StrToInt(Seconds, 10) div 60)
else
Seconds := '0';
AttributeText := TextBetween(NodeBlock, '"attributes":[{"text":"', '"');
if AttributeText <> '' then
AttributeText := ' (' + AttributeText + ')'
else
AttributeText := '';
CountryText := TextBetween(NodeBlock, '"country":{"text":"', '"');
if CountryText <> '' then
CountryText := ' (' + CountryText + ')'
else
CountryText := '';
if ResultText <> '' then
ResultText := ResultText + #13#10;
ResultText := ResultText + PlainText + ' (' + Seconds + ' min)' + AttributeText + CountryText;
RuntimesBlock := TextAfter(RuntimesBlock, NodeBlock);
end;
Result := ResultText;
end;
//==============================================================================
// Pair Actors with Characters
//==============================================================================
function PairActorsWithCharacters(Json: string): string;
var
OneCredit, Actor, CharacterBlock, Character, CharacterList, AttributesBlock, AttributesList, Attribute: string;
begin
Result := '';
while Pos('{', Json) > 0 do
begin
OneCredit := GetJsonBlock(Json, '"node"');
Actor := TextBetween(OneCredit, '"nameText":{"text":"', '"');
if Pos('"characters":null', OneCredit) > 0 then
begin
CharacterList := '';
end else
begin
CharacterBlock := TextBetween(OneCredit, '"characters":[', ']');
CharacterList := '';
while Pos('"name":"', CharacterBlock) > 0 do
begin
Character := TextBetween(CharacterBlock, '"name":"', '"');
Character := StringReplace(Character, ',', '###');
if CharacterList = '' then
CharacterList := Character
else
CharacterList := CharacterList + ' / ' + Character;
CharacterBlock := TextAfter(CharacterBlock, Character);
end;
end;
if Pos('"attributes": null', OneCredit) > 0 then
begin
AttributesList := '';
end else
begin
AttributesBlock := TextBetween(OneCredit, '"attributes":[', ']');
AttributesList := '';
while Pos('"text":"', AttributesBlock) > 0 do
begin
Attribute := TextBetween(AttributesBlock, '"text":"', '"');
if AttributesList = '' then
AttributesList := '(' + Attribute + ')'
else
AttributesList := AttributesList + ' ' + '(' + Attribute + ')';
AttributesBlock := TextAfter(AttributesBlock, Attribute);
end;
end;
if Actor <> '' then
begin
if Result <> '' then
Result := Result + ', ';
if CharacterList <> '' then
begin
if GetOption('GetCharactersFormat') = 1 then
Result := Result + Actor + ' (as ' + CharacterList + ')'
else
Result := Result + Actor + ' ... ' + CharacterList;
end else
Result := Result + Actor;
if AttributesList <> '' then
Result := Result + ' ' + AttributesList;
end;
Json := TextAfter(Json, OneCredit);
end;
end;
//==============================================================================
// Query IMDb's API
//==============================================================================
function QueryIMDb_API(MovieTitleOrID: string): string;
var
query, url, contentType, referer, headers, response, replace_max_titles, Year, replace_start_year, replace_end_year, StrVal1: string;
Deviation: Integer;
forceHTTP11, forceEncodeParams, foundYear: Boolean;
begin
url := 'https://api.graphql.imdb.com';
contentType := 'application/json';
headers := 'Content-Type=application/json' + #13#10 +
'x-imdb-client-name=imdb-web-next-localized' + #13#10 +
'x-imdb-user-country=' + GetParam('userCountryCode');
referer := '';
forceHTTP11 := True;
forceEncodeParams := False;
if RegExprSetExec('tt[0-9]+', MovieTitleOrID) then
begin
query := Query_ID;
query := StringReplace(query, 'replace_imdbid', MovieTitleOrID);
if GetOption('DescriptionLanguage1st') = 0 then
query := StringReplace(query, 'replace_plot_settings', 'first: 2')
else
query := StringReplace(query, 'replace_plot_settings', 'first: 25, includeAllLocales: true');
end else
begin
if GetOption('SearchMethod') = 0 then
query := Query_Search_by_Title
else
query := Query_FuzzySearch_by_Title;
/////////////////////////////// SearchWithYear block
foundYear := False;
MovieTitleOrID := Trim(MovieTitleOrID);
if (GetOption('SearchWithYear') = 1) and (Length(MovieTitleOrID) > 6) then
begin
if RegExprSetExec('\d{4}$', MovieTitleOrID) then
begin
foundYear := True;
Year := RegExprMatch(0);
StrVal1 := StringReplace(MovieTitleOrID, Year, '');
end
else if RegExprSetExec('\(\d{4}\)$', MovieTitleOrID) then
begin
foundYear := True;
Year := RegExprMatch(0);
StrVal1 := StringReplace(MovieTitleOrID, Year, '');
Year := StringReplace(Year, '(', '');
Year := StringReplace(Year, ')', '');
end;
end;
if foundYear then
begin
if (Copy(Year, 1, 2) = '19') or (Copy(Year, 1, 2) = '20') then
begin
MovieTitleOrID := Trim(StrVal1);
case GetOption('SearchYearDeviation') of
0: Deviation := 0;
1: Deviation := 1;
2: Deviation := 3;
end;
replace_start_year := IntToStr(StrToInt(Year, 10) - Deviation);
replace_end_year := IntToStr(StrToInt(Year, 10) + Deviation);
if GetOption('SearchMethod') = 0 then
query := Query_Search_by_Title_and_Year
else
query := Query_FuzzySearch_by_Title_and_Year;
query := StringReplace(query, 'replace_start_year', replace_start_year);
query := StringReplace(query, 'replace_end_year', replace_end_year);
end;
end;
////////////////////////////////////////////////////
if GetOption('BatchMode') > 0 then
replace_max_titles := '1'
else
case GetOption('TitleSelection') of
1: replace_max_titles := '5';
2: replace_max_titles := '10';
3: replace_max_titles := '25';
end;
query := StringReplace(query, 'replace_search_string', MovieTitleOrID);
query := StringReplace(query, 'replace_max_titles', replace_max_titles);
end;
response := PostPage3(url, query, contentType, referer, forceHTTP11, forceEncodeParams, headers);
response := ConvertToASCII(response);
Result := response;
end;
//==============================================================================
// Query IMDb's API2
//==============================================================================
function QueryIMDb_API2(MovieID: string; UserID: string; job: string): string;
var
query, url, contentType, referer, headers, response, max: string;
forceHTTP11, forceEncodeParams: Boolean;
begin
url := 'https://api.graphql.imdb.com';
contentType := 'application/json';
headers := 'Content-Type=application/json' + #13#10 +
'x-imdb-client-name=imdb-web-next-localized' + #13#10 +
'x-imdb-user-country=' + GetParam('userCountryCode');
referer := '';
forceHTTP11 := True;
forceEncodeParams := False;
if job = 'get_myrating' then
begin
query := Query_userRating;
query := StringReplace(query, 'replace_imdbid', MovieID);
query := StringReplace(query, 'replace_userid', UserID);
end
else if job = 'get_actors' then
begin
case GetOption('ActorsLimit') of
0: max := '5';
1: max := '10';
2: max := '25';
3: max := '50';
4: max := '250';
end;
query := Query_actors;
if GetOption('GetCharacters') = 1 then
query := Query_actors_paired;
query := StringReplace(query, 'replace_imdbid', MovieID);
query := StringReplace(query, 'replace_max_actors', max);
end
else if job = 'get_trivia' then
begin
case GetOption('TriviaLimit') of
0: max := '1';
1: max := '10';
2: max := '25';
3: max := '50';
4: max := '250';
end;
query := Query_trivia;
query := StringReplace(query, 'replace_imdbid', MovieID);
query := StringReplace(query, 'replace_max_trivia', max);
end
else
ShowMessage('ERROR: Incorrect job for QueryIMDb_API2!');
response := PostPage3(url, query, contentType, referer, forceHTTP11, forceEncodeParams, headers);
response := ConvertToASCII(response);
Result := response;
end;
//==============================================================================
// Perform search and ask to select a movie from a list
//==============================================================================
procedure SearchForMovie(MovieTitleOrID: string);
var
Json, imdbID: string;
begin
Json := QueryIMDb_API(MovieTitleOrID);
if GetOption('BatchMode') = 0 then
begin
PickTreeClear;
PickTreeAdd('Titles search results', '');
AddMovieTitles(Json);
if PickTreeExec(MovieTitleOrID) then
begin
if RegExprSetExec('tt[0-9]+', MovieTitleOrID) then
MovieTitleOrID := RegExprMatch(0);
GetMovieInfo(MovieTitleOrID);
end;
end else
begin
imdbID := TextBetween(Json, ',"id":"', '"');
if (imdbID <> '') then
begin
GetMovieInfo(imdbID);
end;
end;
end;
//==============================================================================
// Adds the movie titles found on IMDB to a list
//==============================================================================
function AddMovieTitles(Json: string): Boolean;
var
Item, Title, Year, TypeText, Id, TitleLine, url, Director: string;
begin
Result := False;
while Pos('"node":', Json) > 0 do
begin
Item := GetJsonBlock(Json, '"node"');
Title := TextBetween(Item, '"titleText":{"text":"', '"}');
Year := TextBetween(Item, '"releaseYear":{"year":', '}');
TypeText := TextBetween(Item, '"titleType":{"text":"', '"');
Id := TextBetween(Item, ',"id":"', '"');
Director := TextBetween(Item, '"id":"director"},"credits":[{"name":{"nameText":{"text":"', '"');
if (Title <> '') and (Id <> '') then
begin
TitleLine := Title + ' (' + Year + ') - ' + TypeText + ' - ' + Director;
url := 'https://www.imdb.com/title/' + Id;
PickTreeAdd(TitleLine, url);
Result := True;
end;
Json := TextAfter(Json, '"node":');
end;
end;
//==============================================================================
// Fills the fields with a movie info
//==============================================================================
procedure GetMovieInfo(IMDbID: string);
var
StrVal0, StrVal1, StrVal2, StrVal3, Json, Json2, originalTitle, TranslatedTitle, PictureHeight, Block, Directors, Writers, Actors, Genres, Countries, Producers, Composers, ActorsJson: string;
runTime, IntVal1: Integer;
begin
Json := QueryIMDb_API(IMDbID);
// URL
if CanSetField(fieldURL) then
begin
StrVal1 := 'https://www.imdb.com/title/' + IMDbID;
SetField(fieldURL, StrVal1);
end;
// Original title
originalTitle := TextBetween(Json, '"originalTitleText":{"text":"', '"}');
if CanSetField(fieldOriginalTitle) then
begin
SetField(fieldOriginalTitle, originalTitle);
end;
// Translated title
if CanSetField(fieldTranslatedTitle) then
begin
if GetOption('AKAs') <> 0 then
begin
Json2 := GetJsonBlock(Json, '"akas"');
StrVal1 := '';
while Pos('"node":{', Json2) > 0 do
begin
Block := GetJsonBlock(Json2, '"node"');
StrVal2 := TextBetween(Block, '"text":"', '"}');
if StrVal1 = '' then
StrVal1 := TextBetween(Json, '"titleText":{"text":"', '",');
if (Pos(StrVal2, StrVal1) = 0) and (AnsiPosEx('???', StrVal2, False, False) = 0) then // if StrVal2 not present in StrVal1 AND no unrecognized chars (like Cyrillic titles)
StrVal1 := StrVal1 + ' || ' + StrVal2;
Json2 := TextAfter(Json2, Block);
end;
if Pos(' || ', StrVal1) = 1 then
StrVal1 := Copy(StrVal1, 5, Length(StrVal1));
SetField(fieldTranslatedTitle, StrVal1);
end else
begin
TranslatedTitle := TextBetween(Json, '"titleText":{"text":"', '",');
if AnsiCompareStr(TranslatedTitle, originalTitle) <> 0 then
begin
SetField(fieldTranslatedTitle, TranslatedTitle);
end;
end;
end;
// Year
if CanSetField(fieldYear) then
begin
StrVal1 := TextBetween(Json, '"releaseYear":{"year":', '}');
SetField(fieldYear, StrVal1);
end;
// Poster
if CanSetPicture and (GetOption('PosterImageSize') <> 0) then
begin
case GetOption('PosterImageSize') of
1: PictureHeight := '200';
2: PictureHeight := '500';
3: PictureHeight := '700';
4: PictureHeight := '1100';
5: PictureHeight := '1500';
6: PictureHeight := '2000';
7: PictureHeight := '9999';
end;
StrVal1 := TextBetween(Json, '"primaryImage":{"url":"', '"}');