-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScraperType.cs
More file actions
191 lines (167 loc) · 8.13 KB
/
ScraperType.cs
File metadata and controls
191 lines (167 loc) · 8.13 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
using MTGAHelper.Entity.DeckScraper;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MTGAHelper.Entity
{
public enum ScraperTypeEnum
{
Unknown,
UserCustomDeck,
MtgGoldfish,
MtgDecks,
Streamdecker,
Aetherhub,
Tappedout,
MtgTop8,
UserDeckSource,
MtgaTool,
}
public enum ScraperTypeFormatEnum
{
Unknown,
Standard,
ArenaStandard,
HistoricBo1,
HistoricBo3,
}
public class ScraperType
{
public const string NAME_PREFIX_USER = "user_";
public ScraperTypeEnum Type { get; private set; }
public ScraperTypeFormatEnum Format { get; private set; }
public string Name { get; private set; }
public bool IsByUser { get; private set; }
public string Id => $"{Type.ToString().ToLower()}-{Name?.ToLower() ?? "NULL"}{(Format == ScraperTypeFormatEnum.Unknown ? "" : "-" + Format.ToString().ToLower())}";
public string Url
{
get
{
string aetherhubAddFormat(string urlPrefix, ScraperTypeFormatEnum format)
{
var dictFormatToUrl = new Dictionary<ScraperTypeFormatEnum, string>
{
{ ScraperTypeFormatEnum.Standard, "/Standard" },
{ ScraperTypeFormatEnum.ArenaStandard, "/Arena%20Standard" },
{ ScraperTypeFormatEnum.HistoricBo1, "/Historic-BO1" },
{ ScraperTypeFormatEnum.HistoricBo3, "/Traditional-Historic" },
};
if (dictFormatToUrl.ContainsKey(format) == false)
return urlPrefix;
return urlPrefix + dictFormatToUrl[format];
}
Func<ScraperTypeFormatEnum, string> mtgGoldfishAddFormat = (f) =>
f == ScraperTypeFormatEnum.ArenaStandard ? "arena_standard" :
f == ScraperTypeFormatEnum.HistoricBo3 ? "historic" : f.ToString().ToLower();
var url = "#";
switch (Type)
{
case ScraperTypeEnum.Streamdecker:
url = "https://www.streamdecker.com/decks/" + Name;
break;
case ScraperTypeEnum.Aetherhub:
if (Name == AetherhubListingEnum.Meta.ToString().ToLower())
url = aetherhubAddFormat("https://aetherhub.com/Meta/Format", Format);
else if (Name == AetherhubListingEnum.Tier1.ToString().ToLower())
url = "https://aetherhub.com/Meta/TierOne";
else if (Name.StartsWith(NAME_PREFIX_USER))
{
var id = new string(Name.Skip(NAME_PREFIX_USER.Length).ToArray());
url = aetherhubAddFormat($"https://aetherhub.com/User/{id}/Decks", Format);
}
else if (Name == AetherhubListingEnum.TournamentBo3.ToString().ToLower())
url = "https://aetherhub.com/Events/Historic/";
break;
case ScraperTypeEnum.MtgGoldfish:
if (Name == MtgGoldfishArticleEnum.Meta.ToString().ToLower())
url = $"https://www.mtggoldfish.com/metagame/{mtgGoldfishAddFormat(Format)}/full";
else if (Name == MtgGoldfishArticleEnum.AgainstTheOdds.ToString().ToLower())
url = "https://www.mtggoldfish.com/series/against-the-odds";
else if (Name == MtgGoldfishArticleEnum.BudgetMagic.ToString().ToLower())
url = "https://www.mtggoldfish.com/series/budget-magic";
else if (Name == MtgGoldfishArticleEnum.GoldfishGladiators.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?tag=goldfish+gladiators";
else if (Name == MtgGoldfishArticleEnum.InstantDeckTech.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?tag=instant+deck+tech";
else if (Name == MtgGoldfishArticleEnum.FishFiveO.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?tag=fish+five-o";
else if (Name == MtgGoldfishArticleEnum.MuchAbrew.ToString().ToLower())
url = "https://www.mtggoldfish.com/series/much-abrew-about-nothing";
else if (Name == MtgGoldfishArticleEnum.StreamHighlights.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?tag=stream+highlights";
else if (Name == MtgGoldfishArticleEnum.BudgetArena.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?tag=budget+arena";
else if (Name == MtgGoldfishArticleEnum.SingleScoop.ToString().ToLower())
url = "https://www.mtggoldfish.com/articles/search?author=93";
else if (Name == MtgGoldfishArticleEnum.Tournaments.ToString().ToLower())
url = $"https://www.mtggoldfish.com/tournaments/{mtgGoldfishAddFormat(Format)}";
break;
case ScraperTypeEnum.MtgDecks:
//switch (Name)
//{
// case "meta":
// Url = "https://mtgdecks.net/Standard";
// break;
// case "averagearchetype":
// Url = "https://mtgdecks.net/Standard";
// break;
//}
url = "https://mtgdecks.net/Standard";
break;
case ScraperTypeEnum.MtgaTool:
var format =
Format == ScraperTypeFormatEnum.Standard ? "Bo1" :
Format == ScraperTypeFormatEnum.ArenaStandard ? "Bo3" :
Format == ScraperTypeFormatEnum.HistoricBo1 ? "Hbo1" : "Hbo3";
url = "http://mtgatool.com/metagame/{format}";
break;
// WHAT?!????????????
case ScraperTypeEnum.MtgTop8:
if (Name == MtgTop8ListingEnum.DecksToBeat.ToString().ToLower())
url = "https://www.mtggoldfish.com/metagame/{mtgGoldfishAddFormat(Format)}/full";
break;
}
return url;
}
}
public override string ToString() => Id;
public ScraperType(ScraperTypeEnum type, string name, ScraperTypeFormatEnum format = ScraperTypeFormatEnum.Unknown)
{
Type = type;
Name = name;
Format = format;
SetIsByUser();
}
public ScraperType(string id)
{
if (id.IndexOf('-') < 1)
{
var strType = id.Trim('-');
Type = DecodeType(strType);
Name = null;
}
else
{
var parts = id.Split('-');
Type = DecodeType(parts[0]);
Name = parts[1];
if (parts.Length > 2)
{
Format = (ScraperTypeFormatEnum)Enum.Parse(typeof(ScraperTypeFormatEnum), parts[2], true);
}
}
SetIsByUser();
}
void SetIsByUser()
{
IsByUser = Name != null && (Name.StartsWith(NAME_PREFIX_USER) || Type == ScraperTypeEnum.Streamdecker);
//if (IsByUser) System.Diagnostics.Debugger.Break();
}
private ScraperTypeEnum DecodeType(string strType)
{
if (Enum.TryParse(strType, true, out ScraperTypeEnum e))
return e;
return ScraperTypeEnum.Unknown;
}
}
}