開発に使用するリポジトリ
Revision | 4db5e5467d7db056f309a67b88c0cd22f01c8453 (tree) |
---|---|
Time | 2022-01-22 21:32:19 |
Author | upsilon <kim.upsilon@bucy...> |
Commiter | GitHub |
Merge pull request #88 from opentween/update-instagram-pattern
Instagramのサムネイルを表示するURLのパターンを追加
@@ -0,0 +1,50 @@ | ||
1 | +// OpenTween - Client of Twitter | |
2 | +// Copyright (c) 2022 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.Threading.Tasks; | |
27 | +using Xunit; | |
28 | + | |
29 | +namespace OpenTween.Thumbnail | |
30 | +{ | |
31 | + public class ThumbnailGeneratorTest | |
32 | + { | |
33 | + [Theory] | |
34 | + [InlineData("https://www.instagram.com/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] | |
35 | + [InlineData("http://www.instagram.com/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] | |
36 | + [InlineData("https://i.instagram.com/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] | |
37 | + [InlineData("https://instagram.com/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] | |
38 | + [InlineData("https://instagr.am/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] | |
39 | + [InlineData("https://www.instagram.com/hogehoge/p/aaaaaaaaaaa/", "aaaaaaaaaaa")] // ユーザー名付き | |
40 | + [InlineData("https://www.instagram.com/p/aaaaaaaaaaa/?utm_medium=copy_link", "aaaaaaaaaaa")] // トラッキングパラメータ付き | |
41 | + [InlineData("https://www.instagram.com/hogehoge/", null)] // プロフィールページ | |
42 | + public void InstagramPattern_IsMatchTest(string testUrl, string expected) | |
43 | + { | |
44 | + var match = ThumbnailGenerator.InstagramPattern.Match(testUrl); | |
45 | + | |
46 | + var matchedMediaId = match.Success ? match.Groups["mediaId"].Value : null; | |
47 | + Assert.Equal(expected, matchedMediaId); | |
48 | + } | |
49 | + } | |
50 | +} |
@@ -2,6 +2,7 @@ | ||
2 | 2 | |
3 | 3 | ==== Ver 2.4.4-dev(2019/xx/xx) |
4 | 4 | * CHG: pic.twitter.com の画像URLのフォーマット変更に対応 |
5 | + * CHG: Instagramのサムネイルを表示するURLのパターンを追加 | |
5 | 6 | * FIX: DMの添付画像をブラウザで開く場合に使用するURLを変更 |
6 | 7 | * FIX: 大文字アルファベットを含むハッシュタグがユーザー情報画面で正しくリンク化されない不具合を修正 (thx @naminodarie!) |
7 | 8 |
@@ -48,8 +48,13 @@ namespace OpenTween.Thumbnail.Services | ||
48 | 48 | } |
49 | 49 | |
50 | 50 | public SimpleThumbnailService(string pattern, string replacement, string? file_replacement) |
51 | + : this(new Regex(pattern, RegexOptions.IgnoreCase), replacement, file_replacement) | |
51 | 52 | { |
52 | - this.regex = new Regex(pattern, RegexOptions.IgnoreCase); | |
53 | + } | |
54 | + | |
55 | + public SimpleThumbnailService(Regex regex, string replacement, string? file_replacement) | |
56 | + { | |
57 | + this.regex = regex; | |
53 | 58 | this.thumb_replacement = replacement; |
54 | 59 | this.fullsize_replacement = file_replacement; |
55 | 60 | } |
@@ -36,6 +36,11 @@ namespace OpenTween.Thumbnail | ||
36 | 36 | { |
37 | 37 | class ThumbnailGenerator |
38 | 38 | { |
39 | + public static readonly Regex InstagramPattern = new Regex( | |
40 | + @"^https?://(?:instagram.com|instagr\.am|i\.instagram\.com|www\.instagram\.com)/([^/]+/)?p/(?<mediaId>[^/]+)/(\?.*)?$", | |
41 | + RegexOptions.IgnoreCase | |
42 | + ); | |
43 | + | |
39 | 44 | public static List<IThumbnailService> Services { get; protected set; } |
40 | 45 | |
41 | 46 | internal static ImgAzyobuziNet ImgAzyobuziNetInstance { get; private set; } = null!; |
@@ -132,9 +137,9 @@ namespace OpenTween.Thumbnail | ||
132 | 137 | |
133 | 138 | |
134 | 139 | new SimpleThumbnailService( |
135 | - @"^https?://(?:instagram.com|instagr\.am|i\.instagram\.com|www\.instagram\.com)/p/.+/", | |
136 | - "${0}media/?size=m", | |
137 | - "${0}media/?size=l"), | |
140 | + InstagramPattern, | |
141 | + "https://www.instagram.com/p/${mediaId}/media/?size=m", | |
142 | + "https://www.instagram.com/p/${mediaId}/media/?size=l"), | |
138 | 143 | |
139 | 144 | // Foursquare |
140 | 145 | new FoursquareCheckin(), |