-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathProgram.cs
62 lines (46 loc) · 1.74 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using VideoLibrary;
using System;
using System.IO;
namespace Valks
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Welcome to Valks!");
Console.WriteLine("Easily save your favorite videos from YouTube.");
using (var service = Client.For(YouTube.Default))
{
while (true)
{
Console.WriteLine();
Console.Write("Enter your video's ID: ");
string id = Console.ReadLine();
Console.WriteLine("Awesome! Downloading...");
var video = service.GetVideo("https://youtube.com/watch?v=" + id);
Console.Write("Finished! Would you like to save the video to Downloads? [y/n] ");
char opt = Console.ReadKey().KeyChar;
Console.WriteLine();
string folder;
if (char.ToUpper(opt) == 'Y')
folder = GetDefaultFolder();
else
{
Console.Write("Please tell us where you'd like to save it: ");
folder = Console.ReadLine();
}
string path = Path.Combine(folder, video.FullName);
Console.WriteLine("Saving...");
File.WriteAllBytes(path, video.GetBytes());
Console.WriteLine("Done.");
}
}
}
static string GetDefaultFolder()
{
var home = Environment.GetFolderPath(
Environment.SpecialFolder.UserProfile);
return Path.Combine(home, "Downloads");
}
}
}