feat: expand media URLs in tweet
This commit is contained in:
parent
9f31f3890f
commit
cc1eb793d6
3 changed files with 29 additions and 18 deletions
|
|
@ -56,6 +56,7 @@ func (result *result) parse() *Tweet {
|
||||||
if result.QuotedStatusResult.Result != nil {
|
if result.QuotedStatusResult.Result != nil {
|
||||||
tw.QuotedStatus = result.QuotedStatusResult.Result.parse()
|
tw.QuotedStatus = result.QuotedStatusResult.Result.parse()
|
||||||
}
|
}
|
||||||
|
tw.HTML = expandMediaURLs(tw.HTML, legacy.ExtendedEntities.Media)
|
||||||
return tw
|
return tw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
38
types.go
38
types.go
|
|
@ -99,6 +99,25 @@ type (
|
||||||
GIFs []GIF
|
GIFs []GIF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExtendedMedia struct {
|
||||||
|
IDStr string `json:"id_str"`
|
||||||
|
MediaURLHttps string `json:"media_url_https"`
|
||||||
|
ExtSensitiveMediaWarning struct {
|
||||||
|
AdultContent bool `json:"adult_content"`
|
||||||
|
GraphicViolence bool `json:"graphic_violence"`
|
||||||
|
Other bool `json:"other"`
|
||||||
|
} `json:"ext_sensitive_media_warning"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
VideoInfo struct {
|
||||||
|
Variants []struct {
|
||||||
|
Type string `json:"content_type"`
|
||||||
|
Bitrate int `json:"bitrate"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
} `json:"variants"`
|
||||||
|
} `json:"video_info"`
|
||||||
|
}
|
||||||
|
|
||||||
legacyTweet struct {
|
legacyTweet struct {
|
||||||
ConversationIDStr string `json:"conversation_id_str"`
|
ConversationIDStr string `json:"conversation_id_str"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
|
|
@ -121,24 +140,7 @@ type (
|
||||||
} `json:"user_mentions"`
|
} `json:"user_mentions"`
|
||||||
} `json:"entities"`
|
} `json:"entities"`
|
||||||
ExtendedEntities struct {
|
ExtendedEntities struct {
|
||||||
Media []struct {
|
Media []ExtendedMedia `json:"media"`
|
||||||
IDStr string `json:"id_str"`
|
|
||||||
MediaURLHttps string `json:"media_url_https"`
|
|
||||||
ExtSensitiveMediaWarning struct {
|
|
||||||
AdultContent bool `json:"adult_content"`
|
|
||||||
GraphicViolence bool `json:"graphic_violence"`
|
|
||||||
Other bool `json:"other"`
|
|
||||||
} `json:"ext_sensitive_media_warning"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
VideoInfo struct {
|
|
||||||
Variants []struct {
|
|
||||||
Type string `json:"content_type"`
|
|
||||||
Bitrate int `json:"bitrate"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
} `json:"variants"`
|
|
||||||
} `json:"video_info"`
|
|
||||||
} `json:"media"`
|
|
||||||
} `json:"extended_entities"`
|
} `json:"extended_entities"`
|
||||||
IDStr string `json:"id_str"`
|
IDStr string `json:"id_str"`
|
||||||
InReplyToStatusIDStr string `json:"in_reply_to_status_id_str"`
|
InReplyToStatusIDStr string `json:"in_reply_to_status_id_str"`
|
||||||
|
|
|
||||||
8
util.go
8
util.go
|
|
@ -388,6 +388,14 @@ func expandURLs(text string, urls []Url) string {
|
||||||
return expandedText
|
return expandedText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func expandMediaURLs(text string, extendedMediaEntities []ExtendedMedia) string {
|
||||||
|
expandedText := text
|
||||||
|
for _, entity := range extendedMediaEntities {
|
||||||
|
expandedText = strings.ReplaceAll(expandedText, entity.URL, entity.MediaURLHttps)
|
||||||
|
}
|
||||||
|
return expandedText
|
||||||
|
}
|
||||||
|
|
||||||
func parseProfileV2(user userResult) Profile {
|
func parseProfileV2(user userResult) Profile {
|
||||||
u := user.Legacy
|
u := user.Legacy
|
||||||
description := expandURLs(u.Description, u.Entities.Description.Urls)
|
description := expandURLs(u.Description, u.Entities.Description.Urls)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue