instagram: fixes
This commit is contained in:
parent
7dab9207b7
commit
34219a848e
5 changed files with 15 additions and 19 deletions
|
@ -97,7 +97,7 @@ you can configure specific extractors options with `ext-cfg.yaml` file. document
|
||||||
# proxying
|
# proxying
|
||||||
there are two types of proxying available: http and edge.
|
there are two types of proxying available: http and edge.
|
||||||
- **http proxy**: this is a standard http proxy that can be used to route requests through a proxy server. you can set the `HTTP_PROXY` and `HTTPS_PROXY` environment variables to use this feature. (SOCKS5 is supported too)
|
- **http proxy**: this is a standard http proxy that can be used to route requests through a proxy server. you can set the `HTTP_PROXY` and `HTTPS_PROXY` environment variables to use this feature. (SOCKS5 is supported too)
|
||||||
- **edge proxy**: this is a custom proxy that is used to route requests through a specific url. you can set the `EDGE_PROXY_URL` environment variable to use this feature. this is useful for routing requests through a specific server or service. however, this feature is not totally implemented yet.
|
- **edge proxy**: this is a custom proxy that is used to route requests through a specific url. currenrly, you can only set this proxy with `ext-cfg.yaml` file. this is useful for routing requests through a specific server or service. however, this feature is not totally implemented yet.
|
||||||
|
|
||||||
**note:** by settings `NO_PROXY` environment variable, you can specify domains that should not be proxied.
|
**note:** by settings `NO_PROXY` environment variable, you can specify domains that should not be proxied.
|
||||||
|
|
||||||
|
|
|
@ -74,22 +74,12 @@ var ShareURLExtractor = &models.Extractor{
|
||||||
|
|
||||||
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
||||||
client := util.GetHTTPClient(ctx.Extractor.CodeName)
|
client := util.GetHTTPClient(ctx.Extractor.CodeName)
|
||||||
req, err := http.NewRequest(
|
redirectURL, err := util.GetLocationURL(client, ctx.MatchedContentURL, "")
|
||||||
http.MethodGet,
|
|
||||||
ctx.MatchedContentURL,
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
return nil, fmt.Errorf("failed to get url location: %w", err)
|
||||||
}
|
}
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to send request: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
return &models.ExtractorResponse{
|
return &models.ExtractorResponse{
|
||||||
URL: resp.Request.URL.String(),
|
URL: redirectURL,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,9 @@ var ShortExtractor = &models.Extractor{
|
||||||
IsRedirect: true,
|
IsRedirect: true,
|
||||||
|
|
||||||
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
||||||
|
client := util.GetHTTPClient(ctx.Extractor.CodeName)
|
||||||
shortURL := fmt.Sprintf(shortenerAPIFormat, ctx.MatchedContentID)
|
shortURL := fmt.Sprintf(shortenerAPIFormat, ctx.MatchedContentID)
|
||||||
location, err := util.GetLocationURL(shortURL, "")
|
location, err := util.GetLocationURL(client, shortURL, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get real url: %w", err)
|
return nil, fmt.Errorf("failed to get real url: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,13 @@ var VMExtractor = &models.Extractor{
|
||||||
IsRedirect: true,
|
IsRedirect: true,
|
||||||
|
|
||||||
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
Run: func(ctx *models.DownloadContext) (*models.ExtractorResponse, error) {
|
||||||
location, err := util.GetLocationURL(ctx.MatchedContentURL, "")
|
client := util.GetHTTPClient(ctx.Extractor.CodeName)
|
||||||
|
redirectURL, err := util.GetLocationURL(client, ctx.MatchedContentURL, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get url location: %w", err)
|
return nil, fmt.Errorf("failed to get url location: %w", err)
|
||||||
}
|
}
|
||||||
return &models.ExtractorResponse{
|
return &models.ExtractorResponse{
|
||||||
URL: location,
|
URL: redirectURL,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"govd/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -18,9 +19,13 @@ import (
|
||||||
var cookiesCache = make(map[string][]*http.Cookie)
|
var cookiesCache = make(map[string][]*http.Cookie)
|
||||||
|
|
||||||
func GetLocationURL(
|
func GetLocationURL(
|
||||||
|
client models.HTTPClient,
|
||||||
url string,
|
url string,
|
||||||
userAgent string,
|
userAgent string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
|
if client == nil {
|
||||||
|
client = GetDefaultHTTPClient()
|
||||||
|
}
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to create request: %w", err)
|
return "", fmt.Errorf("failed to create request: %w", err)
|
||||||
|
@ -29,8 +34,7 @@ func GetLocationURL(
|
||||||
userAgent = ChromeUA
|
userAgent = ChromeUA
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", userAgent)
|
req.Header.Set("User-Agent", userAgent)
|
||||||
session := GetDefaultHTTPClient()
|
resp, err := client.Do(req)
|
||||||
resp, err := session.Do(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to send request: %w", err)
|
return "", fmt.Errorf("failed to send request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue