From 89130dba7dbee26c16ee35a26d0c10c1deb4fa55 Mon Sep 17 00:00:00 2001 From: wujunwei <1399952803@qq.com> Date: Sun, 22 Dec 2024 22:22:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9A=AE=E7=9A=AE=E8=99=BE?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=A7=A3=E6=9E=90;=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9A=AE=E7=9A=AE=E8=99=BE=E5=9B=BE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser/douyin.go | 4 ++++ parser/pipixia.go | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/parser/douyin.go b/parser/douyin.go index ee2f9ed..8f2b577 100755 --- a/parser/douyin.go +++ b/parser/douyin.go @@ -61,6 +61,10 @@ func (d douYin) parseVideoID(videoId string) (*VideoParseInfo, error) { // 获取视频播放地址 videoUrl := data.Get("video.play_addr.url_list.0").String() videoUrl = strings.ReplaceAll(videoUrl, "playwm", "play") + data.Get("video.play_addr.url_list").ForEach(func(key, value gjson.Result) bool { + fmt.Println(strings.ReplaceAll(value.String(), "playwm", "play")) + return true + }) // 如果图集地址不为空时,因为没有视频,上面抖音返回的视频地址无法访问,置空处理 if len(images) > 0 { diff --git a/parser/pipixia.go b/parser/pipixia.go index 7b7df20..5acb5d9 100755 --- a/parser/pipixia.go +++ b/parser/pipixia.go @@ -12,7 +12,7 @@ type piPiXia struct { } func (p piPiXia) parseVideoID(videoId string) (*VideoParseInfo, error) { - reqUrl := "https://is.snssdk.com/bds/cell/detail/?cell_type=1&aid=1319&app_name=super&cell_id=" + videoId + reqUrl := "https://h5.pipix.com/bds/webapi/item/detail/?item_id=" + videoId client := resty.New() res, err := client.R(). SetHeader(HttpHeaderUserAgent, DefaultUserAgent). @@ -21,11 +21,32 @@ func (p piPiXia) parseVideoID(videoId string) (*VideoParseInfo, error) { return nil, err } - data := gjson.GetBytes(res.Body(), "data.data.item") + data := gjson.GetBytes(res.Body(), "data.item") + authorId := data.Get("author.id").String() + + // 获取图集图片地址 + imagesObjArr := data.Get("note.multi_image").Array() + images := make([]string, 0, len(imagesObjArr)) + for _, imageItem := range imagesObjArr { + imageUrl := imageItem.Get("url_list.0.url").String() + if len(imageUrl) > 0 { + images = append(images, imageUrl) + } + } + + videoUrl := data.Get("video.video_download.url_list.0.url").String() // 备用视频地址, 可能有水印 + // comments中可能带有不带水印视频, comments可能为空, 尝试获取 + for _, comment := range data.Get("comments").Array() { + commentVideoUrl := comment.Get("item.video.video_high.url_list.0.url").String() + if comment.Get("item.author.id").String() == authorId && len(commentVideoUrl) > 0 { + videoUrl = commentVideoUrl + break + } + } + author := data.Get("author.name").String() avatar := data.Get("author.avatar.download_list.0.url").String() title := data.Get("share.title").String() - videoUrl := data.Get("origin_video_download.url_list.0.url").String() cover := data.Get("cover.url_list.0.url").String() parseRes := &VideoParseInfo{ @@ -35,6 +56,7 @@ func (p piPiXia) parseVideoID(videoId string) (*VideoParseInfo, error) { } parseRes.Author.Name = author parseRes.Author.Avatar = avatar + parseRes.Images = images return parseRes, nil }