Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 09e6d21

Browse files
committed
Implements new Tumblr tag search.
Tumblr is now using a non-official, undescribed API v2 Endpoint (api/v2/mobile/search) for their tag search on the website.
1 parent 9b3b575 commit 09e6d21

27 files changed

+3004
-1054
lines changed

src/TumblThree/SharedAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
[assembly: ComVisible(false)]
1414
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
15-
[assembly: AssemblyVersion("1.0.8.75")]
16-
[assembly: AssemblyFileVersion("1.0.8.75")]
15+
[assembly: AssemblyVersion("1.0.8.76")]
16+
[assembly: AssemblyFileVersion("1.0.8.76")]

src/TumblThree/TumblThree.Applications/Crawler/AbstractCrawler.cs

+27-1
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,39 @@ protected async Task<string> RequestDataAsync(string url, Dictionary<string, str
122122
}
123123
}
124124

125+
protected async Task<string> RequestApiDataAsync(string url, string bearerToken, Dictionary<string, string> headers = null,
126+
IEnumerable<string> cookieHosts = null)
127+
{
128+
var requestRegistration = new CancellationTokenRegistration();
129+
try
130+
{
131+
HttpWebRequest request = webRequestFactory.CreateGetReqeust(url, string.Empty, headers);
132+
cookieHosts = cookieHosts ?? new List<string>();
133+
foreach (string cookieHost in cookieHosts)
134+
{
135+
cookieService.GetUriCookie(request.CookieContainer, new Uri(cookieHost));
136+
}
137+
138+
request.PreAuthenticate = true;
139+
request.Headers.Add("Authorization", "Bearer " + bearerToken);
140+
request.Accept = "application/json";
141+
142+
requestRegistration = ct.Register(() => request.Abort());
143+
return await webRequestFactory.ReadReqestToEndAsync(request);
144+
}
145+
finally
146+
{
147+
requestRegistration.Dispose();
148+
}
149+
}
150+
125151
public virtual T ConvertJsonToClass<T>(string json) where T : new()
126152
{
127153
try
128154
{
129155
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
130156
{
131-
var serializer = new DataContractJsonSerializer((typeof(T)));
157+
var serializer = new DataContractJsonSerializer(typeof(T));
132158
return (T)serializer.ReadObject(ms);
133159
}
134160
}

src/TumblThree/TumblThree.Applications/Crawler/CrawlerFactory.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ public ICrawler GetCrawler(IBlog blog, CancellationToken ct, PauseToken pt, IPro
9090
imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
9191
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, blog);
9292
case BlogTypes.tumblrtagsearch:
93+
IPostQueue<TumblrCrawlerData<DataModels.TumblrTaggedSearch.Datum>> jsonTagSearchQueue =
94+
GetJsonQueue<DataModels.TumblrTaggedSearch.Datum>();
9395
return new TumblrTagSearchCrawler(shellService, ct, pt, progress, crawlerService, webRequestFactory,
94-
cookieService, GetTumblrDownloader(ct, pt, progress, blog, files, postQueue), GetTumblrParser(),
95-
imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
96-
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, blog);
96+
cookieService, GetTumblrDownloader(ct, pt, progress, blog, files, postQueue), GetTumblrJsonDownloader(ct, pt, jsonTagSearchQueue, blog),
97+
GetTumblrParser(), imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
98+
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, jsonTagSearchQueue, blog);
9799
default:
98100
throw new ArgumentException("Website is not supported!", "blogType");
99101
}

0 commit comments

Comments
 (0)