lanzou

package module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 15 Imported by: 0

README

gLanz

Lanzou (蓝奏云) Go library + CLI: share resolve and account ops (login / list / upload / mkdir / ...).

Module: github.com/WangTianYou537/gLanz

Install CLI

go install github.com/WangTianYou537/gLanz/cmd/lanzou@latest
# 注意路径必须含 /cmd/lanzou

CLI

# 分享解析(兼容旧用法)
lanzou https://hya.lanzouu.com/xxx
lanzou parse --pwd 5grc --down https://wwbss.lanzouu.com/xxx

# 登录(cookie 默认 ./lanzou.cookie,也可用环境变量 LANZOU_USER/LANZOU_PASS)
lanzou login --user 手机号 --pass 密码
lanzou logout

# 目录 / 上传
lanzou list
lanzou list --folder 123456
lanzou upload ./file.zip --folder -1
lanzou upload ./a.doc --folder 123 --set-pwd abcd --set-desc "说明"
lanzou mkdir demo --folder -1 --desc "新建"
lanzou info --file 111
lanzou passwd --file 111 --pwd ab12
lanzou rm --file 111

Library

import "github.com/WangTianYou537/gLanz"

// share
c := lanzou.New()
res, _ := c.Parse(url, lanzou.Options{ResolveDirect: true})

// account
acc := lanzou.NewAccount(user, pass, lanzou.WithCookieFile("./lanzou.cookie"))
_ = acc.EnsureLogin()
list, _ := acc.List("-1")
up, _ := acc.Upload("./a.zip", "-1")

Upload endpoint: POST fileup.php multipart (task=1, field upload_file), compatible with common Lanzou web clients.

License

MIT

Documentation

Overview

Package lanzou resolves Lanzou (蓝奏云) public and password share links.

Features:

  • public / password shares
  • Alibaba WAF/ESA acw_sc__v2 cookie
  • CDN pseudo-link resolution and risk-page fallback
  • optional local download

Index

Constants

View Source
const (
	EntryFolder = 0
	EntryFile   = 1
)

EntryType: 0 folder, 1 file.

Variables

View Source
var (
	ErrPasswordRequired = errors.New("password required for this share link")
)

Sentinel errors.

Functions

func CalcAcwScV2

func CalcAcwScV2(arg1 string) (string, error)

CalcAcwScV2 computes cookie value from arg1.

func CalcAcwScV2With

func CalcAcwScV2With(arg1, mask string, perm []int) (string, error)

CalcAcwScV2With allows custom mask/perm.

func ExtractArg1

func ExtractArg1(html string) (string, bool)

ExtractArg1 extracts arg1 from challenge HTML.

func IsAcwChallenge

func IsAcwChallenge(html string) bool

IsAcwChallenge reports whether HTML is an acw challenge page.

func IsPasswordProtected

func IsPasswordProtected(html string) bool

IsPasswordProtected detects password share HTML.

Types

type Account added in v0.1.3

type Account struct {
	// contains filtered or unexported fields
}

Account is a logged-in Lanzou control-panel client.

func NewAccount added in v0.1.3

func NewAccount(username, password string, opts ...AccountOption) *Account

NewAccount creates an account client. Call Login or LoadCookie before API use.

func (*Account) Cookie added in v0.1.3

func (a *Account) Cookie() string

Cookie returns the raw cookie string.

func (*Account) CreateFolder added in v0.1.3

func (a *Account) CreateFolder(name, parentID, describe string) (string, error)

CreateFolder creates a folder. Returns raw JSON response body.

func (*Account) DeleteFile added in v0.1.3

func (a *Account) DeleteFile(fileID string) (string, error)

DeleteFile deletes a file by id.

func (*Account) DeleteFolder added in v0.1.3

func (a *Account) DeleteFolder(folderID string) (string, error)

DeleteFolder deletes a folder by id.

func (*Account) DeleteFolderByName added in v0.1.3

func (a *Account) DeleteFolderByName(name, fatherID string) (string, error)

DeleteFolderByName deletes a child folder by name.

func (*Account) EnsureLogin added in v0.1.3

func (a *Account) EnsureLogin() error

EnsureLogin logs in if Verification fails.

func (*Account) GetFileDescribe added in v0.1.3

func (a *Account) GetFileDescribe(fileID string) (string, error)

GetFileDescribe returns file description.

func (*Account) GetFileDownloadInfo added in v0.1.3

func (a *Account) GetFileDownloadInfo(fileID string) (shareURL, pwd string, err error)

GetFileDownloadInfo returns share URL + password for a managed file.

func (*Account) GetFileInfo added in v0.1.3

func (a *Account) GetFileInfo(fileID string) (*FileInfo, error)

GetFileInfo returns parsed file info.

func (*Account) GetFileInfoRaw added in v0.1.3

func (a *Account) GetFileInfoRaw(fileID string) (string, error)

GetFileInfoRaw returns raw JSON for task=22.

func (*Account) GetFilePassword added in v0.1.3

func (a *Account) GetFilePassword(fileID string) (string, error)

GetFilePassword returns share password for a file.

func (*Account) GetFolderIDByName added in v0.1.3

func (a *Account) GetFolderIDByName(name, fatherID string) (string, error)

GetFolderIDByName finds a child folder id by name under fatherID.

func (*Account) GetFolderInfo added in v0.1.3

func (a *Account) GetFolderInfo(folderID string) (*FolderInfo, error)

GetFolderInfo scrapes folder info page.

func (*Account) List added in v0.1.3

func (a *Account) List(folderID string) ([]ListEntry, error)

List returns folders + files under folderID ("-1" is root). Folders via task=47, files via task=5 (JSON APIs).

func (*Account) Login added in v0.1.3

func (a *Account) Login() error

Login POSTs task/uid/pwd to mlogin.php (same as browser/curl simple login).

func (*Account) MoveFile added in v0.1.3

func (a *Account) MoveFile(fileID, folderID string) (string, error)

MoveFile moves a file into folderID.

func (*Account) SetCookie added in v0.1.3

func (a *Account) SetCookie(cookie string)

SetCookie sets session cookie manually.

func (*Account) SetFileDescribe added in v0.1.3

func (a *Account) SetFileDescribe(fileID, describe string) (string, error)

SetFileDescribe sets file description.

func (*Account) SetFilePassword added in v0.1.3

func (a *Account) SetFilePassword(fileID, pwd string) (string, error)

SetFilePassword sets a file share password.

func (*Account) SetFolderNameAndDescribe added in v0.1.3

func (a *Account) SetFolderNameAndDescribe(folderID, name, describe string) (string, error)

SetFolderNameAndDescribe renames a folder and sets description.

func (*Account) SetFolderPassword added in v0.1.3

func (a *Account) SetFolderPassword(folderID, pwd string) (string, error)

SetFolderPassword enables password on a folder.

func (*Account) Upload added in v0.1.3

func (a *Account) Upload(localPath, folderID string) (*UploadResult, error)

Upload uploads a local file to folderID ("-1" = root) via fileup.php. Protocol mirrors common Lanzou web clients (task=1 multipart to fileup.php). See: https://github.com/zaxtyson/LanZouCloud-API

func (*Account) Verification added in v0.1.3

func (a *Account) Verification() bool

Verification checks whether the current cookie session is valid.

type AccountOption added in v0.1.3

type AccountOption func(*Account)

AccountOption configures Account.

func WithAccountBase added in v0.1.3

func WithAccountBase(base string) AccountOption

WithAccountBase overrides the control-panel origin (default up.woozooo.com).

func WithCookieFile added in v0.1.3

func WithCookieFile(path string) AccountOption

WithCookieFile sets a path to load/save session cookies.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client holds HTTP state (cookies) for a lanzou session.

func New

func New() *Client

New creates a Client with browser-like headers and cookie jar map.

func (*Client) Download

func (c *Client) Download(rawURL, destDir, filename, referer string) (string, error)

Download saves url into destDir and returns the path.

func (*Client) Parse

func (c *Client) Parse(shareURL string, opt Options) (*Result, error)

Parse resolves a share URL.

func (*Client) ResolveDirectURL

func (c *Client) ResolveDirectURL(cdnURL string) (string, error)

ResolveDirectURL turns a CDN pseudo link into a downloadable URL.

type FileInfo added in v0.1.3

type FileInfo struct {
	Raw map[string]any
	ID  string
	Pwd string
	// ShareURL is is_newd + "/" + f_id when available.
	ShareURL string
}

FileInfo is a decoded task=22 payload.

type FolderInfo added in v0.1.3

type FolderInfo struct {
	Name        string
	Description string
	URL         string
	Password    string
	FileCount   string
	FileSize    string
}

FolderInfo holds scraped folder metadata.

type ListEntry added in v0.1.3

type ListEntry struct {
	Type        int    `json:"type"` // 0 folder, 1 file
	ID          string `json:"id"`
	Name        string `json:"name"`
	URL         string `json:"url,omitempty"`
	Size        string `json:"size,omitempty"`
	Time        string `json:"time,omitempty"`
	Description string `json:"description,omitempty"`
}

ListEntry is a folder or file row.

type Options

type Options struct {
	Password      string
	ResolveDirect bool
}

Options for Parse.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns options with ResolveDirect enabled.

type Result

type Result struct {
	FID               string
	Filename          string
	PasswordProtected bool
	CDNDomain         string
	Telecom           string
	Unicom            string
	Normal            string
	Direct            string
	SavedPath         string
}

Result of a successful Parse.

type UploadResult added in v0.1.4

type UploadResult struct {
	FileID   string
	Name     string
	RawJSON  string
	FolderID string
}

UploadResult is the outcome of a successful Upload.

Directories

Path Synopsis
cmd
lanzou command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL