From cd161d56db1b40ed1470add9333015e74b452a73 Mon Sep 17 00:00:00 2001 From: vtgare Date: Fri, 4 Mar 2022 20:15:29 +0200 Subject: [PATCH] check tweets for sensitive content --- api.go | 2 +- timeline.go | 20 ++++++++++++++++---- types.go | 47 ++++++++++++++++++++++++----------------------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/api.go b/api.go index bfee5f2..b06f241 100644 --- a/api.go +++ b/api.go @@ -8,7 +8,7 @@ import ( "time" ) -const bearerToken string = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA" +const bearerToken string = "AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw" // RequestAPI get JSON from frontend API and decodes it func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error { diff --git a/timeline.go b/timeline.go index be8cdfe..22299b1 100644 --- a/timeline.go +++ b/timeline.go @@ -30,10 +30,15 @@ type timeline struct { } `json:"entities"` ExtendedEntities struct { Media []struct { - IDStr string `json:"id_str"` - MediaURLHttps string `json:"media_url_https"` - Type string `json:"type"` - VideoInfo 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"` + VideoInfo struct { Variants []struct { Bitrate int `json:"bitrate,omitempty"` URL string `json:"url"` @@ -211,9 +216,16 @@ func (timeline *timeline) parseTweet(id string) *Tweet { maxBitrate = variant.Bitrate } } + tw.Videos = append(tw.Videos, video) } + + if !tw.SensitiveContent { + sensitive := media.ExtSensitiveMediaWarning + tw.SensitiveContent = sensitive.AdultContent || sensitive.GraphicViolence || sensitive.Other + } } + for _, url := range tweet.Entities.URLs { tw.URLs = append(tw.URLs, url.ExpandedURL) } diff --git a/types.go b/types.go index 6055453..9c5b0fe 100644 --- a/types.go +++ b/types.go @@ -12,29 +12,30 @@ type ( // Tweet type. Tweet struct { - Hashtags []string - HTML string - ID string - InReplyToStatus *Tweet - IsQuoted bool - IsPin bool - IsReply bool - IsRetweet bool - Likes int - PermanentURL string - Photos []string - Place *Place - QuotedStatus *Tweet - Replies int - Retweets int - RetweetedStatus *Tweet - Text string - TimeParsed time.Time - Timestamp int64 - URLs []string - UserID string - Username string - Videos []Video + Hashtags []string + HTML string + ID string + InReplyToStatus *Tweet + IsQuoted bool + IsPin bool + IsReply bool + IsRetweet bool + Likes int + PermanentURL string + Photos []string + Place *Place + QuotedStatus *Tweet + Replies int + Retweets int + RetweetedStatus *Tweet + Text string + TimeParsed time.Time + Timestamp int64 + URLs []string + UserID string + Username string + Videos []Video + SensitiveContent bool } // ProfileResult of scrapping.