Skip to content

Commit

Permalink
fix: 合并冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuan0213 committed Apr 18, 2023
2 parents 19f794e + 278a6fa commit 839cc5e
Show file tree
Hide file tree
Showing 35 changed files with 622 additions and 289 deletions.
50 changes: 33 additions & 17 deletions app/brushtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,54 +847,70 @@ def __check_remove_rule(remove_rule,

@staticmethod
def __get_torrent_dict(downloader_type, torrent):
# 当前时间
date_now = int(time.mktime(datetime.now().timetuple()))

# 当前时间戳
date_now = int(time.time())

if downloader_type == "qbittorrent":
# ID
torrent_id = torrent.get("hash")
# 已开始时间 秒
dltime = int(time.time() - torrent.get("added_on"))
# 已做种时间 秒
date_done = torrent.completion_on if torrent.completion_on > 0 else torrent.added_on
seeding_time = date_now - date_done if date_done else 0
# 下载时间
dltime = date_now - torrent.get("added_on") if torrent.get("added_on") else 0
# 做种时间
seeding_time = date_now - torrent.get("completion_on") if torrent.get("completion_on") else 0
# 分享率
ratio = torrent.get("ratio") or 0
# 上传量
uploaded = torrent.get("uploaded") or 0
# 平均上传速度 Byte/s
avg_upspeed = int(uploaded / dltime)
if dltime:
avg_upspeed = int(uploaded / dltime)
else:
avg_upspeed = uploaded
# 已未活动 秒
last_activity = int(torrent.get("last_activity", 0))
iatime = date_now - last_activity if last_activity else 0
iatime = date_now - torrent.get("last_activity") if torrent.get("last_activity") else 0
# 下载量
downloaded = torrent.get("downloaded")
# 种子大小
total_size = torrent.get("total_size")
# 添加时间
add_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(torrent.get("added_on")))
add_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(torrent.get("added_on") or 0))

else:

# ID
torrent_id = torrent.hashString
# 做种时间
date_done = torrent.date_done or torrent.date_added
if not torrent.date_done or torrent.date_done.timestamp() < 1:
seeding_time = 0
else:
seeding_time = date_now - int(torrent.date_done.timestamp())
# 下载耗时
dltime = date_now - int(time.mktime(torrent.date_added.timetuple()))
seeding_time = date_now - int(time.mktime(date_done.timetuple()))
if not torrent.date_added or torrent.date_added.timestamp() < 1:
dltime = 0
else:
dltime = date_now - int(torrent.date_added.timestamp())
# 下载量
downloaded = int(torrent.total_size * torrent.progress / 100)
# 分享率
ratio = torrent.ratio or 0
# 上传量
uploaded = int(downloaded * torrent.ratio)
# 平均上传速度
avg_upspeed = int(uploaded / dltime)
if dltime:
avg_upspeed = int(uploaded / dltime)
else:
avg_upspeed = uploaded
# 未活动时间
iatime = date_now - int(time.mktime(torrent.date_active.timetuple()))
if not torrent.date_active or torrent.date_active.timestamp() < 1:
iatime = 0
else:
iatime = date_now - int(torrent.date_active.timestamp())
# 种子大小
total_size = torrent.total_size
# 添加时间
add_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(torrent.date_added))
add_time = time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(torrent.date_added.timestamp() if torrent.date_added else 0))

return {
"id": torrent_id,
Expand Down
2 changes: 1 addition & 1 deletion app/downloader/client/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Transmission(_IDownloadClient):
# 下载器名称
client_name = DownloaderType.TR.value

# 参考transmission web,仅查询需要的参数,加速种子检索
# 参考transmission web,仅查询需要的参数,加速种子搜索
_trarg = ["id", "name", "status", "labels", "hashString", "totalSize", "percentDone", "addedDate", "trackerStats",
"leftUntilDone", "rateDownload", "rateUpload", "recheckProgress", "rateDownload", "rateUpload",
"peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir",
Expand Down
4 changes: 2 additions & 2 deletions app/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def check_exists_medias(self, meta_info, no_exists=None, total_ep=None):
"""
检查媒体库,查询是否存在,对于剧集同时返回不存在的季集信息
:param meta_info: 已识别的媒体信息,包括标题、年份、季、集信息
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数检索的内容将会叠加后输出
:param no_exists: 在调用该方法前已经存储的不存在的季集信息,有传入时该函数搜索的内容将会叠加后输出
:param total_ep: 各季的总集数
:return: 当前媒体是否缺失,各标题总的季集和缺失的季集,需要发送的消息
"""
Expand All @@ -958,7 +958,7 @@ def check_exists_medias(self, meta_info, no_exists=None, total_ep=None):
if meta_info.type != MediaType.MOVIE:
# 是否存在的标志
return_flag = False
# 检索电视剧的信息
# 搜索电视剧的信息
tv_info = self.media.get_tmdb_info(mtype=MediaType.TV, tmdbid=meta_info.tmdb_id)
if tv_info:
# 传入检查季
Expand Down
8 changes: 4 additions & 4 deletions app/filetransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def transfer_media(self,
识别并转移一个文件、多个文件或者目录
:param in_from: 来源,即调用该功能的渠道
:param in_path: 转移的路径,可能是一个文件也可以是一个目录
:param files: 文件清单,非空时以该文件清单为准,为空时从in_path中按后缀和大小限制检索需要处理的文件清单
:param files: 文件清单,非空时以该文件清单为准,为空时从in_path中按后缀和大小限制搜索需要处理的文件清单
:param target_dir: 目的文件夹,非空的转移到该文件夹,为空时则按类型转移到配置文件中的媒体库文件夹
:param unknown_dir: 未识别文件夹,非空时未识别的媒体文件转移到该文件夹,为空时则使用配置文件中的未识别文件夹
:param rmt_mode: 文件转移方式
Expand Down Expand Up @@ -559,11 +559,11 @@ def __finish_transfer(status, message):
log.info("【Rmt】所有文件均已成功转移过,没有需要处理的文件!如需重新处理,请清理缓存(服务->清理转移缓存)")
return __finish_transfer(True, "没有新文件需要处理")

# API检索出媒体信息,传入一个文件列表,得出每一个文件的名称,这里是当前目录下所有的文件了
# API搜索出媒体信息,传入一个文件列表,得出每一个文件的名称,这里是当前目录下所有的文件了
Medias = self.media.get_media_info_on_files(file_list, tmdb_info, media_type, season, episode[0])
if not Medias:
log.error("【Rmt】检索媒体信息出错!")
return __finish_transfer(False, "检索媒体信息出错")
log.error("【Rmt】搜索媒体信息出错!")
return __finish_transfer(False, "搜索媒体信息出错")

# 更新进度
self.progress.update(ptype=ProgressKey.FileTransfer, text=f"共 {len(Medias)} 个文件需要处理...")
Expand Down
6 changes: 3 additions & 3 deletions app/helper/db_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def insert_search_results(self, media_items: list, title=None, ident_flag=True):

def get_search_result_by_id(self, dl_id):
"""
根据ID从数据库中查询检索结果的一条记录
根据ID从数据库中查询搜索结果的一条记录
"""
return self._db.query(SEARCHRESULTINFO).filter(SEARCHRESULTINFO.ID == dl_id).all()

def get_search_results(self, ):
"""
查询检索结果的所有记录
查询搜索结果的所有记录
"""
return self._db.query(SEARCHRESULTINFO).all()

Expand Down Expand Up @@ -193,7 +193,7 @@ def update_douban_media_state(self, media, state):

def get_douban_search_state(self, title, year=None):
"""
查询未检索的豆瓣数据
查询未搜索的豆瓣数据
"""
if not year:
return self._db.query(DOUBANMEDIAS.STATE).filter(DOUBANMEDIAS.NAME == title).first()
Expand Down
4 changes: 2 additions & 2 deletions app/helper/meta_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_meta_data_by_key(self, key):
def dump_meta_data(self, search, page, num):
"""
分页获取当前缓存列表
@param search: 检索的缓存key
@param search: 搜索的缓存key
@param page: 页码
@param num: 单页大小
@return: 总数, 缓存列表
Expand Down Expand Up @@ -113,7 +113,7 @@ def delete_meta_data_by_tmdbid(self, tmdbid):

def delete_unknown_meta(self):
"""
清除未识别的缓存记录,以便重新检索TMDB
清除未识别的缓存记录,以便重新搜索TMDB
"""
for key in list(self._meta_data):
if str(self._meta_data.get(key, {}).get("id")) == '0':
Expand Down
23 changes: 13 additions & 10 deletions app/helper/ocr_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@


class OcrHelper:
req = None
_ocr_b64_url = "%s/captcha/base64" % DEFAULT_OCR_SERVER

def __init__(self):
self.req = RequestUtils(content_type="application/json")
_ocr_b64_url = "%s/captcha/base64" % DEFAULT_OCR_SERVER

def get_captcha_text(self, image_url=None, image_b64=None):
def get_captcha_text(self, image_url=None, image_b64=None, cookie=None, ua=None):
"""
根据图片地址,获取验证码图片,并识别内容
:param image_url: 图片地址
:param image_b64: 图片base64,跳过图片地址下载
:param cookie: 下载图片使用的cookie
:param ua: 下载图片使用的ua
"""
if not image_url and not image_b64:
return ""
if image_url:
ret = self.req.get_res(image_url)
ret = RequestUtils(headers=ua,
cookies=cookie).get_res(image_url)
if ret is not None:
image_bin = ret.content
if not image_bin:
return ""
image_b64 = base64.b64encode(image_bin).decode()
ret = self.req.post_res(url=self._ocr_b64_url,
json={"base64_img": image_b64})
if not image_b64:
return ""
ret = RequestUtils(content_type="application/json").post_res(
url=self._ocr_b64_url,
json={"base64_img": image_b64})
if ret:
return ret.json().get("result")
return ""
10 changes: 5 additions & 5 deletions app/indexer/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def search(self, order_seq,
match_media,
in_from: SearchType):
"""
根据关键字多线程检索
根据关键字多线程搜索
"""
if not indexer or not key_word:
return None
Expand All @@ -84,7 +84,7 @@ def search(self, order_seq,
return []
# 计算耗时
start_time = datetime.datetime.now()
log.info(f"【{self.index_type}开始检索Indexer{indexer.name} ...")
log.info(f"【{self.index_type}开始搜索Indexer{indexer.name} ...")
# 特殊符号处理
search_word = StringUtils.handler_special_chars(text=key_word,
replace_word=" ",
Expand All @@ -95,8 +95,8 @@ def search(self, order_seq,
# 索引花费时间
seconds = (datetime.datetime.now() - start_time).seconds
if len(result_array) == 0:
log.warn(f"【{self.index_type}{indexer.name} 未检索到数据")
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 未检索到数据")
log.warn(f"【{self.index_type}{indexer.name} 未搜索到数据")
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 未搜索到数据")

self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
Expand Down Expand Up @@ -231,7 +231,7 @@ def filter_search_results(self, result_array: list,
match_media,
start_time):
"""
从检索结果中匹配符合资源条件的记录
从搜索结果中匹配符合资源条件的记录
"""
ret_array = []
index_sucess = 0
Expand Down
18 changes: 9 additions & 9 deletions app/indexer/client/_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TorrentSpider(feapder.AirSpider):
custom_argument=["--ignore-certificate-errors"],
)
)
# 是否检索完成标志
# 是否搜索完成标志
is_complete = False
# 是否出现错误
is_error = False
Expand All @@ -65,13 +65,13 @@ class TorrentSpider(feapder.AirSpider):
render = False
# Referer
referer = None
# 检索关键字
# 搜索关键字
keyword = None
# 媒体类型
mtype = None
# 检索路径、方式配置
# 搜索路径、方式配置
search = {}
# 批量检索配置
# 批量搜索配置
batch = {}
# 浏览配置
browse = {}
Expand All @@ -83,7 +83,7 @@ class TorrentSpider(feapder.AirSpider):
fields = {}
# 页码
page = 0
# 检索条数
# 搜索条数
result_num = 100
# 单个种子信息
torrents_info = {}
Expand All @@ -98,7 +98,7 @@ def setparam(self, indexer,
"""
设置查询参数
:param indexer: 索引器
:param keyword: 检索关键字,如果数组则为批量检索
:param keyword: 搜索关键字,如果数组则为批量搜索
:param page: 页码
:param referer: Referer
:param mtype: 媒体类型
Expand Down Expand Up @@ -181,7 +181,7 @@ def start_requests(self):
# 查询模式与
search_mode = "0"

# 检索URL
# 搜索URL
if self.search.get("params"):
# 变量字典
inputs_dict = {
Expand Down Expand Up @@ -243,7 +243,7 @@ def start_requests(self):
})
elif self.page:
torrentspath = torrentspath + f"?page={self.page}"
# 检索Url
# 搜索Url
searchurl = self.domain + str(torrentspath).format(**inputs_dict)

log.info(f"【Spider】开始请求:{searchurl}")
Expand Down Expand Up @@ -623,7 +623,7 @@ def Getinfo(self, torrent):
self.Getlabels(torrent)
except Exception as err:
ExceptionUtils.exception_traceback(err)
log.error("【Spider】%s 检索出现错误:%s" % (self.indexername, str(err)))
log.error("【Spider】%s 搜索出现错误:%s" % (self.indexername, str(err)))
return self.torrents_info

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions app/indexer/client/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def search(self, order_seq,
match_media,
in_from: SearchType):
"""
根据关键字多线程检索
根据关键字多线程搜索
"""
if not indexer or not key_word:
return None
Expand All @@ -123,7 +123,7 @@ def search(self, order_seq,
# 计算耗时
start_time = datetime.datetime.now()

log.info(f"【{self.client_name}开始检索Indexer{indexer.name} ...")
log.info(f"【{self.client_name}开始搜索Indexer{indexer.name} ...")
# 特殊符号处理
search_word = StringUtils.handler_special_chars(text=key_word,
replace_word=" ",
Expand Down Expand Up @@ -160,9 +160,9 @@ def search(self, order_seq,
result='N' if error_flag else 'Y')
# 返回结果
if len(result_array) == 0:
log.warn(f"【{self.client_name}{indexer.name} 未检索到数据")
log.warn(f"【{self.client_name}{indexer.name} 未搜索到数据")
# 更新进度
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 未检索到数据")
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 未搜索到数据")
return []
else:
log.warn(f"【{self.client_name}{indexer.name} 返回数据:{len(result_array)}")
Expand All @@ -178,7 +178,7 @@ def search(self, order_seq,

def list(self, index_id, page=0, keyword=None):
"""
根据站点ID检索站点首页资源
根据站点ID搜索站点首页资源
"""
if not index_id:
return []
Expand Down
Loading

0 comments on commit 839cc5e

Please sign in to comment.