OSDN Git Service

ChangeLog修正
[opentween/open-tween.git] / OpenTween / Thumbnail / ThumbnailGenerator.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
26 using System.Text.RegularExpressions;
27 using OpenTween.Thumbnail.Services;
28
29 namespace OpenTween.Thumbnail
30 {
31     class ThumbnailGenerator
32     {
33         public static List<IThumbnailService> Services { get; protected set; }
34
35         static ThumbnailGenerator()
36         {
37             ThumbnailGenerator.Services = new List<IThumbnailService>();
38         }
39
40         public static void InitializeGenerator()
41         {
42             ThumbnailGenerator.Services = new List<IThumbnailService>()
43             {
44                 // DirectLink
45                 new SimpleThumbnailService(@"^https?://.*(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$", "${0}"),
46
47                 // img.azyobuzi.net
48                 new ImgAzyobuziNet(autoupdate: true),
49
50                 // ImgUr
51                 new SimpleThumbnailService(@"^http://(?:i\.)?imgur\.com/(\w+)(?:\..{3})?$", "http://img.imgur.com/${1}l.jpg"),
52
53                 // Twitpic
54                 new SimpleThumbnailService(@"^http://(www\.)?twitpic\.com/(?<photoId>\w+)(/full/?)?$", "http://twitpic.com/show/thumb/${photoId}"),
55
56                 // yfrog
57                 new SimpleThumbnailService(@"^http://yfrog\.com/(\w+)$", "${0}:small"),
58
59                 // Lockerz
60                 new SimpleThumbnailService(@"^http://(tweetphoto\.com/[0-9]+|pic\.gd/[a-z0-9]+|(lockerz|plixi)\.com/[ps]/[0-9]+)$", "http://api.plixi.com/api/tpapi.svc/imagefromurl?size=thumbnail&url=${0}"),
61
62                 // MobyPicture
63                 new SimpleThumbnailService(@"^http://moby\.to/(\w+)$", "http://mobypicture.com/?${1}:small"),
64
65                 // 携帯百景
66                 new SimpleThumbnailService(@"^http://movapic\.com/pic/(\w+)$", "http://image.movapic.com/pic/s_${1}.jpeg"),
67
68                 // はてなフォトライフ
69                 new SimpleThumbnailService(@"^http://f\.hatena\.ne\.jp/(([a-z])[a-z0-9_-]{1,30}[a-z0-9])/((\d{8})\d+)$", "http://img.f.hatena.ne.jp/images/fotolife/${2}/${1}/${4}/${3}_120.jpg"),
70
71                 // PhotoShare
72                 new SimpleThumbnailService(@"^http://(?:www\.)?bcphotoshare\.com/photos/\d+/(\d+)$", "http://images.bcphotoshare.com/storages/${1}/thumb180.jpg"),
73
74                 // PhotoShare
75                 new PhotoShareShortlink(@"^http://bctiny\.com/p(\w+)$"),
76
77                 // img.ly
78                 new SimpleThumbnailService(@"^http://img\.ly/(\w+)$", "http://img.ly/show/thumb/${1}"),
79
80                 // Twitgoo
81                 new SimpleThumbnailService(@"^http://twitgoo\.com/(\w+)$", "http://twitgoo.com/${1}/mini"),
82
83                 // youtube
84                 new Youtube(@"^http://(?:(www\.youtube\.com)|(youtu\.be))/(watch\?v=)?(?<videoid>([\w\-]+))", "http://i.ytimg.com/vi/${videoid}/default.jpg"),
85
86                 // ニコニコ動画
87                 new Nicovideo(@"^http://(?:(www|ext)\.nicovideo\.jp/watch|nico\.ms)/(?:sm|nm)?([0-9]+)(\?.+)?$", "http://www.nicovideo.jp/api/getthumbinfo/${id}"),
88
89                 // ニコニコ静画
90                 new SimpleThumbnailService(@"^http://(?:seiga\.nicovideo\.jp/seiga/|nico\.ms/)im(?<id>\d+)", "http://lohas.nicoseiga.jp/thumb/${id}q?"),
91
92                 // pixiv
93                 new MetaThumbnailService(@"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$"),
94
95                 // flickr
96                 new MetaThumbnailService(@"^http://www\.flickr\.com/.+$"),
97
98                 // フォト蔵
99                 new SimpleThumbnailService(@"^http://photozou\.jp/photo/show/(?<userId>[0-9]+)/(?<photoId>[0-9]+)", "http://photozou.jp/p/thumb/${photoId}"),
100
101                 // TwitVideo
102                 new SimpleThumbnailService(@"^http://twitvideo\.jp/(\w+)$", "http://twitvideo.jp/img/thumb/${1}"),
103
104                 // Piapro
105                 new MetaThumbnailService(@"^http://piapro\.jp/(?:content/[0-9a-z]+|t/[0-9a-zA-Z_\-]+)$"),
106
107                 // Tumblr
108                 new Tumblr(@"(?<base>http://.+?\.tumblr\.com/)post/(?<postID>[0-9]+)(/(?<subject>.+?)/)?", "${base}api/read?id=${postID}"),
109
110                 // ついっぷるフォト
111                 new SimpleThumbnailService(@"^http://p\.twipple\.jp/(?<contentId>[0-9a-z]+)", "http://p.twipple.jp/show/large/${contentId}"),
112
113                 // mypix/shamoji
114                 new SimpleThumbnailService(@"^http://www\.(mypix\.jp|shamoji\.info)/app\.php/picture/(?<contentId>[0-9a-z]+)", "${0}/thumb.jpg"),
115
116                 // ow.ly
117                 new SimpleThumbnailService(@"^http://ow\.ly/i/(\w+)$", "http://static.ow.ly/photos/thumb/${1}.jpg"),
118
119                 // vimeo
120                 new Vimeo(@"http://vimeo\.com/(?<postID>[0-9]+)", "http://vimeo.com/api/oembed.xml?url=${0}"),
121
122                 // cloudfiles
123                 new SimpleThumbnailService(@"^http://c[0-9]+\.cdn[0-9]+\.cloudfiles\.rackspacecloud\.com/[a-z_0-9]+", "${0}"),
124
125                 // Instagram
126                 new SimpleThumbnailService(@"^http://instagr\.am/p/.+/", "${0}media/?size=m"),
127
128                 // pikubo
129                 new SimpleThumbnailService(@"^http://pikubo\.me/([a-z0-9-_]+)", "http://pikubo.me/q/${1}"),
130
131                 // Foursquare
132                 new Services.Foursquare(@"^https?://(4sq|foursquare)\.com/.+"),
133
134                 // TINAMI
135                 new Tinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$", "http://api.tinami.com/content/info?cont_id=${ContentId}&api_key=" + ApplicationSettings.TINAMIApiKey),
136
137                 // pic.twitter.com
138                 new SimpleThumbnailService(@"^https?://p\.twimg\.com/.*$", "${0}:thumb"),
139
140                 // TwitrPix
141                 new SimpleThumbnailService(@"^http://twitrpix\.com/(\w+)$", "http://img.twitrpix.com/thumb/${1}"),
142
143                 // Pckles
144                 new SimpleThumbnailService(@"^https?://pckles\.com/\w+/\w+$", "${0}.resize.jpg"),
145
146                 // via.me
147                 new ViaMe(@"^https?://via\.me/-(\w+)$", "http://via.me/api/v1/posts/$1"),
148
149                 // tuna.be
150                 new SimpleThumbnailService(@"^http://tuna\.be/t/(?<entryId>[a-zA-Z0-9\.\-_]+)$", "http://tuna.be/show/thumb/${entryId}"),
151
152                 // Path (path.com)
153                 new MetaThumbnailService(@"^https?://path.com/p/\w+$"),
154             };
155         }
156
157         public static List<ThumbnailInfo> GetThumbnails(PostClass post)
158         {
159             var thumbnails = new List<ThumbnailInfo>();
160
161             if (post.Media != null)
162             {
163                 foreach (var media in post.Media)
164                 {
165                     var thumbInfo = ThumbnailGenerator.GetThumbnailInfo(media.Value, post);
166                     if (thumbInfo != null)
167                     {
168                         thumbnails.Add(thumbInfo);
169                     }
170                 }
171             }
172
173             if (post.PostGeo != null && !(post.PostGeo.Lat == 0 && post.PostGeo.Lng == 0))
174             {
175                 var map = MapThumb.GetDefaultInstance();
176                 thumbnails.Add(new ThumbnailInfo()
177                 {
178                     ImageUrl = map.CreateMapLinkUrl(post.PostGeo.Lat, post.PostGeo.Lng),
179                     ThumbnailUrl = map.CreateStaticMapUrl(post.PostGeo.Lat, post.PostGeo.Lng),
180                     TooltipText = null,
181                 });
182             }
183
184             return thumbnails;
185         }
186
187         public static ThumbnailInfo GetThumbnailInfo(string url, PostClass post)
188         {
189             foreach (var generator in ThumbnailGenerator.Services)
190             {
191                 var result = generator.GetThumbnailInfo(url, post);
192                 if (result != null)
193                 {
194                     return result;
195                 }
196             }
197
198             return null;
199         }
200     }
201 }