Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
moyada committed Feb 5, 2024
1 parent 8a6b0c7 commit 6a3ed03
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 162 deletions.
90 changes: 45 additions & 45 deletions core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,51 +64,51 @@ def download_header(cls) -> dict:
"user-agent": config.user_agent
}

@classmethod
def download(cls, url: str) -> HttpResponse:
"""
下载视频
:param url:
:return:
"""
result = cls.fetch(url)
if result.is_success():
name = cls.index(url) + '.mp4'
url = result.get_data()
data = json.dumps({'name': name, 'url': url})
return HttpResponse(data)
return HttpResponseServerError(result.get_data())

@classmethod
def proxy_download(cls, vtype, url, header: dict, extra: str, mode=1) -> HttpResponse:
# 检查文件
index = cls.index(url)
file, filename = store.find(vtype, index, extra)
if file is not None:
return Service.stream(file, filename)

result = cls.fetch(url, mode=mode)
if not result.is_success():
return HttpResponseServerError(result.get_data())

if mode == 1:
header = header.copy()
header['referer'] = result.ref

if result.is_image():
res = store.save_image(vtype, result.get_data(), index)
if res is not None:
return res
else:
res = http_utils.get(url=result.get_data(), header=header)
if http_utils.is_error(res):
return HttpResponseServerError(str(res))

store.save(vtype, res, index, result.extra)
res.close()

file, filename = store.find(vtype, index, result.extra)
return Service.stream(file, filename)
# @classmethod
# def download(cls, url: str) -> HttpResponse:
# """
# 下载视频
# :param url:
# :return:
# """
# result = cls.fetch(url)
# if result.is_success():
# name = cls.index(url) + '.mp4'
# url = result.get_data()
# data = json.dumps({'name': name, 'url': url})
# return HttpResponse(data)
# return HttpResponseServerError(result.get_data())
#
# @classmethod
# def proxy_download(cls, vtype, url, header: dict, extra: str, mode=1) -> HttpResponse:
# # 检查文件
# index = cls.index(url)
# file, filename = store.find(vtype, index, extra)
# if file is not None:
# return Service.stream(file, filename)
#
# result = cls.fetch(url, mode=mode)
# if not result.is_success():
# return HttpResponseServerError(result.get_data())
#
# if mode == 1:
# header = header.copy()
# header['referer'] = result.ref
#
# if result.is_image():
# res = store.save_image(vtype, result.get_data(), index)
# if res is not None:
# return res
# else:
# res = http_utils.get(url=result.get_data(), header=header)
# if http_utils.is_error(res):
# return HttpResponseServerError(str(res))
#
# store.save(vtype, res, index, result.extra)
# res.close()
#
# file, filename = store.find(vtype, index, result.extra)
# return Service.stream(file, filename)

@classmethod
def complex_download(cls, info: Info):
Expand Down
49 changes: 0 additions & 49 deletions service/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,55 +113,6 @@ def get_info(cls, url: str) -> Result:
# info.extra = extra
return Result.success(info)

@classmethod
def fetch(cls, url: str, mode=0) -> Result:
url = cls.get_url(url)
if url is None:
return ErrorResult.URL_NOT_INCORRECT

# https://api.bilibili.com/pgc/view/web/season?ep_id=280787
# result > episodes > foreach > bvid

# 请求短链接,获得itemId
res = http_utils.get("https://api.bilibili.com/pgc/view/web/season?ep_id=280787", header=headers)
if http_utils.is_error(res):
return Result.error(res)

data = json.loads(res.content)

bvid = ""
cid = None

for e in data["result"]["episodes"]:
if e["ep_id"] == 280787:
bvid = e["bvid"]
cid = e["cid"]

# http://api.bilibili.com/x/player/playurl?cid=227539569&bvid=BV1cD4y1m7ce&qn=112&fnval=16
res = http_utils.get('http://api.bilibili.com/x/player/playurl',
param={
'cid': cid,
'bvid': bvid,
'qn': 112,
'fnval': 0,
'fnver': 0,
'fourk': 1,
}, header=user_headers)
if http_utils.is_error(res):
return Result.error(res)

data = json.loads(res.content)

try:
url = data['data']['durl'][0]['url']
except (KeyError, IndexError):
return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT

result = Result.success(url)
if mode != 0:
result.ref = res.url
return result

@classmethod
def download_header(cls) -> dict:
return download_headers
Expand Down
3 changes: 0 additions & 3 deletions service/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,18 @@ class BiliBiliService(Service):

@classmethod
def get_url(cls, text: str) -> Optional[str]:
print(text)
if "bilibili" in text:
urls = re.findall(r'(?<=www\.bilibili\.com\/video\/).+', text, re.I | re.M)
if urls:
return "https://www.bilibili.com/video/" + urls[0]
return None

urls = re.findall(r'(?<=b23\.tv\/)\w+', text, re.I | re.M)
print(urls)
if len(urls) == 0:
return None
url = "https://b23.tv/" + urls[0]
res = http_utils.get(url, header=headers, redirect=False)
url = res.headers['location']
print(url)
return url

# @classmethod
Expand Down
9 changes: 5 additions & 4 deletions service/douyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ def get_info(cls, url: str) -> Result:
info.desc = DouyinService.get_desc(data)
info.cover = DouyinService.get_cover(data)

if data['aweme_type'] == 0:
info.video = DouyinService.get_video(data)
info.filename = data['aweme_id'] + ".mp4"
else:
# if data['aweme_type'] is not 0:
if data['images'] is not None :
info.images = DouyinService.get_image(data)
info.filename = data['aweme_id'] + ".zip"
else:
info.video = DouyinService.get_video(data)
info.filename = data['aweme_id'] + ".mp4"

return Result.success(info)

Expand Down
31 changes: 0 additions & 31 deletions service/pipixia.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,6 @@ def get_info(cls, url: str) -> Result:
info.video = url
return Result.success(info)

@classmethod
def fetch(cls, url: str, mode=0) -> Result:
url = cls.get_url(url)
if url is None:
return ErrorResult.URL_NOT_INCORRECT

res = http_utils.get(url, header=headers)
if http_utils.is_error(res):
return Result.error(res)

try:
id = re.findall(r"(?<=item\/)(\d+)(?=\?)", res.url)[0]
except IndexError:
return Result.failed(res.reason)

url = "https://h5.pipix.com/bds/webapi/item/detail/?item_id=" + id + "&source=share"

info_res = http_utils.get(url, header=share_headers)
if http_utils.is_error(info_res):
return Result.error(info_res)

data = json.loads(str(info_res.text))

try:
video = data['data']['item']['video']
url = cls.get_video(video)
except (KeyError, IndexError):
return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT

return Result.success(url)

@staticmethod
def get_video(video: dict) -> Optional[str]:
if video['video_download'] is not None:
Expand Down
24 changes: 0 additions & 24 deletions service/xigua.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,3 @@ def get_prefix_pattern(cls) -> str:
def make_url(cls, index) -> str:
return 'https://www.ixigua.com/' + index

@classmethod
def fetch(cls, url: str, mode=0) -> Result:
url = cls.get_url(url)
if url is None:
return ErrorResult.URL_NOT_INCORRECT

# 请求短链接,获得itemId和dytk
res = http_utils.get(url, header=headers)
if http_utils.is_error(res):
return Result.error(res)

html = str(res.content)
url = re.findall(r"(?<=type=\"video\/mp4\" src=\")(.*?)(?=\")", html)[0]
if not url:
return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT

result = Result.success(url)
if mode != 0:
result.ref = res.url
return result

@classmethod
def download(cls, url) -> HttpResponse:
return cls.proxy_download(vtype, url, download_headers, ".mp4")
7 changes: 1 addition & 6 deletions tools/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from requests import Response

from core import config
from tools import terminal, system, http_utils
from tools import http_utils
from core.type import Video

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -72,8 +72,3 @@ def save(vtype: Video, res: Response, index: str, extra: str) -> str:
file.close()

return filename
# if system.is_mac():
# command = 'md5 -q'
# else:
# command = 'md5sum'
# logger.info(terminal.run_cmd('sh video/remd5.sh {} {}'.format(command, filename)))

0 comments on commit 6a3ed03

Please sign in to comment.