• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: Commit

開発に使用するリポジトリ


Commit MetaInfo

Revision4db5e5467d7db056f309a67b88c0cd22f01c8453 (tree)
Time2022-01-22 21:32:19
Authorupsilon <kim.upsilon@bucy...>
CommiterGitHub

Log Message

Merge pull request #88 from opentween/update-instagram-pattern

Instagramのサムネイルを表示するURLのパターンを追加

Change Summary

Incremental Difference

--- /dev/null
+++ b/OpenTween.Tests/Thumbnail/ThumbnailGeneratorTest.cs
@@ -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+}
--- a/OpenTween/Resources/ChangeLog.txt
+++ b/OpenTween/Resources/ChangeLog.txt
@@ -2,6 +2,7 @@
22
33 ==== Ver 2.4.4-dev(2019/xx/xx)
44 * CHG: pic.twitter.com の画像URLのフォーマット変更に対応
5+ * CHG: Instagramのサムネイルを表示するURLのパターンを追加
56 * FIX: DMの添付画像をブラウザで開く場合に使用するURLを変更
67 * FIX: 大文字アルファベットを含むハッシュタグがユーザー情報画面で正しくリンク化されない不具合を修正 (thx @naminodarie!)
78
--- a/OpenTween/Thumbnail/Services/SimpleThumbnailService.cs
+++ b/OpenTween/Thumbnail/Services/SimpleThumbnailService.cs
@@ -48,8 +48,13 @@ namespace OpenTween.Thumbnail.Services
4848 }
4949
5050 public SimpleThumbnailService(string pattern, string replacement, string? file_replacement)
51+ : this(new Regex(pattern, RegexOptions.IgnoreCase), replacement, file_replacement)
5152 {
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;
5358 this.thumb_replacement = replacement;
5459 this.fullsize_replacement = file_replacement;
5560 }
--- a/OpenTween/Thumbnail/ThumbnailGenerator.cs
+++ b/OpenTween/Thumbnail/ThumbnailGenerator.cs
@@ -36,6 +36,11 @@ namespace OpenTween.Thumbnail
3636 {
3737 class ThumbnailGenerator
3838 {
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+
3944 public static List<IThumbnailService> Services { get; protected set; }
4045
4146 internal static ImgAzyobuziNet ImgAzyobuziNetInstance { get; private set; } = null!;
@@ -132,9 +137,9 @@ namespace OpenTween.Thumbnail
132137
133138 // Instagram
134139 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"),
138143
139144 // Foursquare
140145 new FoursquareCheckin(),
Show on old repository browser