上傳檔案到「/」
This commit is contained in:
26
GetEnv.js
Normal file
26
GetEnv.js
Normal file
@@ -0,0 +1,26 @@
|
||||
(function() {
|
||||
// 優先尋找 hd 版本,如果沒有則取第一個
|
||||
let source = fs.video.media.src.find(s => s.src.includes('video_hd.mp4')) || fs.video.media.src[0];
|
||||
|
||||
const videoSrc = source.src;
|
||||
const referer = location.href;
|
||||
const cookie = document.cookie;
|
||||
const userAgent = navigator.userAgent;
|
||||
const fileName = (document.title.split('|')[0].trim() || 'video').replace(/[\\/:*?"<>|]/g, '_') + '.mp4';
|
||||
|
||||
const output = `
|
||||
# === 從 GetEnv.js 複製的內容開始 ===
|
||||
url = "${videoSrc}"
|
||||
headers = {
|
||||
"Referer": "${referer}",
|
||||
"User-Agent": "${userAgent}",
|
||||
"Cookie": "${cookie}"
|
||||
}
|
||||
filename = "${fileName}"
|
||||
# === 從 GetEnv.js 複製的內容結束 ===
|
||||
`.trim();
|
||||
|
||||
console.log("%c已產生 Python 配置資訊:", "color: #28a745; font-weight: bold; font-size: 1.2em;");
|
||||
console.log(output);
|
||||
console.log("%c請直接複製上方內容,覆蓋 download.py 的配置區域。", "color: #007bff;");
|
||||
})();
|
||||
47
download.py
Normal file
47
download.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
# ==========================================
|
||||
# 配置區域 (請將 GetEnv.js 的輸出貼在下方)
|
||||
# ==========================================
|
||||
# url = "https://eeclass.yourschool.edu.tw/sysdata/doc/X/XXXXXXXXXXXXXXXXXX/video/video_hd.mp4"
|
||||
# headers = {
|
||||
# "Referer": "https://eeclass.yourschool.edu.tw/media/doc/*",
|
||||
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0",
|
||||
# "Cookie": "PHPSESSID=; accesstoken=; account="
|
||||
# }
|
||||
# filename = "filename.mp4"
|
||||
|
||||
# ==========================================
|
||||
|
||||
def download_video(video_url, req_headers, output_name):
|
||||
print(f"🚀 準備下載: {output_name}")
|
||||
try:
|
||||
response = requests.get(video_url, headers=req_headers, stream=True, timeout=30)
|
||||
|
||||
# 檢查是否 404 或其他錯誤
|
||||
if response.status_code == 404:
|
||||
print("❌ 錯誤: 伺服器回傳 404。可能是該畫質檔案不存在,請試著更換網址。")
|
||||
return
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
total_size = int(response.headers.get('content-length', 0))
|
||||
downloaded = 0
|
||||
|
||||
with open(output_name, "wb") as f:
|
||||
for chunk in response.iter_content(chunk_size=1024*1024):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
if total_size > 0:
|
||||
percent = (downloaded / total_size) * 100
|
||||
print(f"\r📥 進度: {percent:.2f}% ({downloaded/(1024*1024):.1f}MB / {total_size/(1024*1024):.1f}MB)", end="")
|
||||
|
||||
print(f"\n✅ 下載完成!檔案已儲存於: {os.path.abspath(output_name)}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 發生錯誤: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
download_video(url, headers, filename)
|
||||
Reference in New Issue
Block a user