Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Source] Youtube Download [VB.net]
#1
I posted this on HF. Thought I'd share over here.

This is my take on a Youtube Downloader. Instead of downloading the file automatically I have it generate the links in a webbrowser so the user can right-click save-target-as.

[Image: youtube.gif]

Credits go to:
xSilent - helped me learn mulithreading/use of delegates. Thanks.
TraptCode - original post similar to mine. used .Replace commands(commented in source). Thanks
Mr. Predictable - idea to use Camtasia Studio to produce gif came from him.

now the code.
You will need the following
  • Textbox - txtUrl
  • Button - btnGenerate
  • webbrowser - wb
  • listbox - lstIndex
  • listbox - lstLinks

Here is the code.

Code:
Public Class Form1
    Dim HttpRequest As Net.HttpWebRequest
    Dim HttpResponse As Net.HttpWebResponse
    Dim Stream As IO.StreamReader
    Dim scode As String = ""
    Delegate Sub _generateLinks()
    Private Sub generateLinks()
  Dim type As String = ""
  Dim page As String = ""
  Dim tstring As String = ""
  Dim link As Integer = 1
  Dim index As Integer = 0
  Dim count As Integer = 0
  Dim num1 As Integer = 0
  Dim num2 As Integer = 0
  lstIndex.Items.Clear()
  lstLinks.Items.Clear()
  Do Until index = -1
    index = scode.IndexOf("http://v", index + 1)
    If index <> -1 Then
    lstIndex.Items.Add(index)
    End If
  Loop
  For i = 0 To lstIndex.Items.Count - 2
    num1 = lstIndex.Items(i)
    num2 = lstIndex.Items(i + 1)
    If num2 - num1 < 380 Then
    tstring = scode.Substring(num1, num2 - num1)
    Dim right As String = Microsoft.VisualBasic.Right(tstring, 8)
    If right.Substring(0, 1) = "%" Then
    tstring = tstring.Substring(0, tstring.Count - 8)
    Else
    tstring = tstring.Substring(0, tstring.Count - 7)
    End If
    If Not lstLinks.Items.Contains(tstring) Then
    If Not Microsoft.VisualBasic.Right(tstring, 3) = "com" Then
    lstLinks.Items.Add(tstring)
    End If
    End If
    count += 1
    End If
  Next
  index = 0
  For i = 0 To lstLinks.Items.Count - 1
    HttpRequest = Net.HttpWebRequest.Create(New Uri(lstLinks.Items.Item(i)))
    HttpResponse = HttpRequest.GetResponse
    type = HttpResponse.ContentType
    page = page & "<br>" & "<a href = """ & lstLinks.Items(i) & """>" & "Link " & link & "  -  Type: " & type
    link += 1
  Next
  wb.DocumentText = page
  btnGenerate.Enabled = True
    End Sub
    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
  Dim t As Threading.Thread
  wb.DocumentText = ""
  btnGenerate.Enabled = False
  t = New Threading.Thread(AddressOf getpage)
  t.Start()
    End Sub
    Private Sub getpage()
  HttpRequest = Net.HttpWebRequest.Create(txtUrl.Text)
  HttpResponse = HttpRequest.GetResponse
  Stream = New IO.StreamReader(HttpResponse.GetResponseStream)
  scode = Stream.ReadToEnd
  'credit to TraptCode for replace codes
  scode = scode.Replace("%3A", ":")
  scode = scode.Replace("%2F", "/")
  scode = scode.Replace("%3F", "?")
  scode = scode.Replace("%3D", "=")
  scode = scode.Replace("%26", "&")
  scode = scode.Replace("%25", "%")
  Invoke(New _generateLinks(AddressOf generateLinks))
    End Sub
End Class

I didnt use Try-catch because I meant for this to be more informative for downloading youtube vids rather than releasing it. I plan on making a better GUI and adding error handling. But for the purpose of this thread, i left that out. Also, the code is probably a bit sloppy and im sure there are better ways to do some of things i did in this code. But this is what i know. So if you have a better way to code something, reply and let us know.
Enjoy!

Download Code here

*Message to noobs/skids*
I left this code copy/pasteable... learn from it. Go through the code as you use it and understand the flow of it. Like, when you click the button it starts a thread, which starts another sub, then learn what that sub is doing. I didnt comment this code because it's late and I am tired. If you have a question about something in the code, reply/pm.
Reply
#2
This is good.
Thanks, I will bookmark this.
Future Reference.
★★★★★
Victoire
- Shock!
★★★★★
Reply
#3
Nice man, thanks for sharing. Added to my bookmarks.
Reply
#4
Great share, I will be sure to try this out later and post feedback. This is a good idea.
Reply
#5
Great share dude
Reply
#6
dude how did you create that gif tutorial? please pm me. thanks

btw I'm learning vb and this post would really help me learn new things.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Free Advanced Port Scanner SOURCE [ VB.NET ] Filefinder 6 5,747 01-22-2013, 04:27 AM
Last Post: TalishHF
  [VB.NET]Console app Menu example (amortization calculator)[Source] KoBE 8 8,168 12-28-2012, 06:55 AM
Last Post: mouse719
  [VB.NET] Get Region Info [Source] ƃu∀ ıʞƃu∀ 0 1,252 11-28-2012, 04:38 AM
Last Post: ƃu∀ ıʞƃu∀
  How To Make And Use A Builder And Stub. [VB.NET] [Source] Vorfin 35 23,247 11-25-2012, 10:34 PM
Last Post: ƃu∀ ıʞƃu∀
  [Source] Tricks Using PictureBox Control [VB.NET] Fragma 8 6,496 11-25-2012, 10:32 PM
Last Post: ƃu∀ ıʞƃu∀

Forum Jump:


Users browsing this thread: 1 Guest(s)