-
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: 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
1 parent
8b53403
commit 26b1d95
Showing
4 changed files
with
95 additions
and
0 deletions.
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,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 | ||
} |
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 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{}) | ||
}) | ||
} | ||
} |