1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
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)
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
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.
23 using System.Collections;
24 using System.Collections.Generic;
26 using System.Runtime.Serialization;
28 using System.Threading.Tasks;
30 namespace OpenTween.Api.DataModel
32 // 参照: https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/entities-object
35 public class TwitterEntities : IEnumerable<TwitterEntity>
37 [DataMember(Name = "hashtags", IsRequired = false)]
38 public TwitterEntityHashtag[] Hashtags { get; set; }
40 [DataMember(Name = "media", IsRequired = false)]
41 public TwitterEntityMedia[] Media { get; set; }
43 [DataMember(Name = "symbols", IsRequired = false)]
44 public TwitterEntitySymbol[] Symbols { get; set; }
46 [DataMember(Name = "urls", IsRequired = false)]
47 public TwitterEntityUrl[] Urls { get; set; }
49 [DataMember(Name = "user_mentions", IsRequired = false)]
50 public TwitterEntityMention[] UserMentions { get; set; }
52 public IEnumerator<TwitterEntity> GetEnumerator()
54 var entities = Enumerable.Empty<TwitterEntity>();
56 if (this.Hashtags != null)
57 entities = entities.Concat(this.Hashtags);
59 if (this.Media != null)
60 entities = entities.Concat(this.Media);
62 if (this.Symbols != null)
63 entities = entities.Concat(this.Symbols);
65 if (this.Urls != null)
66 entities = entities.Concat(this.Urls);
68 if (this.UserMentions != null)
69 entities = entities.Concat(this.UserMentions);
71 return entities.GetEnumerator();
74 IEnumerator IEnumerable.GetEnumerator()
75 => this.GetEnumerator();
79 public abstract class TwitterEntity
81 [DataMember(Name = "indices")]
82 public int[] Indices { get; set; }
86 public class TwitterEntityHashtag : TwitterEntity
88 [DataMember(Name = "text")]
89 public string Text { get; set; }
93 public class TwitterEntityMedia : TwitterEntityUrl
95 [DataMember(Name = "additional_media_info", IsRequired = false)]
96 public TwitterMediaAdditionalInfo AdditionalMediaInfo { get; set; }
98 [DataMember(Name = "id")]
99 public long Id { get; set; }
101 [DataMember(Name = "id_str")]
102 public string IdStr { get; set; }
104 [DataMember(Name = "media_url_https")]
105 public string MediaUrlHttps { get; set; }
107 [DataMember(Name = "sizes")]
108 public TwitterMediaSizes Sizes { get; set; }
110 [DataMember(Name = "source_status_id")]
111 public long SourceStatusId { get; set; }
113 [DataMember(Name = "source_status_id_str")]
114 public string SourceStatusIdStr { get; set; }
116 [DataMember(Name = "type")]
117 public string Type { get; set; }
119 [DataMember(Name = "video_info", IsRequired = false)]
120 public TwitterMediaVideoInfo VideoInfo { get; set; }
122 [DataMember(Name = "ext_alt_text", IsRequired = false)]
123 public string AltText { get; set; }
127 public class TwitterMediaSizes
129 [DataMember(Name = "thumb")]
130 public TwitterMediaSizes.Size Thumb { get; set; }
132 [DataMember(Name = "large")]
133 public TwitterMediaSizes.Size Large { get; set; }
135 [DataMember(Name = "medium")]
136 public TwitterMediaSizes.Size Medium { get; set; }
138 [DataMember(Name = "small")]
139 public TwitterMediaSizes.Size Small { get; set; }
144 [DataMember(Name = "h")]
145 public int Height { get; set; }
147 [DataMember(Name = "resize")]
148 public string Resize { get; set; }
150 [DataMember(Name = "w")]
151 public int Width { get; set; }
156 public class TwitterMediaVideoInfo
158 [DataMember(Name = "aspect_ratio")]
159 public int[] AspectRatio { get; set; }
161 [DataMember(Name = "duration_millis", IsRequired = false)]
162 public long? DurationMillis { get; set; }
164 [DataMember(Name = "variants")]
165 public TwitterMediaVideoInfo.Variant[] Variants { get; set; }
170 [DataMember(Name = "bitrate")]
171 public int? Bitrate { get; set; }
173 [DataMember(Name = "content_type")]
174 public string ContentType { get; set; }
176 [DataMember(Name = "url")]
177 public string Url { get; set; }
182 public class TwitterMediaAdditionalInfo
184 [DataMember(Name = "title")]
185 public string Title { get; set; }
187 [DataMember(Name = "description")]
188 public string Description { get; set; }
190 [DataMember(Name = "embeddable")]
191 public bool Embeddable { get; set; }
193 [DataMember(Name = "monetizable")]
194 public bool Monetizable { get; set; }
198 public class TwitterEntitySymbol : TwitterEntity
200 [DataMember(Name = "text")]
201 public string Text { get; set; }
205 public class TwitterEntityUrl : TwitterEntity
207 [DataMember(Name = "display_url")]
208 public string DisplayUrl { get; set; }
210 [DataMember(Name = "expanded_url")]
211 public string ExpandedUrl { get; set; }
213 [DataMember(Name = "url")]
214 public string Url { get; set; }
218 public class TwitterEntityMention : TwitterEntity
220 [DataMember(Name = "id")]
221 public long Id { get; set; }
223 [DataMember(Name = "id_str")]
224 public string IdStr { get; set; }
226 [DataMember(Name = "name")]
227 public string Name { get; set; }
229 [DataMember(Name = "screen_name")]
230 public string ScreenName { get; set; }