当前位置: 首页> 健康> 美食 > 阿里云盘分享文件无会员保存方法

阿里云盘分享文件无会员保存方法

时间:2025/8/27 13:32:23来源:https://blog.csdn.net/leoxow/article/details/142314960 浏览次数:0次

阿里云盘分享文件无会员保存方法

  • 背景
  • 代码

背景

阿里云盘分享一次保存大量文件是需要会员的,咱没有,又想节省8块钱成本,只好自己动手了,逻辑比较简单,代码如下,谨慎使用,比较阿里云盘要挣钱,用的频繁了,肯定会被修改的

代码

# -*- coding: utf-8 -*-
#阿里云批量保存程序
import requests
import json
import time
authorization = ""
share_token = ''
device_id = ''def get_file_list(share_id, parent_file_id, marker=None):url = "https://api.aliyundrive.com/adrive/v2/file/list_by_share"payload = {"share_id": share_id,"parent_file_id": parent_file_id,"limit": 40,"image_thumbnail_process": "image/resize,w_256/format,jpeg","image_url_process": "image/resize,w_1920/format,jpeg/interlace,1","video_thumbnail_process": "video/snapshot,t_1000,f_jpg,ar_auto,w_256","order_by": "name","order_direction": "DESC"}if marker:payload["marker"] = markerheaders = {'accept': 'application/json, text/plain, */*','content-type': 'application/json','origin': 'https://www.aliyundrive.com','referer': 'https://www.aliyundrive.com/','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36','x-canary': 'client=web,app=share,version=v2.3.1','x-device-id': device_id,'x-share-token': share_token}response = requests.post(url, headers=headers, json=payload)return json.loads(response.text)def copy_file(file_id, share_id, to_parent_file_id, to_drive_id):url = "https://api.aliyundrive.com/adrive/v4/batch"payload = {"requests": [{"body": {"file_id": file_id,"share_id": share_id,"auto_rename": True,"to_parent_file_id": to_parent_file_id,"to_drive_id": to_drive_id},"headers": {"Content-Type": "application/json"},"id": "0","method": "POST","url": "/file/copy"}],"resource": "file"}headers = {'accept': 'application/json, text/plain, */*','authorization': authorization,'content-type': 'application/json','origin': 'https://www.aliyundrive.com','referer': 'https://www.aliyundrive.com/','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36','x-canary': 'client=web,app=share,version=v2.3.1','x-device-id': device_id,'x-share-token': share_token}response = requests.post(url, headers=headers, json=payload)return json.loads(response.text)def main(share_id, parent_file_id, to_parent_file_id, to_drive_id):response_data = get_file_list(share_id, parent_file_id)if 'items' in response_data:for item in response_data['items']:file_id = item['file_id']print(f"处理文件: {file_id}")sub_files = get_file_list(share_id, file_id)for sub_item in sub_files.get('items', []):sub_file_id = sub_item['file_id']copy_result = copy_file(sub_file_id, share_id, to_parent_file_id, to_drive_id, authorization)print(f"复制文件结果: {copy_result}")time.sleep(2)time.sleep(5)else:print("未找到文件列表")if __name__ == "__main__":#分享idshare_id = ""#分享文件idparent_file_id = ""#保存路径to_parent_file_id = "" #自己账号的device_idto_drive_id = ""main(share_id, parent_file_id, to_parent_file_id, to_drive_id)
关键字:阿里云盘分享文件无会员保存方法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: