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

Commit

Permalink
Implements new Tumblr tag search.
Browse files Browse the repository at this point in the history
Tumblr is now using a non-official, undescribed API v2 Endpoint (api/v2/mobile/search) for their tag search on the website.
  • Loading branch information
johanneszab committed Aug 12, 2020
1 parent 9b3b575 commit 09e6d21
Show file tree
Hide file tree
Showing 27 changed files with 3,004 additions and 1,054 deletions.
4 changes: 2 additions & 2 deletions src/TumblThree/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
[assembly: AssemblyVersion("1.0.8.75")]
[assembly: AssemblyFileVersion("1.0.8.75")]
[assembly: AssemblyVersion("1.0.8.76")]
[assembly: AssemblyFileVersion("1.0.8.76")]
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,39 @@ protected async Task<string> RequestDataAsync(string url, Dictionary<string, str
}
}

protected async Task<string> RequestApiDataAsync(string url, string bearerToken, Dictionary<string, string> headers = null,
IEnumerable<string> cookieHosts = null)
{
var requestRegistration = new CancellationTokenRegistration();
try
{
HttpWebRequest request = webRequestFactory.CreateGetReqeust(url, string.Empty, headers);
cookieHosts = cookieHosts ?? new List<string>();
foreach (string cookieHost in cookieHosts)
{
cookieService.GetUriCookie(request.CookieContainer, new Uri(cookieHost));
}

request.PreAuthenticate = true;
request.Headers.Add("Authorization", "Bearer " + bearerToken);
request.Accept = "application/json";

requestRegistration = ct.Register(() => request.Abort());
return await webRequestFactory.ReadReqestToEndAsync(request);
}
finally
{
requestRegistration.Dispose();
}
}

public virtual T ConvertJsonToClass<T>(string json) where T : new()
{
try
{
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
{
var serializer = new DataContractJsonSerializer((typeof(T)));
var serializer = new DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(ms);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ public ICrawler GetCrawler(IBlog blog, CancellationToken ct, PauseToken pt, IPro
imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, blog);
case BlogTypes.tumblrtagsearch:
IPostQueue<TumblrCrawlerData<DataModels.TumblrTaggedSearch.Datum>> jsonTagSearchQueue =
GetJsonQueue<DataModels.TumblrTaggedSearch.Datum>();
return new TumblrTagSearchCrawler(shellService, ct, pt, progress, crawlerService, webRequestFactory,
cookieService, GetTumblrDownloader(ct, pt, progress, blog, files, postQueue), GetTumblrParser(),
imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, blog);
cookieService, GetTumblrDownloader(ct, pt, progress, blog, files, postQueue), GetTumblrJsonDownloader(ct, pt, jsonTagSearchQueue, blog),
GetTumblrParser(), imgurParser, gfycatParser, GetWebmshareParser(), GetMixtapeParser(), GetUguuParser(),
GetSafeMoeParser(), GetLoliSafeParser(), GetCatBoxParser(), postQueue, jsonTagSearchQueue, blog);
default:
throw new ArgumentException("Website is not supported!", "blogType");
}
Expand Down
Loading

0 comments on commit 09e6d21

Please sign in to comment.