save photo ids

This commit is contained in:
windowsdeveloperwannabe 2023-05-10 03:18:34 -07:00
parent deb946cf22
commit 6a929cde9c
3 changed files with 35 additions and 14 deletions

View file

@ -202,7 +202,12 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
for _, media := range tweet.ExtendedEntities.Media {
if media.Type == "photo" {
tw.Photos = append(tw.Photos, media.MediaURLHttps)
photo := Photo{
ID: media.IDStr,
URL: media.MediaURLHttps,
}
tw.Photos = append(tw.Photos, photo)
} else if media.Type == "video" {
video := Video{
ID: media.IDStr,
@ -217,7 +222,6 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
}
}
tw.Photos = append(tw.Photos, video.Preview)
tw.Videos = append(tw.Videos, video)
}
@ -259,7 +263,15 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
}
return tco
})
for _, url := range tw.Photos {
for _, photo := range tw.Photos {
url := photo.URL
if stringInSlice(url, foundedMedia) {
continue
}
tw.HTML += fmt.Sprintf(`<br><img src="%s"/>`, url)
}
for _, video := range tw.Videos {
url := video.Preview
if stringInSlice(url, foundedMedia) {
continue
}

View file

@ -76,7 +76,7 @@ func TestGetTweet(t *testing.T) {
HTML: "That thing you didnt Tweet but wanted to but didnt but got so close but then were like nah. <br><br>We have a place for that now—Fleets! <br><br>Rolling out to everyone starting today. <br><a href=\"https://t.co/auQAHXZMfH\"><img src=\"https://pbs.twimg.com/amplify_video_thumb/1328684333599756289/img/cP5KwbIXbGunNSBy.jpg\"/></a>",
ID: "1328684389388185600",
PermanentURL: "https://twitter.com/Twitter/status/1328684389388185600",
Photos: []string{"https://pbs.twimg.com/amplify_video_thumb/1328684333599756289/img/cP5KwbIXbGunNSBy.jpg"},
Photos: nil,
Text: "That thing you didnt Tweet but wanted to but didnt but got so close but then were like nah. \n\nWe have a place for that now—Fleets! \n\nRolling out to everyone starting today. https://t.co/auQAHXZMfH",
TimeParsed: time.Date(2020, 11, 17, 13, 0, 18, 0, time.FixedZone("UTC", 0)),
Timestamp: 1605618018,
@ -105,15 +105,18 @@ func TestQuotedAndReply(t *testing.T) {
ID: "1237110546383724547",
Likes: 485,
PermanentURL: "https://twitter.com/VsauceTwo/status/1237110546383724547",
Photos: []string{"https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg"},
Replies: 12,
Retweets: 18,
Text: "The Easiest Problem Everyone Gets Wrong \n\n[new video] --&gt; https://t.co/YdaeDYmPAU https://t.co/iKu4Xs6o2V",
TimeParsed: time.Date(2020, 03, 9, 20, 18, 33, 0, time.FixedZone("UTC", 0)),
Timestamp: 1583785113,
URLs: []string{"https://youtu.be/ytfCdqWhmdg"},
UserID: "978944851",
Username: "VsauceTwo",
Photos: []twitterscraper.Photo{{
ID: "1237110473486729218",
URL: "https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg",
}},
Replies: 12,
Retweets: 18,
Text: "The Easiest Problem Everyone Gets Wrong \n\n[new video] --&gt; https://t.co/YdaeDYmPAU https://t.co/iKu4Xs6o2V",
TimeParsed: time.Date(2020, 0o3, 9, 20, 18, 33, 0, time.FixedZone("UTC", 0)),
Timestamp: 1583785113,
URLs: []string{"https://youtu.be/ytfCdqWhmdg"},
UserID: "978944851",
Username: "VsauceTwo",
}
scraper := twitterscraper.New()
tweet, err := scraper.GetTweet("1237110897597976576")

View file

@ -3,6 +3,12 @@ package twitterscraper
import "time"
type (
// Photo type.
Photo struct {
ID string
URL string
}
// Video type.
Video struct {
ID string
@ -22,7 +28,7 @@ type (
IsRetweet bool
Likes int
PermanentURL string
Photos []string
Photos []Photo
Place *Place
QuotedStatus *Tweet
Replies int