• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

dev


Commit MetaInfo

Revision7c7194111f16802edbf190ee0cd3466b5b3d59be (tree)
Time2014-01-13 07:46:42
AuthorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

Pixivサムネイル取得処理の改善

Change Summary

Incremental Difference

--- a/OpenTween/MyCommon.cs
+++ b/OpenTween/MyCommon.cs
@@ -744,13 +744,17 @@ namespace OpenTween
744744
745745 public static string fileVersion = "";
746746
747- public static string GetUserAgentString()
747+ public static string GetUserAgentString(bool fakeMSIE = false)
748748 {
749749 if (string.IsNullOrEmpty(fileVersion))
750750 {
751751 throw new Exception("fileversion is not Initialized.");
752752 }
753- return GetAssemblyName() + "/" + fileVersion;
753+
754+ if (fakeMSIE)
755+ return GetAssemblyName() + "/" + fileVersion + " (compatible; MSIE 10.0)";
756+ else
757+ return GetAssemblyName() + "/" + fileVersion;
754758 }
755759
756760 public static TwitterApiStatus TwitterApiInfo = new TwitterApiStatus();
--- a/OpenTween/Thumbnail/Services/Pixiv.cs
+++ b/OpenTween/Thumbnail/Services/Pixiv.cs
@@ -22,8 +22,10 @@
2222 using System;
2323 using System.Collections.Generic;
2424 using System.Linq;
25+using System.Net;
2526 using System.Text;
2627 using System.Text.RegularExpressions;
28+using System.Threading.Tasks;
2729
2830 namespace OpenTween.Thumbnail.Services
2931 {
@@ -34,12 +36,36 @@ namespace OpenTween.Thumbnail.Services
3436 {
3537 }
3638
37- protected override string FetchImageUrl(string url)
39+ public override ThumbnailInfo GetThumbnailInfo(string url, PostClass post)
3840 {
39- var thumbnailUrl = base.FetchImageUrl(url);
41+ var thumb = base.GetThumbnailInfo(url, post);
42+ if (thumb == null) return null;
4043
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+ }
4369 }
4470 }
4571 }
--- a/OpenTween/Thumbnail/ThumbnailGenerator.cs
+++ b/OpenTween/Thumbnail/ThumbnailGenerator.cs
@@ -118,7 +118,7 @@ namespace OpenTween.Thumbnail
118118 "http://lohas.nicoseiga.jp/thumb/${id}l?"),
119119
120120 // 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]+)).*$"),
122122
123123 // flickr
124124 new MetaThumbnailService(@"^http://www\.flickr\.com/.+$"),