/
preprocess.go
196 lines (180 loc) · 5.65 KB
/
preprocess.go
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
package mtgstocks
import (
"errors"
"fmt"
"strings"
"github.com/mtgban/go-mtgban/mtgmatcher"
)
var cardTable = map[string]string{
"Cevill, Bane of Monsters": "Chevill, Bane of Monsters",
"Frontland Felidar": "Frondland Felidar",
"Ragurin Crystal": "Raugrin Crystal",
"Bastion of Rememberance": "Bastion of Remembrance",
"Rograkh, Son of Gohgahh": "Rograkh, Son of Rohgahh",
"Swords of Plowshares": "Swords to Plowshares",
"Kedniss, Emberclaw Familiar": "Kediss, Emberclaw Familiar",
"Gilanra, Caller or Wirewood": "Gilanra, Caller of Wirewood",
"Rengade Tactics": "Renegade Tactics",
"Iona's Judgement": "Iona's Judgment",
"Axguard Armory": "Axgard Armory",
"Immersturn Raider": "Immersturm Raider",
"Artifact of Mishra": "Ankh of Mishra",
"Rosethron Acolyte": "Rosethorn Acolyte",
"Blackboom Rogue": "Blackbloom Rogue",
"Nezumi Shortfang // Nezumi Shortfang": "Nezumi Shortfang",
"Corpse Knight (2/3 Misprint)": "Corpse Knight (Misprint)",
"Subira, Tulzidi Caravaneer (Extended Art)": "Subira, Tulzidi Caravanner (Extended Art)",
"Fiendish Duo (JP Exclusive Store Support Promo)": "Fiendish Duo (PKHM)",
"Wind Drake (17/264)": "Wind Drake (Intro)",
"Valakut Awakening // Valakut Stoneforge (Borderless)": "Valakut Awakening (Extended Art)",
"Darkbore Pathway (Extended Art)": "Darkbore Pathway // Slitherbore Pathway (Borderless)",
"Hengegate Pathway (Extended Art)": "Hengegate Pathway // Mistgate Pathway (Borderless)",
"Blightstep Pathway (Extended Art)": "Blightstep Pathway // Searstep Pathway (Borderless)",
"Barkchannel Pathway (Extended Art)": "Barkchannel Pathway // Tidechannel Pathway (Borderless)",
"Haunting Voyage (Extended Art)": "Haunting Voyage (Borderless)",
"Quakebringer (Extended Art)": "Quakebringer (Borderless)",
"Tevesh Szat, Doom of Fools (Extended Art)": "Tevesh Szat, Doom of Fools (Borderless)",
"Battra, Terror of the City (JP Alternate Art)": "Dirge Bat (Godzilla)",
}
var promoTable = map[string]string{
"Crucible of Worlds": "PWOR",
"Mana Crypt": "PHPR",
"Fireball": "PMEI",
"Loam Lion": "PRES",
"Oran-Rief, the Vastwood": "PRES",
"Treasure Hunt": "PIDW",
"Reliquary Tower": "PLG20",
"Flooded Strand": "PNAT",
"Serra Avatar": "PDP13",
"Corrupt": "PI13",
"Duress": "PI14",
"Electrolyze": "PIDW",
"Jaya Ballard, Task Mage": "PRES",
"Liliana Vess": "PDP10",
"Llanowar Elves": "PDOM",
"Noble Hierarch": "PPRO",
"Cryptic Command": "PPRO",
"Chandra, Torch of Defiance": "Q06",
}
func preprocess(fullName, edition string, foil bool) (*mtgmatcher.Card, error) {
fullName = strings.Replace(fullName, "[", "(", 1)
fullName = strings.Replace(fullName, "]", ")", 1)
lutName, found := cardTable[fullName]
if found {
fullName = lutName
}
s := mtgmatcher.SplitVariants(fullName)
variant := ""
cardName := s[0]
if len(s) > 1 {
variant = strings.Join(s[1:], " ")
}
s = strings.Split(cardName, " - ")
cardName = s[0]
if len(s) > 1 {
if variant != "" {
variant += " "
}
variant += s[1]
}
lutName, found = cardTable[cardName]
if found {
cardName = lutName
}
switch edition {
case "Oversize Cards":
if !strings.Contains(variant, "Planechase") {
return nil, errors.New("unsupported")
}
if cardName == "Stairs to Infinity" && variant == "Planechase 2012" {
return nil, errors.New("does not exist")
}
case "Secret Lair Series":
switch cardName {
case "Thalia, Guardian of Thraben":
if variant == "" {
variant = "37"
}
}
case "Arabian Nights":
if variant == "Version 2" {
variant = "dark"
} else if variant == "Version 1" {
variant = "light"
}
case "Prerelease Cards":
variant = edition
case "JSS/MSS Promos":
edition = "Junior Super Series"
case "Arena Promos":
if cardName == "Underworld Dreams" {
edition = "DCI"
}
case "WPN & Gateway Promos":
if cardName == "Deathless Angel" {
edition = "Rise of the Eldrazi Promos"
}
case "Launch Party & Release Event Promos":
if mtgmatcher.IsBasicLand(cardName) {
edition = "Ravnica Weekend"
}
case "Judge Promos":
switch cardName {
case "Vampiric Tutor":
if variant == "" {
variant = "2000"
}
case "Demonic Tutor":
if variant == "" {
variant = "2008"
}
case "Wasteland":
if variant == "" {
variant = "2010"
}
}
case "Miscellaneous Promos",
"Media Promos",
"Open House Promos",
"Pro Tour Promos":
if variant == "Magic Scholarship" {
edition = "Junior Super Series"
} else {
ed, found := promoTable[cardName]
if found {
edition = ed
}
}
case "Unglued":
if strings.HasSuffix(variant, "Right") {
variant = "29"
} else if strings.HasSuffix(variant, "Left") {
variant = "28"
}
case "Ikoria: Lair of Behemoths: Extras":
if variant == "JP Alternate Art" {
variant = "Godzilla"
}
edition = "Ikoria: Lair of Behemoths"
}
return &mtgmatcher.Card{
Name: cardName,
Variation: variant,
Edition: edition,
Foil: foil,
}, nil
}
// Some slug strings are missing quotes and are plain numbers
// use this function to parse it
func getLink(raw interface{}) (string, error) {
var slug string
switch v := raw.(type) {
case string:
slug = v
case float64:
slug = fmt.Sprintf("%.0f", v)
default:
return "", errors.New("invalid type")
}
return "https://www.mtgstocks.com/prints/" + slug, nil
}