Updated video download code
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
724e48da04
commit
ae4c436a1a
19
Program.cs
19
Program.cs
@ -60,12 +60,27 @@ namespace TeleTok
|
||||
return;
|
||||
|
||||
var chatId = message.Chat.Id;
|
||||
var messageText = update.Message.Text;
|
||||
|
||||
bool isUri = Uri.IsWellFormedUriString(message.ToString(), UriKind.RelativeOrAbsolute);
|
||||
string videoPath;
|
||||
|
||||
// Checks if the text contains a valid URL
|
||||
bool isUri = Uri.IsWellFormedUriString(messageText, UriKind.RelativeOrAbsolute);
|
||||
|
||||
// Passes the url along to the video downloader if it is valid AND a tiktok link
|
||||
if (isUri)
|
||||
{
|
||||
Regex isTikTok = new Regex(@"(?x)(http(s)?:\/\/)?(?:www|m)\.(?:tiktok.com)\/(?:v|embed|trending)(?:\/)?(?:\?shareId=)?(?P<id>[\da-z]+)", RegexOptions.Singleline);
|
||||
if(messageText.Contains("tiktok.com"))
|
||||
{
|
||||
videoPath = VidDownload.TikTokUrl(messageText);
|
||||
|
||||
Message ttVideo = await botClient.SendVideoAsync(
|
||||
chatId: chatId,
|
||||
videoPath: videoPath,
|
||||
supportsStreaming: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Received a '{messageText}' message in chat {chatId}.");
|
||||
|
@ -5,6 +5,41 @@ namespace TeleTok
|
||||
{
|
||||
public class VidDownload
|
||||
{
|
||||
static void TikTokURL(string videourl)
|
||||
{
|
||||
string url = videourl;
|
||||
|
||||
if(url.Contains("vm.tiktok.com"))
|
||||
{
|
||||
url = UnshortenUrl(url);
|
||||
}
|
||||
|
||||
var proc = new Process
|
||||
{
|
||||
// Function downloads tiktok urls passed from the listener
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/bin/bash",
|
||||
Arguments = "-c \"tiktok-scraper --filepath /app/videos -d " + videourl + "\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
|
||||
}
|
||||
|
||||
static string UnshortenUrl(string videourl)
|
||||
{
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);
|
||||
req.AllowAutoRedirect = false;
|
||||
var resp = req.GetResponse();
|
||||
string realUrl = resp.Headers["Location"];
|
||||
|
||||
return realUrl;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user