instagram: fixes share urls
This commit is contained in:
parent
34219a848e
commit
3e307658fa
5 changed files with 33 additions and 9 deletions
|
@ -74,7 +74,11 @@ 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)
|
||||||
redirectURL, err := util.GetLocationURL(client, ctx.MatchedContentURL, "")
|
redirectURL, err := util.GetLocationURL(
|
||||||
|
client,
|
||||||
|
ctx.MatchedContentURL,
|
||||||
|
igHeaders,
|
||||||
|
)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,26 @@ import (
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var captionPattern = regexp.MustCompile(
|
var (
|
||||||
`(?s)<meta property="og:title" content=".*?: "(.*?)""`,
|
captionPattern = regexp.MustCompile(
|
||||||
|
`(?s)<meta property="og:title" content=".*?: "(.*?)""`)
|
||||||
|
|
||||||
|
igHeaders = map[string]string{
|
||||||
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||||
|
"Accept-Language": "en-GB,en;q=0.9",
|
||||||
|
"Cache-Control": "max-age=0",
|
||||||
|
"Dnt": "1",
|
||||||
|
"Priority": "u=0, i",
|
||||||
|
"Sec-Ch-Ua": `Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99`,
|
||||||
|
"Sec-Ch-Ua-Mobile": "?0",
|
||||||
|
"Sec-Ch-Ua-Platform": "macOS",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "none",
|
||||||
|
"Sec-Fetch-User": "?1",
|
||||||
|
"Upgrade-Insecure-Requests": "1",
|
||||||
|
"User-Agent": util.ChromeUA,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildSignedPayload(contentURL string) (io.Reader, error) {
|
func BuildSignedPayload(contentURL string) (io.Reader, error) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ var ShortExtractor = &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)
|
||||||
shortURL := fmt.Sprintf(shortenerAPIFormat, ctx.MatchedContentID)
|
shortURL := fmt.Sprintf(shortenerAPIFormat, ctx.MatchedContentID)
|
||||||
location, err := util.GetLocationURL(client, shortURL, "")
|
location, err := util.GetLocationURL(client, shortURL, nil)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ var VMExtractor = &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)
|
||||||
redirectURL, err := util.GetLocationURL(client, ctx.MatchedContentURL, "")
|
redirectURL, err := util.GetLocationURL(client, ctx.MatchedContentURL, nil)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
10
util/misc.go
10
util/misc.go
|
@ -21,7 +21,7 @@ var cookiesCache = make(map[string][]*http.Cookie)
|
||||||
func GetLocationURL(
|
func GetLocationURL(
|
||||||
client models.HTTPClient,
|
client models.HTTPClient,
|
||||||
url string,
|
url string,
|
||||||
userAgent string,
|
headers map[string]string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
client = GetDefaultHTTPClient()
|
client = GetDefaultHTTPClient()
|
||||||
|
@ -30,10 +30,12 @@ func GetLocationURL(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to create request: %w", err)
|
return "", fmt.Errorf("failed to create request: %w", err)
|
||||||
}
|
}
|
||||||
if userAgent == "" {
|
for k, v := range headers {
|
||||||
userAgent = ChromeUA
|
req.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
if req.Header.Get("User-Agent") == "" {
|
||||||
|
req.Header.Set("User-Agent", ChromeUA)
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", userAgent)
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.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