forked from kyleconroy/deckbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcgplayer.go
202 lines (191 loc) · 4.29 KB
/
tcgplayer.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
197
198
199
200
201
202
package brew
import (
"fmt"
"regexp"
"strings"
)
func ReplaceUnicode(name string) string {
replace := map[string]string{
"Æ": "AE",
"é": "e",
"ö": "o",
"û": "u",
"á": "a",
"â": "a",
"ú": "u",
"à": "a",
}
s := name
for unicode, ascii := range replace {
s = strings.Replace(s, unicode, ascii, -1)
}
return s
}
func TCGSlug(name string) string {
re := regexp.MustCompile(`[,.'"?:]`)
d := strings.Replace(strings.ToLower(name), " ", "-", -1)
return ReplaceUnicode(re.ReplaceAllLiteralString(d, ""))
}
func TCGCardURL(c *Card) string {
if len(c.Editions) == 1 {
return TCGEditionURL(c, &c.Editions[0])
} else {
return "http://store.tcgplayer.com/magic/product/show?partner=DECKBREW&ProductName=" + TCGSlug(c.Name)
}
}
func TCGEditionURL(c *Card, e *Edition) string {
set := TCGSlug(TCGSet(e.SetId, e.Set))
id := TCGSlug(TCGName(c.Name, e.MultiverseId))
return fmt.Sprintf("http://store.tcgplayer.com/magic/%s/%s?partner=DECKBREW", set, id)
}
func NormalizeName(name string) string {
return strings.ToLower(ReplaceUnicode(strings.TrimSpace(name)))
}
func TCGName(name string, id int) string {
translation := TranslateID(id)
if translation != "" {
return NormalizeName(translation)
} else {
return NormalizeName(name)
}
}
func TranslateID(id int) string {
switch id {
case 1071:
return "Mishra's Factory (Fall)"
case 1072:
return "Mishra's Factory (Spring)"
case 1073:
return "Mishra's Factory (Summer)"
case 1074:
return "Mishra's Factory (Winter)"
case 1076:
return "Strip Mine (Even Horizon)"
case 1077:
return "Strip Mine (Uneven Horizon)"
case 1078:
return "Strip Mine (No Horizon)"
case 1079:
return "Strip Mine (Tower)"
case 1080, 2888:
return "Urza's Mine (Clawed Sphere)"
case 1081, 2889:
return "Urza's Mine (Mouth)"
case 1082, 2890:
return "Urza's Mine (Pulley)"
case 1083, 2891:
return "Urza's Mine (Tower)"
case 1084, 2892:
return "Urza's Power Plant (Bug)"
case 1085, 2893:
return "Urza's Power Plant (Columns)"
case 1086, 2894:
return "Urza's Power Plant (Sphere)"
case 1087, 2895:
return "Urza's Power Plant (Rock in Pot)"
case 1088, 2896:
return "Urza's Tower (Forest)"
case 1089, 2897:
return "Urza's Tower (Mountains)"
case 2898, 1090:
return "Urza's Tower (Plains)"
case 1091, 2899:
return "Urza's Tower (Shore)"
case 2969:
return "Hungry Mist [Version 1]"
case 2970:
return "Hungry Mist [Version 2]"
case 3021:
return "Mesa Falcon [Version 1]"
case 3022:
return "Mesa Falcon [Version 2]"
case 3207:
return "Reinforcements (Version 2)"
case 4979:
return "Pegasus Token"
case 5472:
return "Soldier Token"
case 5503:
return "Goblin Token"
case 5560:
return "Sheep Token"
case 5601:
return "Zombie Token"
case 5607:
return "Squirrel Token"
case 9757:
return "The Ultimate Nightmare of Wizards of the Coast Cu"
case 9780:
return "B.F.M. (Big Furry Monster Left)"
case 9844:
return "B.F.M. (Big Furry Monster Right)"
case 74237:
return "Our Market Research..."
case 78968:
return "Brothers Yamazaki (160a Sword)"
case 85106:
return "Brothers Yamazaki (160b Pike)"
case 209163:
return "Hornet Token"
case 386322:
return "Goblin Token"
}
return ""
}
func TCGSet(setId, set string) string {
switch setId {
case "10E":
return "10th Edition"
case "9ED":
return "9th Edition"
case "8ED":
return "8th Edition"
case "7ED":
return "7th Edition"
case "M15":
return "Magic 2015 (M15)"
case "M14":
return "Magic 2014 (M14)"
case "M13":
return "Magic 2013 (M13)"
case "M12":
return "Magic 2012 (M12)"
case "M11":
return "Magic 2011 (M11)"
case "M10":
return "Magic 2010 (M10)"
case "CMD":
return "Commander"
case "HHO":
return "Special Occasion"
case "RAV":
return "Ravnica"
case "DDG":
return "Duel Decks: Knights vs Dragons"
case "DDL":
return "Duel Decks: Heroes vs. Monsters"
case "PC2":
return "Planechase 2012"
case "C13":
return "Commander 2013"
case "C14":
return "Commander 2014"
case "PD2":
return "Premium Deck Series: Fire and Lightning"
case "LEB":
return "Beta Edition"
case "LEA":
return "Alpha Edition"
case "TSB":
return "Timeshifted"
case "MD1":
return "Magic Modern Event Deck"
case "CNS":
return "Conspiracy"
case "DKM":
return "Deckmasters Garfield vs. Finkel"
case "KTK":
return "Khans of Tarkir"
}
return set
}