{
public string FakeXml { get; set; }
- public TestTinami(string pattern)
- : base(null, pattern)
+ public TestTinami()
+ : base(null)
{
}
[Fact]
public async Task ApiTest()
{
- var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$");
+ var service = new TestTinami();
service.FakeXml = @"<?xml version='1.0' encoding='utf-8' ?>
<rsp stat='ok'>
[Fact]
public async Task ApiErrorTest()
{
- var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$");
+ var service = new TestTinami();
service.FakeXml = @"<?xml version='1.0' encoding='utf-8'?>
<rsp stat='user_only'>
{
class Nicovideo : IThumbnailService
{
- protected readonly Regex regex;
-
- public Nicovideo(string pattern)
- {
- this.regex = new Regex(pattern);
- }
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"^http://(?:(www|ext)\.nicovideo\.jp/watch|nico\.ms)/(?<id>(?:sm|nm)?[0-9]+)(\?.+)?$");
public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
return Task.Run(() =>
{
- var match = this.regex.Match(url);
+ var match = Nicovideo.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
{
class PhotoShareShortlink : IThumbnailService
{
- protected Regex regex;
-
- public PhotoShareShortlink(string pattern)
- {
- this.regex = new Regex(pattern);
- }
+ public static readonly Regex UrlPatternRegex = new Regex(@"^http://bctiny\.com/p(\w+)$");
public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
return Task.Run(() =>
{
- var match = this.regex.Match(url);
+ var match = PhotoShareShortlink.UrlPatternRegex.Match(url);
- if (!match.Success) return null;
+ if (!match.Success)
+ return null;
return new ThumbnailInfo
{
{
class Pixiv : MetaThumbnailService
{
- public Pixiv(HttpClient http, string urlPattern)
- : base(http, urlPattern)
+ public static readonly string UrlPattern =
+ @"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$";
+
+ public Pixiv(HttpClient http)
+ : base(http, Pixiv.UrlPattern)
{
}
{
class Tinami : IThumbnailService
{
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$");
+
protected readonly HttpClient http;
- protected readonly Regex regex;
- public Tinami(HttpClient http, string urlPattern)
+ public Tinami(HttpClient http)
{
this.http = http;
- this.regex = new Regex(urlPattern);
}
public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
- var match = this.regex.Match(url);
+ var match = Tinami.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
{
class Tumblr : IThumbnailService
{
- protected readonly Regex regex;
-
- public Tumblr(string urlPattern)
- {
- this.regex = new Regex(urlPattern);
- }
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"(?<base>http://.+?\.tumblr\.com/)post/(?<postID>[0-9]+)(/(?<subject>.+?)/)?");
public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
return Task.Run(() =>
{
- var match = this.regex.Match(url);
+ var match = Tumblr.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
{
class ViaMe : IThumbnailService
{
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"^https?://via\.me/-(\w+)$");
+
protected readonly HttpClient http;
- protected readonly Regex regex;
- public ViaMe(HttpClient http, string urlPattern)
+ public ViaMe(HttpClient http)
{
this.http = http;
- this.regex = new Regex(urlPattern);
}
public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
- var match = this.regex.Match(url);
+ var match = ViaMe.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
{
class Vimeo : IThumbnailService
{
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"http://vimeo\.com/(?<postID>[0-9]+)");
+
protected readonly HttpClient http;
- protected readonly Regex regex;
- public Vimeo(HttpClient http, string urlPattern)
+ public Vimeo(HttpClient http)
{
this.http = http;
- this.regex = new Regex(urlPattern);
}
public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
- var match = this.regex.Match(url);
+ var match = Vimeo.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
{
class Youtube : IThumbnailService
{
- protected readonly Regex regex;
-
- public Youtube(string urlPattern)
- {
- this.regex = new Regex(urlPattern);
- }
+ public static readonly Regex UrlPatternRegex =
+ new Regex(@"^http://(?:(www\.youtube\.com)|(youtu\.be))/(watch\?v=)?(?<videoid>([\w\-]+))");
public override Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
{
return Task.Run(() =>
{
- var match = this.regex.Match(url);
+ var match = Youtube.UrlPatternRegex.Match(url);
if (!match.Success)
return null;
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+)$"),
+ new PhotoShareShortlink(),
// img.ly
new SimpleThumbnailService(@"^http://img\.ly/(\w+)$",
"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, @"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$"),
+ new Pixiv(http),
// flickr
new MetaThumbnailService(http, @"^http://www\.flickr\.com/.+$"),
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, @"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}"),
new FoursquareCheckin(http),
// TINAMI
- new Tinami(http, @"^http://www\.tinami\.com/view/(?<ContentId>\d+)$"),
+ new Tinami(http),
// pic.twitter.com
new SimpleThumbnailService(
"${0}.jpg"),
// via.me
- new ViaMe(http, @"^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}"),