Skip to content

Commit

Permalink
extractors/miaopai: Add support
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Apr 3, 2018
1 parent 740ade3 commit 8f7d746
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ Tumblr | <https://www.tumblr.com> | ✓ | ✓ | |
Vimeo | <https://vimeo.com> | ✓ | | |
Facebook | <https://facebook.com> | ✓ | | |
斗鱼视频 | <https://v.douyu.com> | ✓ | | |
秒拍 | <https://www.miaopai.com> | ✓ | | |


## Known issues
Expand Down
37 changes: 37 additions & 0 deletions extractors/miaopai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package extractors

import (
"github.com/iawia002/annie/downloader"
"github.com/iawia002/annie/parser"
"github.com/iawia002/annie/request"
"github.com/iawia002/annie/utils"
)

// Miaopai download function
func Miaopai(url string) downloader.VideoData {
html := request.Get(url, url)
doc := parser.GetDoc(html)
title := parser.Title(doc)

realURL := utils.MatchOneOf(html, `"videoSrc":"(.+?)"`)[1]
size := request.Size(realURL, url)
urlData := downloader.URLData{
URL: realURL,
Size: size,
Ext: "mp4",
}
format := map[string]downloader.FormatData{
"default": {
URLs: []downloader.URLData{urlData},
Size: size,
},
}
extractedData := downloader.VideoData{
Site: "秒拍 miaopai.com",
Title: title,
Type: "video",
Formats: format,
}
extractedData.Download(url)
return extractedData
}
31 changes: 31 additions & 0 deletions extractors/miaopai_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package extractors

import (
"testing"

"github.com/iawia002/annie/config"
"github.com/iawia002/annie/test"
)

func TestMiaopai(t *testing.T) {
config.InfoOnly = true
tests := []struct {
name string
args test.Args
}{
{
name: "normal test",
args: test.Args{
URL: "https://www.miaopai.com/show/nPWJvdR4z2Bg1Sz3PJpNYffjpDgEiuv4msALgw__.htm",
Title: "情人节特辑:一个来自绝地求生的爱情故事,送给已经离开的你-绝地求生大逃杀的秒拍",
Size: 12135847,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data := Miaopai(tt.args.URL)
test.Check(t, tt.args, data)
})
}
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func main() {
extractors.Facebook(videoURL)
case "douyu":
extractors.Douyu(videoURL)
case "miaopai":
extractors.Miaopai(videoURL)
default:
extractors.Universal(videoURL)
}
Expand Down
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ func Title(doc *goquery.Document) string {
// Bilibili: Some movie page got no h1 tag
title, _ = doc.Find("meta[property=\"og:title\"]").Attr("content")
}
if title == "" {
title = doc.Find("title").Text()
}
return utils.FileName(title)
}
3 changes: 3 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func MatchOneOf(text string, patterns ...string) []string {
value []string
)
for _, pattern := range patterns {
// (?flags): set flags within current group; non-capturing
// s: let . match \n (default false)
// https://github.com/google/re2/wiki/Syntax
re = regexp.MustCompile(pattern)
value = re.FindStringSubmatch(text)
if len(value) > 0 {
Expand Down

0 comments on commit 8f7d746

Please sign in to comment.