Skip to content

Commit

Permalink
抖音支持电脑网页端链接: https://www.iesdouyin.com/share/video/xxxxxx/ , https://…
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunwei928 committed Jul 13, 2024
1 parent 4008349 commit a033489
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions parser/douyin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/rand"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -88,6 +89,25 @@ func (d douYin) parseVideoID(videoId string) (*VideoParseInfo, error) {
}

func (d douYin) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
urlRes, err := url.Parse(shareUrl)
if err != nil {
return nil, err
}

switch urlRes.Host {
case "www.iesdouyin.com", "www.douyin.com":
return d.parsePcShareUrl(shareUrl) // 解析电脑网页端链接
case "v.douyin.com":
return d.parseAppShareUrl(shareUrl) // 解析App分享链接
}

return nil, fmt.Errorf("douyin not support this host: %s", urlRes.Host)
}

func (d douYin) parseAppShareUrl(shareUrl string) (*VideoParseInfo, error) {
// 适配App分享链接类型:
// https://v.douyin.com/xxxxxx/

client := resty.New()
// disable redirects in the HTTP client, get params before redirects
client.SetRedirectPolicy(resty.NoRedirectPolicy())
Expand Down Expand Up @@ -120,6 +140,17 @@ func (d douYin) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
return d.parseVideoID(videoId)
}

func (d douYin) parsePcShareUrl(shareUrl string) (*VideoParseInfo, error) {
// 适配电脑网页端链接类型
// https://www.iesdouyin.com/share/video/xxxxxx/
// https://www.douyin.com/video/xxxxxx
videoId, err := d.parseVideoIdFromPath(shareUrl)
if err != nil {
return nil, err
}
return d.parseVideoID(videoId)
}

func (d douYin) parseVideoIdFromPath(urlPath string) (string, error) {
if len(urlPath) <= 0 {
return "", errors.New("url path is empty")
Expand Down
2 changes: 1 addition & 1 deletion parser/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type videoSourceInfo struct {
// 视频渠道映射信息
var videoSourceInfoMapping = map[string]videoSourceInfo{
SourceDouYin: {
VideoShareUrlDomain: []string{"v.douyin.com"},
VideoShareUrlDomain: []string{"v.douyin.com", "www.iesdouyin.com", "www.douyin.com"},
VideoShareUrlParser: douYin{},
VideoIdParser: douYin{},
},
Expand Down

0 comments on commit a033489

Please sign in to comment.