parent
9667832b32
commit
cdbfda8921
@ -137,13 +137,19 @@ func (d *BaiduPhoto) Link(ctx context.Context, file model.Obj, args model.LinkAr
|
|||||||
case *File:
|
case *File:
|
||||||
return d.linkFile(ctx, file, args)
|
return d.linkFile(ctx, file, args)
|
||||||
case *AlbumFile:
|
case *AlbumFile:
|
||||||
f, err := d.CopyAlbumFile(ctx, file)
|
// 处理共享相册
|
||||||
if err != nil {
|
if d.Uk != file.Uk {
|
||||||
return nil, err
|
// 有概率无法获取到链接
|
||||||
|
return d.linkAlbum(ctx, file, args)
|
||||||
|
|
||||||
|
// 接口被限制,只能使用cookie
|
||||||
|
// f, err := d.CopyAlbumFile(ctx, file)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// return d.linkFile(ctx, f, args)
|
||||||
}
|
}
|
||||||
return d.linkFile(ctx, f, args)
|
return d.linkFile(ctx, &file.File, args)
|
||||||
// 有概率无法获取到链接
|
|
||||||
//return d.linkAlbum(ctx, file, args)
|
|
||||||
}
|
}
|
||||||
return nil, errs.NotFile
|
return nil, errs.NotFile
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ const (
|
|||||||
FILE_API_URL_V2 = API_URL + "/file/v2"
|
FILE_API_URL_V2 = API_URL + "/file/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
func (d *BaiduPhoto) Request(client *resty.Client, furl string, method string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||||
req := base.RestyClient.R().
|
req := client.R().
|
||||||
SetQueryParam("access_token", d.AccessToken)
|
SetQueryParam("access_token", d.AccessToken)
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
callback(req)
|
callback(req)
|
||||||
@ -88,11 +88,11 @@ func (d *BaiduPhoto) refreshToken() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *BaiduPhoto) Get(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
func (d *BaiduPhoto) Get(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||||
return d.Request(furl, http.MethodGet, callback, resp)
|
return d.Request(base.RestyClient, furl, http.MethodGet, callback, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *BaiduPhoto) Post(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
func (d *BaiduPhoto) Post(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||||
return d.Request(furl, http.MethodPost, callback, resp)
|
return d.Request(base.RestyClient, furl, http.MethodPost, callback, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有文件
|
// 获取所有文件
|
||||||
@ -338,24 +338,33 @@ func (d *BaiduPhoto) linkAlbum(ctx context.Context, file *AlbumFile, args model.
|
|||||||
headers["X-Forwarded-For"] = args.IP
|
headers["X-Forwarded-For"] = args.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := base.NoRedirectClient.R().
|
resp, err := d.Request(base.NoRedirectClient, ALBUM_API_URL+"/download", http.MethodHead, func(r *resty.Request) {
|
||||||
SetContext(ctx).
|
r.SetContext(ctx)
|
||||||
SetHeaders(headers).
|
r.SetHeaders(headers)
|
||||||
SetQueryParams(map[string]string{
|
r.SetQueryParams(map[string]string{
|
||||||
"access_token": d.AccessToken,
|
"fsid": fmt.Sprint(file.Fsid),
|
||||||
"fsid": fmt.Sprint(file.Fsid),
|
"album_id": file.AlbumID,
|
||||||
"album_id": file.AlbumID,
|
"tid": fmt.Sprint(file.Tid),
|
||||||
"tid": fmt.Sprint(file.Tid),
|
"uk": fmt.Sprint(file.Uk),
|
||||||
"uk": fmt.Sprint(file.Uk),
|
})
|
||||||
}).
|
}, nil)
|
||||||
Head(ALBUM_API_URL + "/download")
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode() != 302 {
|
||||||
|
return nil, fmt.Errorf("not found 302 redirect")
|
||||||
|
}
|
||||||
|
|
||||||
|
location := resp.Header().Get("Location")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
link := &model.Link{
|
link := &model.Link{
|
||||||
URL: res.Header().Get("location"),
|
URL: location,
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
"User-Agent": []string{headers["User-Agent"]},
|
"User-Agent": []string{headers["User-Agent"]},
|
||||||
"Referer": []string{"https://photo.baidu.com/"},
|
"Referer": []string{"https://photo.baidu.com/"},
|
||||||
@ -375,22 +384,36 @@ func (d *BaiduPhoto) linkFile(ctx context.Context, file *File, args model.LinkAr
|
|||||||
headers["X-Forwarded-For"] = args.IP
|
headers["X-Forwarded-For"] = args.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadUrl struct {
|
// var downloadUrl struct {
|
||||||
Dlink string `json:"dlink"`
|
// Dlink string `json:"dlink"`
|
||||||
}
|
// }
|
||||||
_, err := d.Get(FILE_API_URL_V2+"/download", func(r *resty.Request) {
|
// _, err := d.Get(FILE_API_URL_V1+"/download", func(r *resty.Request) {
|
||||||
|
// r.SetContext(ctx)
|
||||||
|
// r.SetHeaders(headers)
|
||||||
|
// r.SetQueryParams(map[string]string{
|
||||||
|
// "fsid": fmt.Sprint(file.Fsid),
|
||||||
|
// })
|
||||||
|
// }, &downloadUrl)
|
||||||
|
|
||||||
|
resp, err := d.Request(base.NoRedirectClient, FILE_API_URL_V1+"/download", http.MethodHead, func(r *resty.Request) {
|
||||||
r.SetContext(ctx)
|
r.SetContext(ctx)
|
||||||
r.SetHeaders(headers)
|
r.SetHeaders(headers)
|
||||||
r.SetQueryParams(map[string]string{
|
r.SetQueryParams(map[string]string{
|
||||||
"fsid": fmt.Sprint(file.Fsid),
|
"fsid": fmt.Sprint(file.Fsid),
|
||||||
})
|
})
|
||||||
}, &downloadUrl)
|
}, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode() != 302 {
|
||||||
|
return nil, fmt.Errorf("not found 302 redirect")
|
||||||
|
}
|
||||||
|
|
||||||
|
location := resp.Header().Get("Location")
|
||||||
link := &model.Link{
|
link := &model.Link{
|
||||||
URL: downloadUrl.Dlink,
|
URL: location,
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
"User-Agent": []string{headers["User-Agent"]},
|
"User-Agent": []string{headers["User-Agent"]},
|
||||||
"Referer": []string{"https://photo.baidu.com/"},
|
"Referer": []string{"https://photo.baidu.com/"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user