Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 37 additions & 111 deletions src/Ytdlp.NET.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ private static async Task Main(string[] args)

// Run all demos/tests sequentially
//await TestGetVersionAsync(ytdlp);
//await TestUpdateVersionAsync(ytdlp);

//await TestGetFormatsAsync(ytdlp);
//await TestGetFormatsDetailedAsync(ytdlp);
await TestGetMetadataAsync(ytdlp);
//await TestGetMetadataAsync(ytdlp);
//await TestGetSimpleMetadataAsync(ytdlp);
//await TestDownloadVideoAsync(ytdlp);
//await TestDownloadAudioAsync(ytdlp);
// await TestBatchDownloadAsync(ytdlp);
// await TestSponsorBlockAsync(ytdlp);
// await TestConcurrentFragmentsAsync(ytdlp);
// await TestCancellationAsync(ytdlp);
//await TestGetTitleAsync(ytdlp);

await TestDownloadVideoAsync(ytdlp);
await TestDownloadAudioAsync(ytdlp);
await TestBatchDownloadAsync(ytdlp);
//await TestSponsorBlockAsync(ytdlp);
await TestConcurrentFragmentsAsync(ytdlp);
await TestCancellationAsync(ytdlp);


Console.WriteLine("\nAll tests completed. Press any key to exit...");
Console.ReadKey();
Expand Down Expand Up @@ -63,13 +66,20 @@ private static async Task TestGetVersionAsync(Ytdlp ytdlp)
Console.WriteLine($"Version: {version}");
}

private static async Task TestUpdateVersionAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 1: Getting yt-dlp version...");
var version = await ytdlp.UpdateAsync(UpdateChannel.Stable);
Console.WriteLine($"Version: {version}");
}

// Test 2: Get detailed formats
private static async Task TestGetFormatsAsync(Ytdlp ytdlp)
{
var stopwatch = Stopwatch.StartNew();

Console.WriteLine("\nTest 2: Fetching available formats...");
var url = "https://www.youtube.com/watch?v=Xt50Sodg7sA";
var url = "https://www.youtube.com/watch?v=ZGnQH0LN_98";
var formats = await ytdlp.GetAvailableFormatsAsync(url);

stopwatch.Stop(); // stop timer
Expand Down Expand Up @@ -98,7 +108,7 @@ private static async Task TestGetFormatsDetailedAsync(Ytdlp ytdlp)
var stopwatch = Stopwatch.StartNew();

Console.WriteLine("\nTest 3: Fetching detailed formats...");
var url = "https://www.youtube.com/watch?v=cbGywxIH4mI";
var url = "https://www.youtube.com/watch?v=ZGnQH0LN_98";
var formats = await ytdlp.GetAvailableFormatsAsync(url);

stopwatch.Stop(); // stop timer
Expand Down Expand Up @@ -128,9 +138,9 @@ private static async Task TestGetMetadataAsync(Ytdlp ytdlp)

Console.WriteLine("\nTest 4: Fetching detailed metedata...");

var url1 = "https://www.youtube.com/watch?v=YyepU5ztLf4&list=PLXCoHsJ9oLef1c83KIbl9_h7tYyodL15J"; //playlist
var url2 = "https://www.youtube.com/watch?v=JOIqPThxFb8"; // video
var url3 = "https://www.youtube.com/watch?v=lY5V4hSLWY8&list=RDlY5V4hSLWY8&start_radio=1&pp=ygUJcGxheWxpc3RzoAcB";
var url1 = "https://www.youtube.com/watch?v=983bBbJx0Mk&list=RD983bBbJx0Mk&start_radio=1&pp=ygUFc29uZ3OgBwE%3D"; //playlist
var url2 = "https://www.youtube.com/watch?v=ZGnQH0LN_98"; // video
var url3 = "https://www.youtube.com/watch?v=983bBbJx0Mk&list=RD983bBbJx0Mk&start_radio=1&pp=ygUFc29uZ3OgBwE%3D";
var metadata = await ytdlp.GetMetadataAsync(url3);
stopwatch.Stop(); // stop timer

Expand Down Expand Up @@ -163,7 +173,7 @@ private static async Task TestGetSimpleMetadataAsync(Ytdlp ytdlp)
var stopwatch = Stopwatch.StartNew();
Console.WriteLine("\nTest 5: Fetching simple metedata...");

var url = "https://www.youtube.com/watch?v=1K7OkfKAx24";
var url = "https://www.youtube.com/watch?v=ZGnQH0LN_98";

var fields = new[] { "id", "thumbnail" };
var data = await ytdlp.GetMetadataLiteAsync(url, fields);
Expand Down Expand Up @@ -193,7 +203,7 @@ private static async Task TestGetSimpleMetadataAsync(Ytdlp ytdlp)
private static async Task TestDownloadVideoAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 6: Downloading a video...");
var url = "https://www.youtube.com/watch?v=OOdEdZ5lYQc";
var url = "https://www.youtube.com/watch?v=ZGnQH0LN_98";

// Subscribe to events
ytdlp.OnProgressDownload += (sender, args) =>
Expand All @@ -216,7 +226,7 @@ await ytdlp
private static async Task TestDownloadAudioAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 7: Extracting audio...");
var url = "https://www.youtube.com/watch?v=Xt50Sodg7sA";
var url = "https://www.youtube.com/watch?v=ZGnQH0LN_98";

await ytdlp
.ExtractAudio("mp3")
Expand All @@ -231,9 +241,9 @@ private static async Task TestBatchDownloadAsync(Ytdlp ytdlp)
Console.WriteLine("\nTest 8: Batch download (3 concurrent)...");
var urls = new List<string>
{
"https://www.youtube.com/watch?v=oRpzM-I2p-I",
"https://www.youtube.com/watch?v=scRQR-FRfIo",
"https://www.youtube.com/watch?v=xeOttl1d2bo"
"https://www.youtube.com/watch?v=ZGnQH0LN_98",
"https://www.youtube.com/watch?v=983bBbJx0Mk",
"https://www.youtube.com/watch?v=oDSEGkT6J-0"
};

await ytdlp
Expand All @@ -246,7 +256,7 @@ await ytdlp
private static async Task TestSponsorBlockAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 9: Download with SponsorBlock removal...");
var url = "https://www.youtube.com/watch?v=JOIqPThxFb8";
var url = "https://www.youtube.com/watch?v=oDSEGkT6J-0";

await ytdlp
.SetFormat("best")
Expand All @@ -259,7 +269,7 @@ await ytdlp
private static async Task TestConcurrentFragmentsAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 10: Download with concurrent fragments...");
var url = "https://www.youtube.com/watch?v=BxX31pR0EcU";
var url = "https://www.youtube.com/watch?v=oDSEGkT6J-0";

await ytdlp
.WithConcurrentFragments(8) // 8 parallel fragments
Expand All @@ -273,7 +283,7 @@ await ytdlp
private static async Task TestCancellationAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 11: Testing cancellation (will cancel after 10 seconds)...");
var url = "https://www.youtube.com/watch?v=JOIqPThxFb8"; // A longer video
var url = "https://www.youtube.com/watch?v=zGlwuHqGVIA"; // A longer video

var cts = new CancellationTokenSource();
var downloadTask = ytdlp
Expand All @@ -300,15 +310,16 @@ private static async Task TestCancellationAsync(Ytdlp ytdlp)
private static async Task TestGetTitleAsync(Ytdlp ytdlp)
{
Console.WriteLine("\nTest 12: Get Title Test");
var url = "https://www.youtube.com/watch?v=cbGywxIH4mI";
var url = "https://www.youtube.com/watch?v=zGlwuHqGVIA";

try
{
var downloadTask = ytdlp
.AddCustomCommand("-e")
.AddCustomCommand("--no-simulate --no-warning")
var downloadTask = ytdlp
.Simulate()
.NoWarning()
.SetOutputTemplate("%(title)s.%(ext)s")
.SetOutputFolder("./downloads/cancel")
.AddCustomCommand("--get-title")
.ExecuteAsync(url);

await downloadTask;
Expand Down Expand Up @@ -389,89 +400,4 @@ public static void Complete(string message = "Done!")
}
}

}

public class Rootobject
{
public string id { get; set; }
public string title { get; set; }
public object availability { get; set; }
public object channel_follower_count { get; set; }
public string description { get; set; }
public object[] tags { get; set; }
public Thumbnail[] thumbnails { get; set; }
public string modified_date { get; set; }
public int view_count { get; set; }
public int playlist_count { get; set; }
public string channel { get; set; }
public string channel_id { get; set; }
public string uploader_id { get; set; }
public string uploader { get; set; }
public string channel_url { get; set; }
public string uploader_url { get; set; }
public string _type { get; set; }
public Entry[] entries { get; set; }
public string extractor_key { get; set; }
public string extractor { get; set; }
public string webpage_url { get; set; }
public string original_url { get; set; }
public string webpage_url_basename { get; set; }
public string webpage_url_domain { get; set; }
public object release_year { get; set; }
public int epoch { get; set; }
public __Files_To_Move __files_to_move { get; set; }
public _Version _version { get; set; }
}

public class __Files_To_Move
{
}

public class _Version
{
public string version { get; set; }
public object current_git_head { get; set; }
public string release_git_head { get; set; }
public string repository { get; set; }
}

public class Thumbnail
{
public string url { get; set; }
public int height { get; set; }
public int width { get; set; }
public string id { get; set; }
public string resolution { get; set; }
}

public class Entry
{
public string _type { get; set; }
public string ie_key { get; set; }
public string id { get; set; }
public string url { get; set; }
public string title { get; set; }
public object description { get; set; }
public int duration { get; set; }
public string channel_id { get; set; }
public string channel { get; set; }
public string channel_url { get; set; }
public string uploader { get; set; }
public string uploader_id { get; set; }
public string uploader_url { get; set; }
public Thumbnail1[] thumbnails { get; set; }
public object timestamp { get; set; }
public object release_timestamp { get; set; }
public object availability { get; set; }
public int view_count { get; set; }
public object live_status { get; set; }
public object channel_is_verified { get; set; }
public object __x_forwarded_for_ip { get; set; }
}

public class Thumbnail1
{
public string url { get; set; }
public int height { get; set; }
public int width { get; set; }
}
}
Loading