using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
{
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
new SimpleThumbnailService(@"^https?://.*(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$", "${0}"),
// img.azyobuzi.net
- ImgAzyobuziNetInstance.Value,
+ ImgAzyobuziNetInstance,
// ImgUr
new SimpleThumbnailService(
// 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}",
"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(
"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(
"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}"),
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"),
"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(
"${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+$"),
};
}
{
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)