Initial commit

This commit is contained in:
ivamp 2024-02-08 02:22:06 +08:00
commit 900c1efa53
5 changed files with 125 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__
downloads
config.py

3
animes.py Normal file
View File

@ -0,0 +1,3 @@
anime_ids = [
810
]

14
config.py.example Normal file
View File

@ -0,0 +1,14 @@
import os
baseurl = "https://anime-api.5t5.top/v2"
token = "lDr7fxW8tDFoY2CdySoaEs1gCaiA3dUP1GwIe6Khg"
node = "2AG_CF"
save_path="./downloads"
# 处理 save_path(自动获取绝对路径)
save_path = os.path.abspath(save_path)
print("save_path: ", save_path)
def joinpath(dir):
return os.path.join(save_path, dir)

44
get.py Normal file
View File

@ -0,0 +1,44 @@
import config
import animes
import req
import os
def downloadAnime(id, filepath):
print("正在下载到: " + filepath)
episodes = req.get("anime/file", {
"id": id,
"drive": config.node,
})
for episode in episodes:
ext = episode["parseResult"]["extensionName"]["raw"]
filename = os.path.join(filepath, episode["name"] + '.' + ext)
print("正在下载: " + episode["name"])
req.download(episode["url"], filename)
for anime in animes.anime_ids:
print("正在查询: " + str(anime))
a = req.get("anime/get", {
"id": "810",
"full": "true"
})
name = a["name"]
name_cn = a["name_cn"]
fullname = name_cn + " - " + name
# create dir
dir_path = config.joinpath(fullname)
print(dir_path)
# 检测文件夹是否存在
if not os.path.exists(dir_path):
# mkdir
os.mkdir(dir_path)
# 开始下载
downloadAnime(anime, dir_path)

61
req.py Normal file
View File

@ -0,0 +1,61 @@
import requests
import config
from urllib import parse
import sys
import os
# 屏蔽warning信息
requests.packages.urllib3.disable_warnings()
hello=parse.quote("想保存番剧但是怕你觉得麻烦就没找你要 WebDav 了 qxq")
headers={
"Authorization": config.token,
"Referer": "https://lavani.me/",
"iVampireSPcom": hello
}
def get(url, params):
resp = requests.get(
config.baseurl + "/" + url,
headers=headers,
params=params
)
# json
return resp.json()["data"]
def download(url, file_path):
# 第一次请求是为了得到文件总大小
r1 = requests.get(url, stream=True, verify=False)
total_size = int(r1.headers['Content-Length'])
# 这重要了,先看看本地文件下载了多少
if os.path.exists(file_path):
temp_size = os.path.getsize(file_path) # 本地已经下载的文件大小
else:
temp_size = 0
# 显示一下下载了多少
print(temp_size)
print(total_size)
# 核心部分,这个是请求下载时,从本地文件已经下载过的后面下载
headers = {'Range': 'bytes=%d-' % temp_size}
# 重新请求网址,加入新的请求头的
r = requests.get(url, stream=True, verify=False, headers=headers)
# 下面写入文件也要注意,看到"ab"了吗?
# "ab"表示追加形式写入文件
with open(file_path, "ab") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
temp_size += len(chunk)
f.write(chunk)
f.flush()
###这是下载实现进度显示####
done = int(50 * temp_size / total_size)
sys.stdout.write("\r[%s%s] %d%%" % ('' * done, ' ' * (50 - done), 100 * temp_size / total_size))
sys.stdout.flush()
print() # 避免上面\r 回车符