dev
Revision | 7c7194111f16802edbf190ee0cd3466b5b3d59be (tree) |
---|---|
Time | 2014-01-13 07:46:42 |
Author | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
Pixivサムネイル取得処理の改善
@@ -744,13 +744,17 @@ namespace OpenTween | ||
744 | 744 | |
745 | 745 | public static string fileVersion = ""; |
746 | 746 | |
747 | - public static string GetUserAgentString() | |
747 | + public static string GetUserAgentString(bool fakeMSIE = false) | |
748 | 748 | { |
749 | 749 | if (string.IsNullOrEmpty(fileVersion)) |
750 | 750 | { |
751 | 751 | throw new Exception("fileversion is not Initialized."); |
752 | 752 | } |
753 | - return GetAssemblyName() + "/" + fileVersion; | |
753 | + | |
754 | + if (fakeMSIE) | |
755 | + return GetAssemblyName() + "/" + fileVersion + " (compatible; MSIE 10.0)"; | |
756 | + else | |
757 | + return GetAssemblyName() + "/" + fileVersion; | |
754 | 758 | } |
755 | 759 | |
756 | 760 | public static TwitterApiStatus TwitterApiInfo = new TwitterApiStatus(); |
@@ -22,8 +22,10 @@ | ||
22 | 22 | using System; |
23 | 23 | using System.Collections.Generic; |
24 | 24 | using System.Linq; |
25 | +using System.Net; | |
25 | 26 | using System.Text; |
26 | 27 | using System.Text.RegularExpressions; |
28 | +using System.Threading.Tasks; | |
27 | 29 | |
28 | 30 | namespace OpenTween.Thumbnail.Services |
29 | 31 | { |
@@ -34,12 +36,36 @@ namespace OpenTween.Thumbnail.Services | ||
34 | 36 | { |
35 | 37 | } |
36 | 38 | |
37 | - protected override string FetchImageUrl(string url) | |
39 | + public override ThumbnailInfo GetThumbnailInfo(string url, PostClass post) | |
38 | 40 | { |
39 | - var thumbnailUrl = base.FetchImageUrl(url); | |
41 | + var thumb = base.GetThumbnailInfo(url, post); | |
42 | + if (thumb == null) return null; | |
40 | 43 | |
41 | - // og:image のサムネイルURLにそのままアクセスすると403が返ってくるので回避 | |
42 | - return Regex.Replace(thumbnailUrl, @"_s(?=\..{3}$)", "_m"); | |
44 | + return new Pixiv.Thumbnail | |
45 | + { | |
46 | + ImageUrl = thumb.ImageUrl, | |
47 | + ThumbnailUrl = thumb.ThumbnailUrl, | |
48 | + TooltipText = thumb.TooltipText, | |
49 | + FullSizeImageUrl = thumb.FullSizeImageUrl, | |
50 | + }; | |
51 | + } | |
52 | + | |
53 | + public class Thumbnail : ThumbnailInfo | |
54 | + { | |
55 | + protected override Task<MemoryImage> LoadThumbnailImageAsync() | |
56 | + { | |
57 | + var client = new OTWebClient(); | |
58 | + | |
59 | + client.UserAgent = MyCommon.GetUserAgentString(fakeMSIE: true); | |
60 | + client.Headers[HttpRequestHeader.Referer] = this.ImageUrl; | |
61 | + | |
62 | + var task = client.DownloadDataAsync(new Uri(this.ThumbnailUrl)) | |
63 | + .ContinueWith(t => MemoryImage.CopyFromBytes(t.Result)); | |
64 | + | |
65 | + task.ContinueWith(_ => client.Dispose()); | |
66 | + | |
67 | + return task; | |
68 | + } | |
43 | 69 | } |
44 | 70 | } |
45 | 71 | } |
@@ -118,7 +118,7 @@ namespace OpenTween.Thumbnail | ||
118 | 118 | "http://lohas.nicoseiga.jp/thumb/${id}l?"), |
119 | 119 | |
120 | 120 | // pixiv |
121 | - new MetaThumbnailService(@"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$"), | |
121 | + new Pixiv(@"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$"), | |
122 | 122 | |
123 | 123 | // flickr |
124 | 124 | new MetaThumbnailService(@"^http://www\.flickr\.com/.+$"), |