TeleTok/VidDownload.cs

60 lines
2.0 KiB
C#
Raw Normal View History

2023-02-13 19:18:49 -05:00
using System;
using System.Diagnostics;
2023-02-14 12:04:24 -05:00
using System.Net;
2023-02-13 19:18:49 -05:00
namespace TeleTok
{
public class VidDownload
{
2023-02-14 12:04:24 -05:00
// Takes the scraped TikTok URL and appends it to the proxy downloader link then returns it
2023-02-14 13:59:20 -05:00
public static string TikTokURL(string videourl)
2023-02-14 00:35:28 -05:00
{
string url = videourl;
2023-02-14 12:04:24 -05:00
string proxyUrl;
2023-02-14 00:35:28 -05:00
2023-02-15 12:19:40 -05:00
TeleTok.LogMessage("Video for " + videourl + " processing..");
2023-02-15 10:05:14 -05:00
2023-02-14 00:35:28 -05:00
if(url.Contains("vm.tiktok.com"))
{
url = UnshortenUrl(url);
}
2023-02-15 12:19:40 -05:00
proxyUrl = CreateDownloadLink(url);
2023-02-14 00:35:28 -05:00
2023-02-15 12:25:05 -05:00
TeleTok.LogMessage("Sending video link for " + proxyUrl);
2023-02-14 12:04:24 -05:00
return proxyUrl;
2023-02-14 00:35:28 -05:00
}
2023-02-14 12:04:24 -05:00
// Runs the URL through a web request then returns the full url
2023-02-14 00:35:28 -05:00
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;
}
2023-02-15 12:19:40 -05:00
//Breaks apart the URL and extracts the User and Video ID to be processed into a working download link
static string CreateDownloadLink(string videourl)
{
Uri segmentedUri = new Uri(videourl);
segmentedUri = new Uri(segmentedUri.AbsoluteUri.Replace(segmentedUri.Query, string.Empty));
string videoUser = segmentedUri.Segments[1];
videoUser = videoUser.Replace(@"/", "");
string videoID = segmentedUri.Segments[3];
string fixedUrl = "https://www.tiktok.com/" + videoUser + "/video/" + videoID + @"&id=" + videoID + @"&user=" + videoUser.Remove(0, 1);
2023-02-15 12:19:40 -05:00
string proxyLink = TeleTok.ptInstance + "/download?url=" + fixedUrl;
TeleTok.LogMessage("Input User ID is: " + videoUser);
TeleTok.LogMessage("Input video ID is: " + videoID);
return proxyLink;
}
2023-02-13 19:18:49 -05:00
}
}