-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 支持虎牙视频下载 * style: format * style: format Co-authored-by: 瓜瓜 <schromelon@gmail.com>
- Loading branch information
1 parent
bfc1b1d
commit 2da619c
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package huya | ||
|
||
import ( | ||
"github.com/iawia002/lux/extractors/types" | ||
"github.com/iawia002/lux/request" | ||
"github.com/iawia002/lux/utils" | ||
) | ||
|
||
type extractor struct{} | ||
|
||
const huyaVideoHost = "https://videotx-platform.cdn.huya.com/" | ||
|
||
// New returns a huya extractor. | ||
func New() types.Extractor { | ||
return &extractor{} | ||
} | ||
|
||
func (e *extractor) Extract(url string, option types.Options) ([]*types.Data, error) { | ||
html, err := request.Get(url, url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var title string | ||
titleDesc := utils.MatchOneOf(html, `<h1>(.+?)</h1>`) | ||
if len(titleDesc) > 1 { | ||
title = titleDesc[1] | ||
} else { | ||
title = "huya video" | ||
} | ||
|
||
var videoUrl string | ||
videoDesc := utils.MatchOneOf(html, `//videotx-platform.cdn.huya.com/(.*)" poster=(.+?)`) | ||
if len(videoDesc) > 1 { | ||
videoUrl = huyaVideoHost + videoDesc[1] | ||
} else { | ||
return nil, types.ErrURLParseFailed | ||
} | ||
|
||
size, err := request.Size(videoUrl, url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
urlData := &types.Part{ | ||
URL: videoUrl, | ||
Size: size, | ||
Ext: "mp4", | ||
} | ||
quality := "normal" | ||
streams := map[string]*types.Stream{ | ||
quality: { | ||
Parts: []*types.Part{urlData}, | ||
Size: size, | ||
Quality: quality, | ||
}, | ||
} | ||
return []*types.Data{ | ||
{ | ||
Site: "虎牙 huya.com", | ||
Title: title, | ||
Type: types.DataTypeVideo, | ||
Streams: streams, | ||
URL: url, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package huya | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/iawia002/lux/extractors/types" | ||
"github.com/iawia002/lux/test" | ||
) | ||
|
||
func TestHuya(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args test.Args | ||
}{ | ||
{ | ||
name: "normal test", | ||
args: test.Args{ | ||
URL: "https://m.v.huya.com/play/fans/630103747.html/?shareid=4597484513543964249&shareUid=2179142017&source=ios&sharetype=other&platform=2", | ||
Title: "12.28 集梦薛小谦【封号斗罗】直播名场面", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
New().Extract(tt.args.URL, types.Options{}) | ||
}) | ||
} | ||
} |