From 46fcc459315bfa5b42cccd5ee3b4a9addb25ca3a Mon Sep 17 00:00:00 2001 From: Chris Plaatjes Date: Tue, 14 Feb 2023 12:04:24 -0500 Subject: [PATCH] Changed to use Proxitok --- Program.cs | 25 ++++++++++++------------- VidDownload.cs | 24 ++++++++---------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Program.cs b/Program.cs index b41e853..6090410 100644 --- a/Program.cs +++ b/Program.cs @@ -10,17 +10,18 @@ using Telegram.Bot.Types.Enums; namespace TeleTok { - class TeleTok + public class TeleTok { + public static IConfigurationRoot config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("config.json", true) + .Build(); + + public static string token = config.GetSection("TeleTokConf:token").Value; + public static string ptInstance = config.GetSection("TeleTokConf:proxitokInstance").Value; + static async Task Main(string[] args) { - var config = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("config.json", true) - .Build(); - - var token = config.GetSection("TeleTokConf:token").Value; - var botClient = new TelegramBotClient(token); using var cts = new CancellationTokenSource(); @@ -60,9 +61,8 @@ namespace TeleTok return; var chatId = message.Chat.Id; - var messageText = update.Message.Text; - string videoPath; + string proxyUrl; // Checks if the text contains a valid URL bool isUri = Uri.IsWellFormedUriString(messageText, UriKind.RelativeOrAbsolute); @@ -72,12 +72,11 @@ namespace TeleTok { if(messageText.Contains("tiktok.com")) { - videoPath = VidDownload.TikTokUrl(messageText); + proxyUrl = VidDownload.TikTokURL(messageText); Message ttVideo = await botClient.SendVideoAsync( chatId: chatId, - videoPath: videoPath, - supportsStreaming: true, + video: proxyUrl, cancellationToken: cancellationToken ); } diff --git a/VidDownload.cs b/VidDownload.cs index f5aa893..b5d5e22 100644 --- a/VidDownload.cs +++ b/VidDownload.cs @@ -1,37 +1,29 @@ using System; using System.Diagnostics; +using System.Net; namespace TeleTok { public class VidDownload { - static void TikTokURL(string videourl) + // Takes the scraped TikTok URL and appends it to the proxy downloader link then returns it + public string TikTokURL(string videourl) { string url = videourl; + string proxyUrl; 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(); + proxyUrl = TeleTok.ptInstance + "/download?url=" + url; + return proxyUrl; } + // Runs the URL through a web request then returns the full url + // If the URL is already the full one, it won't really do anything but will catch shortened ones static string UnshortenUrl(string videourl) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);