Giter Club home page Giter Club logo

lanzoucloud-api's Introduction

                                                       _oo0oo_
                                                      o8888888o
                                                      88" . "88
                                                      (| -_- |)
                                                      0\  =  /0
                                                    ___/`---'\___
                                                  .' \\|     |// '.
                                                 / \\|||  :  |||// \
                                                / _||||| -:- |||||- \
                                               |   | \\\  -  /// |   |
                                               | \_|  ''\---/''  |_/ |
                                               \  .-\__  '-'  ___/-. /
                                             ___'. .'  /--.--\  `. .'___
                                          ."" '<  `.___\_<|>_/___.' >' "".
                                         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
                                         \  \ `_.   \_ __\ /__ _/   .-` /  /
                                     =====`-.____`.___ \_____/___.-`___.-'=====
                                                       `=---='


                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                               菩提本无树   明镜亦非台
                                               本来无BUG    何必常修改

lanzoucloud-api's People

Contributors

178me avatar cosin avatar fzls avatar kx-y avatar novashen555 avatar rachpt avatar zaxtyson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lanzoucloud-api's Issues

使用时遇到一些问题

提示检测更新时发生异常,列出文件夹没反应,上传文件也失败,我是纯萌新,cmd都不懂那种。。。。是我哪里操作的不对吗?
注:我没有把软件安在默认位置,没有开管理员权限(看她貌似也不需要)
image

线程中使用的过程中,出现几种错误

第一种:
Exception in thread Thread-34:
Traceback (most recent call last):
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "E:\AllByOne\Project\Source\ZhaoSF\ZSF\zsfmm\zsfmm\spiders\PreSvr.py", line 100, in lanzoudown
code = lzy.down_file_by_url(url)
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\core.py", line 920, in down_file_by_url
file_info = un_serialize(last_512_bytes[-512:])
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\utils.py", line 112, in un_serialize
ret = pickle.loads(data)
EOFError: Ran out of input
第二种
Exception in thread Thread-14:
Traceback (most recent call last):
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "E:\AllByOne\Project\Source\ZhaoSF\ZSF\zsfmm\zsfmm\spiders\PreSvr.py", line 100, in lanzoudown
code = lzy.down_file_by_url(url)
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\core.py", line 920, in down_file_by_url
file_info = un_serialize(last_512_bytes[-512:])
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\utils.py", line 112, in un_serialize
ret = pickle.loads(data)
ValueError: unregistered extension code 31766
第三种
Exception in thread Thread-7:
Traceback (most recent call last):
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "E:\AllByOne\Project\Source\ZhaoSF\ZSF\zsfmm\zsfmm\spiders\PreSvr.py", line 100, in lanzoudown
code = lzy.down_file_by_url(url)
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\core.py", line 920, in down_file_by_url
file_info = un_serialize(last_512_bytes[-512:])
File "C:\Users\Administrator.USER-20190402YM\AppData\Local\Programs\Python\Python38\lib\site-packages\lanzou\api\utils.py", line 112, in un_serialize
ret = pickle.loads(data)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 0: invalid start byte

这几种问题,我满脑子浆糊,不知道怎么处理,请大佬指点

文件列表获取问题

测试了下,文件列表,如何选择某个下载啊。 方法都测试了貌似没有成功的

遇到上传失败问题

上传总是失败,接口都是直接调用的
同样的代码在我电脑上无法上传,换一个电脑却可以上传
早上还可以上传,现在就不行了
请问大佬,这是什么问题?

上传失效

上传方法失效,未允许的文件格式返回11,允许的文件格式返回-1,其它未测试

使用api登录失败

from lanzou.api import LanZouCloud

lzy = LanZouCloud()
code = lzy.login('username','pwd')
if code == LanZouCloud.SUCCESS:
print("成功")
else:
print(code)

在源码中 lanzou/api/core.py,下面这句执行失败,是否是应为滑动块的验证
html = self._post(self._account_url, login_data, headers=phone_header)

上传问题

感谢大佬提供开源代码。其他都没问题,上传没反应不知道什么问题

python3.6 导入api异常

api版本-2.4.0.1

[root@ixxxxxx ~]# pip install lanzou-api
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting lanzou-api
  Downloading https://pypi.doubanio.com/packages/fa/9a/574e9c19b51bd19765ca5127c7f5cd0354a9af24199481c1a6c1af373a27/lanzou_api-2.4.0.1-py3-none-any.whl
Requirement already satisfied: requests in /usr/local/lib/python3.6/site-packages (from lanzou-api) (2.20.1)
Requirement already satisfied: requests-toolbelt in /usr/local/lib/python3.6/site-packages (from lanzou-api) (0.8.0)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests->lanzou-api) (2.7)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests->lanzou-api) (1.24.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests->lanzou-api) (2018.11.29)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/site-packages (from requests->lanzou-api) (3.0.4)
Installing collected packages: lanzou-api
Successfully installed lanzou-api-2.4.0.1
You are using pip version 18.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

centos7的python3.6.8版本

[root@ixxxxxx ~]# python3.6
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.

异常报错

>>> from lanzhou import api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lanzhou'
>>> from lanzou import api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/lanzou/api/__init__.py", line 1, in <module>
    from lanzou.api.core import LanZouCloud
  File "<fstring>", line 1
    (parent_id=)
              ^
SyntaxError: invalid syntax

又发现了新的url模式

1)https://www.lanzoux.com/iRGL1em4prc 网址里有大写字母,因此后面的部分需要加A-Z
2)(我自己弄的)https://hb-az.lanzous.com/izijcenly5c 三级域名部分有连字符- 注:亲自改了下个性域名,果然跟url规范一样,只允许数字、字母和连字符
3)还有一个可以改善的地方~
比如有这样一个长字符串 https://habo.qq.com/file/showdetail?pk=ADcGYl1sB24IOVs%2BU2M界面截图:协yi:安卓转PC功能就简单说下吧关闭真锁:拖进去的格式必须是账号-本帖隐藏的内容https://www.lanzoux.com/iRGL1em4prc
如果正则表达式里的三级域名部分(比如www)用现在的.*?而不是[a-zA-Z0-9-]*?的话,会导致上面一大长串都被匹配到,而不仅匹配到结尾的URL,哪怕用了非贪婪模式也是如此。

综上三点,建议 base_pat 改成https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/.+
user_pat 改成 https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/i[a-zA-Z0-9]{5,}/?,文件夹同理

base_pat = r'https?://.*?\.?lanzou[six].com/.+' # 子域名可个性化设置或者不存在

user_pat = r'https?://.*?\.?lanzou[six].com/b[a-z0-9]{7,}/?'

如何打包

我用pyinstaller打包后,其他人无法正常使用
主要使用下载dir这个,别人用的时候直接闪退,也不会创建Download文件夹

提示语法错误

Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/脚本/lanzhou_api.py", line 3, in
from lanzou.api import LanZouCloud
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\lanzou\api_init_.py", line 1, in
from lanzou.api.core import LanZouCloud
File "", line 1
(parent_id=)
^
SyntaxError: invalid syntax

纯小白,在get_cookie时报语法错误,代码如下

-- coding: utf-8 --

author = 'Administrator'
from lanzou.api import LanZouCloud
lzy=LanZouCloud()
cookie=lzy.get_cookie()
print(cookie)

同名文件下载,会追加而不是覆盖

就我突然想到,
比如我本地有一个1.txt,然后里面输入一大堆文字
我发现调用下载功能下载另一个1.txt的时候,从callback看,是追加的写入,而没有覆盖
并且确认了下,下载“完成”的文件里,开头的部分还是原来的文件内容

另外,是否可以给错误码加一个,“文件已下载过”?

我是遇到这么个需求哈:
我在下载文件,通过之前说的callback来获取文件名。但是如果这个文件已经下载过,callback哪怕一次都不会触发,这样的话我就无从获得文件名(之前提到过,用另一个api来解析文件名有额外的时间开销)

auto_rename() can be optimized

正好我的代码里也需要类似的功能,于是借鉴了一下,发现可能有个小bug,虽然一般不会出现。
比如现在文件夹里有1.jpg和1(2).jpg,然后还要下载1.jpg,那么如果用这种计算方式,算出的新文件名应该是1(2).jpg

flist = [f for f in os.listdir(fpath) if re.fullmatch(rf"{fname_no_ext}\(?\d*\)?{extension}", f)]

我自己的写法是从1(1).jpg、1(2).jpg……1(N).jpg开始遍历(可能先获取文件名列表,再在内存里判断会更快):

def auto_rename(file_path):
        if not os.path.exists(file_path):
            return file_path
        fpath, fname = os.path.split(file_path)
        fname_no_ext, ext = os.path.splitext(fname)
        for index in range(1,999):
            temp_path = fpath + os.sep + fname_no_ext + '(' + str(index) + ')' + ext
            if not os.path.exists(temp_path):
                return temp_path

然后我用chrome试了下,有1.jpg、1(2).jpg和1(3).jpg的情况下,再次下载1.jpg,它会跟我一样重命名为1(1).jpg

上传后-1报错

上传文件加了进度条,发现进度条走完后报错-1,看了错误码不知道一般错误是啥意思.....

适合拿来当本地盘用吗?

1.对于4层文件夹的限制,目前的想法是自己造一套文件系统;但这会不会导致同一层的文件过多,引起什么问题吗?
2.假设有100GB的小文件,那么文件数量很容易上千万,而8位id也只有九千万个,这会不会出问题?
3.想拿python开比如本地ftp服务器,无奈搜了一圈都只能以文件夹开ftp服务器

生成requirements.txt时有两个lanzou库

在我使用pipreqs . --encoding=utf8 --force智能地生成requirements.txt的时候,别的库都正常,但是lanzou相关的居然有两个:

lanzou_api==2.5.3
lanzou==1.0.0

而我在代码里也没用到lanzou这个库,不知道是否保留一个就好了,还是是历史遗留(兼容)问题~

在线程中使用,不会下载

我在线程中使用出现不下载的情况,使用的函数
def lanzoudown(self,url):
print("蓝奏云.地址:..%s" % url)
lzy = LanZouCloud()
code = lzy.down_file_by_url(url)
开启线程的代码
for l in downUrlList:
# 判断是不是蓝奏云
if "www.lanzous.com" in l:
t = threading.Thread(target=self.lanzoudown, args=(l,))
t.start()
如果不使用线程的话如下,直接使用会卡顿,如何正确的在线程中使用啊?
lzy = LanZouCloud()
code = lzy.down_file_by_url(url)

可以 附带返回文件夹 是否有密码与描述吗?

get_dir_list 只返回 文件夹的 id,其实文件夹是否有密码以及部分描述 也可以通过
self._mydisk_url + '?item=files&action=index&folder_node=1&folder_id=' + str(folder_id)
这个链接获得。
style="display:initial 表示有密码,文件夹描述在末尾位置 <font color="#BBBBBB">[这里是描述]</font></div>
要是get_dir_listget_file_list2能返回的dict值是列表就好了。这样就可以获得更多的信息。

def get_dir_list(self, folder_id=-1):
    """获取子文件夹列表"""
    folder_list = {}
    try:
        url = self._mydisk_url + '?item=files&action=index&folder_node=1&folder_id=' + str(folder_id)
        pattern = r'&nbsp;(.+?)</a>&nbsp;.+folkey\((.+?)\).*(style="display:initial")?.*>(.*)?</font>'
        for k, v, have_key, desc in re.findall(pattern, self._session.get(url).text):
            have_key = True if have_key else False
            desc = desc[1:-1] if desc else ''
            folder_list[k.replace('&amp;', '&')] = [int(v), have_key, desc]  # 文件夹名 : [id, key, desc]
        return folder_list
    except requests.RequestException:
        return {}

文件夹链接判断是否打错了?

user_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/i[a-zA-Z0-9]{7,}/?'

看改动,文件和文件夹两处都是 ...com/i[...,应该是替换错了吧?

同时,这样的链接也是合法的:
http://汉字.hh.s--s.dd.lanzous.com/b0f14h1od
http://a--.lanzous.com/b0f14h1od
非法:
http://--.lanzous.com/b0f14h1od

'https?://(\w[-\w]*\.)?lanzou[six].com/i[a-zA-Z0-9]{7,}/?'

\w 可以匹配到汉字

登录不了

现在登录不了了,需要滑动验证。怎么办?

down_file_by_url相关Bug

不知道是不是蓝奏云又更新了,这三个都是
https://www.lanzous.com/i301ape
https://www.lanzous.com/i31su1i
https://www.lanzous.com/i31tsne

Traceback (most recent call last):
  File "D:\Program Files\Python38\lib\site-packages\lanzou\api\core.py", line 933, in down_file_by_url
    info = self.get_durl_by_url(share_url, pwd)
  File "D:\Program Files\Python38\lib\site-packages\lanzou\api\core.py", line 529, in get_durl_by_url
    file_info = self.get_file_info_by_url(share_url, pwd)
  File "D:\Program Files\Python38\lib\site-packages\lanzou\api\core.py", line 456, in get_file_info_by_url
    para = re.search(r'<iframe.*?src="(.+?)"', first_page).group(1)  # 提取下载页面 URL 的参数
AttributeError: 'NoneType' object has no attribute 'group'

un_serialize增加开关以避免读取特定文件末尾512字节时会导致内存暴涨的问题

问题说明

目前在下载完文件时,如果这个文件大于512字节,会尝试对其末尾512字节使用pickle.loads函数进行解析,如果未曾编码过,在特定文件内容时,这个函数有可能会造成大量调用内存,比如下面这个例子中会占用34G的内存。

示例

示例文件网盘链接:https://fzls.lanzoui.com/iwnVktkr9je
若链接失效,可直接下载附件文件自行上传后得到新的链接

示例代码

lzy = LanZouCloud()
lzy.down_file_by_url("https://fzls.lanzoui.com/iwnVktkr9je")

现象
Snipaste_2021-09-06_00-24-31

修复办法

api/utils.py中增加开关,比如直接复用self._limit_mode,从而在确定不会使用额外编码来绕开官方限制的情况下(不调用ignore_limits的情况下)不会尝试使用pickle解析文件末尾512字节

原来代码

def un_serialize(data: bytes):
    """反序列化文件信息数据"""
    try:
        ret = pickle.loads(data)
        if not isinstance(ret, dict):
            return None
        return ret
    except Exception:  # 这里可能会丢奇怪的异常
        return None

调整后代码

def un_serialize(data: bytes, _limit_mode: bool):
    """反序列化文件信息数据"""
    try:
        if _limit_mode:
            # 不尝试从文件末尾解析额外编码进去的信息
            return None

        ret = pickle.loads(data)
        if not isinstance(ret, dict):
            return None
        return ret
    except Exception:  # 这里可能会丢奇怪的异常
        return None

文件夹上传问题

上传文件夹, 蓝奏盘中确实生成了文件夹, 但是只上传了一个文件后报错. (文件夹中文件全部<100M)

Traceback (most recent call last):
lzy.upload_dir(dirname)
File "/home/ubuntu/.local/lib/python3.8/site-packages/lanzou/api/core.py", line 915, in upload_dir
code = self.upload_file(file_path, dir_id, callback=callback, uploaded_handler=uploaded_handler)
File "/home/ubuntu/.local/lib/python3.8/site-packages/lanzou/api/core.py", line 870, in upload_file
return self._upload_small_file(file_path, folder_id, callback=callback, uploaded_handler=uploaded_handler)
File "/home/ubuntu/.local/lib/python3.8/site-packages/lanzou/api/core.py", line 766, in _upload_small_file
result = self._post('https://pc.woozooo.com/fileup.php', data=monitor, headers=tmp_header, timeout=3600)
File "/home/ubuntu/.local/lib/python3.8/site-packages/lanzou/api/core.py", line 72, in _post
return self._session.post(url, data, verify=False, **kwargs)
File "/home/ubuntu/.local/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/ubuntu/.local/lib/python3.8/site-packages/requests_cache/core.py", line 141, in request
main_key = self.cache.create_key(response.request)
File "/home/ubuntu/.local/lib/python3.8/site-packages/requests_cache/backends/base.py", line 227, in create_key
key.update(_to_bytes(body))
File "/home/ubuntu/.local/lib/python3.8/site-packages/requests_cache/backends/base.py", line 259, in _to_bytes
return bytes(s, encoding)
TypeError: encoding without a string argument

有些界面 文件名匹配不到

比如 https://www.lanzous.com/iat4bpe 这个

get_share_file_info

f_name = re.findall(r'<div style="[^"]+">([^><]*?)</div>', first_page)
if f_name:
    f_name = f_name[0]
else:
    f_name = re.findall(r"var filename = '(.*)';", first_page)[0]

这两个都匹配不到,列表解析直接越界 IndexError: list index out of range

可以这样改:

f_name = re.findall(r'<div style="[^"]+">([^><]*?)</div>', first_page)
if not f_name:
    f_name = re.findall(r"var filename = '(.*)';", first_page)
if not f_name:
    f_name = re.findall(r'<div class="filethetext" id="[^"]*">(.*?)?</div>', first_page)
f_name = f_name[0] if f_name else ""

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.