using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
{
class Foursquare : IThumbnailService
{
+ protected readonly HttpClient http;
protected Regex regex;
public Foursquare(string pattern)
+ : this(null, pattern)
{
+ }
+
+ public Foursquare(HttpClient http, string pattern)
+ {
+ this.http = http ?? MyCommon.CreateHttpClient();
this.regex = new Regex(pattern);
}
if (mapUrl == null)
return null;
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = mapUrl,
using System.Collections.Generic;
using System.Linq;
using System.Net;
+using System.Net.Http;
using System.Runtime.Serialization.Json;
using System.Xml;
using System.Xml.Linq;
protected IEnumerable<Regex> UrlRegex = null;
protected Timer UpdateTimer;
+ protected readonly HttpClient http;
+
private object LockObj = new object();
- public ImgAzyobuziNet(bool autoupdate = false)
+ public ImgAzyobuziNet()
+ : this(autoupdate: false)
+ {
+ }
+
+ public ImgAzyobuziNet(bool autoupdate)
+ : this(null, autoupdate)
+ {
+ }
+
+ public ImgAzyobuziNet(HttpClient http)
+ : this(http, autoupdate: false)
+ {
+ }
+
+ public ImgAzyobuziNet(HttpClient http, bool autoupdate)
{
this.UpdateTimer = new Timer(_ => this.LoadRegex());
this.AutoUpdate = autoupdate;
this.Enabled = true;
this.DisabledInDM = true;
+
+ this.http = http ?? MyCommon.CreateHttpClient();
}
public bool AutoUpdate
{
if (regex.IsMatch(url))
{
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = this.ApiBase + "redirect?size=large&uri=" + Uri.EscapeDataString(url),
var thumbnailUrl = this.GetThumbnailUrl(content);
if (string.IsNullOrEmpty(thumbnailUrl)) return null;
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = thumbnailUrl,
if (!string.IsNullOrEmpty(imgurl))
{
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = imgurl,
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
{
class PhotoShareShortlink : IThumbnailService
{
+ protected readonly HttpClient http;
protected Regex regex;
public PhotoShareShortlink(string pattern)
+ : this(null, pattern)
{
+ }
+
+ public PhotoShareShortlink(HttpClient http, string pattern)
+ {
+ this.http = http ?? MyCommon.CreateHttpClient();
this.regex = new Regex(pattern);
}
if (!match.Success) return null;
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = "http://images.bcphotoshare.com/storages/" + RadixConvert.ToInt32(match.Result("${1}"), 36) + "/thumb180.jpg",
using System.Collections.Generic;
using System.Linq;
using System.Net;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
var thumb = await base.GetThumbnailInfoAsync(url, post, token);
if (thumb == null) return null;
- return new Pixiv.Thumbnail
+ return new Pixiv.Thumbnail(this.http)
{
ImageUrl = thumb.ImageUrl,
ThumbnailUrl = thumb.ThumbnailUrl,
public class Thumbnail : ThumbnailInfo
{
+ public Thumbnail(HttpClient http)
+ : base(http)
+ {
+ }
+
public async override Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken token)
{
- using (var client = new OTWebClient())
+ var request = new HttpRequestMessage(HttpMethod.Get, this.ThumbnailUrl);
+
+ request.Headers.Add("User-Agent", MyCommon.GetUserAgentString(fakeMSIE: true));
+ request.Headers.Referrer = new Uri(this.ImageUrl);
+
+ using (var response = await this.http.SendAsync(request, token).ConfigureAwait(false))
{
- client.UserAgent = MyCommon.GetUserAgentString(fakeMSIE: true);
- client.Headers[HttpRequestHeader.Referer] = this.ImageUrl;
+ response.EnsureSuccessStatusCode();
- var imageBytes = await client.DownloadDataAsync(new Uri(this.ThumbnailUrl), token)
+ var imageStream = await response.Content.ReadAsStreamAsync()
.ConfigureAwait(false);
- return MemoryImage.CopyFromBytes(imageBytes);
+ return await MemoryImage.CopyFromStreamAsync(imageStream)
+ .ConfigureAwait(false);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
protected string thumb_replacement;
protected string fullsize_replacement;
+ protected readonly HttpClient http;
+
public SimpleThumbnailService(string pattern, string replacement)
+ : this(null, pattern, replacement, null)
+ {
+ }
+
+ public SimpleThumbnailService(HttpClient http, string pattern, string replacement)
+ : this(http, pattern, replacement, null)
{
- this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
- this.thumb_replacement = replacement;
}
public SimpleThumbnailService(string pattern, string replacement, string file_replacement)
+ : this(null, pattern, replacement, file_replacement)
+ {
+ }
+
+ public SimpleThumbnailService(HttpClient http, string pattern, string replacement, string file_replacement)
{
+ this.http = http ?? MyCommon.CreateHttpClient();
this.regex = new Regex(pattern, RegexOptions.IgnoreCase);
this.thumb_replacement = replacement;
this.fullsize_replacement = file_replacement;
var thumbnailUrl = this.ReplaceUrl(url);
if (thumbnailUrl == null) return null;
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = thumbnailUrl,
{
var descElm = xdoc.XPathSelectElement("/rsp/content/description");
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = thumbUrlElm.Attribute("url").Value,
return null;
}
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = imgurl,
var textElm = xElm.XPathSelectElement("/response/post/text");
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = thumbUrlElm.Value,
tooltipText = string.Format("{0} ({1:00}:{2:00})", titleElm.Value, minute, second);
}
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = thumbUrlElm.Value,
}
- return new ThumbnailInfo()
+ return new ThumbnailInfo(this.http)
{
ImageUrl = url,
ThumbnailUrl = imgUrl,
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
public string TooltipText { get; set; }
public string FullSizeImageUrl { get; set; }
+ protected readonly HttpClient http;
+
+ public ThumbnailInfo()
+ : this(null)
+ {
+ }
+
+ public ThumbnailInfo(HttpClient http)
+ {
+ this.http = http ?? MyCommon.CreateHttpClient();
+ }
+
public Task<MemoryImage> LoadThumbnailImageAsync()
{
return this.LoadThumbnailImageAsync(CancellationToken.None);
public async virtual Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken token)
{
- using (var client = new OTWebClient())
+ using (var response = await this.http.GetAsync(this.ThumbnailUrl, token).ConfigureAwait(false))
{
- var imageBytes = await client.DownloadDataAsync(new Uri(this.ThumbnailUrl), token)
+ response.EnsureSuccessStatusCode();
+
+ var imageStream = await response.Content.ReadAsStreamAsync()
.ConfigureAwait(false);
- return MemoryImage.CopyFromBytes(imageBytes);
+ return await MemoryImage.CopyFromStreamAsync(imageStream)
+ .ConfigureAwait(false);
}
}
}
using System.Data;
using System.Linq;
using System.Net;
+using System.Net.Http;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
.ContinueWith(t2 =>
{
if (t2.IsFaulted)
- t2.Exception.Flatten().Handle(x => x is WebException || x is InvalidImageException || x is TaskCanceledException);
+ t2.Exception.Flatten().Handle(x => x is HttpRequestException ||
+ x is WebException || x is InvalidImageException ||
+ x is TaskCanceledException);
if (t2.IsFaulted || t2.IsCanceled)
{