bingsanyu / feishu_minutes Goto Github PK
View Code? Open in Web Editor NEW多线程上传/下载飞书妙记视频&SRT字幕 语音转文字 飞书爬虫
多线程上传/下载飞书妙记视频&SRT字幕 语音转文字 飞书爬虫
批量上传 不行啊 ,下载也挂了. 下载了700个就好了一天,上传没成过.
def upload_blocks(self):
with open(self.file_path, "rb") as f:
f.seek(0)
block_count = (self.file_size + self.block_size - 1) // self.block_size
with ThreadPoolExecutor(max_workers=6) as executor:
completed_threads = []
with tqdm(total=block_count, unit="block") as progress_bar:
for i in range(block_count):
block_data = f.read(self.block_size) # 要求读取的字节数
block_size = len(block_data) # 实际读取的字节数
checksum = zlib.adler32(block_data) % (10**10)
upload_url = f"https://internal-api-space.feishu.cn/space/api/box/stream/upload/block?upload_id={self.upload_id}&seq={i}&size={block_size}&checksum={checksum}"
thread = executor.submit(
requests.post,
upload_url,
headers=self.headers,
proxies=proxies,
data=block_data,
)
completed_threads.append(thread)
for thread in as_completed(completed_threads):
progress_bar.update(1)
其中有这样一行代码:
checksum = zlib.adler32(block_data) % (10**10)
这里adler32函数返回值是一个32位无符号整数,为什么还要取模10的10次方呢?
2^32=4294967296,是小于10^10的,这样的取模结果始终为0。
我昨天脑子肯定是短路了,取模是取余数,不是取商,对10^10取模应该就是32位函数值本身。
def upload_blocks(self):
with open(self.file_path, "rb") as f:
f.seek(0)
block_count = (self.file_size + self.block_size - 1) // self.block_size
with ThreadPoolExecutor(max_workers=6) as executor:
completed_threads = []
with tqdm(total=block_count, unit="block") as progress_bar:
for i in range(block_count):
block_data = f.read(self.block_size) # 要求读取的字节数
block_size = len(block_data) # 实际读取的字节数
checksum = zlib.adler32(block_data) % (10**10)
upload_url = f"https://internal-api-space.feishu.cn/space/api/box/stream/upload/block?upload_id={self.upload_id}&seq={i}&size={block_size}&checksum={checksum}"
thread = executor.submit(
requests.post,
upload_url,
headers=self.headers,
proxies=proxies,
data=block_data,
)
completed_threads.append(thread)
for thread in as_completed(completed_threads):
progress_bar.update(1)
其中有这样一行代码:
checksum = zlib.adler32(block_data) % (10**10)
这里adler32函数返回值是一个32位无符号整数,为什么还要取模10的10次方呢?
2^32=4294967296,是小于10^10的,这样的取模结果始终为0。
hi,前两天跟据你的回复,我恶补了一下网络抓包,学跟着你的代码尝试自己写一个版本,但是我遇到了关于token的问题,源于你在FeishuUploader
的构造函数中编写了这样一个请求头:
self.headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"cookie": cookie,
"bv-csrf-token": cookie[
cookie.find("bv_csrf_token=")
+ len("bv_csrf_token=") : cookie.find(
";", cookie.find("bv_csrf_token=")
)
],
"referer": "https://minutes.feishu.cn/minutes/home",
}
让我疑惑的时这里token的选择,因为我在开发者工具中返回的cookie中还看到了很多不一样的token:_csrf_token, lgw_csrf_token, csrf_token, swp_csrf_token,你选择bv-csrf-token有什么理由吗?
希望得到你的指点!谢谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.