בגלל המגבלה של 50 מ''ב ההעלאה לapi - עשיתי את הפיצול של הקבצים כדי שמעלה גם קבצים גדולים.
משום מה זה עובד לי רק בקבצים של 70-80 מ''ב,
אבל קבצים גדולים יותר הוא מעלה לשלוחה קובץ תקול.
זה הקוד שעשיתי, אשמח מאוד אם מישהו יוכל לבדוק אם יש לי כאן טעות
def upload_to_ymot(file_path):
file_size = os.path.getsize(file_path)
if file_size <= 50 * 1024 * 1024:
# 🔹 העלאה רגילה
with open(file_path, "rb") as f:
files = {"file": (os.path.basename(file_path), f, "audio/wav")}
data = {
"token": YMOT_TOKEN,
"path": YMOT_PATH,
"convertAudio": "1",
"autoNumbering": "true"
}
response = requests.post(UPLOAD_URL, data=data, files=files)
print("📞 תגובת ימות:", response.text)
else:
# 🔹 Chunk Upload
qquuid = str(uuid.uuid4())
total_parts = math.ceil(file_size / CHUNK_SIZE)
filename = os.path.basename(file_path)
with open(file_path, "rb") as f:
for part_index in range(total_parts):
chunk = f.read(CHUNK_SIZE)
byte_offset = part_index * CHUNK_SIZE
files = {"qqfile": (filename, chunk, "application/octet-stream")}
data = {
"token": YMOT_TOKEN,
"path": YMOT_PATH,
"convertAudio": "1",
"autoNumbering": "true",
"qquuid": qquuid,
"qqpartindex": part_index, # מתחיל מ-0
"qqpartbyteoffset": byte_offset,
"qqchunksize": len(chunk),
"qqtotalparts": total_parts, # סה"כ חלקים (לא פחות 1)
"qqtotalfilesize": file_size,
"qqfilename": filename,
"uploader": "yemot-admin"
}
response = requests.post(UPLOAD_URL, data=data, files=files)
print(f"⬆️ חלק {part_index+1}/{total_parts} הועלה:", response.text)
# 🔹 בקשת סיום
data = {
"token": YMOT_TOKEN,
"path": YMOT_PATH,
"convertAudio": "1",
"autoNumbering": "true",
"qquuid": qquuid,
"qqfilename": filename,
"qqtotalfilesize": file_size,
"qqtotalparts": total_parts
}
response = requests.post(UPLOAD_URL + "?done", data=data)
print("✅ סיום העלאה:", response.text)