mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-08 03:55:30 +00:00
Improved parameter parsing
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Config - Runtime configuration
|
||||
@@ -32,3 +34,17 @@ func GetConfig() {
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user