Changed to use Proxitok
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Chris Plaatjes 2023-02-14 12:04:24 -05:00
parent a6c7f1ef2a
commit 46fcc45931
2 changed files with 20 additions and 29 deletions

View File

@ -10,17 +10,18 @@ using Telegram.Bot.Types.Enums;
namespace TeleTok namespace TeleTok
{ {
class TeleTok public class TeleTok
{ {
static async Task Main(string[] args) public static IConfigurationRoot config = new ConfigurationBuilder()
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) .SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json", true) .AddJsonFile("config.json", true)
.Build(); .Build();
var token = config.GetSection("TeleTokConf:token").Value; 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 botClient = new TelegramBotClient(token); var botClient = new TelegramBotClient(token);
using var cts = new CancellationTokenSource(); using var cts = new CancellationTokenSource();
@ -60,9 +61,8 @@ namespace TeleTok
return; return;
var chatId = message.Chat.Id; var chatId = message.Chat.Id;
var messageText = update.Message.Text;
string videoPath; string proxyUrl;
// Checks if the text contains a valid URL // Checks if the text contains a valid URL
bool isUri = Uri.IsWellFormedUriString(messageText, UriKind.RelativeOrAbsolute); bool isUri = Uri.IsWellFormedUriString(messageText, UriKind.RelativeOrAbsolute);
@ -72,12 +72,11 @@ namespace TeleTok
{ {
if(messageText.Contains("tiktok.com")) if(messageText.Contains("tiktok.com"))
{ {
videoPath = VidDownload.TikTokUrl(messageText); proxyUrl = VidDownload.TikTokURL(messageText);
Message ttVideo = await botClient.SendVideoAsync( Message ttVideo = await botClient.SendVideoAsync(
chatId: chatId, chatId: chatId,
videoPath: videoPath, video: proxyUrl,
supportsStreaming: true,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
} }

View File

@ -1,37 +1,29 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Net;
namespace TeleTok namespace TeleTok
{ {
public class VidDownload 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 url = videourl;
string proxyUrl;
if(url.Contains("vm.tiktok.com")) if(url.Contains("vm.tiktok.com"))
{ {
url = UnshortenUrl(url); url = UnshortenUrl(url);
} }
var proc = new Process proxyUrl = TeleTok.ptInstance + "/download?url=" + url;
{
// 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();
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) static string UnshortenUrl(string videourl)
{ {
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(videourl);