mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-06 02:56:57 +00:00
Initial commit
This commit is contained in:
28
models/config.go
Normal file
28
models/config.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config - Runtime configuration
|
||||
var Config struct {
|
||||
UserName string
|
||||
OutputPath string
|
||||
}
|
||||
|
||||
// GetConfig - Returns Config object
|
||||
func GetConfig() {
|
||||
outputPath := flag.String("output", "./downloads", "Output path")
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
fmt.Println("Usage: tiktok-dl [OPTIONS] TIKTOK_USERNAME")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
Config.UserName = flag.Args()[len(args)-1]
|
||||
Config.OutputPath = *outputPath
|
||||
}
|
||||
25
models/upload.go
Normal file
25
models/upload.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Upload - Upload object
|
||||
type Upload struct {
|
||||
ShareLink string `json:"shareLink"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// ParseUploads - Parses json uploads array
|
||||
func ParseUploads(str string) []Upload {
|
||||
var uploads []Upload
|
||||
json.Unmarshal([]byte(str), &uploads)
|
||||
return uploads
|
||||
}
|
||||
|
||||
// GetUploadID - Returns upload id
|
||||
func (u Upload) GetUploadID() string {
|
||||
parts := strings.Split(u.ShareLink, "/")
|
||||
return parts[len(parts)-1]
|
||||
}
|
||||
36
models/upload_test.go
Normal file
36
models/upload_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestParseUploads - Test parsing
|
||||
func TestParseUploads(t *testing.T) {
|
||||
jsonStr := "[{\"shareLink\":\"some_share_link\", \"url\": \"some_url\"}]"
|
||||
actual := ParseUploads(jsonStr)
|
||||
|
||||
expectedLen := 1
|
||||
if len(actual) != expectedLen {
|
||||
t.Errorf("Array len incorrect: Expected %d, but got %d", expectedLen, len(actual))
|
||||
}
|
||||
|
||||
expectedShareLink := "some_share_link"
|
||||
if actual[0].ShareLink != expectedShareLink {
|
||||
t.Errorf("ShareLink is incorrect: Expected %s, but got %s", expectedShareLink, actual[0].ShareLink)
|
||||
}
|
||||
|
||||
expectedURL := "some_url"
|
||||
if actual[0].URL != expectedURL {
|
||||
t.Errorf("URL is incorrect: Expected %s, but got %s", expectedURL, actual[0].URL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUploadID(t *testing.T) {
|
||||
var upload Upload
|
||||
upload.ShareLink = "http://pikami.org/some_thing/some_upload_id"
|
||||
expected := "some_upload_id"
|
||||
|
||||
actual := upload.GetUploadID()
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("UploadId is incorrect: Expected %s, but got %s", expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user