Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

youku add m3u8 url #1308

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions extractors/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,36 +382,36 @@ func bilibiliDownload(options bilibiliOptions, extractOption extractors.Options)
if dashData.Streams.Audio != nil {
// Get audio part
var audioID int
audios := map[int]string{}
audios := map[int]dashStream{}
bandwidth := 0
for _, stream := range dashData.Streams.Audio {
if stream.Bandwidth > bandwidth {
audioID = stream.ID
bandwidth = stream.Bandwidth
}
audios[stream.ID] = stream.BaseURL
}
s, err := request.Size(audios[audioID], referer)
if err != nil {
return extractors.EmptyData(options.url, err)
audios[stream.ID] = stream
}
//s, err := request.Size(audios[audioID], referer)
//if err != nil {
// return extractors.EmptyData(options.url, err)
//}
Comment on lines +424 to +427
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//s, err := request.Size(audios[audioID], referer)
//if err != nil {
// return extractors.EmptyData(options.url, err)
//}

audioPart = &extractors.Part{
URL: audios[audioID],
Size: s,
URL: audios[audioID].BaseURL,
Size: audios[audioID].Size,
Ext: "m4a",
}
}

streams := make(map[string]*extractors.Stream, len(dashData.Quality))
for _, stream := range dashData.Streams.Video {
s, err := request.Size(stream.BaseURL, referer)
if err != nil {
return extractors.EmptyData(options.url, err)
}
//s, err := request.Size(stream.BaseURL, referer)
//if err != nil {
// return extractors.EmptyData(options.url, err)
//}
Comment on lines +437 to +440
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//s, err := request.Size(stream.BaseURL, referer)
//if err != nil {
// return extractors.EmptyData(options.url, err)
//}

parts := make([]*extractors.Part, 0, 2)
parts = append(parts, &extractors.Part{
URL: stream.BaseURL,
Size: s,
Size: stream.Size,
Ext: getExtFromMimeType(stream.MimeType),
})
if audioPart != nil {
Expand Down Expand Up @@ -488,6 +488,7 @@ func bilibiliDownload(options bilibiliOptions, extractOption extractors.Options)
"subtitle": getSubTitleCaptionPart(options.aid, options.cid),
},
URL: options.url,
Raw: jsonString,
}
}

Expand Down
32 changes: 24 additions & 8 deletions extractors/bilibili/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,40 @@ type multiPage struct {
VideoData multiPageVideoData `json:"videoData"`
}

type segmentBase struct {
Initialization string `json:"Initialization"`
indexRange string `json:"indexRange"`
}

type dashStream struct {
ID int `json:"id"`
BaseURL string `json:"baseUrl"`
Bandwidth int `json:"bandwidth"`
MimeType string `json:"mimeType"`
Codecid int `json:"codecid"`
Codecs string `json:"codecs"`
ID int `json:"id"`
BaseURL string `json:"baseUrl"`
Bandwidth int `json:"bandwidth"`
MimeType string `json:"mimeType"`
Codecid int `json:"codecid"`
Codecs string `json:"codecs"`
StartWithSAP int `json:"startWithSAP"`
Sar string `json:"sar"`
FrameRate string `json:"frameRate"`
Width int `json:"width"`
Height int `json:"height"`
BackupUrl []string `json:"backupUrl"`
SegmentBase segmentBase `json:"SegmentBase"`
Size int64 `json:"size"`
}

type dashStreams struct {
Video []dashStream `json:"video"`
Audio []dashStream `json:"audio"`
Duration int64 `json:"duration"`
MinBufferTime float32 `json:"minBufferTime"`
Video []dashStream `json:"video"`
Audio []dashStream `json:"audio"`
}

type dashInfo struct {
CurQuality int `json:"quality"`
Description []string `json:"accept_description"`
Quality []int `json:"accept_quality"`
TimeLength int `json:"timelength"`
Streams dashStreams `json:"dash"`
DURLFormat string `json:"format"`
DURLs []dURL `json:"durl"`
Expand Down
11 changes: 8 additions & 3 deletions extractors/douyin/douyin.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,15 @@ func (e *extractor) Extract(url string, option extractors.Options) ([]*extractor
} else {
douyinType = extractors.DataTypeVideo
realURL := douyin.AwemeDetail.Video.PlayAddr.URLList[0]
totalSize, err = request.Size(realURL, url)
if err != nil {
return nil, errors.WithStack(err)

totalSize = int64(douyin.AwemeDetail.Video.PlayAddr.DataSize)
if totalSize == 0 {
totalSize, err = request.Size(realURL, url)
if err != nil {
return nil, errors.WithStack(err)
}
}

urlData = append(urlData, &extractors.Part{
URL: realURL,
Size: totalSize,
Expand Down
2 changes: 2 additions & 0 deletions extractors/iqiyi/iqiyi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type iqiyi struct {
L string `json:"l"`
B int64 `json:"b"`
} `json:"fs"`
M3u8Url string `json:"m3u8Url"`
} `json:"vs"`
} `json:"tkl"`
} `json:"vp"`
Expand Down Expand Up @@ -230,6 +231,7 @@ func (e *extractor) Extract(url string, _ extractors.Options) ([]*extractors.Dat
Parts: urls,
Size: video.Vsize,
Quality: video.Scrsz,
M3u8Url: video.M3u8Url,
}
}

Expand Down
4 changes: 4 additions & 0 deletions extractors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Stream struct {
Ext string `json:"ext"`
// if the parts need mux
NeedMux bool
// 如果有m3u8地址
M3u8Url string `json:"m3u8_url"`
}

// DataType indicates the type of extracted data, eg: video or image.
Expand Down Expand Up @@ -55,6 +57,8 @@ type Data struct {
Captions map[string]*CaptionPart `json:"caption"`
// Err is used to record whether an error occurred when extracting the list data
Err error `json:"err"`

Raw string `json:"raw"`
}

// FillUpStreamsData fills up some data automatically.
Expand Down
2 changes: 2 additions & 0 deletions extractors/youku/youku.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type stream struct {
Segs []segs `json:"segs"`
Type string `json:"stream_type"`
AudioLang string `json:"audio_lang"`
M3u8Url string `json:"m3u8_url"`
}

type youkuVideo struct {
Expand Down Expand Up @@ -203,6 +204,7 @@ func genData(youkuData data) map[string]*extractors.Stream {
Parts: urls,
Size: stream.Size,
Quality: quality,
M3u8Url: stream.M3u8Url,
}
}
return streams
Expand Down