Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Compare Binary
- Option Explicit On
- Option Strict On
- Imports Microsoft.VisualBasic
- Imports System
- Imports System.ComponentModel
- Imports System.Diagnostics
- Imports System.Globalization
- Imports System.Text
- Imports System.Threading
- Imports System.Windows.Forms
- Public Class MainForm
- Inherits System.Windows.Forms.Form
- Private m_Process As Process
- Private m_OutputThread As Thread
- Private m_ErrorThread As Thread
- Friend WithEvents PasteButton As System.Windows.Forms.Button
- Friend WithEvents ClearButton As System.Windows.Forms.Button
- Friend WithEvents AudioOnly As System.Windows.Forms.CheckBox
- Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
- Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents ExitToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents HelpToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents AboutToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents Form1 As System.Windows.Forms.Form
- Friend WithEvents txtConsole As System.Windows.Forms.TextBox
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Private m_TextToAdd As String
- Private m_YoutubeClearCacheInput As String
- Private m_YoutubeInput As String
- Private m_AudioOnly As String
- Private m_ClearCache As String
- Private m_BestVideo As String
- Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
- Friend WithEvents HD1 As System.Windows.Forms.CheckBox
- Friend WithEvents HD2 As System.Windows.Forms.CheckBox
- Friend WithEvents SettingsToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents ViewLogToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Friend WithEvents ToolStripSeparator1 As System.Windows.Forms.ToolStripSeparator
- Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
- Friend WithEvents ClearCacheToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
- Private Sub StreamInput(ByVal Text As String)
- m_Process.StandardInput.WriteLine(Text)
- m_Process.StandardInput.Flush()
- End Sub
- Private Function ConvertFromOem(ByVal Text As String) As String
- Return _
- Encoding.GetEncoding( _
- CultureInfo.InstalledUICulture.TextInfo.OEMCodePage _
- ).GetString(Encoding.Default.GetBytes(Text))
- End Function
- Private Sub StreamOutput()
- Dim Line As String = m_Process.StandardOutput.ReadLine()
- Try
- Do While Line.Length >= 0
- If Line.Length > 0 Then
- AddText(ConvertFromOem(Line))
- End If
- Line = m_Process.StandardOutput.ReadLine()
- Loop
- Catch
- End Try
- End Sub
- Private Sub StreamError()
- Dim Line As String = m_Process.StandardError.ReadLine()
- End Sub
- Private Sub AddText(ByVal Text As String)
- m_TextToAdd = Text
- m_YoutubeInput = "Youtube-dl "
- m_YoutubeClearCacheInput = "Youtube-dl"
- m_AudioOnly = " --extract-audio --audio-format mp3 --audio-quality 320k"
- m_BestVideo = " -f bestvideo+bestaudio -o %(title)s.%(ext)s"
- m_ClearCache = " --rm-cache-dir"
- Me.Invoke(CType(AddressOf Me.AddTextToTextBox, MethodInvoker))
- End Sub
- Public Sub AddTextToTextBox()
- LogForm.txtConsole.AppendText(m_TextToAdd & ControlChars.NewLine)
- LogForm.txtConsole.SelectionStart = LogForm.txtConsole.Text.Length
- End Sub
- Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
- m_Process = New Process
- With m_Process.StartInfo
- .FileName = "cmd"
- .UseShellExecute = False
- .CreateNoWindow = True
- .RedirectStandardOutput = True
- .RedirectStandardError = True
- .RedirectStandardInput = True
- End With
- m_Process.Start()
- m_OutputThread = New Thread(AddressOf StreamOutput)
- m_OutputThread.IsBackground = True
- m_OutputThread.Start()
- End Sub
- Private Sub ProcessButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ProcessButton.Click
- If AudioOnly.Checked Then
- StreamInput(m_YoutubeInput & Me.txtCommandInput.Text & m_AudioOnly)
- ElseIf HD1.Checked Then
- StreamInput(m_YoutubeInput & Me.txtCommandInput.Text & m_BestVideo)
- ElseIf HD2.Checked Then
- StreamInput(m_YoutubeInput & Me.txtCommandInput.Text)
- ElseIf HD1.Checked = False And HD2.Checked = False And AudioOnly.Checked = False Then
- MsgBox("You need to choose an option before downloading", MsgBoxStyle.Critical, "Oh No!")
- End If
- End Sub
- Private Sub MainForm_Closing(ByVal sender As Object, ByVal e As CancelEventArgs) Handles MyBase.Closing
- If Not m_Process.HasExited Then
- m_Process.Kill()
- End If
- m_Process.Close()
- End Sub
- Private Sub txtConsole_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
- If (txtConsole.Text.Contains("[download] 100.0%")) Then
- ProgressBar1.Increment(100)
- End If
- End Sub
- Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
- txtCommandInput.Clear()
- HD1.Checked = False
- HD2.Checked = False
- AudioOnly.Checked = False
- End Sub
- Private Sub PasteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteButton.Click
- txtCommandInput.Paste()
- End Sub
- Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
- AboutBox1.Show()
- End Sub
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- Application.Exit()
- End Sub
- Private Sub ClearCacheToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearCacheToolStripMenuItem.Click
- StreamInput(m_YoutubeClearCacheInput & m_ClearCache)
- ClearCacheToolStripMenuItem.Enabled = False
- End Sub
- Private Sub txtCommandInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCommandInput.TextChanged
- If (txtCommandInput.Text.StartsWith("http")) Then
- ProcessButton.Enabled = True
- Else : ProcessButton.Enabled = False
- End If
- End Sub
- Private Sub AudioOnly_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioOnly.CheckedChanged
- If AudioOnly.Checked = True Then HD1.Enabled = False
- If AudioOnly.Checked = True Then HD2.Enabled = False
- If AudioOnly.Checked = False Then HD1.Enabled = True
- If AudioOnly.Checked = False Then HD2.Enabled = True
- End Sub
- Private Sub HD2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HD2.CheckedChanged
- If HD2.Checked = True Then HD1.Enabled = False
- If HD2.Checked = True Then AudioOnly.Enabled = False
- If HD2.Checked = False Then HD1.Enabled = True
- If HD2.Checked = False Then AudioOnly.Enabled = True
- End Sub
- Private Sub HD1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HD1.CheckedChanged
- If HD1.Checked = True Then HD2.Enabled = False
- If HD1.Checked = True Then AudioOnly.Enabled = False
- If HD1.Checked = False Then HD2.Enabled = True
- If HD1.Checked = False Then AudioOnly.Enabled = True
- End Sub
- Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
- End Sub
- Private Sub ViewLogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewLogToolStripMenuItem.Click
- LogForm.Show()
- End Sub
- Public Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
- End Sub
- End Class
Add Comment
Please, Sign In to add comment