Skip to content

Commit

Permalink
新增虎扑视频下载 (#986)
Browse files Browse the repository at this point in the history
* feat: Add Hupu Download

* feat: readme

* feat: fix note

* fix: package sort

* fix: code style

* feat: delete unused struct

Co-authored-by: 瓜瓜 <wangjunwei03@corp.netease.com>
  • Loading branch information
saltcoffee and 瓜瓜 committed Jan 10, 2022
1 parent 8b53403 commit 26b1d95
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ $ annie -j "https://www.bilibili.com/video/av20203945"
| AcFun | <https://www.acfun.cn> || || |
| Eporner | <https://eporner.com> || | | |
| StreamTape | <https://streamtape.com> || | | |
| 虎扑 | https://hupu.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 @@ -13,6 +13,7 @@ import (
"github.com/iawia002/annie/extractors/facebook"
"github.com/iawia002/annie/extractors/geekbang"
"github.com/iawia002/annie/extractors/haokan"
"github.com/iawia002/annie/extractors/hupu"
"github.com/iawia002/annie/extractors/instagram"
"github.com/iawia002/annie/extractors/iqiyi"
"github.com/iawia002/annie/extractors/mgtv"
Expand Down Expand Up @@ -81,6 +82,7 @@ func init() {
"eporner": eporner.New(),
"streamtape": stExtractor,
"streamta": stExtractor, // streamta.pe
"hupu": hupu.New(),
}
}

Expand Down
64 changes: 64 additions & 0 deletions extractors/hupu/hupu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package hupu

import (
"github.com/iawia002/annie/extractors/types"
"github.com/iawia002/annie/request"
"github.com/iawia002/annie/utils"
)

type extractor struct{}

// New returns a hupu 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, `<span class="post-user-comp-info-bottom-title">(.+?)</span>`)
if len(titleDesc) > 1 {
title = titleDesc[1]
} else {
title = "hupu video"
}

var videoUrl string
urlDesc := utils.MatchOneOf(html, `<video src="(.+?)" controls="" poster=(.+?)></video>`)
if len(urlDesc) > 1 {
videoUrl = urlDesc[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: "虎扑 hupu.com",
Title: title,
Type: types.DataTypeVideo,
Streams: streams,
URL: url,
},
}, nil
}
28 changes: 28 additions & 0 deletions extractors/hupu/hupu_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package hupu

import (
"testing"

"github.com/iawia002/annie/extractors/types"
"github.com/iawia002/annie/test"
)

func TestHupu(t *testing.T) {
tests := []struct {
name string
args test.Args
}{
{
name: "normal test",
args: test.Args{
URL: "https://bbs.hupu.com/47401018.html?is_reflow=1&cid=84752419&bddid=56KXU5QUJH4VGM26SFPTYTKNI5CFNJMX736TIZ52DXLGUAAMBJVA01&puid=16522089&client=8577E496-4D9B-4E5C-A9DB-A8EF5C1956D2",
Title: "结局引起舒适",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
New().Extract(tt.args.URL, types.Options{})
})
}
}

0 comments on commit 26b1d95

Please sign in to comment.