140 lines
4.1 KiB
Go
140 lines
4.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
|
||
|
"github.com/iawia002/annie/config"
|
||
|
"github.com/iawia002/annie/downloader"
|
||
|
"github.com/iawia002/annie/extractors/bcy"
|
||
|
"github.com/iawia002/annie/extractors/bilibili"
|
||
|
"github.com/iawia002/annie/extractors/douyin"
|
||
|
"github.com/iawia002/annie/extractors/douyu"
|
||
|
"github.com/iawia002/annie/extractors/facebook"
|
||
|
"github.com/iawia002/annie/extractors/geekbang"
|
||
|
"github.com/iawia002/annie/extractors/instagram"
|
||
|
"github.com/iawia002/annie/extractors/iqiyi"
|
||
|
"github.com/iawia002/annie/extractors/mgtv"
|
||
|
"github.com/iawia002/annie/extractors/miaopai"
|
||
|
"github.com/iawia002/annie/extractors/netease"
|
||
|
"github.com/iawia002/annie/extractors/pixivision"
|
||
|
"github.com/iawia002/annie/extractors/pornhub"
|
||
|
"github.com/iawia002/annie/extractors/qq"
|
||
|
"github.com/iawia002/annie/extractors/tangdou"
|
||
|
"github.com/iawia002/annie/extractors/tiktok"
|
||
|
"github.com/iawia002/annie/extractors/tumblr"
|
||
|
"github.com/iawia002/annie/extractors/twitter"
|
||
|
"github.com/iawia002/annie/extractors/udn"
|
||
|
"github.com/iawia002/annie/extractors/universal"
|
||
|
"github.com/iawia002/annie/extractors/vimeo"
|
||
|
"github.com/iawia002/annie/extractors/weibo"
|
||
|
"github.com/iawia002/annie/extractors/xvideos"
|
||
|
"github.com/iawia002/annie/extractors/yinyuetai"
|
||
|
"github.com/iawia002/annie/extractors/youku"
|
||
|
"github.com/iawia002/annie/extractors/youtube"
|
||
|
"github.com/iawia002/annie/utils"
|
||
|
)
|
||
|
|
||
|
// The following code is slightly modified from
|
||
|
//
|
||
|
// https://github.com/iawia002/annie/blob/master/main.go
|
||
|
|
||
|
func download(videoURL string) bool {
|
||
|
var (
|
||
|
domain string
|
||
|
err error
|
||
|
data []downloader.Data
|
||
|
)
|
||
|
bilibiliShortLink := utils.MatchOneOf(videoURL, `^(av|ep)\d+`)
|
||
|
if bilibiliShortLink != nil && len(bilibiliShortLink) > 1 {
|
||
|
bilibiliURL := map[string]string{
|
||
|
"av": "https://www.bilibili.com/video/",
|
||
|
"ep": "https://www.bilibili.com/bangumi/play/",
|
||
|
}
|
||
|
domain = "bilibili"
|
||
|
videoURL = bilibiliURL[bilibiliShortLink[1]] + videoURL
|
||
|
} else {
|
||
|
u, err := url.ParseRequestURI(videoURL)
|
||
|
if err != nil {
|
||
|
printError(videoURL, err)
|
||
|
return false
|
||
|
}
|
||
|
domain = utils.Domain(u.Host)
|
||
|
}
|
||
|
switch domain {
|
||
|
case "douyin", "iesdouyin":
|
||
|
data, err = douyin.Extract(videoURL)
|
||
|
case "bilibili":
|
||
|
data, err = bilibili.Extract(videoURL)
|
||
|
case "bcy":
|
||
|
data, err = bcy.Extract(videoURL)
|
||
|
case "pixivision":
|
||
|
data, err = pixivision.Extract(videoURL)
|
||
|
case "youku":
|
||
|
data, err = youku.Extract(videoURL)
|
||
|
case "youtube", "youtu": // youtu.be
|
||
|
data, err = youtube.Extract(videoURL)
|
||
|
case "iqiyi":
|
||
|
data, err = iqiyi.Extract(videoURL)
|
||
|
case "mgtv":
|
||
|
data, err = mgtv.Extract(videoURL)
|
||
|
case "tangdou":
|
||
|
data, err = tangdou.Extract(videoURL)
|
||
|
case "tumblr":
|
||
|
data, err = tumblr.Extract(videoURL)
|
||
|
case "vimeo":
|
||
|
data, err = vimeo.Extract(videoURL)
|
||
|
case "facebook":
|
||
|
data, err = facebook.Extract(videoURL)
|
||
|
case "douyu":
|
||
|
data, err = douyu.Extract(videoURL)
|
||
|
case "miaopai":
|
||
|
data, err = miaopai.Extract(videoURL)
|
||
|
case "163":
|
||
|
data, err = netease.Extract(videoURL)
|
||
|
case "weibo":
|
||
|
data, err = weibo.Extract(videoURL)
|
||
|
case "instagram":
|
||
|
data, err = instagram.Extract(videoURL)
|
||
|
case "twitter":
|
||
|
data, err = twitter.Extract(videoURL)
|
||
|
case "qq":
|
||
|
data, err = qq.Extract(videoURL)
|
||
|
case "yinyuetai":
|
||
|
data, err = yinyuetai.Extract(videoURL)
|
||
|
case "geekbang":
|
||
|
data, err = geekbang.Extract(videoURL)
|
||
|
case "pornhub":
|
||
|
data, err = pornhub.Extract(videoURL)
|
||
|
case "xvideos":
|
||
|
data, err = xvideos.Extract(videoURL)
|
||
|
case "udn":
|
||
|
data, err = udn.Extract(videoURL)
|
||
|
case "tiktok":
|
||
|
data, err = tiktok.Extract(videoURL)
|
||
|
default:
|
||
|
data, err = universal.Extract(videoURL)
|
||
|
}
|
||
|
if err != nil {
|
||
|
// if this error occurs, it means that an error occurred before actually starting to extract data
|
||
|
// (there is an error in the preparation step), and the data list is empty.
|
||
|
printError(videoURL, err)
|
||
|
return false
|
||
|
}
|
||
|
var isErr bool
|
||
|
for _, item := range data {
|
||
|
if item.Err != nil {
|
||
|
// if this error occurs, the preparation step is normal, but the data extraction is wrong.
|
||
|
// the data is an empty struct.
|
||
|
printError(item.URL, item.Err)
|
||
|
isErr = true
|
||
|
continue
|
||
|
}
|
||
|
err = downloader.Download(item, videoURL, config.ChunkSizeMB)
|
||
|
if err != nil {
|
||
|
printError(item.URL, err)
|
||
|
isErr = true
|
||
|
}
|
||
|
}
|
||
|
return !isErr
|
||
|
}
|