-
Notifications
You must be signed in to change notification settings - Fork 921
/
entities.go
104 lines (90 loc) · 3.32 KB
/
entities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package twitter
// Entities represent metadata and context info parsed from Twitter components.
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/entities-object
// TODO: symbols
type Entities struct {
Hashtags []HashtagEntity `json:"hashtags"`
Media []MediaEntity `json:"media"`
Urls []URLEntity `json:"urls"`
UserMentions []MentionEntity `json:"user_mentions"`
}
// HashtagEntity represents a hashtag which has been parsed from text.
type HashtagEntity struct {
Indices Indices `json:"indices"`
Text string `json:"text"`
}
// URLEntity represents a URL which has been parsed from text.
type URLEntity struct {
Indices Indices `json:"indices"`
DisplayURL string `json:"display_url"`
ExpandedURL string `json:"expanded_url"`
URL string `json:"url"`
}
// MediaEntity represents media elements associated with a Tweet.
type MediaEntity struct {
URLEntity
ID int64 `json:"id"`
IDStr string `json:"id_str"`
MediaURL string `json:"media_url"`
MediaURLHttps string `json:"media_url_https"`
SourceStatusID int64 `json:"source_status_id"`
SourceStatusIDStr string `json:"source_status_id_str"`
Type string `json:"type"`
Sizes MediaSizes `json:"sizes"`
VideoInfo VideoInfo `json:"video_info"`
}
// MentionEntity represents Twitter user mentions parsed from text.
type MentionEntity struct {
Indices Indices `json:"indices"`
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
}
// UserEntities contain Entities parsed from User url and description fields.
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/entities-object#mentions
type UserEntities struct {
URL Entities `json:"url"`
Description Entities `json:"description"`
}
// ExtendedEntity contains media information.
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object
type ExtendedEntity struct {
Media []MediaEntity `json:"media"`
}
// Indices represent the start and end offsets within text.
type Indices [2]int
// Start returns the index at which an entity starts, inclusive.
func (i Indices) Start() int {
return i[0]
}
// End returns the index at which an entity ends, exclusive.
func (i Indices) End() int {
return i[1]
}
// MediaSizes contain the different size media that are available.
// https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/entities-object#media-size
type MediaSizes struct {
Thumb MediaSize `json:"thumb"`
Large MediaSize `json:"large"`
Medium MediaSize `json:"medium"`
Small MediaSize `json:"small"`
}
// MediaSize describes the height, width, and resizing method used.
type MediaSize struct {
Width int `json:"w"`
Height int `json:"h"`
Resize string `json:"resize"`
}
// VideoInfo is available on video media objects.
type VideoInfo struct {
AspectRatio [2]int `json:"aspect_ratio"`
DurationMillis int `json:"duration_millis"`
Variants []VideoVariant `json:"variants"`
}
// VideoVariant describes one of the available video formats.
type VideoVariant struct {
ContentType string `json:"content_type"`
Bitrate int `json:"bitrate"`
URL string `json:"url"`
}