mirror of
https://github.com/pikami/tiktok-dl.git
synced 2025-12-21 01:39:51 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1782a2f12b | ||
|
|
6e0e39ada2 | ||
|
|
320e044f3c | ||
|
|
3ac05993af | ||
|
|
4e7093250f | ||
|
|
5609abb04c | ||
|
|
943cf48c8b | ||
|
|
9707ed790d |
21
.github/workflows/go.yml
vendored
21
.github/workflows/go.yml
vendored
@@ -15,30 +15,35 @@ jobs:
|
|||||||
go-version: 1.13
|
go-version: 1.13
|
||||||
id: go
|
id: go
|
||||||
|
|
||||||
|
- name: Set up node 10
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: '10.x'
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
- name: Get dependencies
|
- name: Get dependencies
|
||||||
run: |
|
run: |
|
||||||
go get -v -t -d ./...
|
npm install
|
||||||
|
npm run install-dependencies
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v .
|
run: npm run build:dist
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
go test -v ./models
|
|
||||||
|
|
||||||
- name: Upload Unix Artifacts
|
- name: Upload Unix Artifacts
|
||||||
if: startsWith(matrix.os, 'ubuntu-')
|
if: startsWith(matrix.os, 'ubuntu-')
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: tiktok-dl_linux
|
name: tiktok-dl_linux
|
||||||
path: tiktok-dl
|
path: out
|
||||||
|
|
||||||
- name: Upload Windows Artifacts
|
- name: Upload Windows Artifacts
|
||||||
if: startsWith(matrix.os, 'windows-')
|
if: startsWith(matrix.os, 'windows-')
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: tiktok-dl_win64
|
name: tiktok-dl_win64
|
||||||
path: tiktok-dl.exe
|
path: out
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
|
node_modules
|
||||||
__debug_bin
|
__debug_bin
|
||||||
downloads
|
downloads
|
||||||
*.exe
|
*.exe
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
# TikTok-DL
|
# TikTok-DL
|
||||||
|
|
||||||
[](https://goreportcard.com/report/github.com/pikami/tiktok-dl)
|
[](https://goreportcard.com/report/github.com/pikami/tiktok-dl)
|
||||||
|

|
||||||
|
|
||||||
A simple tiktok video downloader written in go
|
A simple tiktok video downloader written in go
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
Clone this repository and run `go build` to build the executable.\
|
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`
|
||||||
|
|
||||||
|
## Build instructions
|
||||||
|
Clone this repository and run `go build` to build the executable.
|
||||||
|
|
||||||
## Available options
|
## Available options
|
||||||
* `-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
|
||||||
|
|
||||||
## 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
|
||||||
44
main.go
44
main.go
@@ -1,12 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
client "./client"
|
|
||||||
models "./models"
|
models "./models"
|
||||||
utils "./utils"
|
workflows "./workflows"
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -14,44 +10,16 @@ func main() {
|
|||||||
url := models.Config.URL
|
url := models.Config.URL
|
||||||
|
|
||||||
// Single video
|
// Single video
|
||||||
match, _ := regexp.MatchString("\\/@.+\\/video\\/[0-9]+", url)
|
if workflows.CanUseDownloadSingleVideo(url) {
|
||||||
if match {
|
workflows.DownloadSingleVideo(url)
|
||||||
getUsernameFromVidURLRegex, _ := regexp.Compile("com\\/@.*")
|
|
||||||
parts := strings.Split(getUsernameFromVidURLRegex.FindString(url), "/")
|
|
||||||
username := parts[1][1:]
|
|
||||||
upload := client.GetVideoDetails(url)
|
|
||||||
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
|
||||||
|
|
||||||
utils.InitOutputDirectory(downloadDir)
|
|
||||||
downloadVideo(upload, downloadDir)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiktok user
|
// Tiktok user
|
||||||
downloadUser()
|
if workflows.CanUseDownloadUser(url) {
|
||||||
}
|
workflows.DownloadUser(models.GetUsername())
|
||||||
|
|
||||||
func downloadVideo(upload models.Upload, downloadDir string) {
|
|
||||||
uploadID := upload.GetUploadID()
|
|
||||||
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
|
||||||
|
|
||||||
if utils.CheckIfExists(downloadPath) {
|
|
||||||
fmt.Println("Upload '" + uploadID + "' already downloaded, skipping")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Downloading upload item '" + uploadID + "' to " + downloadPath)
|
panic("Could not recognise URL format")
|
||||||
utils.DownloadFile(downloadPath, upload.URL)
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadUser() {
|
|
||||||
username := models.Config.URL
|
|
||||||
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
|
||||||
uploads := client.GetUserUploads(username)
|
|
||||||
|
|
||||||
utils.InitOutputDirectory(downloadDir)
|
|
||||||
|
|
||||||
for _, upload := range uploads {
|
|
||||||
downloadVideo(upload, downloadDir)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config - Runtime configuration
|
// Config - Runtime configuration
|
||||||
@@ -11,12 +13,14 @@ var Config struct {
|
|||||||
URL string
|
URL string
|
||||||
OutputPath string
|
OutputPath string
|
||||||
Debug bool
|
Debug bool
|
||||||
|
MetaData bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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")
|
||||||
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")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
@@ -28,4 +32,19 @@ func GetConfig() {
|
|||||||
Config.URL = flag.Args()[len(args)-1]
|
Config.URL = flag.Args()[len(args)-1]
|
||||||
Config.OutputPath = *outputPath
|
Config.OutputPath = *outputPath
|
||||||
Config.Debug = *debug
|
Config.Debug = *debug
|
||||||
|
Config.MetaData = *metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUsername - Get's username from passed URL param
|
||||||
|
func GetUsername() string {
|
||||||
|
if match := strings.Contains(Config.URL, "/"); !match { // Not url
|
||||||
|
return strings.Replace(Config.URL, "@", "", -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if match, _ := regexp.MatchString(".+tiktok\\.com/@.+", Config.URL); match { // URL
|
||||||
|
stripedSuffix := strings.Split(Config.URL, "@")[1]
|
||||||
|
return strings.Split(stripedSuffix, "/")[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("Could not recognise URL format")
|
||||||
}
|
}
|
||||||
|
|||||||
36
models/config_test.go
Normal file
36
models/config_test.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
testUtil "../unitTestUtil"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetUsername(t *testing.T) {
|
||||||
|
testCaseDelegate := func(t *testing.T, url string, username string) {
|
||||||
|
tu := testUtil.TestUtil{T: t}
|
||||||
|
Config.URL = url
|
||||||
|
actual := GetUsername()
|
||||||
|
tu.AssertString(actual, username, "Username")
|
||||||
|
}
|
||||||
|
|
||||||
|
testVideoURL := func(t *testing.T) {
|
||||||
|
testCaseDelegate(t, "https://www.tiktok.com/@some_username/video/0000000000000000000", "some_username")
|
||||||
|
}
|
||||||
|
|
||||||
|
testProfileURL := func(t *testing.T) {
|
||||||
|
testCaseDelegate(t, "https://www.tiktok.com/@some_username", "some_username")
|
||||||
|
}
|
||||||
|
|
||||||
|
testPlainUsername := func(t *testing.T) {
|
||||||
|
testCaseDelegate(t, "some_username", "some_username")
|
||||||
|
}
|
||||||
|
|
||||||
|
testAtUsername := func(t *testing.T) {
|
||||||
|
testCaseDelegate(t, "@some_username", "some_username")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("Video URL", testVideoURL)
|
||||||
|
t.Run("Username URL", testProfileURL)
|
||||||
|
t.Run("Plain username", testPlainUsername)
|
||||||
|
t.Run("Username with @ suffix", testAtUsername)
|
||||||
|
}
|
||||||
@@ -2,13 +2,23 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Upload - Upload object
|
// Upload - Upload object
|
||||||
type Upload struct {
|
type Upload struct {
|
||||||
ShareLink string `json:"shareLink"`
|
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
ShareLink string `json:"shareLink"`
|
||||||
|
Caption string `json:"caption"`
|
||||||
|
Sound Sound `json:"sound"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sound - Sound object
|
||||||
|
type Sound struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Link string `json:"link"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseUploads - Parses json uploads array
|
// ParseUploads - Parses json uploads array
|
||||||
@@ -30,3 +40,26 @@ func (u Upload) GetUploadID() string {
|
|||||||
parts := strings.Split(u.ShareLink, "/")
|
parts := strings.Split(u.ShareLink, "/")
|
||||||
return parts[len(parts)-1]
|
return parts[len(parts)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteToFile - Writes object to file
|
||||||
|
func (u Upload) WriteToFile(outputPath string) {
|
||||||
|
bytes, err := json.Marshal(u)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Could not serialize json for video: %s", u.GetUploadID())
|
||||||
|
fmt.Println()
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the file
|
||||||
|
out, err := os.Create(outputPath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
// Write to file
|
||||||
|
_, err = out.Write(bytes)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,36 +1,67 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
testUtil "../unitTestUtil"
|
||||||
|
utils "../utils"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
// TestParseUploads - Test parsing
|
|
||||||
func TestParseUploads(t *testing.T) {
|
func TestParseUploads(t *testing.T) {
|
||||||
jsonStr := "[{\"shareLink\":\"some_share_link\", \"url\": \"some_url\"}]"
|
tu := testUtil.TestUtil{T: t}
|
||||||
|
jsonStr := "[{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}]"
|
||||||
actual := ParseUploads(jsonStr)
|
actual := ParseUploads(jsonStr)
|
||||||
|
|
||||||
expectedLen := 1
|
tu.AssertInt(len(actual), 1, "Array len")
|
||||||
if len(actual) != expectedLen {
|
|
||||||
t.Errorf("Array len incorrect: Expected %d, but got %d", expectedLen, len(actual))
|
tu.AssertString(actual[0].URL, "some_url", "URL")
|
||||||
|
tu.AssertString(actual[0].Caption, "some_caption", "Caption")
|
||||||
|
tu.AssertString(actual[0].ShareLink, "some_share_link", "ShareLink")
|
||||||
|
|
||||||
|
tu.AssertString(actual[0].Sound.Link, "some_link", "Sound.Link")
|
||||||
|
tu.AssertString(actual[0].Sound.Title, "some_title", "Sound.Title")
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedShareLink := "some_share_link"
|
func TestParseUpload(t *testing.T) {
|
||||||
if actual[0].ShareLink != expectedShareLink {
|
tu := testUtil.TestUtil{T: t}
|
||||||
t.Errorf("ShareLink is incorrect: Expected %s, but got %s", expectedShareLink, actual[0].ShareLink)
|
jsonStr := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
|
||||||
}
|
actual := ParseUpload(jsonStr)
|
||||||
|
|
||||||
expectedURL := "some_url"
|
tu.AssertString(actual.URL, "some_url", "URL")
|
||||||
if actual[0].URL != expectedURL {
|
tu.AssertString(actual.Caption, "some_caption", "Caption")
|
||||||
t.Errorf("URL is incorrect: Expected %s, but got %s", expectedURL, actual[0].URL)
|
tu.AssertString(actual.ShareLink, "some_share_link", "ShareLink")
|
||||||
}
|
|
||||||
|
tu.AssertString(actual.Sound.Link, "some_link", "Sound.Link")
|
||||||
|
tu.AssertString(actual.Sound.Title, "some_title", "Sound.Title")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetUploadID(t *testing.T) {
|
func TestGetUploadID(t *testing.T) {
|
||||||
|
tu := testUtil.TestUtil{T: t}
|
||||||
var upload Upload
|
var upload Upload
|
||||||
upload.ShareLink = "http://pikami.org/some_thing/some_upload_id"
|
upload.ShareLink = "http://pikami.org/some_thing/some_upload_id"
|
||||||
expected := "some_upload_id"
|
|
||||||
|
|
||||||
actual := upload.GetUploadID()
|
actual := upload.GetUploadID()
|
||||||
|
|
||||||
if actual != expected {
|
tu.AssertString(actual, "some_upload_id", "Upload ID")
|
||||||
t.Errorf("UploadId is incorrect: Expected %s, but got %s", expected, actual)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriteToFile(t *testing.T) {
|
||||||
|
tu := testUtil.TestUtil{T: t}
|
||||||
|
expected := "{\"url\":\"some_url\",\"shareLink\":\"some_share_link\",\"caption\":\"some_caption\",\"sound\":{\"title\":\"some_title\",\"link\":\"some_link\"}}"
|
||||||
|
filePath := "test_file.txt"
|
||||||
|
upload := Upload{
|
||||||
|
URL: "some_url",
|
||||||
|
Caption: "some_caption",
|
||||||
|
ShareLink: "some_share_link",
|
||||||
|
Sound: Sound{
|
||||||
|
Link: "some_link",
|
||||||
|
Title: "some_title",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
upload.WriteToFile(filePath)
|
||||||
|
|
||||||
|
actual := utils.ReadFileToString(filePath)
|
||||||
|
tu.AssertString(actual, expected, "File content")
|
||||||
|
|
||||||
|
os.Remove(filePath)
|
||||||
}
|
}
|
||||||
|
|||||||
42
package-lock.json
generated
Normal file
42
package-lock.json
generated
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "tiktok-dl",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-from": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
|
||||||
|
},
|
||||||
|
"commander": {
|
||||||
|
"version": "2.20.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||||
|
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
|
||||||
|
},
|
||||||
|
"source-map": {
|
||||||
|
"version": "0.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||||
|
},
|
||||||
|
"source-map-support": {
|
||||||
|
"version": "0.5.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz",
|
||||||
|
"integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==",
|
||||||
|
"requires": {
|
||||||
|
"buffer-from": "^1.0.0",
|
||||||
|
"source-map": "^0.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"terser": {
|
||||||
|
"version": "4.6.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/terser/-/terser-4.6.3.tgz",
|
||||||
|
"integrity": "sha512-Lw+ieAXmY69d09IIc/yqeBqXpEQIpDGZqT34ui1QWXIUpR2RjbqEkT8X7Lgex19hslSqcWM5iMN2kM11eMsESQ==",
|
||||||
|
"requires": {
|
||||||
|
"commander": "^2.20.0",
|
||||||
|
"source-map": "~0.6.1",
|
||||||
|
"source-map-support": "~0.5.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "tiktok-dl",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"scripts": {
|
||||||
|
"install-dependencies": "go get -v -t -d ./...",
|
||||||
|
"test": "go test -v ./models",
|
||||||
|
"clean": "rm -rf out",
|
||||||
|
"build:scraper": "node node_modules/terser/bin/terser -c -m -- scraper.js > out/scraper.js",
|
||||||
|
"build:app": "go build -o out/ -v .",
|
||||||
|
"build:dist": "mkdir out && npm run build:app && npm run build:scraper",
|
||||||
|
"build": "go build -v ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"terser": "^4.6.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
51
scraper.js
51
scraper.js
@@ -1,14 +1,19 @@
|
|||||||
optStrings = {
|
optStrings = {
|
||||||
selectors: {
|
selectors: {
|
||||||
feedVideoItem: 'video-feed-item-wrapper',
|
feedLoading: 'div.tiktok-loading.feed-loading',
|
||||||
modalArrowLeft: 'div.video-card-modal > div > img.arrow-right',
|
modalArrowLeft: 'div.video-card-modal > div > img.arrow-right',
|
||||||
modalClose: '.video-card-modal > div > div.close',
|
modalClose: '.video-card-modal > div > div.close',
|
||||||
modalPlayer: 'div > div > main > div.video-card-modal > div > div.video-card-big > div.video-card-container > div > div > video',
|
modalPlayer: 'div > div > main > div.video-card-modal > div > div.video-card-big > div.video-card-container > div > div > video',
|
||||||
modalShareInput: '.copy-link-container > input',
|
modalShareInput: '.copy-link-container > input',
|
||||||
|
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',
|
||||||
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',
|
||||||
|
videoSoundLink: 'div.content-container.border > div.video-meta-info > h2.music-info > a',
|
||||||
},
|
},
|
||||||
classes: {
|
classes: {
|
||||||
|
feedVideoItem: 'video-feed-item-wrapper',
|
||||||
modalCloseDisabled: 'disabled',
|
modalCloseDisabled: 'disabled',
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
@@ -27,7 +32,7 @@ createVidUrlElement = function(outputObj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buldVidUrlArray = function(finishCallback) {
|
buldVidUrlArray = function(finishCallback) {
|
||||||
var feedItem = document.getElementsByClassName(optStrings.selectors.feedVideoItem)[0];
|
var feedItem = document.getElementsByClassName(optStrings.classes.feedVideoItem)[0];
|
||||||
feedItem.click();
|
feedItem.click();
|
||||||
|
|
||||||
var videoArray = [];
|
var videoArray = [];
|
||||||
@@ -42,17 +47,26 @@ buldVidUrlArray = function(finishCallback) {
|
|||||||
} else {
|
} else {
|
||||||
arrowRight.click();
|
arrowRight.click();
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 20);
|
||||||
};
|
};
|
||||||
|
|
||||||
getCurrentModalVideo = function() {
|
getCurrentModalVideo = function() {
|
||||||
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
||||||
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
||||||
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 soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
||||||
|
var soundHref = soundLink.getAttribute("href");
|
||||||
|
var soundText = soundLink.text;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
shareLink: shareLink
|
shareLink: shareLink,
|
||||||
|
caption: caption,
|
||||||
|
sound: {
|
||||||
|
title: soundText,
|
||||||
|
link: soundHref,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,10 +74,19 @@ getCurrentVideo = function() {
|
|||||||
var player = document.querySelector(optStrings.selectors.videoPlayer);
|
var player = document.querySelector(optStrings.selectors.videoPlayer);
|
||||||
var vidUrl = player.getAttribute(optStrings.attributes.src);
|
var vidUrl = player.getAttribute(optStrings.attributes.src);
|
||||||
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 soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
||||||
|
var soundHref = soundLink.getAttribute("href");
|
||||||
|
var soundText = soundLink.text;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
shareLink: shareLink
|
shareLink: shareLink,
|
||||||
|
caption: caption,
|
||||||
|
sound: {
|
||||||
|
title: soundText,
|
||||||
|
link: soundHref,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,24 +94,22 @@ scrollWhileNew = function(finishCallback) {
|
|||||||
var state = { count: 0 };
|
var state = { count: 0 };
|
||||||
var intervalID = window.setInterval(x => {
|
var intervalID = window.setInterval(x => {
|
||||||
var oldCount = state.count;
|
var oldCount = state.count;
|
||||||
state.count = document.getElementsByClassName(optStrings.selectors.feedVideoItem).length;
|
state.count = document.getElementsByClassName(optStrings.classes.feedVideoItem).length;
|
||||||
if (oldCount !== state.count) {
|
if (oldCount !== state.count) {
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
window.scrollTo(0, document.body.scrollHeight);
|
||||||
} else {
|
} else {
|
||||||
|
if (document.querySelector(optStrings.selectors.feedLoading)) {
|
||||||
|
window.scrollTo(0, document.body.scrollHeight);
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.clearInterval(intervalID);
|
window.clearInterval(intervalID);
|
||||||
finishCallback();
|
finishCallback(createVidUrlElement);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
bootstrapIteratingVideos = function() {
|
bootstrapIteratingVideos = function() {
|
||||||
var intervalID = window.setInterval(() => {
|
scrollWhileNew(buldVidUrlArray);
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
|
||||||
if (document.getElementsByClassName(optStrings.selectors.feedVideoItem).length > 0) {
|
|
||||||
window.setTimeout(() => buldVidUrlArray(createVidUrlElement), 100);
|
|
||||||
window.clearInterval(intervalID);
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
return 'bootstrapIteratingVideos';
|
return 'bootstrapIteratingVideos';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,7 +123,7 @@ init = () => {
|
|||||||
const newProto = navigator.__proto__;
|
const newProto = navigator.__proto__;
|
||||||
delete newProto.webdriver;
|
delete newProto.webdriver;
|
||||||
navigator.__proto__ = newProto;
|
navigator.__proto__ = newProto;
|
||||||
|
return 'script initialized';
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
'script initialized'
|
|
||||||
15
unitTestUtil/assert.go
Normal file
15
unitTestUtil/assert.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package unittestutil
|
||||||
|
|
||||||
|
// AssertString - Check if two strings match
|
||||||
|
func (tu *TestUtil) AssertString(actual string, expected string, name string) {
|
||||||
|
if actual != expected {
|
||||||
|
tu.T.Errorf("%s is incorrect: Expected '%s', but got '%s'", name, expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertInt - Check if two intagers match
|
||||||
|
func (tu *TestUtil) AssertInt(actual int, expected int, name string) {
|
||||||
|
if actual != expected {
|
||||||
|
tu.T.Errorf("%s is incorrect: Expected '%d', but got '%d'", name, expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
10
unitTestUtil/unitTestUtil.go
Normal file
10
unitTestUtil/unitTestUtil.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package unittestutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestUtil - Utility for testing
|
||||||
|
type TestUtil struct {
|
||||||
|
T *testing.T
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,3 +20,13 @@ func InitOutputDirectory(path string) {
|
|||||||
os.MkdirAll(path, os.ModePerm)
|
os.MkdirAll(path, os.ModePerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadFileToString - Reads file and returns content
|
||||||
|
func ReadFileToString(path string) string {
|
||||||
|
content, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(content)
|
||||||
|
}
|
||||||
|
|||||||
27
workflows/downloadUser.go
Normal file
27
workflows/downloadUser.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
client "../client"
|
||||||
|
models "../models"
|
||||||
|
utils "../utils"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanUseDownloadUser - Test's if this workflow can be used for parameter
|
||||||
|
func CanUseDownloadUser(url string) bool {
|
||||||
|
match := strings.Contains(url, "/")
|
||||||
|
return !match
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadUser - Download all user's videos
|
||||||
|
func DownloadUser(username string) {
|
||||||
|
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||||
|
uploads := client.GetUserUploads(username)
|
||||||
|
|
||||||
|
utils.InitOutputDirectory(downloadDir)
|
||||||
|
|
||||||
|
for _, upload := range uploads {
|
||||||
|
downloadVideo(upload, downloadDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
44
workflows/downloadVideo.go
Normal file
44
workflows/downloadVideo.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
client "../client"
|
||||||
|
models "../models"
|
||||||
|
utils "../utils"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanUseDownloadSingleVideo - Check's if DownloadSingleVideo can be used for parameter
|
||||||
|
func CanUseDownloadSingleVideo(url string) bool {
|
||||||
|
match, _ := regexp.MatchString("\\/@.+\\/video\\/[0-9]+", url)
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadSingleVideo - Downloads single video
|
||||||
|
func DownloadSingleVideo(url string) {
|
||||||
|
username := models.GetUsername()
|
||||||
|
upload := client.GetVideoDetails(url)
|
||||||
|
downloadDir := fmt.Sprintf("%s/%s", models.Config.OutputPath, username)
|
||||||
|
|
||||||
|
utils.InitOutputDirectory(downloadDir)
|
||||||
|
downloadVideo(upload, downloadDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadVideo - Downloads one video
|
||||||
|
func downloadVideo(upload models.Upload, downloadDir string) {
|
||||||
|
uploadID := upload.GetUploadID()
|
||||||
|
downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID)
|
||||||
|
|
||||||
|
if utils.CheckIfExists(downloadPath) {
|
||||||
|
fmt.Println("Upload '" + uploadID + "' already downloaded, skipping")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Downloading upload item '" + uploadID + "' to " + downloadPath)
|
||||||
|
utils.DownloadFile(downloadPath, upload.URL)
|
||||||
|
|
||||||
|
if models.Config.MetaData {
|
||||||
|
metadataPath := fmt.Sprintf("%s/%s.json", downloadDir, uploadID)
|
||||||
|
upload.WriteToFile(metadataPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user