Spaces:
Running
Running
Update watcher.py
Browse files- watcher.py +43 -1
watcher.py
CHANGED
|
@@ -351,6 +351,47 @@ def send_to_channel(text):
|
|
| 351 |
)
|
| 352 |
res.raise_for_status()
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
# ===== Main =====
|
| 355 |
def main():
|
| 356 |
processed_messages = set() # 処理済みメッセージを追跡
|
|
@@ -475,9 +516,10 @@ def main():
|
|
| 475 |
nonce
|
| 476 |
)
|
| 477 |
send_to_channel(f"<link type=\"url\" value=\"{merged_url}\">{q}p 結合済み動画</link>")
|
|
|
|
|
|
|
| 478 |
except Exception as e:
|
| 479 |
send_to_channel(f"結合失敗: {e}")
|
| 480 |
-
|
| 481 |
send_to_channel("完了しました!")
|
| 482 |
processed_messages.add(latest_msg["id"])
|
| 483 |
|
|
|
|
| 351 |
)
|
| 352 |
res.raise_for_status()
|
| 353 |
|
| 354 |
+
|
| 355 |
+
def upload_file_to_channel(file_url):
|
| 356 |
+
# mp4バイナリ取得
|
| 357 |
+
file_res = requests.get(file_url, timeout=60)
|
| 358 |
+
file_res.raise_for_status()
|
| 359 |
+
|
| 360 |
+
upload_url = "https://media.channel.io/cht/v1/pri-file/200605/groups/519217/message/send_yt_video_file.mp4"
|
| 361 |
+
|
| 362 |
+
files = {
|
| 363 |
+
"file": ("video.mp4", file_res.content, "video/mp4")
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
headers = {
|
| 367 |
+
"x-account": X_ACCOUNT,
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
res = requests.post(upload_url, headers=headers, files=files, timeout=60)
|
| 371 |
+
res.raise_for_status()
|
| 372 |
+
|
| 373 |
+
return res.json() # ←これを messages POST の body.files に入れる
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def send_video_message(file_json):
|
| 377 |
+
request_id = f"desk-web-{int(time.time() * 1000)}"
|
| 378 |
+
|
| 379 |
+
payload = {
|
| 380 |
+
"requestId": request_id,
|
| 381 |
+
"blocks": [
|
| 382 |
+
{"type": "text", "value": "プレビュー:"}
|
| 383 |
+
],
|
| 384 |
+
"files": [file_json], # ←ここが重要!
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
res = requests.post(
|
| 388 |
+
POST_URL,
|
| 389 |
+
headers=HEADERS_POST,
|
| 390 |
+
data=json.dumps(payload),
|
| 391 |
+
timeout=30
|
| 392 |
+
)
|
| 393 |
+
res.raise_for_status()
|
| 394 |
+
|
| 395 |
# ===== Main =====
|
| 396 |
def main():
|
| 397 |
processed_messages = set() # 処理済みメッセージを追跡
|
|
|
|
| 516 |
nonce
|
| 517 |
)
|
| 518 |
send_to_channel(f"<link type=\"url\" value=\"{merged_url}\">{q}p 結合済み動画</link>")
|
| 519 |
+
file_json = upload_file_to_channel(merged_url)
|
| 520 |
+
send_video_message(file_json)
|
| 521 |
except Exception as e:
|
| 522 |
send_to_channel(f"結合失敗: {e}")
|
|
|
|
| 523 |
send_to_channel("完了しました!")
|
| 524 |
processed_messages.add(latest_msg["id"])
|
| 525 |
|