163相册批量上传下载类(vb.net)

原创 2007年09月21日 19:03:00

 

'163相册的属性

Public Structure AlbumInfo

    Dim albumID, albumName, albumUrl, photoCount, albumDesc As String

End Structure

 

'163照片的属性

Public Structure PhotoInfo

    Dim photoID, photoDesc, photoSmallUrl, photoBigUrl As String

End Structure

 

 

'实现对163相册管理的类

Public Class Album163

 

    Friend http As New WebClient

    Dim r As System.Text.RegularExpressions.Regex

    Dim m As System.Text.RegularExpressions.Match

    Dim username, password As String

 

 

    '登录相册

    Function Login(ByVal username As String, ByVal password As String) As Boolean

        Me.username = username

        Me.password = password

 

        http.strUrl = "https://reg.163.com/logins.jsp"

 

        http.strTextField = "type=1&username=" + username + "&password=" + password

        http.Proc(True)

        http.cookiePost = http.cookieGet

        m = r.Match(http.RespHtml, "http://reg.163.com/Main.jsp/?username=" + username)

        If m.Success Then

            Return True

        Else

            Return False

        End If

    End Function

 

    '获取相册目录信息

    Function GetAlbums() As ArrayList

        http.strUrl = "http://photo.163.com/js/albumsinfo.php?user=" + username

        http.Proc()

 

        Dim arr() As String = Split(http.RespHtml, "gAlbumsInfo[")

 

        Dim i As Integer

        Dim albumsInfo As New ArrayList

        For i = 1 To UBound(arr)

 

            m = r.Match(arr(i), "(/d+)[^,]+,/d,(/d+),""([^""]+)"",""([^""]+)""")

            If m.Success Then

                Dim aInfo As AlbumInfo

                aInfo.albumID = m.Groups(1).Value

                aInfo.photoCount = m.Groups(2).Value

                aInfo.albumName = m.Groups(3).Value

                aInfo.albumDesc = m.Groups(4).Value

                albumsInfo.Add(aInfo)

            End If

        Next

        Return albumsInfo

    End Function

 

 

    '获取照片信息

    Function GetPhotos(ByVal albumID As String) As ArrayList

        http.strUrl = "http://photo.163.com/js/photosinfo.php?user=" + username + "&aid=" + albumID + "&level=2"

        http.Proc()

 

        Dim photosInfo As New ArrayList

        Dim pInfo As PhotoInfo

 

        m = r.Match(http.RespHtml, "gPhotosInfo/[(/d+)[^,]+,[^,]+,[^,]+,""([^""]*)"",""([^""]*)"",""([^""]*)""")

        Do While m.Success

            pInfo.photoID = m.Groups(1).Value

            pInfo.photoDesc = m.Groups(2).Value

            pInfo.photoSmallUrl = m.Groups(3).Value

            pInfo.photoBigUrl = m.Groups(4).Value

            photosInfo.Add(pInfo)

            m = m.NextMatch

        Loop

 

        Return photosInfo

    End Function

 

    '创建目录

    Function CreateAlbum(ByVal AlbumName As String, ByVal AlbumDesc As String, Optional ByVal power As String = "1") As String

 

        http.strUrl = "http://photo.163.com/pholder_new_pro.php"

        http.strRefUrl = "http://photo.163.com/pholder_new.php"

        http.strTextField = "albumname=" & AlbumName & "&albumdesc=" + AlbumDesc + "&bigclass=%C8%CB%CE%EF&newcate=1&lvl=" + power + "&create=%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%B4%B4%26nbsp%3B%26nbsp%3B%BD%A8%26nbsp%3B%26nbsp%3B%C4%BF%26nbsp%3B%26nbsp%3B%C2%BC%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B"

        http.Proc()

 

        m = r.Match(http.RespHtml, "(?<=/upload/)/d+")

        If m.Success Then

            Return m.Value

        Else

            Return "0"

        End If

    End Function

 

    '修改目录属性

    Function EditAlbum(ByVal albumID As String, ByVal albumName As String, ByVal albumDesc As String, Optional ByVal power As String = "1", Optional ByVal password As String = "") As Boolean

        http.strUrl = "http://photo.163.com/pholder_edit_pro.php"

        http.strTextField = "user=" + username + "&aid=" + albumID + "&albumname=" + albumName + "&albumdesc=" + albumDesc + "&bigclass=%C8%CB%CE%EF&newcate=1&lvl=" + power + "&password=" + password  'lvl:0私有1公开2半公开

        http.Proc()

        m = r.Match(http.RespHtml, "成功修改目录属性")

        If m.Success Then

            Return True

        Else

            Return False

        End If

    End Function

 

    '删除目录

    Function DeleteAlbum(ByVal albumID As String) As Boolean

        http.strUrl = "http://control.photo.163.com/pholder_del.php?user=" + username + "&aid=" + albumID

        http.Proc()

        m = r.Match(http.RespHtml, "删除目录成功")

        If m.Success Then

            Return True

        Else

            Return False

        End If

    End Function

 

    '上传照片

    Function UpPhoto(ByVal AlbumID As String, ByVal BigPhotoPath As String, ByVal smallPhotoPath As String) As Boolean

        Static sid As String

        If sid = "" Then '获取sid

            http.strUrl = "http://photo.163.com/upload.php?aid=" + AlbumID

            http.Proc()

            m = r.Match(http.RespHtml, "(?<=<param.+name=.*Sid.+value=.*)/w+==")

            If m.Success Then

                sid = m.Value

            Else

                Return False

            End If

 

        End If

        http.strUrl = "http://upload.photo.163.com/AppUpload.do?ApiName=uploadPhoto"

        http.strTextField = "albumId=" + AlbumID + "&sid=" + sid + "&OriginDim=1024;768&SmallerDim=200;200&descr=hedaodewoaininihaoma"

        http.strFileField = "OriginFile=" + BigPhotoPath + "&SmallerFile=" + smallPhotoPath

        http.UploadFile()

 

        m = r.Match(http.RespHtml, "<added>1<")

        If m.Success Then

            Return True

        Else

            sid = ""

            Return False

        End If

    End Function

 

    '修改照片描述

    Function EditPhoto(ByVal albumID As String, ByVal photoID As String, ByVal photoDesc As String) As Boolean

        http.strUrl = "http://photo.163.com/photo_descr_edit.php"

        http.strTextField = "user=" + username + "&aid=" + albumID + "&pid=" + photoID + "&descr=" + photoDesc

        http.Proc()

        If http.RespHtml = "success" Then

            Return True

        Else

            Return False

        End If

    End Function

 

    '删除照片

    Function DeletePhoto(ByVal albumID As String, ByVal photoID As String) As Boolean

        http.strUrl = "http://control.photo.163.com/photo_del.php?user=" + username + "&aid=" + albumID + "&pid=" + photoID

        http.Proc()

        m = r.Match(http.RespHtml, "<added>1<")

        If m.Success Then

            Return True

        Else

            Return False

        End If

    End Function

 

 

 

End Class

相关文章推荐

FTP上传下载源代码 VB.net

  • 2012年05月27日 12:40
  • 92KB
  • 下载

.NET仿QQ相冊批量上傳圖片

  • 2014年03月21日 11:46
  • 40KB
  • 下载

.Net Core 图片文件上传下载

当下.Net Core项目可是如雨后春笋一般发展起来,作为.Net大军中的一员,我热忱地拥抱了.Net Core并且积极使用其进行业务的开发,我们先介绍下.Net Core项目下实现文件上传下载接口。...

vb控制vss,批量上传下载

  • 2015年03月14日 13:32
  • 87KB
  • 下载

微信公共服务平台开发(.Net 的实现)8-------处理图片(上传下载发送)

微信公共服务平台开发(.Net 的实现)8-------处理图片(上传下载发送)
  • hemeng
  • hemeng
  • 2014年02月20日 19:42
  • 4824

163相册批量下载器.rar

  • 2009年06月02日 22:17
  • 24KB
  • 下载

在ASP.NET中上传下载文件(转)

//TransmitFile实现下载     protected void Button1_Click(object sender, EventArgs e)     {         /*...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:163相册批量上传下载类(vb.net)
举报原因:
原因补充:

(最多只允许输入30个字)