OSDN Git Service

ツイートに添付された画像の ext_alt_text の受信に対応
authorKimura Youichi <kim.upsilon@bucyou.net>
Wed, 30 Mar 2016 15:48:38 +0000 (00:48 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 3 Apr 2016 11:02:19 +0000 (20:02 +0900)
参照: https://blog.twitter.com/2016/alt-text-support-for-twitter-cards-and-the-rest-api

OpenTween/Api/DataModel/TwitterEntity.cs
OpenTween/Connection/HttpTwitter.cs
OpenTween/Resources/ChangeLog.txt
OpenTween/StatusDictionary.cs
OpenTween/Twitter.cs

index 1945cc7..c3ad676 100644 (file)
@@ -111,6 +111,9 @@ namespace OpenTween.Api.DataModel
 
         [DataMember(Name = "video_info", IsRequired = false)]
         public TwitterMediaVideoInfo VideoInfo { get; set; }
+
+        [DataMember(Name = "ext_alt_text", IsRequired = false)]
+        public string AltText { get; set; }
     }
 
     [DataContract]
index 0874a83..e8c7a60 100644 (file)
@@ -158,6 +158,7 @@ namespace OpenTween
             param.Add("status", status);
             if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
             //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
 
             if (mediaIds != null && mediaIds.Count > 0)
@@ -178,6 +179,7 @@ namespace OpenTween
             param.Add("status", status);
             if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
             //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
 
             var binary = new List<KeyValuePair<string, IMediaItem>>();
@@ -253,6 +255,7 @@ namespace OpenTween
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(PostMethod,
                 this.CreateTwitterUri("/1.1/statuses/retweet/" + id + ".json"),
@@ -267,6 +270,7 @@ namespace OpenTween
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("screen_name", screenName);
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/users/show.json"),
                 param,
@@ -358,6 +362,7 @@ namespace OpenTween
         {
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/statuses/show/" + id + ".json"),
                 param,
@@ -403,6 +408,7 @@ namespace OpenTween
                 param.Add("since_id", since_id.ToString());
 
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
@@ -432,6 +438,7 @@ namespace OpenTween
 
             param.Add("include_rts", "true");
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
@@ -452,6 +459,7 @@ namespace OpenTween
                 param.Add("since_id", since_id.ToString());
 
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
@@ -472,6 +480,7 @@ namespace OpenTween
                 param.Add("since_id", since_id.ToString());
             param.Add("full_text", "true");
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/direct_messages.json"),
@@ -492,6 +501,7 @@ namespace OpenTween
                 param.Add("since_id", since_id.ToString());
             param.Add("full_text", "true");
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/direct_messages/sent.json"),
@@ -507,6 +517,7 @@ namespace OpenTween
             if (count != null)
                 param.Add("count", count.ToString());
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/favorites/list.json"),
@@ -529,6 +540,7 @@ namespace OpenTween
 
             param.Add("result_type", "recent");
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/search/tweets.json"),
                 param,
@@ -656,6 +668,7 @@ namespace OpenTween
             if (since_id != null)
                 param.Add("since_id", since_id.ToString());
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(GetMethod,
                 this.CreateTwitterUri("/1.1/lists/statuses.json"),
@@ -771,6 +784,7 @@ namespace OpenTween
             param.Add("description", escapedDescription);
 
             param.Add("include_entities", "true");
+            param.Add("include_ext_alt_text", "true");
 
             return httpCon.GetContent(PostMethod,
                 this.CreateTwitterUri("/1.1/account/update_profile.json"),
index 19a2298..e777033 100644 (file)
@@ -2,6 +2,7 @@
 
 ==== Ver 1.3.2-dev(2016/xx/xx)
  * NEW: touch.pixiv.net のサムネイル表示に対応 (pixiv.net は既に対応しています)
+ * NEW: pic.twitter.com の画像に設定された代替テキストの取得に対応
  * FIX: 投稿欄の複数行入力が有効かつCtrl+Enterで投稿する設定の状態でハッシュタグの自動付与が行われない不具合を修正 (thx @nt776!)
  * FIX: タブレット端末などでサムネイル画像が1枚のみ表示された状態で2本指スクロールするとエラーが発生する問題を回避
  * FIX: 発言詳細部に表示されるハッシュタグやメンションで「URLをコピー」が機能しない不具合を修正 (thx @ufoprincess!)
index 769e956..4b1db36 100644 (file)
@@ -506,16 +506,18 @@ namespace OpenTween
     public class MediaInfo
     {
         public string Url { get; }
+        public string AltText { get; }
         public string VideoUrl { get; }
 
         public MediaInfo(string url)
-            : this(url, null)
+            : this(url, altText: null, videoUrl: null)
         {
         }
 
-        public MediaInfo(string url, string videoUrl)
+        public MediaInfo(string url, string altText, string videoUrl)
         {
             this.Url = url;
+            this.AltText = altText;
             this.VideoUrl = !string.IsNullOrEmpty(videoUrl) ? videoUrl : null;
         }
 
index d79cd6d..724af75 100644 (file)
@@ -2716,10 +2716,10 @@ namespace OpenTween
                                     //    .Where(v => v.ContentType == "video/mp4")
                                     //    .OrderByDescending(v => v.Bitrate)
                                     //    .Select(v => v.Url).FirstOrDefault();
-                                    media.Add(new MediaInfo(ent.MediaUrl, ent.ExpandedUrl));
+                                    media.Add(new MediaInfo(ent.MediaUrl, ent.AltText, ent.ExpandedUrl));
                                 }
                                 else
-                                    media.Add(new MediaInfo(ent.MediaUrl));
+                                    media.Add(new MediaInfo(ent.MediaUrl, ent.AltText, videoUrl: null));
                             }
                         }
                     }