Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Plaatjes
ae4c436a1a Updated video download code
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-02-14 00:35:28 -05:00
Chris Plaatjes
724e48da04 Added pipeline type 2023-02-14 00:34:54 -05:00
3 changed files with 54 additions and 3 deletions

View File

@ -1,5 +1,6 @@
---
kind: pipeline
type: docker
name: build-app
steps:

View File

@ -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}.");

View File

@ -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;
}
}
}