阿里云盘上传脚本

Overview

阿里云盘上传脚本

如有侵权,请联系我删除

禁止用于非法用途,违者后果自负

环境要求

  • python3

使用方法

安装

git clone https://github.com/Hidove/aliyundrive-uploader.git
cd aliyundrive-uploader
pip install -r requirements.txt

如果执行pip install时提示-bash: pip: command not found 就是pip命令没有安装,执行下方命令安装即可,然后再执行即可

wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
  • 重命名example.config.jsonconfig.json
  • 填写好config.json的内容

{
  "REFRESH_TOKEN": "refresh_token",
  "DRIVE_ID": "drive_id",
  "ROOT_PATH": "网盘目录",
  "FILE_PATH": "D:\\Pictures\\",
  "MULTITHREADING": false,
  "MAX_WORKERS": 5,
  "CHUNK_SIZE": 104857600
}
参数 注释
REFRESH_TOKEN 阿里云盘刷新的token
DRIVE_ID 阿里云盘驱动ID,目前不知道做何使用的,可能后续官方有新想法吧
ROOT_PATH 阿里云盘目录 我的照片
FILE_PATH 文件夹目录,填写绝对路径 D:\Pictures\
MULTITHREADING 是否启用多线程 true/false
MAX_WORKERS 线程池最大线程数,请根据自己机器填写 5
CHUNK_SIZE 分块上传大小,请根据自己机器填写,单位:字节 104857600
RESUME 断点续传,分块续传 true/false

运行

chmod +x main.py

多文件上传

python3 main.py
python3 main.py /www/wwwroot/download/

单文件上传

python3 main.py /www/lixiaoen.jpg

更新

cd ~/aliyundrive-uploader
git fetch --all 
git reset --hard origin/master 
git pull

文件解读

  • config.json
    • 脚本配置文件
  • task.json
    • 脚本上传任务记录文件
  • /log
    • 脚本执行记录

支持

觉得写得不错可以给我打赏哦

Comments
  • 上传文件时报错

    上传文件时报错

    {"code":"InvalidParameter.ContentHash","message":"The input parameter content_hash is not valid. file content hash is not matched with content_hash in complete file request"}

    opened by gifyic 12
  • 开始上传后报错

    开始上传后报错

    检索目录中 目录id获取成功60898fee4524df8614d74fa6a9df689e35b4ea0a 正在上传: 1%|1 | 53.0M/6.84G [00:30<1:06:53, 1.82MB/s] Traceback (most recent call last): File "/root/aliyundrive-uploader/main.py", line 137, in if res.result(): File "/usr/lib/python3.9/concurrent/futures/_base.py", line 438, in result return self.__get_result() File "/usr/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result raise self._exception File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/root/aliyundrive-uploader/main.py", line 61, in upload_file drive.upload(upload_url) File "/root/aliyundrive-uploader/AliyunDrive.py", line 117, in upload res.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://bj29.cn-beijing.data.alicloudccp.com/xYBXOEkb%2F69848%2F608991ae51a2863ccd5b466b8bf84ab711c83d46%2F608991ae11f21bbc22964fbbaf08e0f2fca9d24f?Expires=1619632062&OSSAccessKeyId=LTAIsE5mAn2F493Q&Signature=IUxxWsQ36QnVxA0W%2FnwWESNHsfs%3D&partNumber=1&uploadId=658982D766A74E5AB6BB7D64A564C38C

    opened by zsbai 9
  • 能加断点续传吗?

    能加断点续传吗?

    我一个1G的文件从Ubuntu 20.04服务器上传到阿里云网盘老是出错,每次都有重新开始传,错误提示:

    pipes-presentation-20210423.mp4正在校检文件中,耗时与文件大小有关 文件名:11-pipes-presentation-20210423.mp4 hash:4817bcc8425ac8be2264ff379887a64b0f46e661 文件大小:1134460273 文件路径:youtube/11-pipes-presentation-20210423.mp4

    检索目录中 目录id获取成功6073f804da645896ab184012afdfd4e0c7fe9ab3 Traceback (most recent call last): File "main.py", line 137, in if res.result(): File "/usr/lib/python3.8/concurrent/futures/_base.py", line 432, in result return self.__get_result() File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result raise self._exception File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "main.py", line 61, in upload_file drive.upload(upload_url) File "/root/aliyundrive-uploader/AliyunDrive.py", line 117, in upload res.raise_for_status() File "/usr/local/lib/python3.8/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://bj29.cn-beijing.data.alicloudccp.com/4oW5G1mH%2F27564%2F6088ab6af27e6944c74c4b0aa509838b6182e85d%2F6088ab6a58520b3afd2b480a8a7b020fa7df8982?Expires=1619573114&OSSAccessKeyId=LTAIsE5mAn2F493Q&Signature=xEewGJ4QSlF1Ir8u7%2Bd0biuKyp4%3D&partNumber=1&uploadId=BD00C9F4C9CF4E2B8C71C5620236BB42

    opened by ddfiberglass 7
  • 是否可以跳过文件校检(哈希),直接上传

    是否可以跳过文件校检(哈希),直接上传

    现在上传文件前都需要检查文件哈希值,如果云端存在该文件,就会秒传。

    我会打包并加密上传的照片,因此每个文件必定是独一无二的,因此希望直接跳过哈希计算,直接上传。

    由于每次会上传数百G的文件,浪费CPU也浪费电,浪费煤炭,产生二氧化碳,污染环境。。。(喂扯远了。。)

    希望能稍微增加一个配置选项。谢谢!

    opened by lesca 5
  • 关于应用性能的建议

    关于应用性能的建议

    建议重写ACCESS_TOKEN管理服务

    • Aliyundrive当前阶段ACCESS_TOKEN约每2h刷新一次,而本项目关于ACCESS_TOKEN管理方案似乎并不科学。

    • 大概看了一下源码,本人认为本项目的ACCESS_TOKEN处于欠初始化状态。配置文件中只要求开发者(首次)手动获取DRIVE_IDREFRESH_TOKEN(然而完全可以手动初始化ACCESS_TOKEN因为它们就隔了一行,如README中的截图所示),于是程序运行后(无论ACCESS_TOKEN是否真的失效),都会在上传任务正式开始前被重新更新一次,并且在后续长段时间内子线程通过强竞争的方式进行”倒计时600s被动更新ACCESS_TOKEN“的任务。

    • 这会引发一系列难以应付的问题,check_auth()被放置在如“新建网盘目录”等多个核心业务当中。当用户配置多线程下载大量(指向目录的)小文件时,每个“分发线程”都会执行一次ACCESS_TOKEN更新请求。

    • 此外,ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())在 3.5 版本后,如果 max_workers 为 None 或没有指定,将默认为机器处理器的个数而非1;在3.8版本后则默认启动至少5个核心线程min(32, os.cpu_count() + 4),所以我们可能消耗了成倍的资源的去”计算“更新时间,程序也会在某个时间点频繁更新权限出现“绊脚”的情况。

    建议使用 Coroutine-Pool 多路复用协程池管理任务队列

    使用通信共享内存,而不是使用内存通信。

    本项目中写满了子线程的竞争行为,这在批量传输小文件时将带来极大的性能损耗。可以使用gevent等优秀的协程框架处理密集I/O业务,在虚拟线程阻塞时让出资源,也能更加方便地管理事务回滚以及标记异常实例。

    opened by QIN2DIM 4
  • 后台运行机制代码存在bug

    后台运行机制代码存在bug

    Client.py文件中,第77行判断是否有后台运行参数时,如果存在,立刻删除会导致后面数组访问越界,原始代码如下。

    77 def init_command_line_parameter(self): 78 for k in range(len(sys.argv)): 79 if sys.argv[k] == '--resident' or sys.argv[k] == '-r': 80 DATA['config']['RESIDENT'] = True 81 del sys.argv[k]

    报错情况为: Traceback (most recent call last): File "/root/aliyundrive-uploader-master/main.py", line 26, in client.init_command_line_parameter() File "/root/aliyundrive-uploader-master/Client.py", line 77, in init_command_line_parameter if sys.argv[k] == '--resident' or sys.argv[k] == '-r': IndexError: list index out of range

    修改建议,增加标识位,for循环后再删除,如 label = -1 for k in range(len(sys.argv)): if sys.argv[k] == '--resident' or sys.argv[k] == '-r': DATA['config']['RESIDENT'] = True label = k if label>-1: del sys.argv[label]

    bug 
    opened by Nuaalzy 4
  • 上传中出现错误

    上传中出现错误

    win10 编译版本

    Traceback (most recent call last): File "main.py", line 51, in File "common.py", line 161, in print_info File "common.py", line 208, in log UnicodeEncodeError: 'gbk' codec can't encode character '\u200b' in position 69: illegal multibyte sequence

    [4044] Failed to execute script 'main' due to unhandled exception!

    opened by seeblog 2
  • 这种报错能否跳过,程序停下来了。

    这种报错能否跳过,程序停下来了。

    正在上传【0138 - 五一假期带孩子出去玩怎么拍美美的亲子照?.mp4】: 100MB [00:00, ?B/s] {'code': 'InvalidParameter.ContentHash', 'message': 'The input parameter content_hash is not valid. file content hash is not matched with content_hash in complete file request'}

    opened by luolovehk 2
  • Update common.py

    Update common.py

    优化大文件,添加从文件读取sha1。

    超过1T的文件,由于上传太长,上传过程中会出现上传地址失效的情况。这时如果重新上传,会再次计算sha1,然而每次计算sha1都会花费好几个小时,因此添加了这个功能。 实现比较简单,也没有考虑太多异常情况,希望作者在此基础上优化一下。这个功能对于大文件来说至关重要!感谢作者! PS: 尝试了rclone/WebDAV和其他的API后,发现这个工具是最棒的,真心感谢!

    opened by ihobin 2
  • 无法使用绝对路径上传

    无法使用绝对路径上传

    image

    单文件上传如果是传入绝对路径参数,config里的FILE_PATH为空时会出现如图的报错,文件路径变成了脚本的运行目录,如果将FILE_PATH改成文件路径就能正常上传

    所以这个FILE_PATH有什么作用吗,能否直接通过传入的路径参数修改该值?如果每次上传都要填一遍FILE_PATH岂不是很麻烦

    opened by auqhjjqdo 2
  • 建议增加日志功能

    建议增加日志功能

    首先非常感谢作者的无私分享,这个项目相当实用好用,我也非常有需求。相比Rclone机械性的上传,这个项目最大优势是支持秒传,我现在主要是利用qbittorrent下载完成后调用这个项目上传下载完的文件至阿里云盘,由于该过程均在VPS后台运行,故希望增加日志功能,便于时候查看上传的具体情况,最后再次致敬!

    opened by xiatao 1
Releases(v2.2.1)
Owner
Hidove
Hidove
Nowadays we don't have time to listen to each and every song that we come across in a playlist.

Nowadays we don't have time to listen to each and every song that we come across in a playlist. so, this project helps you. we used Spotify API for collecting the dataset information and able to do E

3 Apr 26, 2022
A pypi package that helps in generating discord bots.

A pypi package that helps in generating discord bots.

KlevrHQ 3 Nov 17, 2021
A GitHub Follower Bot that is a WIP.

GitHub Follower Bot (WIP) Work In Progress This bot is a WIP. There are still many features I plan to add and code I need to improve (I'm still fairly

Christian Deacon 71 Dec 29, 2022
WatonAPI is an API used to connect to spigot servers with the WatonPlugin to communicate.

WatonAPI is an API used to connect to spigot servers with the WatonPlugin to communicate. You can send messages to the server and read messages, making it useful for cross-chat programs.

Waton 1 Nov 22, 2021
SSH-Restricted deploys an SSH compliance rule (AWS Config) with auto-remediation via AWS Lambda if SSH access is public.

SSH-Restricted SSH-Restricted deploys an SSH compliance rule with auto-remediation via AWS Lambda if SSH access is public. SSH-Auto-Restricted checks

Adrian Hornsby 30 Nov 08, 2022
A telegram bot that messages you available vaccine appointments in the Veneto region

Serenissimo, domande frequenti Chi sei? Sono Alberto Granzotto, libero professionista a Berlino. Mi occupo di servizi software, privacy, decentralizza

vrde 31 Sep 30, 2022
A Telegram Bot That Provides Permanent Download Links For Sent Files.

FileStreamBot A Telegram bot to all media and documents files to web link . Report a Bug | Request Feature Demo Bot: 🍁 About This Bot : This bot will

Flux Inc. 1 Nov 02, 2021
Python script using Twitter API to change user banner to see 100DaysOfCode process.

100DaysOfCode - Automatic Banners 👩‍💻 Adds a number to your twitter banner indicating the number of days you have in the #100DaysOfCode challenge Se

Ingrid Echeverri 10 Jul 06, 2022
The Most advanced and User-Friendly Google Collab NoteBook to download Torrent directly to Google Drive with File or Magnet Link support and with added protection of Timeout Preventer.

Torrent To Google Drive (UI Added! 😊 ) A Simple and User-Friendly Google Collab Notebook with UI to download Torrent to Google Drive using (.Torrent)

Dr.Caduceus 33 Aug 16, 2022
Space Bot, a Discord bot built for HackerSpace Club of PES University

Space Bot Space Bot, a Discord bot built for HackerSpace Club of PES University What can Space Bot do? Space Bot allows you to lookup any mentor or to

HackerSpace @PESU 7 Oct 23, 2022
A tool to customize your discord tokens

Fastest Discord Token Manager - Features: Change Token Username Change Token Password Change Token Avatar Change Token Bio This tool is created by Ace

trey 15 Dec 27, 2022
A Python AWS Lambda Webhook listener that generates a permanent URL when an asset is created in Contentstack.

Webhook Listener A Python Lambda Webhook Listener - Generates a permanent URL on created assets. See doc on Generating a Permanent URL: https://www.co

Contentstack Solutions 1 Nov 04, 2021
Discord.py Bot Series With Python

Discord.py Bot Series YouTube Playlist: https://www.youtube.com/playlist?list=PL9nZZVP3OGOAx2S75YdBkrIbVpiSL5oc5 Installation pip install -r requireme

Step 1 Dec 17, 2021
A website application running in Google app engine, deliver rss news to your kindle. generate mobi using python, multilanguages supported.

Readme of english version refers to Readme_EN.md 简介 这是一个运行在Google App Engine(GAE)上的Kindle个人推送服务应用,生成排版精美的杂志模式mobi/epub格式自动每天推送至您的Kindle或其他邮箱。 此应用目前的主要

2.6k Jan 06, 2023
A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

22 Dec 26, 2022
A stable and Fast telegram video convertor bot which can compress, convert(video into audio and other video formats), rename with permanent thumbnail and trim.

ᴠɪᴅᴇᴏ ᴄᴏɴᴠᴇʀᴛᴏʀ A stable and Fast telegram video convertor bot which can compress, convert(video into audio and other video formats), rename and trim.

Mahesh Chauhan 183 Jan 04, 2023
A Telegram Bot to display Codeforces Contest Ranklist

CFRankListBot A bot that displays the top ranks for a Codeforces contest. Participants' Details All the details of a participant is in the utils/__ini

Code IIEST 5 Dec 25, 2021
📷 An Instagram bot written in Python using Selenium on Google Chrome

📷 An Instagram bot written in Python using Selenium on Google Chrome. It will go through posts in hashtag(s) and like and comment on them.

anniedotexe 47 Dec 19, 2022
This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. If you like this project please consider donating via brave. Thanks.

This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. The bot f

Andrei 157 Dec 15, 2022