code cleanup
This commit is contained in:
parent
917be1687f
commit
5336968e05
34 changed files with 193 additions and 115 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"govd/util"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -45,7 +46,7 @@ var ShortExtractor = &models.Extractor{
|
|||
}
|
||||
matchedURL := Extractor.URLPattern.FindStringSubmatch(string(body))
|
||||
if matchedURL == nil {
|
||||
return nil, fmt.Errorf("failed to find url in body")
|
||||
return nil, errors.New("failed to find url in body")
|
||||
}
|
||||
return &models.ExtractorResponse{
|
||||
URL: matchedURL[0],
|
||||
|
@ -62,7 +63,6 @@ var Extractor = &models.Extractor{
|
|||
Host: []string{
|
||||
"twitter.com",
|
||||
"x.com",
|
||||
"vxx.com",
|
||||
"vxtwitter.com",
|
||||
},
|
||||
|
||||
|
@ -95,7 +95,7 @@ func MediaListFromAPI(ctx *models.DownloadContext) ([]*models.Media, error) {
|
|||
} else if tweetData.Entities != nil && len(tweetData.Entities.Media) > 0 {
|
||||
mediaEntities = tweetData.Entities.Media
|
||||
} else {
|
||||
return nil, fmt.Errorf("no media found in tweet")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
for _, mediaEntity := range mediaEntities {
|
||||
|
@ -140,7 +140,7 @@ func GetTweetAPI(
|
|||
}
|
||||
headers := BuildAPIHeaders(cookies)
|
||||
if headers == nil {
|
||||
return nil, fmt.Errorf("failed to build headers. check cookies")
|
||||
return nil, errors.New("failed to build headers. check cookies")
|
||||
}
|
||||
query := BuildAPIQuery(tweetID)
|
||||
|
||||
|
|
|
@ -2,15 +2,17 @@ package twitter
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"govd/enums"
|
||||
"govd/models"
|
||||
"govd/util"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"govd/enums"
|
||||
"govd/models"
|
||||
"govd/util"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const authToken = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
||||
|
@ -137,7 +139,7 @@ func extractResolution(url string) (int64, int64) {
|
|||
func FindTweetData(resp *APIResponse, tweetID string) (*Tweet, error) {
|
||||
instructions := resp.Data.ThreadedConversationWithInjectionsV2.Instructions
|
||||
if len(instructions) == 0 {
|
||||
return nil, fmt.Errorf("tweet data missing")
|
||||
return nil, errors.New("tweet data missing")
|
||||
}
|
||||
|
||||
entries := instructions[0].Entries
|
||||
|
@ -155,9 +157,9 @@ func FindTweetData(resp *APIResponse, tweetID string) (*Tweet, error) {
|
|||
return result.Legacy, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid tweet data")
|
||||
return nil, errors.New("invalid tweet data")
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("tweet not found")
|
||||
return nil, errors.New("tweet not found")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue