Option Strict On
Imports System.IO
Imports MultiUpload_Uploader.Utility.Http
Imports System.Text.RegularExpressions
Imports System.Collections.Specialized
Namespace API
''' <summary>
''' For uploading files to http://www.multiupload.nl
''' Coded By: loyalty
''' Contact: loyalty.exe@gmail.com
''' Website: http://loyaltyHF.blogspot.com
''' Credits: idb for his HTTP Class (http://s.olution.cc)
''' </summary>
Public Class MultiUpload
Implements IDisposable
#Region "Debug Const"
#Const DEBUG = False
#End Region
#Region "Declerations"
Private Http As Utility.Http = Nothing
#End Region
#Region "Structures"
Public Structure Result
Dim Success As Boolean
Dim ErrMsg As String
Dim Link As String
Dim Info As String
End Structure
#End Region
#Region "Constructor"
Sub New()
NewSession()
End Sub
#End Region
#Region "Private Methods"
Private Sub NewSession()
If Not IsNothing(Http) Then Http.Dispose()
Http = New Utility.Http
End Sub
Private Function GetInfo() As String()
Dim res As HttpResponse = Http.GetResponse(Verb.GET, "http://www.multiupload.nl/")
If IsNothing(res.Error) Then
Dim Mat As Match = Regex.Match(res.Html, "action=""(?<url>http://.*?)/progress/\?id=(?<id>.*?)""")
Return New String() {Mat.Groups("url").Value, Mat.Groups("id").Value}
Else
Return New String() {}
End If
End Function
Private Function UploadData(ByVal path As String) As UploadData()
Dim UploadArgs As New List(Of UploadData)
UploadArgs.Add(New UploadData(File.ReadAllBytes(path), path.Substring(path.LastIndexOf("\") + 1), "file_0"))
For i = 1 To 9
UploadArgs.Add(New UploadData(Nothing, "", "file_" & i))
Next
Return UploadArgs.ToArray
End Function
Private Function FieldsInfo(ByVal Description As String, ByVal id As String) As NameValueCollection
Dim Fields As New NameValueCollection
Fields.Add("UPLOAD_IDENTIFIER", id)
Fields.Add("u", "")
Fields.Add("description_0", Description)
Fields.Add("fetchfield0", "")
Fields.Add("fetchdesc0", "")
For i = 1 To 9
Fields.Add("description_" & i, "")
Next
For i = 1 To 9
Fields.Add("fetchfield" & i, "http://")
Fields.Add("fetchdesc" & i, "")
Next
Fields.Add("service_7", "1")
Fields.Add("service_19", "1")
Fields.Add("service_27", "1")
Fields.Add("service_24", "1")
Fields.Add("service_26", "1")
Fields.Add("service_28", "1")
Fields.Add("fromemail", "")
Fields.Add("toemail", "")
Fields.Add("username_7", "")
Fields.Add("password_7", "")
Fields.Add("remember_7", "1")
Return Fields
End Function
#End Region
#Region "Public Methods"
Public Function Upload(ByVal path As String, ByVal Description As String) As Result
Dim Result As New Result
Try
If Not String.IsNullOrEmpty(path) Then
Dim Info As String() = GetInfo()
If Info.Length = 2 Then
Dim URL As String = Info(0)
Dim ID As String = Info(1)
#If DEBUG Then
Debug.WriteLine(ID)
Debug.WriteLine(URL)
#End If
With Http
.Referer = "http://wwww.multiupload.nl/"
Dim res As HttpResponse = .GetResponse(Verb.POST, String.Format("{0}/progress/?id={1}", URL, ID), String.Format("random={0}&t=", TimeStampLong))
If IsNothing(res.Error) Then
res = .GetResponse(Verb.POST, String.Format("{0}/upload/?UPLOAD_IDENTIFIER={1}", URL, ID), Nothing, FieldsInfo(Description, ID), UploadData(path))
If IsNothing(res.Error) Then
Dim m As Match = Regex.Match(res.Html, """downloadid"":""(?<download>.*?)"",""filesize"":""(?<size>.*?)"",""filename"":""(?<name>.*?)""")
Result.Link = "http://wwww.multiupload.nl/" & m.Groups("download").Value
Result.Info = String.Format("Name: {0}{1}Size: {2}", m.Groups("name").Value, vbCrLf, m.Groups("size").Value)
If Result.Link.Length > "http://wwww.multiupload.nl/".Length Then
Result.Success = True
End If
#If DEBUG Then
Debug.WriteLine(res.Html)
#End If
Else
#If DEBUG Then
Debug.WriteLine(res.Error.Message)
Debug.WriteLine(res.Error.Html)
#End If
End If
Else
Result.ErrMsg = res.Error.Message
#If DEBUG Then
Debug.WriteLine(res.Error.Message)
Debug.WriteLine(res.Error.Html)
#End If
End If
End With
Else
Result.ErrMsg = "Unable to get the UID"
End If
Else
Result.ErrMsg = "Invalid Path!"
End If
Catch ex As Exception
Result.ErrMsg = ex.Message
End Try
Return Result
End Function
#End Region
#Region "Destructor"
Private disposedValue As Boolean
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
If Not IsNothing(Http) Then Http.Dispose()
Http = Nothing
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace