Skip to content

Commit

Permalink
fix: 公开站点修复
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuan0213 committed Apr 3, 2024
1 parent 3e196f6 commit 3ec6b88
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 70 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
1. 复制令牌到 nas-tools 站点维护
2. 添加请求头参数 格式:{"x-api-key": "xxxx"}

### 开启公开站点

在 config.yaml 的 laboratory 添加 ```show_more_sites: true```

### Docker 镜像地址:

Expand Down
7 changes: 1 addition & 6 deletions app/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,7 @@ def __download_fail(msg):
return None, None, "下载链接为空"
# 获取种子内容,磁力链不解析
if url.startswith("magnet:"):
file_dir = Config().get_temp_path()
torrent_file, retmsg = Torrent().magent2torrent(url, file_dir)
if not torrent_file:
return {"code": -1, "msg": f"下载种子文件失败: {retmsg}"}
url = os.path.basename(torrent_file)
content, dl_files_folder, dl_files, retmsg = Torrent().read_torrent_content(torrent_file)
content = url
else:
# 获取Cookie和ua等
site_info = self.sites.get_sites(siteurl=url)
Expand Down
18 changes: 15 additions & 3 deletions app/indexer/client/_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def setparam(self, indexer,
self.category = indexer.category
self.list = indexer.torrents.get('list', {})
self.fields = indexer.torrents.get('fields')
self.browse_list = indexer.torrents.get('browse_list')
self.browse_fields = indexer.torrents.get('browse_fields')
self.render = indexer.render
self.domain = indexer.domain
self.page = page
Expand Down Expand Up @@ -144,6 +146,7 @@ def start_requests(self):

# 种子搜索相对路径
paths = self.search.get('paths', [])
params = self.search.get('params')
torrentspath = ""
if len(paths) == 1:
torrentspath = paths[0].get('path', '')
Expand Down Expand Up @@ -236,6 +239,9 @@ def start_requests(self):
}
# 有单独浏览路径
if self.browse:
if self.browse_list:
self.list = self.browse_list
self.fields = self.browse_fields
torrentspath = self.browse.get("path")
if self.browse.get("start"):
start_page = int(self.browse.get("start")) + int(self.page or 0)
Expand All @@ -248,9 +254,15 @@ def start_requests(self):
searchurl = self.domain + str(torrentspath).format(**inputs_dict)

log.info(f"【Spider】开始请求:{searchurl}")
yield feapder.Request(url=searchurl,
use_session=True,
render=self.render)
if params:
yield feapder.Request(url=searchurl,
use_session=True,
data=params,
render=self.render)
else:
yield feapder.Request(url=searchurl,
use_session=True,
render=self.render)

def download_midware(self, request):
request.headers = {
Expand Down
52 changes: 0 additions & 52 deletions app/utils/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,55 +283,3 @@ def get_sort_str(x):
can_download_list.append(media_name)
can_download_list_item.append(t_item)
return can_download_list_item

@staticmethod
def magent2torrent(url, path, timeout=30):
"""
磁力链接转种子文件
:param url: 磁力链接
:param path: 保存目录
:param timeout: 获取元数据超时时间
:return: 转换后种子路径
"""

log.info(f"【Downloader】转换磁力链接:{url}")
session = libtorrent.session()
magnet_info = libtorrent.parse_magnet_uri(url)
magnet_info.save_path = path
handle = session.add_torrent(magnet_info)

log.debug("【Downloader】获取元数据中")
tout = 0
while not handle.status().name:
time.sleep(1)
tout += 1
if tout > timeout:
log.debug("【Downloader】元数据获取超时")
return None, "种子元数据获取超时"
log.debug("【Downloader】获取元数据完成")
tout = 0
while True:
tf = handle.torrent_file()
if tf:
session.pause()
break
time.sleep(1)
tout += 1
if tout > timeout:
log.debug("【Downloader】种子获取超时")
return None, "种子获取超时"

ti = libtorrent.torrent_info(tf)
torrent_file = libtorrent.create_torrent(ti)
torrent_file.set_comment(ti.comment())
torrent_file.set_creator(ti.creator())

file_path = os.path.join(path, "%s.torrent" % handle.status().name)

with open(file_path, 'wb') as f_handle:
f_handle.write(libtorrent.bencode(torrent_file.generate()))
f_handle.close()

session.remove_torrent(handle, 1)
log.info(f"【Downloader】转换后的种子路径:{file_path}")
return file_path, ""
Binary file modified config/sites.dat
Binary file not shown.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ flask-compress==1.13
flask-restx==1.0.6
flask-sock==0.6.0
func_timeout==4.3.5
greenlet==1.1.3.post0
greenlet==3.0.3
h11==0.14.0
humanize==4.4.0
icalendar==5.0.4
Expand All @@ -45,7 +45,6 @@ jsonpath==0.82
jsonschema==4.16.0
loguru==0.6.0
lxml==4.9.1
libtorrent==2.0.7
Mako==1.2.3
MarkupSafe==2.1.1
matplotlib-inline==0.1.6
Expand Down
17 changes: 10 additions & 7 deletions web/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,17 @@ def __download_torrent(data):
ua=site_info.get("ua"),
proxy=site_info.get("proxy")
)
media_info = Media().get_media_info(title=os.path.basename(file_path))
if media_info:
media_info.site = "WEB"
if not file_path:
return {"code": -1, "msg": f"下载种子文件失败: {retmsg}"}

else:
file_dir = Config().get_temp_path()
file_path, retmsg = Torrent().magent2torrent(url, file_dir)
if not file_path:
return {"code": -1, "msg": f"下载种子文件失败: {retmsg}"}
media_info = Media().get_media_info(title=os.path.basename(file_path))
if media_info:
media_info.site = "WEB"
media_info = MetaInfo('')
media_info.enclosure = url
file_path = None

# 添加下载
Downloader().download(media_info=media_info,
download_dir=dl_dir,
Expand Down

0 comments on commit 3ec6b88

Please sign in to comment.