TeleTok/VidDownload.cs
2023-02-14 12:29:11 -05:00

38 lines
1.1 KiB
C#

using System;
using System.Diagnostics;
using System.Net;
namespace TeleTok
{
public class VidDownload
{
// 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);
}
proxyUrl = TeleTok.ptInstance + "/download?url=" + url;
Console.WriteLine("Video for " + url + " has been sent..");
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);
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
return realUrl;
}
}
}