From 979081a2ea7bf7f1b92ce65c8f8ee86b3b8ff36c Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Sep 2019 23:21:40 +0800 Subject: [PATCH 1/2] support download video and playlist for tang dou. --- README.md | 1 + extractors/tangdou/tangdou.go | 98 ++++++++++++++++++++++++++++++ extractors/tangdou/tangdou_test.go | 73 ++++++++++++++++++++++ main.go | 3 + 4 files changed, 175 insertions(+) create mode 100644 extractors/tangdou/tangdou.go create mode 100644 extractors/tangdou/tangdou_test.go diff --git a/README.md b/README.md index d48963518..4a9386df3 100644 --- a/README.md +++ b/README.md @@ -588,6 +588,7 @@ pixivision | | | ✓ | | | YouTube | | ✓ | | ✓ | | 爱奇艺 | | ✓ | | | | 芒果TV | | ✓ | | | | +糖豆广场舞 | | ✓ | | ✓ | | Tumblr | | ✓ | ✓ | | | Vimeo | | ✓ | | | | Facebook | | ✓ | | | | diff --git a/extractors/tangdou/tangdou.go b/extractors/tangdou/tangdou.go new file mode 100644 index 000000000..ab145fe51 --- /dev/null +++ b/extractors/tangdou/tangdou.go @@ -0,0 +1,98 @@ +package tangdou + +import ( + "github.com/iawia002/annie/config" + "github.com/iawia002/annie/downloader" + "github.com/iawia002/annie/request" + "github.com/iawia002/annie/utils" +) + +const referer = "http://www.tangdou.com/html/playlist/view/4173" + +// Extract is the main function for extracting data +func Extract(uri string) ([]downloader.Data, error) { + var err error + if !config.Playlist { + return []downloader.Data{tangdouDownload(uri)}, nil + } + html, err := request.Get(uri, referer, nil) + if err != nil { + return downloader.EmptyList, err + } + videoIDs := utils.MatchAll(html, ``) + needDownloadItems := utils.NeedDownloadList(len(videoIDs)) + extractedData := make([]downloader.Data, len(needDownloadItems)) + wgp := utils.NewWaitGroupPool(config.ThreadNumber) + dataIndex := 0 + for index, videoID := range videoIDs { + if !utils.ItemInSlice(index+1, needDownloadItems) { + continue + } + wgp.Add() + go func(index int, videURI string, extractedData []downloader.Data) { + defer wgp.Done() + extractedData[index] = tangdouDownload(videURI) + }(dataIndex, videoID[1], extractedData) + dataIndex++ + } + wgp.Wait() + return extractedData, nil +} + +// tangdouDownload download function for single url +func tangdouDownload(uri string) downloader.Data { + var err error + html, err := request.Get(uri, referer, nil) + if err != nil { + return downloader.EmptyData(uri, err) + } + + title := utils.MatchOneOf( + html, `
(.+?)
`, ``, + )[1] + + var realURL string + videoURLs := utils.MatchOneOf( + html, `video:'(.+?)'`, `video:"(.+?)"`, + ) + if videoURLs == nil { + shareURL := utils.MatchOneOf( + html, `
\s*