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

 

'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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值