Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeanAmier committed Nov 14, 2023
1 parent dc2c3a2 commit 6cf2c14
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/DataAcquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ class Acquirer:
follow_api = "https://www.douyin.com/aweme/v1/web/follow/feed/" # 关注账号作品推荐API
history_api = "https://www.douyin.com/aweme/v1/web/history/read/" # 观看历史API
following_api = "https://www.douyin.com/aweme/v1/web/user/following/list/" # 关注列表API
hot_params = (
(0, ""),
(2, 2),
(2, 4),
(2, "hotspot_challenge"),
)

# TikTok API
recommend_api = "https://www.tiktok.com/api/recommend/item_list/" # 推荐页API
Expand Down Expand Up @@ -329,6 +323,7 @@ def run(self) -> tuple[list[dict], date, date]:
self.early_stop()
self.pages -= 1
num += 1
# break # 调试使用
self.summary_works()
self.favorite_mode()
return self.response, self.earliest, self.latest
Expand Down Expand Up @@ -463,6 +458,7 @@ def run(self, extractor: Extractor, recorder, source=False) -> list[dict]:
self.get_comments_data(self.comment_api)
self.pages -= 1
num += 1
# break # 调试使用
self.all_data, self.reply_ids = extractor.run(
self.response, recorder, "comment", source=source)
self.response = []
Expand All @@ -473,6 +469,7 @@ def run(self, extractor: Extractor, recorder, source=False) -> list[dict]:
self.console.print(f"{next(self.cycle)} 正在获取评论回复数据...")
self.get_comments_data(self.comment_api_reply, i)
self.pages -= 1
# break # 调试使用
self.all_data.extend(
self._check_reply_ids(
*
Expand Down Expand Up @@ -559,6 +556,7 @@ def run(self) -> list:
self.console.print(f"正在获取第 {num} 页数据...")
self._get_mix_data()
num += 1
# break # 调试使用
return self.response

def _get_mix_data(self):
Expand Down
3 changes: 2 additions & 1 deletion src/DataExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def preprocessing_data(self,
title = self.cleaner.filter_name(self.safe_extract(
item, "mix_info.mix_name", f"合集_{str(time())[:10]}"),
default="无效合集标题")
mark = self.cleaner.filter_name(mark, default=title if mix else name)
mark = self.cleaner.filter_name(
mark, inquire=False, default=title if mix else name)
return id_, name, mid, title, mark, data[:None if post else -1]

def works(self, data: list[dict], recorder) -> list[dict]:
Expand Down
6 changes: 6 additions & 0 deletions src/main_api_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import redirect
from flask import request

from src.DataAcquirer import Comment
Expand All @@ -22,6 +23,11 @@ def _generate_record_params(self, data: dict, merge=True, **kwargs):
data["logger"] = logger

def run_server(self, app):
@app.route("/")
def index():
return redirect(
"https://github.com/JoeanAmier/TikTokDownloader/wiki/Documentation")

@app.route('/settings/', methods=['POST'])
def settings():
return self.update_settings(request.json)
Expand Down
7 changes: 5 additions & 2 deletions src/main_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def _deal_mix_works(self,
logger,
mix_id: bool = None,
id_: str = None,
mark: str = None,
mark="",
num: int = 0,
api=False,
source=False, ):
Expand Down Expand Up @@ -628,19 +628,21 @@ def _deal_search_data(
if not any(search_data):
self.logger.warning("采集搜索数据失败")
return None
# print(search_data) # 调试使用
if source:
return search_data
name = self._generate_search_name(
keyword, type_[1], sort[1], publish[1])
root, params, logger = self.record.run(self.parameter,
type_=self.DATA_TYPE[type_[0]])
with logger(root, name=name, **params) as logger:
self.extractor.run(
search_data = self.extractor.run(
search_data,
logger,
type_="search",
tab=type_[0])
self.logger.info(f"搜索数据已保存至 {name}")
# print(search_data) # 调试使用
return search_data

@check_storage_format
Expand All @@ -662,6 +664,7 @@ def _deal_hot_data(self, source=False):
data.append(
{Hot.board_params[i].name: self.extractor.run(j, record, type_="hot")})
self.logger.info(f"热榜数据已储存至 {time_} + 榜单类型")
# print(time_, data, source) # 调试使用
return time_, data

def collection_interactive(self):
Expand Down

0 comments on commit 6cf2c14

Please sign in to comment.