From a9bef5d86896dd646cf3496984a8770e4764e387 Mon Sep 17 00:00:00 2001 From: Todd Bednarczyk Date: Thu, 2 Jan 2020 05:13:29 -0500 Subject: [PATCH] Add TikTok support (#591) * added tiktok support * Added tiktok to readme --- README.md | 1 + extractors/tiktok/tiktok.go | 61 ++++++++++++++++++++++++++++++++ extractors/tiktok/tiktok_test.go | 37 +++++++++++++++++++ main.go | 3 ++ 4 files changed, 102 insertions(+) create mode 100644 extractors/tiktok/tiktok.go create mode 100644 extractors/tiktok/tiktok_test.go diff --git a/README.md b/README.md index 5169a32e1..6ae40c954 100644 --- a/README.md +++ b/README.md @@ -615,6 +615,7 @@ Twitter | | ✓ | | | | Pornhub | | ✓ | | | | XVIDEOS | | ✓ | | | | 聯合新聞網 | | ✓ | | | | +TikTok | | ✓ | | | | ## Known issues diff --git a/extractors/tiktok/tiktok.go b/extractors/tiktok/tiktok.go new file mode 100644 index 000000000..413ae076d --- /dev/null +++ b/extractors/tiktok/tiktok.go @@ -0,0 +1,61 @@ +package tiktok + +import ( + "github.com/iawia002/annie/downloader" + "github.com/iawia002/annie/extractors" + "github.com/iawia002/annie/request" + "github.com/iawia002/annie/utils" +) + +// Extract is the main function for extracting data +func Extract(uri string) ([]downloader.Data, error) { + html, err := request.Get(uri, uri, nil) + if err != nil { + return nil, err + } + + // There are a few json objects loaded into the html that are useful. We're able to parse the video url from the + // videoObject json. + + videoScriptTag := utils.MatchOneOf(html, `