main: changes, fixes

- refactors http session usage across modules
- adjusts video info extraction
- improves temporary directory, concurrency limits, buffering, and error handling in download routines
This commit is contained in:
stefanodvx 2025-04-14 23:45:54 +02:00
parent 10c113f400
commit 58bd5827b3
12 changed files with 171 additions and 51 deletions

View file

@ -16,6 +16,8 @@ import (
// feel free to open PR, if you want to
// add support for the official Instagram API
var httpSession = util.GetHTTPSession()
const (
apiHostname = "api.igram.world"
apiKey = "aaeaf2805cea6abef3f9d2b6a666fce62fd9d612a43ab772bb50ce81455112e0"
@ -42,8 +44,6 @@ var igHeaders = map[string]string{
"User-Agent": util.ChromeUA,
}
var HTTPSession = util.NewHTTPSession()
var Extractor = &models.Extractor{
Name: "Instagram",
CodeName: "instagram",
@ -96,7 +96,7 @@ var ShareURLExtractor = &models.Extractor{
for k, v := range igHeaders {
req.Header.Set(k, v)
}
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
@ -183,7 +183,7 @@ func GetVideoAPI(contentURL string) (*IGramResponse, error) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", util.ChromeUA)
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}

View file

@ -115,7 +115,7 @@ func GetPostCaption(
req.Header.Set("Cache-Control", "no-cache")
req.Header.Set("TE", "trailers")
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return "", fmt.Errorf("failed to send request: %w", err)
}

View file

@ -17,7 +17,7 @@ const (
shortenerAPIFormat = "https://api.pinterest.com/url_shortener/%s/redirect/"
)
var HTTPSession = util.NewHTTPSession()
var httpSession = util.GetHTTPSession()
var ShortExtractor = &models.Extractor{
Name: "Pinterest (Short)",
@ -148,7 +148,7 @@ func GetPinData(pinID string) (*PinData, error) {
// fix 403 error
req.Header.Set("X-Pinterest-PWS-Handler", "www/[username].js")
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}

View file

@ -12,7 +12,7 @@ import (
"govd/util"
)
var HTTPSession = util.NewHTTPSession()
var httpSession = util.GetHTTPSession()
var ShortExtractor = &models.Extractor{
Name: "Reddit (Short)",
@ -37,7 +37,7 @@ var ShortExtractor = &models.Extractor{
req.AddCookie(cookie)
}
res, err := HTTPSession.Do(req)
res, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
@ -229,7 +229,7 @@ func GetRedditData(host string, slug string) (RedditResponse, error) {
req.AddCookie(cookie)
}
res, err := HTTPSession.Do(req)
res, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}

View file

@ -23,7 +23,7 @@ const (
appUserAgent = packageID + " (Linux; U; Android 13; en_US; Pixel 7; Build/TD1A.220804.031; Cronet/58.0.2991.0)"
)
var HTTPSession = util.NewHTTPSession()
var httpSession = util.GetHTTPSession()
var VMExtractor = &models.Extractor{
Name: "TikTok VM",
@ -147,7 +147,7 @@ func GetVideoAPI(awemeID string) (*AwemeDetails, error) {
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Argus", "")
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}

View file

@ -17,7 +17,7 @@ const (
apiEndpoint = "https://x.com/i/api/graphql/zZXycP0V6H7m-2r0mOnFcA/TweetDetail"
)
var HTTPSession = util.NewHTTPSession()
var httpSession = util.GetHTTPSession()
var ShortExtractor = &models.Extractor{
Name: "Twitter (Short)",
@ -33,7 +33,7 @@ var ShortExtractor = &models.Extractor{
return nil, fmt.Errorf("failed to create req: %w", err)
}
req.Header.Set("User-Agent", util.ChromeUA)
res, err := HTTPSession.Do(req)
res, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
@ -151,7 +151,7 @@ func GetTweetAPI(tweetID string) (*Tweet, error) {
}
req.URL.RawQuery = q.Encode()
resp, err := HTTPSession.Do(req)
resp, err := httpSession.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}