save photo ids
This commit is contained in:
parent
deb946cf22
commit
6a929cde9c
3 changed files with 35 additions and 14 deletions
18
timeline.go
18
timeline.go
|
|
@ -202,7 +202,12 @@ 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)
|
photo := Photo{
|
||||||
|
ID: media.IDStr,
|
||||||
|
URL: media.MediaURLHttps,
|
||||||
|
}
|
||||||
|
|
||||||
|
tw.Photos = append(tw.Photos, photo)
|
||||||
} else if media.Type == "video" {
|
} else if media.Type == "video" {
|
||||||
video := Video{
|
video := Video{
|
||||||
ID: media.IDStr,
|
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)
|
tw.Videos = append(tw.Videos, video)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,7 +263,15 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
|
||||||
}
|
}
|
||||||
return tco
|
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) {
|
if stringInSlice(url, foundedMedia) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func TestGetTweet(t *testing.T) {
|
||||||
HTML: "That thing you didn’t Tweet but wanted to but didn’t 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>",
|
HTML: "That thing you didn’t Tweet but wanted to but didn’t 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",
|
ID: "1328684389388185600",
|
||||||
PermanentURL: "https://twitter.com/Twitter/status/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 didn’t Tweet but wanted to but didn’t 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",
|
Text: "That thing you didn’t Tweet but wanted to but didn’t 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)),
|
TimeParsed: time.Date(2020, 11, 17, 13, 0, 18, 0, time.FixedZone("UTC", 0)),
|
||||||
Timestamp: 1605618018,
|
Timestamp: 1605618018,
|
||||||
|
|
@ -105,15 +105,18 @@ func TestQuotedAndReply(t *testing.T) {
|
||||||
ID: "1237110546383724547",
|
ID: "1237110546383724547",
|
||||||
Likes: 485,
|
Likes: 485,
|
||||||
PermanentURL: "https://twitter.com/VsauceTwo/status/1237110546383724547",
|
PermanentURL: "https://twitter.com/VsauceTwo/status/1237110546383724547",
|
||||||
Photos: []string{"https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg"},
|
Photos: []twitterscraper.Photo{{
|
||||||
Replies: 12,
|
ID: "1237110473486729218",
|
||||||
Retweets: 18,
|
URL: "https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg",
|
||||||
Text: "The Easiest Problem Everyone Gets Wrong \n\n[new video] --> https://t.co/YdaeDYmPAU https://t.co/iKu4Xs6o2V",
|
}},
|
||||||
TimeParsed: time.Date(2020, 03, 9, 20, 18, 33, 0, time.FixedZone("UTC", 0)),
|
Replies: 12,
|
||||||
Timestamp: 1583785113,
|
Retweets: 18,
|
||||||
URLs: []string{"https://youtu.be/ytfCdqWhmdg"},
|
Text: "The Easiest Problem Everyone Gets Wrong \n\n[new video] --> https://t.co/YdaeDYmPAU https://t.co/iKu4Xs6o2V",
|
||||||
UserID: "978944851",
|
TimeParsed: time.Date(2020, 0o3, 9, 20, 18, 33, 0, time.FixedZone("UTC", 0)),
|
||||||
Username: "VsauceTwo",
|
Timestamp: 1583785113,
|
||||||
|
URLs: []string{"https://youtu.be/ytfCdqWhmdg"},
|
||||||
|
UserID: "978944851",
|
||||||
|
Username: "VsauceTwo",
|
||||||
}
|
}
|
||||||
scraper := twitterscraper.New()
|
scraper := twitterscraper.New()
|
||||||
tweet, err := scraper.GetTweet("1237110897597976576")
|
tweet, err := scraper.GetTweet("1237110897597976576")
|
||||||
|
|
|
||||||
8
types.go
8
types.go
|
|
@ -3,6 +3,12 @@ package twitterscraper
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Photo type.
|
||||||
|
Photo struct {
|
||||||
|
ID string
|
||||||
|
URL string
|
||||||
|
}
|
||||||
|
|
||||||
// Video type.
|
// Video type.
|
||||||
Video struct {
|
Video struct {
|
||||||
ID string
|
ID string
|
||||||
|
|
@ -22,7 +28,7 @@ type (
|
||||||
IsRetweet bool
|
IsRetweet bool
|
||||||
Likes int
|
Likes int
|
||||||
PermanentURL string
|
PermanentURL string
|
||||||
Photos []string
|
Photos []Photo
|
||||||
Place *Place
|
Place *Place
|
||||||
QuotedStatus *Tweet
|
QuotedStatus *Tweet
|
||||||
Replies int
|
Replies int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue