1
Telegram documentation電報API文件說,以下有關文件ID:上傳
文件的二進制內容,然後分成幾部分。所有部件必須 具有相同的尺寸(part_size)和下列條件必須 滿足:
part_size%1024 = 0(整除1KB)
524288%part_size = 0(512KB必須是整除part_size)
只要 大小小於part_size,最後一部分不一定要滿足這些條件。每個部分應該有一個序列號, file_part,值範圍從0到2,999。
我的代碼:
def check_conditions(file_name):
b = False
file_binary_data = open("D:\\" + file_name, "br").read()
length = len(bytearray(file_binary_data))
print(file_name + ", size: " + str(length) + " bytes")
for i in range(1, 3000):
part = length // i
if part % 1024 == 0 and 524288 % part == 0:
print("i: " + str(i) + " | part size: " + str(part))
b = True
if not b:
print("No mathces")
print()
check_conditions("The White Stripes - Truth Doesn't Make A Noise.mp3")
check_conditions("Depeche Mode - Precious.mp3")
check_conditions("Placebo - Meds.mp3")
輸出:
The White Stripes - Truth Doesn't Make A Noise.mp3, size: 7782220 bytes
No mathces
Depeche Mode - Precious.mp3, size: 10298248 bytes
i: 1257 | part size: 8192
i: 2514 | part size: 4096
Placebo - Meds.mp3, size: 11808625 bytes
No mathces
哪裏錯了嗎?或者如果一切正常,如何處理不符合的文件?