mirror of
https://github.com/pikami/tiktok-dl.git
synced 2025-12-21 17:59:51 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
673bbe1340 | ||
|
|
2af96e899e | ||
|
|
18c745aaba | ||
|
|
cd2f2d818b | ||
|
|
884f9040db | ||
|
|
672bacd3dd | ||
|
|
6f8ab8a277 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ __debug_bin
|
|||||||
downloads
|
downloads
|
||||||
*.exe
|
*.exe
|
||||||
tiktok-dl
|
tiktok-dl
|
||||||
|
batch_file.txt
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ A simple tiktok video downloader written in go
|
|||||||
## Basic usage
|
## Basic usage
|
||||||
Download the executable from `https://github.com/pikami/tiktok-dl/releases`\
|
Download the executable from `https://github.com/pikami/tiktok-dl/releases`\
|
||||||
You can download all videos from user by running `./tiktok-dl [Options] TIKTOK_USERNAME`\
|
You can download all videos from user by running `./tiktok-dl [Options] TIKTOK_USERNAME`\
|
||||||
You can download single video by running `./tiktok-dl [Options] VIDEO_URL`
|
You can download single video by running `./tiktok-dl [Options] VIDEO_URL`\
|
||||||
|
You can download all videos by music by running `./tiktok-dl [Options] MUSIC_URL`\
|
||||||
|
You can download items listed in a text file by running `./tiktok-dl [OPTIONS] -batch-file path/to/items.txt`
|
||||||
|
|
||||||
## Build instructions
|
## Build instructions
|
||||||
Clone this repository and run `go build` to build the executable.
|
Clone this repository and run `go build` to build the executable.
|
||||||
@@ -17,6 +19,9 @@ Clone this repository and run `go build` to build the executable.
|
|||||||
* `-debug` - enables debug mode
|
* `-debug` - enables debug mode
|
||||||
* `-output some_directory` - Output path (default "./downloads")
|
* `-output some_directory` - Output path (default "./downloads")
|
||||||
* `-metadata` - Write video metadata to a .json file
|
* `-metadata` - Write video metadata to a .json file
|
||||||
|
* `-batch-file` - File containing URLs/Usernames to download, one value per line. Lines starting with '#', are considered as comments and ignored.
|
||||||
|
* `-deadline` - Sets the timout for scraper logic in seconds (used as a workaround for context deadline exceeded error) (default 1500)
|
||||||
|
|
||||||
## Acknowledgments
|
## Acknowledgments
|
||||||
This software uses the chromedp for web scraping, it can be found here: https://github.com/chromedp/chromedp
|
This software uses the **chromedp** for web scraping, it can be found here: https://github.com/chromedp/chromedp \
|
||||||
|
For releases the JS code is minified by using **terser** toolkit, it can be found here: https://github.com/terser/terser
|
||||||
|
|||||||
58
client/executeClientAction.go
Normal file
58
client/executeClientAction.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/chromedp/chromedp"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
models "../models"
|
||||||
|
utils "../utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetMusicUploads - Get all uploads by given music
|
||||||
|
func executeClientAction(url string, jsAction string) string {
|
||||||
|
dir, err := ioutil.TempDir("", "chromedp-example")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||||
|
chromedp.DisableGPU,
|
||||||
|
chromedp.UserDataDir(dir),
|
||||||
|
chromedp.Flag("headless", !models.Config.Debug),
|
||||||
|
)
|
||||||
|
|
||||||
|
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ctx, cancel := chromedp.NewContext(
|
||||||
|
allocCtx,
|
||||||
|
chromedp.WithLogf(log.Printf),
|
||||||
|
)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, time.Duration(models.Config.Deadline)*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
var jsOutput string
|
||||||
|
err = chromedp.Run(ctx,
|
||||||
|
// Navigate to user's page
|
||||||
|
chromedp.Navigate(url),
|
||||||
|
// Execute url grabber script
|
||||||
|
chromedp.EvaluateAsDevTools(utils.ReadFileAsString("scraper.js"), &jsOutput),
|
||||||
|
chromedp.EvaluateAsDevTools(jsAction, &jsOutput),
|
||||||
|
// Wait until custom js finishes
|
||||||
|
chromedp.WaitVisible(`video_urls`),
|
||||||
|
// Grab url links from our element
|
||||||
|
chromedp.InnerHTML(`video_urls`, &jsOutput),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsOutput
|
||||||
|
}
|
||||||
11
client/getMusicUploads.go
Normal file
11
client/getMusicUploads.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
models "../models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetMusicUploads - Get all uploads by given music
|
||||||
|
func GetMusicUploads(url string) []models.Upload {
|
||||||
|
actionOutput := executeClientAction(url, "bootstrapIteratingVideos()")
|
||||||
|
return models.ParseUploads(actionOutput)
|
||||||
|
}
|
||||||
@@ -1,58 +1,11 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"github.com/chromedp/chromedp"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
models "../models"
|
models "../models"
|
||||||
utils "../utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUserUploads - Get all uploads by user
|
// GetUserUploads - Get all uploads by user
|
||||||
func GetUserUploads(username string) []models.Upload {
|
func GetUserUploads(username string) []models.Upload {
|
||||||
dir, err := ioutil.TempDir("", "chromedp-example")
|
actionOutput := executeClientAction(`https://www.tiktok.com/@`+username, "bootstrapIteratingVideos()")
|
||||||
if err != nil {
|
return models.ParseUploads(actionOutput)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
|
||||||
chromedp.DisableGPU,
|
|
||||||
chromedp.UserDataDir(dir),
|
|
||||||
chromedp.Flag("headless", !models.Config.Debug),
|
|
||||||
)
|
|
||||||
|
|
||||||
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ctx, cancel := chromedp.NewContext(
|
|
||||||
allocCtx,
|
|
||||||
chromedp.WithLogf(log.Printf),
|
|
||||||
)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ctx, cancel = context.WithTimeout(ctx, 1500*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var jsOutput string
|
|
||||||
err = chromedp.Run(ctx,
|
|
||||||
// Navigate to user's page
|
|
||||||
chromedp.Navigate(`https://www.tiktok.com/@`+username),
|
|
||||||
// Execute url grabber script
|
|
||||||
chromedp.EvaluateAsDevTools(utils.ReadFileAsString("scraper.js"), &jsOutput),
|
|
||||||
chromedp.EvaluateAsDevTools("bootstrapIteratingVideos()", &jsOutput),
|
|
||||||
// Wait until custom js finishes
|
|
||||||
chromedp.WaitVisible(`video_urls`),
|
|
||||||
// Grab url links from our element
|
|
||||||
chromedp.InnerHTML(`video_urls`, &jsOutput),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return models.ParseUploads(jsOutput)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,11 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"github.com/chromedp/chromedp"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
models "../models"
|
models "../models"
|
||||||
utils "../utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetVideoDetails - returns details of video
|
// GetVideoDetails - returns details of video
|
||||||
func GetVideoDetails(videoURL string) models.Upload {
|
func GetVideoDetails(videoURL string) models.Upload {
|
||||||
dir, err := ioutil.TempDir("", "chromedp-example")
|
actionOutput := executeClientAction(videoURL, "bootstrapGetCurrentVideo()")
|
||||||
if err != nil {
|
return models.ParseUpload(actionOutput)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
|
||||||
chromedp.DisableGPU,
|
|
||||||
chromedp.UserDataDir(dir),
|
|
||||||
chromedp.Flag("headless", !models.Config.Debug),
|
|
||||||
)
|
|
||||||
|
|
||||||
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ctx, cancel := chromedp.NewContext(
|
|
||||||
allocCtx,
|
|
||||||
chromedp.WithLogf(log.Printf),
|
|
||||||
)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ctx, cancel = context.WithTimeout(ctx, 1500*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var jsOutput string
|
|
||||||
err = chromedp.Run(ctx,
|
|
||||||
// Navigate to user's page
|
|
||||||
chromedp.Navigate(videoURL),
|
|
||||||
// Execute url grabber script
|
|
||||||
chromedp.EvaluateAsDevTools(utils.ReadFileAsString("scraper.js"), &jsOutput),
|
|
||||||
chromedp.EvaluateAsDevTools("bootstrapGetCurrentVideo()", &jsOutput),
|
|
||||||
// Wait until custom js finishes
|
|
||||||
chromedp.WaitVisible(`video_urls`),
|
|
||||||
// Grab url links from our element
|
|
||||||
chromedp.InnerHTML(`video_urls`, &jsOutput),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return models.ParseUpload(jsOutput)
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
main.go
15
main.go
@@ -8,18 +8,13 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
models.GetConfig()
|
models.GetConfig()
|
||||||
url := models.Config.URL
|
url := models.Config.URL
|
||||||
|
batchFilePath := models.Config.BatchFilePath
|
||||||
|
|
||||||
// Single video
|
// Batch file
|
||||||
if workflows.CanUseDownloadSingleVideo(url) {
|
if workflows.CanUseDownloadBatchFile(batchFilePath) {
|
||||||
workflows.DownloadSingleVideo(url)
|
workflows.DownloadBatchFile(batchFilePath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiktok user
|
workflows.StartWorkflowByParameter(url)
|
||||||
if workflows.CanUseDownloadUser(url) {
|
|
||||||
workflows.DownloadUser(models.GetUsername())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("Could not recognise URL format")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,39 +10,55 @@ import (
|
|||||||
|
|
||||||
// Config - Runtime configuration
|
// Config - Runtime configuration
|
||||||
var Config struct {
|
var Config struct {
|
||||||
URL string
|
URL string
|
||||||
OutputPath string
|
OutputPath string
|
||||||
Debug bool
|
BatchFilePath string
|
||||||
MetaData bool
|
Debug bool
|
||||||
|
MetaData bool
|
||||||
|
Deadline int
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig - Returns Config object
|
// GetConfig - Returns Config object
|
||||||
func GetConfig() {
|
func GetConfig() {
|
||||||
outputPath := flag.String("output", "./downloads", "Output path")
|
outputPath := flag.String("output", "./downloads", "Output path")
|
||||||
|
batchFilePath := flag.String("batch-file", "", "File containing URLs/Usernames to download, one value per line. Lines starting with '#', are considered as comments and ignored.")
|
||||||
debug := flag.Bool("debug", false, "Enables debug mode")
|
debug := flag.Bool("debug", false, "Enables debug mode")
|
||||||
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
|
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
|
||||||
|
deadline := flag.Int("deadline", 1500, "Sets the timout for scraper logic in seconds (used as a workaround for 'context deadline exceeded' error)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 && *batchFilePath == "" {
|
||||||
fmt.Println("Usage: tiktok-dl [OPTIONS] TIKTOK_USERNAME|TIKTOK_URL")
|
fmt.Println("Usage: tiktok-dl [OPTIONS] TIKTOK_USERNAME|TIKTOK_URL")
|
||||||
|
fmt.Println(" or: tiktok-dl [OPTIONS] -batch-file path/to/users.txt")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.URL = flag.Args()[len(args)-1]
|
if len(args) > 0 {
|
||||||
|
Config.URL = flag.Args()[len(args)-1]
|
||||||
|
} else {
|
||||||
|
Config.URL = ""
|
||||||
|
}
|
||||||
Config.OutputPath = *outputPath
|
Config.OutputPath = *outputPath
|
||||||
|
Config.BatchFilePath = *batchFilePath
|
||||||
Config.Debug = *debug
|
Config.Debug = *debug
|
||||||
Config.MetaData = *metadata
|
Config.MetaData = *metadata
|
||||||
|
Config.Deadline = *deadline
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsername - Get's username from passed URL param
|
// GetUsername - Get's username from passed URL param
|
||||||
func GetUsername() string {
|
func GetUsername() string {
|
||||||
if match := strings.Contains(Config.URL, "/"); !match { // Not url
|
return GetUsernameFromString(Config.URL)
|
||||||
return strings.Replace(Config.URL, "@", "", -1)
|
}
|
||||||
|
|
||||||
|
// GetUsernameFromString - Get's username from passed param
|
||||||
|
func GetUsernameFromString(str string) string {
|
||||||
|
if match := strings.Contains(str, "/"); !match { // Not url
|
||||||
|
return strings.Replace(str, "@", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if match, _ := regexp.MatchString(".+tiktok\\.com/@.+", Config.URL); match { // URL
|
if match, _ := regexp.MatchString(".+tiktok\\.com/@.+", str); match { // URL
|
||||||
stripedSuffix := strings.Split(Config.URL, "@")[1]
|
stripedSuffix := strings.Split(str, "@")[1]
|
||||||
return strings.Split(stripedSuffix, "/")[0]
|
return strings.Split(stripedSuffix, "/")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type Upload struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
ShareLink string `json:"shareLink"`
|
ShareLink string `json:"shareLink"`
|
||||||
Caption string `json:"caption"`
|
Caption string `json:"caption"`
|
||||||
|
Uploader string `json:"uploader"`
|
||||||
Sound Sound `json:"sound"`
|
Sound Sound `json:"sound"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestParseUploads(t *testing.T) {
|
func TestParseUploads(t *testing.T) {
|
||||||
tu := testUtil.TestUtil{T: t}
|
tu := testUtil.TestUtil{T: t}
|
||||||
jsonStr := "[{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}]"
|
jsonStr := "[{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\", \"uploader\": \"some.uploader\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}]"
|
||||||
actual := ParseUploads(jsonStr)
|
actual := ParseUploads(jsonStr)
|
||||||
|
|
||||||
tu.AssertInt(len(actual), 1, "Array len")
|
tu.AssertInt(len(actual), 1, "Array len")
|
||||||
@@ -17,6 +17,7 @@ func TestParseUploads(t *testing.T) {
|
|||||||
tu.AssertString(actual[0].URL, "some_url", "URL")
|
tu.AssertString(actual[0].URL, "some_url", "URL")
|
||||||
tu.AssertString(actual[0].Caption, "some_caption", "Caption")
|
tu.AssertString(actual[0].Caption, "some_caption", "Caption")
|
||||||
tu.AssertString(actual[0].ShareLink, "some_share_link", "ShareLink")
|
tu.AssertString(actual[0].ShareLink, "some_share_link", "ShareLink")
|
||||||
|
tu.AssertString(actual[0].Uploader, "some.uploader", "Uploader")
|
||||||
|
|
||||||
tu.AssertString(actual[0].Sound.Link, "some_link", "Sound.Link")
|
tu.AssertString(actual[0].Sound.Link, "some_link", "Sound.Link")
|
||||||
tu.AssertString(actual[0].Sound.Title, "some_title", "Sound.Title")
|
tu.AssertString(actual[0].Sound.Title, "some_title", "Sound.Title")
|
||||||
@@ -46,12 +47,13 @@ func TestGetUploadID(t *testing.T) {
|
|||||||
|
|
||||||
func TestWriteToFile(t *testing.T) {
|
func TestWriteToFile(t *testing.T) {
|
||||||
tu := testUtil.TestUtil{T: t}
|
tu := testUtil.TestUtil{T: t}
|
||||||
expected := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
|
expected := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"uploader\":\"some.uploader\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
|
||||||
filePath := "test_file.txt"
|
filePath := "test_file.txt"
|
||||||
upload := Upload{
|
upload := Upload{
|
||||||
URL: "some_url",
|
URL: "some_url",
|
||||||
Caption: "some_caption",
|
Caption: "some_caption",
|
||||||
ShareLink: "some_share_link",
|
ShareLink: "some_share_link",
|
||||||
|
Uploader: "some.uploader",
|
||||||
Sound: Sound{
|
Sound: Sound{
|
||||||
Link: "some_link",
|
Link: "some_link",
|
||||||
Title: "some_title",
|
Title: "some_title",
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ optStrings = {
|
|||||||
modalShareInput: '.copy-link-container > input',
|
modalShareInput: '.copy-link-container > input',
|
||||||
modalCaption: 'div.video-card-big > div.content-container > div.video-meta-info > h1',
|
modalCaption: 'div.video-card-big > div.content-container > div.video-meta-info > h1',
|
||||||
modalSoundLink: 'div.content-container > div.video-meta-info > h2.music-info > a',
|
modalSoundLink: 'div.content-container > div.video-meta-info > h2.music-info > a',
|
||||||
|
modalUploader: '.user-username',
|
||||||
videoPlayer: 'div.video-card-container > div > div > video',
|
videoPlayer: 'div.video-card-container > div > div > video',
|
||||||
videoShareInput: 'div.content-container.border > div.copy-link-container > input',
|
videoShareInput: 'div.content-container.border > div.copy-link-container > input',
|
||||||
videoCaption: 'div.content-container.border > div.video-meta-info > h1',
|
videoCaption: 'div.content-container.border > div.video-meta-info > h1',
|
||||||
videoSoundLink: 'div.content-container.border > div.video-meta-info > h2.music-info > a',
|
videoSoundLink: 'div.content-container.border > div.video-meta-info > h2.music-info > a',
|
||||||
|
videoUploader: '.user-username',
|
||||||
},
|
},
|
||||||
classes: {
|
classes: {
|
||||||
feedVideoItem: 'video-feed-item-wrapper',
|
feedVideoItem: 'video-feed-item-wrapper',
|
||||||
@@ -56,6 +58,7 @@ getCurrentModalVideo = function() {
|
|||||||
var shareLink = document.querySelector(optStrings.selectors.modalShareInput).value;
|
var shareLink = document.querySelector(optStrings.selectors.modalShareInput).value;
|
||||||
var caption = document.querySelector(optStrings.selectors.modalCaption).textContent;
|
var caption = document.querySelector(optStrings.selectors.modalCaption).textContent;
|
||||||
var soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
var soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
||||||
|
var uploader = document.querySelector(optStrings.selectors.modalUploader).textContent;
|
||||||
var soundHref = soundLink.getAttribute("href");
|
var soundHref = soundLink.getAttribute("href");
|
||||||
var soundText = soundLink.text;
|
var soundText = soundLink.text;
|
||||||
|
|
||||||
@@ -63,6 +66,7 @@ getCurrentModalVideo = function() {
|
|||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
shareLink: shareLink,
|
shareLink: shareLink,
|
||||||
caption: caption,
|
caption: caption,
|
||||||
|
uploader: uploader,
|
||||||
sound: {
|
sound: {
|
||||||
title: soundText,
|
title: soundText,
|
||||||
link: soundHref,
|
link: soundHref,
|
||||||
@@ -76,6 +80,7 @@ getCurrentVideo = function() {
|
|||||||
var shareLink = document.querySelector(optStrings.selectors.videoShareInput).value;
|
var shareLink = document.querySelector(optStrings.selectors.videoShareInput).value;
|
||||||
var caption = document.querySelector(optStrings.selectors.videoCaption).textContent;
|
var caption = document.querySelector(optStrings.selectors.videoCaption).textContent;
|
||||||
var soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
var soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
||||||
|
var uploader = document.querySelector(optStrings.selectors.videoUploader).textContent;
|
||||||
var soundHref = soundLink.getAttribute("href");
|
var soundHref = soundLink.getAttribute("href");
|
||||||
var soundText = soundLink.text;
|
var soundText = soundLink.text;
|
||||||
|
|
||||||
@@ -83,6 +88,7 @@ getCurrentVideo = function() {
|
|||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
shareLink: shareLink,
|
shareLink: shareLink,
|
||||||
caption: caption,
|
caption: caption,
|
||||||
|
uploader: uploader,
|
||||||
sound: {
|
sound: {
|
||||||
title: soundText,
|
title: soundText,
|
||||||
link: soundHref,
|
link: soundHref,
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type delegateString func(string)
|
||||||
|
|
||||||
// CheckIfExists - Checks if file or directory exists
|
// CheckIfExists - Checks if file or directory exists
|
||||||
func CheckIfExists(path string) bool {
|
func CheckIfExists(path string) bool {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
@@ -30,3 +33,21 @@ func ReadFileToString(path string) string {
|
|||||||
|
|
||||||
return string(content)
|
return string(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadFileLineByLine - Reads file line by line and calls delegate
|
||||||
|
func ReadFileLineByLine(path string, delegate delegateString) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
delegate(scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
28
workflows/downloadBatchFile.go
Normal file
28
workflows/downloadBatchFile.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
utils "../utils"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanUseDownloadBatchFile - Check's if DownloadBatchFile can be used
|
||||||
|
func CanUseDownloadBatchFile(batchFilePath string) bool {
|
||||||
|
return batchFilePath != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadBatchFile - Download items from batch file
|
||||||
|
func DownloadBatchFile(batchFilePath string) {
|
||||||
|
if !utils.CheckIfExists(batchFilePath) {
|
||||||
|
panic(fmt.Sprintf("File path %s not found.", batchFilePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.ReadFileLineByLine(batchFilePath, downloadItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadItem(batchItem string) {
|
||||||
|
if batchItem[0] == '#' {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
StartWorkflowByParameter(batchItem)
|
||||||
|
}
|
||||||
28
workflows/downloadMusic.go
Normal file
28
workflows/downloadMusic.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
client "../client"
|
||||||
|
models "../models"
|
||||||
|
utils "../utils"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanUseDownloadMusic - Check's if DownloadMusic can be used for parameter
|
||||||
|
func CanUseDownloadMusic(url string) bool {
|
||||||
|
match, _ := regexp.MatchString(".com\\/music\\/.+", url)
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadMusic - Download all videos by given music
|
||||||
|
func DownloadMusic(url string) {
|
||||||
|
uploads := client.GetMusicUploads(url)
|
||||||
|
|
||||||
|
for _, upload := range uploads {
|
||||||
|
username := models.GetUsernameFromString(upload.Uploader)
|
||||||
|
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||||
|
|
||||||
|
utils.InitOutputDirectory(downloadDir)
|
||||||
|
downloadVideo(upload, downloadDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ func CanUseDownloadSingleVideo(url string) bool {
|
|||||||
|
|
||||||
// DownloadSingleVideo - Downloads single video
|
// DownloadSingleVideo - Downloads single video
|
||||||
func DownloadSingleVideo(url string) {
|
func DownloadSingleVideo(url string) {
|
||||||
username := models.GetUsername()
|
username := models.GetUsernameFromString(url)
|
||||||
upload := client.GetVideoDetails(url)
|
upload := client.GetVideoDetails(url)
|
||||||
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||||
|
|
||||||
|
|||||||
30
workflows/startWorkflowByParameter.go
Normal file
30
workflows/startWorkflowByParameter.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
models "../models"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StartWorkflowByParameter - Start needed workflow by given parameter
|
||||||
|
func StartWorkflowByParameter(url string) {
|
||||||
|
|
||||||
|
// Music
|
||||||
|
if CanUseDownloadMusic(url) {
|
||||||
|
DownloadMusic(url)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single video
|
||||||
|
if CanUseDownloadSingleVideo(url) {
|
||||||
|
DownloadSingleVideo(url)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tiktok user
|
||||||
|
if CanUseDownloadUser(url) {
|
||||||
|
DownloadUser(models.GetUsernameFromString(url))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(fmt.Sprintf("Could not recognise URL format of string %s", url))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user