home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Video_Grab213908122009.psc / facebook.cls < prev    next >
Text File  |  2009-01-01  |  6KB  |  190 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "facebook"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Function downloadFacebookVideo(fUrl As String)
  17.     Dim urlFBParsed As String
  18.     Dim urlVDParsed As String
  19.     Dim urlUnparsed As String
  20.     
  21.   '  On Local Error GoTo son
  22.     
  23.     urlFBParsed = parseFacebookUrl(fUrl)
  24.     urlUnparsed = getFacebookVideoUPLink(urlFBParsed)
  25.     urlVDParsed = parseVideoUrl(urlUnparsed)
  26.     
  27.     downloadFile urlVDParsed
  28. 'son:
  29.  '   MsgBox xmlDoc.langVar(0).strFull(18), vbOKOnly + vbExclamation + vbApplicationModal, "Video Grabber"
  30. End Function
  31.  
  32. Function parseFacebookUrl(fUrl As String)
  33.     Dim videoID As String
  34.     Dim videoIDPos_sta As String
  35.     Dim videoIDPos_sto As String
  36.     
  37.     showState xmlDoc.langVar(0).strFull(19)
  38.     
  39.     videoIDPos_sta = InStr(1, fUrl, "v=")
  40.     videoIDPos_sto = InStr(videoIDPos_sta + 1, fUrl, "&")
  41.     
  42.     videoID = Mid(fUrl, videoIDPos_sta + 2, videoIDPos_sto - videoIDPos_sta - 2)
  43.     
  44.     parseFacebookUrl = "http://www.facebook.com/video/video.php?v=" & videoID
  45. End Function
  46.  
  47. Function getFacebookVideoUPLink(fUrl As String)
  48.  
  49.     Dim fbBuffer
  50.     Dim oid_sta, oid_sto, oid
  51.     Dim url_sta, url_sto, urlp
  52.     
  53.     Dim fbLoginReq As New XMLHTTPRequest
  54.     
  55.     showState xmlDoc.langVar(0).strFull(20)
  56.     
  57.     fbLoginReq.open "POST", "https://login.facebook.com/login.php?", False
  58.     fbLoginReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  59.     fbLoginReq.send "email=" & URLEncode(Form1.Text2.Text) & "&pass=" & URLEncode(Form1.Text3.Text)
  60.     
  61.     showState xmlDoc.langVar(0).strFull(21)
  62.     
  63.     fbLoginReq.open "GET", fUrl, False
  64.     fbLoginReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  65.     fbLoginReq.setRequestHeader "Referer", fUrl
  66.     fbLoginReq.send
  67.     fbBuffer = fbLoginReq.responseText
  68.     
  69.     
  70.     oid_sta = InStr(1, fbBuffer, "oid")
  71.     oid_sto = InStr(oid_sta + 3, fbBuffer, ")")
  72.  
  73.     oid = Mid(fbBuffer, oid_sta + 4, oid_sto - oid_sta - 5)
  74.     
  75.     If (Len(oid) > 15) Then
  76.         oid = ""
  77.     End If
  78.     
  79.     showState xmlDoc.langVar(0).strFull(22)
  80.     
  81.     fbLoginReq.open "GET", fUrl & "&oid=" & oid, False
  82.     fbLoginReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  83.     fbLoginReq.setRequestHeader "Referer", fUrl & "&oid=" & oid
  84.     fbLoginReq.send
  85.     fbBuffer = fbLoginReq.responseText
  86.     
  87.     url_sta = InStr(1, fbBuffer, "video_src")
  88.     url_sto = InStr(url_sta + 9, fbBuffer, ")")
  89.  
  90.     urlp = Mid(fbBuffer, url_sta + 13, url_sto - url_sta - 14)
  91.     
  92.     showState xmlDoc.langVar(0).strFull(23)
  93.     
  94.     getFacebookVideoUPLink = urlp
  95.  
  96. End Function
  97. Function parseVideoUrl(urlUnparsed As String)
  98.     Dim urlParsed As String
  99.     
  100.     showState xmlDoc.langVar(0).strFull(24)
  101.     
  102.     urlParsed = Replace(urlUnparsed, "%3A", ":")
  103.     urlParsed = Replace(urlParsed, "%2F", "/")
  104.     
  105.     parseVideoUrl = urlParsed
  106. End Function
  107.  
  108. Function downloadFile(fParsedFileUrl As String)
  109.     Dim Size As Long, Remaining As Long, FFile As Integer, Chunk() As Byte
  110.     Dim FileName As String, NowSize As Long, Yuzde As Integer
  111.     
  112.     FileName = Right(fParsedFileUrl, Len(fParsedFileUrl) - InStrRev(fParsedFileUrl, "/"))
  113.     
  114.     Form1.Inet2.Cancel
  115.     
  116.     Form1.Inet2.Execute Trim(fParsedFileUrl), "GET"
  117.     
  118.     Do While Form1.Inet2.StillExecuting
  119.         DoEvents
  120.     Loop
  121.     
  122.     Form1.ProgressBar1.Max = 100
  123.     
  124.     On Local Error GoTo son
  125.     Size = CLng(Form1.Inet2.GetHeader("Content-Length"))
  126.     Remaining = Size
  127.     NowSize = 0
  128.     Form1.Label8.Caption = Size & " Byte"
  129.     
  130.     FFile = FreeFile
  131.     On Local Error Resume Next
  132.     MkDir App.Path + "\downloaded"
  133.     
  134.     Form1.Label9.Caption = App.Path + "\downloaded\" + FileName
  135.     Form1.Command1.Enabled = False
  136.     Form1.Command3.Enabled = False
  137.     Form1.Check1.Enabled = False
  138.     Form1.Text1.Enabled = False
  139.     Form1.Text2.Enabled = False
  140.     Form1.Text3.Enabled = False
  141.     
  142.     showState xmlDoc.langVar(0).strFull(25)
  143.     
  144.     Open App.Path + "\downloaded\" + FileName For Binary Access Write As #FFile
  145.     Do Until Remaining = 0
  146.         If Remaining > 1024 Then
  147.             Chunk = Form1.Inet2.GetChunk(1024, icByteArray)
  148.             Remaining = Remaining - 1024
  149.         Else
  150.             Chunk = Form1.Inet2.GetChunk(Remaining, icByteArray)
  151.             Remaining = 0
  152.         End If
  153.         NowSize = Size - Remaining
  154.         Yuzde = CInt((100 / Size) * NowSize)
  155.         Form1.Label7.Caption = "% " & Yuzde
  156.         Form1.Caption = "Video Grabber | Grabbing : % " & Yuzde
  157.         Form1.Label10.Caption = NowSize & " Byte"
  158.         Form1.Label12.Caption = Remaining & " Byte"
  159.         Form1.ProgressBar1.Value = Yuzde
  160.         Put #FFile, , Chunk
  161.     Loop
  162.     Close #FFile
  163.     
  164.     
  165.     Form1.Command1.Enabled = True
  166.     Form1.Command3.Enabled = True
  167.     Form1.Check1.Enabled = True
  168.     Form1.Text1.Enabled = True
  169.     Form1.Text2.Enabled = True
  170.     Form1.Text3.Enabled = True
  171.     
  172.     showState xmlDoc.langVar(0).strFull(26)
  173.     
  174.     Form1.Caption = "Video Grabber"
  175.     
  176.     Exit Function
  177. son:
  178.     
  179.     Form1.Command1.Enabled = True
  180.     Form1.Command3.Enabled = True
  181.     Form1.Check1.Enabled = True
  182.     Form1.Text1.Enabled = True
  183.     Form1.Text2.Enabled = True
  184.     Form1.Text3.Enabled = True
  185.     
  186.     showState "N/A"
  187.     
  188.     Form1.Caption = "Video Grabber"
  189. End Function
  190.