mirror of
https://github.com/pikami/tiktok-dl.git
synced 2025-06-05 06:20:04 +01:00
Added support for vm.tiktok.com
urls
This commit is contained in:
parent
af7972685e
commit
feee0a9154
52
client/getRedirectUrl.go
Normal file
52
client/getRedirectUrl.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/chromedp/chromedp"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
config "../models/config"
|
||||||
|
log "../utils/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRedirectUrl(url string) (string, error) {
|
||||||
|
dir, err := ioutil.TempDir("", "chromedp-example")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||||
|
chromedp.DisableGPU,
|
||||||
|
chromedp.UserDataDir(dir),
|
||||||
|
chromedp.Flag("headless", !config.Config.Debug),
|
||||||
|
)
|
||||||
|
|
||||||
|
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ctx, cancel := chromedp.NewContext(
|
||||||
|
allocCtx,
|
||||||
|
chromedp.WithLogf(log.Logf),
|
||||||
|
)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, time.Duration(config.Config.Deadline)*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
var jsOutput string
|
||||||
|
if err := chromedp.Run(ctx,
|
||||||
|
// Navigate to user's page
|
||||||
|
chromedp.Navigate(url),
|
||||||
|
// Wait until page loads
|
||||||
|
chromedp.WaitReady(`div`),
|
||||||
|
// Grab url links from our element
|
||||||
|
chromedp.EvaluateAsDevTools(`window.location.href`, &jsOutput),
|
||||||
|
); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsOutput, err
|
||||||
|
}
|
27
workflows/downloadShareLink.go
Normal file
27
workflows/downloadShareLink.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package workflows
|
||||||
|
|
||||||
|
import (
|
||||||
|
client "../client"
|
||||||
|
res "../resources"
|
||||||
|
log "../utils/log"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CanUseDownloadShareLink - Check's if DownloadShareLink can be used
|
||||||
|
func CanUseDownloadShareLink(url string) bool {
|
||||||
|
match, _ := regexp.MatchString("vm.tiktok.com\\/.+", url)
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
|
||||||
|
// DownloadShareLink - Download item by share link
|
||||||
|
func DownloadShareLink(url string) {
|
||||||
|
log.Logf("Resolving share link: %s\n", url)
|
||||||
|
|
||||||
|
finalURL, err := client.GetRedirectUrl(url)
|
||||||
|
if err != nil {
|
||||||
|
log.LogErr(res.ErrorCouldNotGetUserUploads, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
StartWorkflowByParameter(finalURL)
|
||||||
|
}
|
@ -47,5 +47,11 @@ func StartWorkflowByParameter(url string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Share URL
|
||||||
|
if CanUseDownloadShareLink(url) {
|
||||||
|
DownloadShareLink(url)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log.LogFatal(res.ErrorCouldNotRecogniseURL, url)
|
log.LogFatal(res.ErrorCouldNotRecogniseURL, url)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user