Skip to content

Commit

Permalink
feat: 支持虎牙视频下载 (#1007)
Browse files Browse the repository at this point in the history
* feat: 支持虎牙视频下载

* style: format

* style: format

Co-authored-by: 瓜瓜 <schromelon@gmail.com>
  • Loading branch information
saltcoffee and 瓜瓜 committed Jan 25, 2022
1 parent bfc1b1d commit 2da619c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ $ lux -j "https://www.bilibili.com/video/av20203945"
| AcFun | <https://www.acfun.cn> || || |
| Eporner | <https://eporner.com> || | | |
| StreamTape | <https://streamtape.com> || | | |
| 虎扑 | https://hupu.com || | | |
| 虎扑 | <https://hupu.com> || | | |
| 虎牙视频 | <https://v.huya.com> || | | |


## Known issues
Expand Down
2 changes: 2 additions & 0 deletions extractors/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/iawia002/lux/extractors/geekbang"
"github.com/iawia002/lux/extractors/haokan"
"github.com/iawia002/lux/extractors/hupu"
"github.com/iawia002/lux/extractors/huya"
"github.com/iawia002/lux/extractors/instagram"
"github.com/iawia002/lux/extractors/iqiyi"
"github.com/iawia002/lux/extractors/mgtv"
Expand Down Expand Up @@ -83,6 +84,7 @@ func init() {
"streamtape": stExtractor,
"streamta": stExtractor, // streamta.pe
"hupu": hupu.New(),
"huya": huya.New(),
}
}

Expand Down
66 changes: 66 additions & 0 deletions extractors/huya/huya.go
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
}
28 changes: 28 additions & 0 deletions extractors/huya/huya_test.go
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{})
})
}
}

0 comments on commit 2da619c

Please sign in to comment.