Multiple images in HTML

This commit is contained in:
Alexander Sheiko 2022-04-09 20:01:04 +03:00
parent 7c236e105c
commit dcb8906748

View file

@ -38,6 +38,7 @@ type timeline struct {
Other bool `json:"other"` Other bool `json:"other"`
} `json:"ext_sensitive_media_warning"` } `json:"ext_sensitive_media_warning"`
Type string `json:"type"` Type string `json:"type"`
URL string `json:"url"`
VideoInfo struct { VideoInfo struct {
Variants []struct { Variants []struct {
Bitrate int `json:"bitrate,omitempty"` Bitrate int `json:"bitrate,omitempty"`
@ -202,9 +203,7 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
for _, media := range tweet.ExtendedEntities.Media { for _, media := range tweet.ExtendedEntities.Media {
if media.Type == "photo" { if media.Type == "photo" {
tw.Photos = append(tw.Photos, media.MediaURLHttps) tw.Photos = append(tw.Photos, media.MediaURLHttps)
} } else if media.Type == "video" {
if media.Type == "video" {
video := Video{ video := Video{
ID: media.IDStr, ID: media.IDStr,
Preview: media.MediaURLHttps, Preview: media.MediaURLHttps,
@ -251,7 +250,7 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
return fmt.Sprintf(`<a href="%s">%s</a>`, entity.ExpandedURL, tco) return fmt.Sprintf(`<a href="%s">%s</a>`, entity.ExpandedURL, tco)
} }
} }
for _, entity := range tweet.Entities.Media { for _, entity := range tweet.ExtendedEntities.Media {
if tco == entity.URL { if tco == entity.URL {
return fmt.Sprintf(`<br><a href="%s"><img src="%s"/></a>`, tco, entity.MediaURLHttps) return fmt.Sprintf(`<br><a href="%s"><img src="%s"/></a>`, tco, entity.MediaURLHttps)
} }