OSDN Git Service

GIFMAGAZINE のサムネイル表示に対応
[opentween/open-tween.git] / OpenTween / Thumbnail / ThumbnailGenerator.cs
index 7ab1030..03ccef1 100644 (file)
@@ -22,6 +22,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net.Http;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
@@ -34,16 +35,17 @@ namespace OpenTween.Thumbnail
     {
         public static List<IThumbnailService> Services { get; protected set; }
 
-        internal static readonly Lazy<ImgAzyobuziNet> ImgAzyobuziNetInstance;
+        internal static ImgAzyobuziNet ImgAzyobuziNetInstance { get; private set; }
 
         static ThumbnailGenerator()
         {
             ThumbnailGenerator.Services = new List<IThumbnailService>();
-            ImgAzyobuziNetInstance = new Lazy<ImgAzyobuziNet>(() => new ImgAzyobuziNet(autoupdate: true));
         }
 
-        public static void InitializeGenerator()
+        public static void InitializeGenerator(HttpClient http)
         {
+            ImgAzyobuziNetInstance = new ImgAzyobuziNet(http, autoupdate: true);
+
             ThumbnailGenerator.Services = new List<IThumbnailService>()
             {
                 // ton.twitter.com
@@ -53,7 +55,7 @@ namespace OpenTween.Thumbnail
                 new SimpleThumbnailService(@"^https?://.*(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$", "${0}"),
 
                 // img.azyobuzi.net
-                ImgAzyobuziNetInstance.Value,
+                ImgAzyobuziNetInstance,
 
                 // ImgUr
                 new SimpleThumbnailService(
@@ -100,9 +102,6 @@ namespace OpenTween.Thumbnail
                 // PhotoShare
                 new SimpleThumbnailService(@"^http://(?:www\.)?bcphotoshare\.com/photos/\d+/(\d+)$", "http://images.bcphotoshare.com/storages/${1}/thumb180.jpg"),
 
-                // PhotoShare
-                new PhotoShareShortlink(@"^http://bctiny\.com/p(\w+)$"),
-
                 // img.ly
                 new SimpleThumbnailService(@"^http://img\.ly/(\w+)$",
                     "http://img.ly/show/thumb/${1}",
@@ -114,10 +113,10 @@ namespace OpenTween.Thumbnail
                     "http://twitgoo.com/${1}/img"),
 
                 // youtube
-                new Youtube(@"^http://(?:(www\.youtube\.com)|(youtu\.be))/(watch\?v=)?(?<videoid>([\w\-]+))"),
+                new Youtube(),
 
                 // ニコニコ動画
-                new Nicovideo(@"^http://(?:(www|ext)\.nicovideo\.jp/watch|nico\.ms)/(?<id>(?:sm|nm)?[0-9]+)(\?.+)?$"),
+                new Nicovideo(),
 
                 // ニコニコ静画
                 new SimpleThumbnailService(
@@ -126,10 +125,10 @@ namespace OpenTween.Thumbnail
                     "http://lohas.nicoseiga.jp/thumb/${id}l?"),
 
                 // pixiv
-                new Pixiv(@"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$"),
+                new Pixiv(http),
 
                 // flickr
-                new MetaThumbnailService(@"^http://www\.flickr\.com/.+$"),
+                new MetaThumbnailService(http, @"^https?://www\.flickr\.com/.+$"),
 
                 // フォト蔵
                 new SimpleThumbnailService(
@@ -138,10 +137,10 @@ namespace OpenTween.Thumbnail
                     "http://photozou.jp/p/img/${photoId}"),
 
                 // Piapro
-                new MetaThumbnailService(@"^http://piapro\.jp/(?:content/[0-9a-z]+|t/[0-9a-zA-Z_\-]+)$"),
+                new MetaThumbnailService(http, @"^http://piapro\.jp/(?:content/[0-9a-z]+|t/[0-9a-zA-Z_\-]+)$"),
 
                 // Tumblr
-                new Tumblr(@"(?<base>http://.+?\.tumblr\.com/)post/(?<postID>[0-9]+)(/(?<subject>.+?)/)?"),
+                new Tumblr(),
 
                 // ついっぷるフォト
                 new SimpleThumbnailService(@"^http://p\.twipple\.jp/(?<contentId>[0-9a-z]+)", "http://p.twipple.jp/show/large/${contentId}"),
@@ -153,14 +152,14 @@ namespace OpenTween.Thumbnail
                 new SimpleThumbnailService(@"^http://ow\.ly/i/(\w+)$", "http://static.ow.ly/photos/thumb/${1}.jpg"),
 
                 // vimeo
-                new Vimeo(@"http://vimeo\.com/(?<postID>[0-9]+)"),
+                new Vimeo(http),
 
                 // cloudfiles
                 new SimpleThumbnailService(@"^http://c[0-9]+\.cdn[0-9]+\.cloudfiles\.rackspacecloud\.com/[a-z_0-9]+", "${0}"),
 
                 // Instagram
                 new SimpleThumbnailService(
-                    @"^http://instagr\.am/p/.+/",
+                    @"^http://(?:instagram.com|instagr\.am)/p/.+/",
                     "${0}media/?size=m",
                     "${0}media/?size=l"),
 
@@ -171,10 +170,10 @@ namespace OpenTween.Thumbnail
                     "http://pikubo.me/l/${1}"),
 
                 // Foursquare
-                new FoursquareCheckin(),
+                new FoursquareCheckin(http),
 
                 // TINAMI
-                new Tinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$"),
+                new Tinami(http),
 
                 // pic.twitter.com
                 new SimpleThumbnailService(
@@ -195,13 +194,16 @@ namespace OpenTween.Thumbnail
                     "${0}.jpg"),
 
                 // via.me
-                new ViaMe(@"^https?://via\.me/-(\w+)$"),
+                new ViaMe(http),
 
                 // tuna.be
                 new SimpleThumbnailService(@"^http://tuna\.be/t/(?<entryId>[a-zA-Z0-9\.\-_]+)$", "http://tuna.be/show/thumb/${entryId}"),
 
                 // Path (path.com)
-                new MetaThumbnailService(@"^https?://path.com/p/\w+$"),
+                new MetaThumbnailService(http, @"^https?://path.com/p/\w+$"),
+
+                // GIFMAGAZINE
+                new MetaThumbnailService(http, @"^http?://gifmagazine\.net/post_images/\d+$"),
             };
         }
 
@@ -213,7 +215,7 @@ namespace OpenTween.Thumbnail
             {
                 foreach (var media in post.Media)
                 {
-                    var thumbInfo = await ThumbnailGenerator.GetThumbnailInfoAsync(media.Value, post, token)
+                    var thumbInfo = await ThumbnailGenerator.GetThumbnailInfoAsync(media, post, token)
                         .ConfigureAwait(false);
 
                     if (thumbInfo != null)