关闭

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

标签: 相册vb.netstringfunctionstructure照片
1700人阅读 评论(1) 收藏 举报

 

'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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29659次
    • 积分:424
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:0篇
    • 译文:0篇
    • 评论:18条
    最新评论