Guest User

Untitled

a guest
Oct 17th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.29 KB | None | 0 0
  1. Option Compare Binary
  2. Option Explicit On
  3. Option Strict On
  4.  
  5. Imports Microsoft.VisualBasic
  6. Imports System
  7. Imports System.ComponentModel
  8. Imports System.Diagnostics
  9. Imports System.Globalization
  10. Imports System.Text
  11. Imports System.Threading
  12. Imports System.Windows.Forms
  13.  
  14.  
  15. Public Class MainForm
  16.     Inherits System.Windows.Forms.Form
  17.  
  18.  
  19.     Private m_Process As Process
  20.     Private m_OutputThread As Thread
  21.     Private m_ErrorThread As Thread
  22.     Friend WithEvents PasteButton As System.Windows.Forms.Button
  23.     Friend WithEvents ClearButton As System.Windows.Forms.Button
  24.     Friend WithEvents AudioOnly As System.Windows.Forms.CheckBox
  25.     Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
  26.     Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  27.     Friend WithEvents ExitToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  28.     Friend WithEvents HelpToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  29.     Friend WithEvents AboutToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  30.     Friend WithEvents Form1 As System.Windows.Forms.Form
  31.     Friend WithEvents txtConsole As System.Windows.Forms.TextBox
  32.     Friend WithEvents Label1 As System.Windows.Forms.Label
  33.     Private m_TextToAdd As String
  34.     Private m_YoutubeClearCacheInput As String
  35.     Private m_YoutubeInput As String
  36.     Private m_AudioOnly As String
  37.     Private m_ClearCache As String
  38.     Private m_BestVideo As String
  39.     Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
  40.     Friend WithEvents HD1 As System.Windows.Forms.CheckBox
  41.     Friend WithEvents HD2 As System.Windows.Forms.CheckBox
  42.     Friend WithEvents SettingsToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  43.     Friend WithEvents ViewLogToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  44.     Friend WithEvents ToolStripSeparator1 As System.Windows.Forms.ToolStripSeparator
  45.     Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
  46.     Friend WithEvents ClearCacheToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
  47.  
  48.  
  49.     Private Sub StreamInput(ByVal Text As String)
  50.         m_Process.StandardInput.WriteLine(Text)
  51.         m_Process.StandardInput.Flush()
  52.     End Sub
  53.  
  54.  
  55.     Private Function ConvertFromOem(ByVal Text As String) As String
  56.         Return _
  57.             Encoding.GetEncoding( _
  58.                 CultureInfo.InstalledUICulture.TextInfo.OEMCodePage _
  59.             ).GetString(Encoding.Default.GetBytes(Text))
  60.     End Function
  61.  
  62.     Private Sub StreamOutput()
  63.         Dim Line As String = m_Process.StandardOutput.ReadLine()
  64.         Try
  65.             Do While Line.Length >= 0
  66.                 If Line.Length > 0 Then
  67.                     AddText(ConvertFromOem(Line))
  68.                 End If
  69.                 Line = m_Process.StandardOutput.ReadLine()
  70.             Loop
  71.         Catch
  72.         End Try
  73.     End Sub
  74.  
  75.  
  76.     Private Sub StreamError()
  77.         Dim Line As String = m_Process.StandardError.ReadLine()
  78.     End Sub
  79.  
  80.  
  81.     Private Sub AddText(ByVal Text As String)
  82.         m_TextToAdd = Text
  83.         m_YoutubeInput = "Youtube-dl "
  84.         m_YoutubeClearCacheInput = "Youtube-dl"
  85.         m_AudioOnly = " --extract-audio --audio-format mp3 --audio-quality 320k"
  86.         m_BestVideo = " -f bestvideo+bestaudio -o %(title)s.%(ext)s"
  87.         m_ClearCache = " --rm-cache-dir"
  88.         Me.Invoke(CType(AddressOf Me.AddTextToTextBox, MethodInvoker))
  89.     End Sub
  90.  
  91.     Public Sub AddTextToTextBox()
  92.         LogForm.txtConsole.AppendText(m_TextToAdd & ControlChars.NewLine)
  93.         LogForm.txtConsole.SelectionStart = LogForm.txtConsole.Text.Length
  94.     End Sub
  95.  
  96.     Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  97.         m_Process = New Process
  98.         With m_Process.StartInfo
  99.             .FileName = "cmd"
  100.             .UseShellExecute = False
  101.             .CreateNoWindow = True
  102.             .RedirectStandardOutput = True
  103.             .RedirectStandardError = True
  104.             .RedirectStandardInput = True
  105.         End With
  106.         m_Process.Start()
  107.         m_OutputThread = New Thread(AddressOf StreamOutput)
  108.         m_OutputThread.IsBackground = True
  109.         m_OutputThread.Start()
  110.     End Sub
  111.  
  112.     Private Sub ProcessButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ProcessButton.Click
  113.         If AudioOnly.Checked Then
  114.             StreamInput(m_YoutubeInput & Me.txtCommandInput.Text & m_AudioOnly)
  115.         ElseIf HD1.Checked Then
  116.             StreamInput(m_YoutubeInput & Me.txtCommandInput.Text & m_BestVideo)
  117.         ElseIf HD2.Checked Then
  118.             StreamInput(m_YoutubeInput & Me.txtCommandInput.Text)
  119.         ElseIf HD1.Checked = False And HD2.Checked = False And AudioOnly.Checked = False Then
  120.             MsgBox("You need to choose an option before downloading", MsgBoxStyle.Critical, "Oh No!")
  121.         End If
  122.  
  123.     End Sub
  124.  
  125.     Private Sub MainForm_Closing(ByVal sender As Object, ByVal e As CancelEventArgs) Handles MyBase.Closing
  126.         If Not m_Process.HasExited Then
  127.             m_Process.Kill()
  128.         End If
  129.         m_Process.Close()
  130.     End Sub
  131.  
  132.     Private Sub txtConsole_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  133.  
  134.         If (txtConsole.Text.Contains("[download] 100.0%")) Then
  135.             ProgressBar1.Increment(100)
  136.         End If
  137.     End Sub
  138.  
  139.     Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
  140.         txtCommandInput.Clear()
  141.         HD1.Checked = False
  142.         HD2.Checked = False
  143.         AudioOnly.Checked = False
  144.     End Sub
  145.  
  146.     Private Sub PasteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteButton.Click
  147.         txtCommandInput.Paste()
  148.     End Sub
  149.  
  150.     Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
  151.         AboutBox1.Show()
  152.     End Sub
  153.  
  154.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  155.         Application.Exit()
  156.     End Sub
  157.  
  158.     Private Sub ClearCacheToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearCacheToolStripMenuItem.Click
  159.         StreamInput(m_YoutubeClearCacheInput & m_ClearCache)
  160.         ClearCacheToolStripMenuItem.Enabled = False
  161.     End Sub
  162.  
  163.     Private Sub txtCommandInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCommandInput.TextChanged
  164.         If (txtCommandInput.Text.StartsWith("http")) Then
  165.             ProcessButton.Enabled = True
  166.         Else : ProcessButton.Enabled = False
  167.         End If
  168.     End Sub
  169.  
  170.     Private Sub AudioOnly_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioOnly.CheckedChanged
  171.         If AudioOnly.Checked = True Then HD1.Enabled = False
  172.         If AudioOnly.Checked = True Then HD2.Enabled = False
  173.         If AudioOnly.Checked = False Then HD1.Enabled = True
  174.         If AudioOnly.Checked = False Then HD2.Enabled = True
  175.  
  176.     End Sub
  177.  
  178.     Private Sub HD2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HD2.CheckedChanged
  179.         If HD2.Checked = True Then HD1.Enabled = False
  180.         If HD2.Checked = True Then AudioOnly.Enabled = False
  181.         If HD2.Checked = False Then HD1.Enabled = True
  182.         If HD2.Checked = False Then AudioOnly.Enabled = True
  183.  
  184.     End Sub
  185.  
  186.     Private Sub HD1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HD1.CheckedChanged
  187.         If HD1.Checked = True Then HD2.Enabled = False
  188.         If HD1.Checked = True Then AudioOnly.Enabled = False
  189.         If HD1.Checked = False Then HD2.Enabled = True
  190.         If HD1.Checked = False Then AudioOnly.Enabled = True
  191.  
  192.     End Sub
  193.  
  194.     Private Sub SettingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click
  195.  
  196.     End Sub
  197.  
  198.     Private Sub ViewLogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewLogToolStripMenuItem.Click
  199.         LogForm.Show()
  200.     End Sub
  201.  
  202.     Public Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
  203.  
  204.     End Sub
  205. End Class
Add Comment
Please, Sign In to add comment