-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYoutubeBrowser.cs
62 lines (55 loc) · 2.09 KB
/
YoutubeBrowser.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 System;
using CefSharp;
namespace Spotifly
{
public partial class Form1
{
private readonly string initialBrowserUrl = "https://www.youtube.com/";
private string currentLink;
private void WebBrowser_AddressChanged(object sender, AddressChangedEventArgs e)
{
try
{
if (e.Address.Contains(initialBrowserUrl) && e.Address != initialBrowserUrl && e.Address.Contains("/watch"))//address is a video
{
GetVideo(e.Address);
System.Threading.Thread.Sleep(2000);
Invoke(new Action(() => SetDownloadGroupBox(true)));
}
else
{
Invoke(new Action(() => SetDownloadGroupBox(false)));
}
BrowserBackBttn.Visible = !IsBrowserOnHomePage();
DownloadGroupBox.Visible = IsBrowserOnVideo();
}
catch (Exception)
{ }
void SetDownloadGroupBox(bool value)
{
if (value && !downloading)
{
StaticWebDwnldSttsLabel.Text = (string)table["status"];
WebDownloadStatusLabel.Text = (string)table["prepared"];
}
DownloadGroupBox.Enabled = value;
DownloadGroupBox.BringToFront();
}
}
private void WebVideoDwnldBtnn_Click(object sender, EventArgs e)
{
DownloadVideo(WebBrowser.Address);
}
private void WebAudioDwnldBttn_Click(object sender, EventArgs e)
{
DownloadVideo(WebBrowser.Address, true);
}
private void BrowserBackBttn_Click(object sender, EventArgs e)
{
if (WebBrowser.CanGoBack)
WebBrowser.Back();
}
private bool IsBrowserOnVideo() => WebBrowser.Address.Contains("/watch");
private bool IsBrowserOnHomePage() => WebBrowser.Address == initialBrowserUrl;
}
}