From 523c3b685dc4a46d6437145bb9b1abcc636ee677 Mon Sep 17 00:00:00 2001 From: Evil0ctal Date: Tue, 30 Apr 2024 18:43:47 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B:=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=B0=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 18 ++++-------------- app/web/views/ParseVideo.py | 6 +++++- crawlers/douyin/web/config.yaml | 2 +- crawlers/tiktok/web/utils.py | 6 ++++-- crawlers/utils/logger.py | 4 ++-- start.sh | 11 ++--------- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a890ee..2d36f97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,22 +19,12 @@ WORKDIR /app # Copy the application source code to the container COPY . /app -# Install virtualenv +# Install pip and set the PyPI mirror (Aliyun) RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -U pip \ - && pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ \ - && pip3 install virtualenv + && pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ -# Check virtualenv is installed -RUN which virtualenv - -# Create and activate virtual environment using the virtualenv command -RUN virtualenv venv -p python3.11 - -# Set the virtual environment path -ENV PATH="/app/venv/bin:$PATH" - -# Install dependencies in the virtual environment -RUN pip install --no-cache-dir -r requirements.txt +# Install dependencies directly +RUN pip3 install --no-cache-dir -r requirements.txt # Make the start script executable RUN chmod +x start.sh diff --git a/app/web/views/ParseVideo.py b/app/web/views/ParseVideo.py index 0886681..8c90e54 100644 --- a/app/web/views/ParseVideo.py +++ b/app/web/views/ParseVideo.py @@ -61,10 +61,13 @@ def error_do(reason: str, value: str) -> None: "- The video has been deleted or the link is incorrect.")) put_markdown(ViewsUtils.t("- 接口风控,请求过于频繁。", "- Interface risk control, request too frequent.")), + put_markdown(ViewsUtils.t("- 没有使用有效的Cookie,如果你部署后没有替换相应的Cookie,可能会导致解析失败。", + "- No valid Cookie is used. If you do not replace the corresponding Cookie after deployment, it may cause parsing failure.")) put_markdown(ViewsUtils.t("> 寻求帮助:", "> Seek help:")) put_markdown(ViewsUtils.t( "- 你可以尝试再次解析,或者尝试自行部署项目,然后替换`./app/crawlers/平台文件夹/config.yaml`中的`cookie`值。", "- You can try to parse again, or try to deploy the project by yourself, and then replace the `cookie` value in `./app/crawlers/platform folder/config.yaml`.")) + put_markdown( "- GitHub Issue: [Evil0ctal/Douyin_TikTok_Download_API](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/issues)") put_html("
") @@ -157,7 +160,8 @@ def parse_video(): f"/api/download?url={url}&prefix=true&with_watermark=false", new_window=True)]) # 添加视频信息 - table_list.insert(0, [put_video(data.get('video_data').get('nwm_video_url_HQ'), poster=None, loop=True, width='50%')]) + table_list.insert(0, [ + put_video(data.get('video_data').get('nwm_video_url_HQ'), poster=None, loop=True, width='50%')]) # 如果是图片/If it's image elif url_type == ViewsUtils.t('图片', 'Image'): # 添加图片下载链接 diff --git a/crawlers/douyin/web/config.yaml b/crawlers/douyin/web/config.yaml index 4a6a658..4e3dbde 100644 --- a/crawlers/douyin/web/config.yaml +++ b/crawlers/douyin/web/config.yaml @@ -4,7 +4,7 @@ TokenManager: Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Referer: https://www.douyin.com/ - Cookie: __ac_nonce=06629f03b000ca74fd5d0; __ac_signature=_02B4Z6wo00f018OnaAwAAIDCyYGzp89TogfDh2yAAJbJ17; s_v_web_id=verify_lvetxr14_jPt0ZofI_p5Nw_44FG_BGSL_SVodoPoGUlGG; ttwid=1%7CtCoZxPEZnSPKZQhxavM2S9G9udonQu1yTp4eeGEhmOU%7C1714024522%7Ce9786696e4a0d08ac93356835424aece59d214e5f5c1d054dcb62cc18a48b829; IsDouyinActive=true; home_can_add_dy_2_desktop=%220%22; dy_swidth=1463; dy_sheight=915; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1463%2C%5C%22screen_height%5C%22%3A915%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A32%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A7.85%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22 + Cookie: __ac_nonce=066319b1d00a2c3a5a32; __ac_signature=_02B4Z6wo00f01CAwRGAAAIDDX8H3JTg7X-ggAUDAAG5E57; ttwid=1%7CIce39UJBic2W8B8JRj9tkzb3BMl_LVmwKdahq4T_TQ4%7C1714527006%7C7831bb5a3935a2aaa8e4605d99cffb648fff799220f7c912d53d358937975aa6; douyin.com; device_web_cpu_core=16; device_web_memory_size=-1; architecture=amd64; IsDouyinActive=true; home_can_add_dy_2_desktop=%220%22; dy_swidth=1323; dy_sheight=827; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1323%2C%5C%22screen_height%5C%22%3A827%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A0%2C%5C%22downlink%5C%22%3A%5C%22%5C%22%2C%5C%22effective_type%5C%22%3A%5C%22%5C%22%2C%5C%22round_trip_time%5C%22%3A0%7D%22; strategyABtestKey=%221714527007.257%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.5%7D; stream_player_status_params=%22%7B%5C%22is_auto_play%5C%22%3A0%2C%5C%22is_full_screen%5C%22%3A0%2C%5C%22is_full_webscreen%5C%22%3A1%2C%5C%22is_mute%5C%22%3A1%2C%5C%22is_speed%5C%22%3A1%2C%5C%22is_visible%5C%22%3A0%7D%22; xgplayer_user_id=367707317542; csrf_session_id=6f34e666e71445c9d39d8d06a347a13f; xg_device_score=Infinity; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; passport_csrf_token=92247773d074342637df81db51489969; passport_csrf_token_default=92247773d074342637df81db51489969; msToken=kyCxymhw2m4Lc4K-n-Vr-OY3Kv7R72D9GXpmxrE3Ka4kRkHy-zvLatY3pXrsaEOyxlsTw-3I5JSDRGWNAFAyydNkomXzvVwKeL_GDMQ4P-jvvWbyw1eKeJq2kG7H9-4=; bd_ticket_guard_client_web_domain=2; odin_tt=5576b2ace24aa26f57c5fcec2a416b05a1f7ba785c62b93d6757376f421d2da7cf23b79de915f1eca97affb19b7270782382245533ceeaa8cdfa7f35d5ccd4c8c5a4d1f624ad356376ce6ffda93bc741; s_v_web_id=verify_lvn54e5x_fb563a9d_f244_ce83_cc4f_45789afba4ce; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCTTlxYlFUOWlOdTRzZFg2MldFT1lnVUdrZENsaUU3WllsK1JrK3lRVCs0RDdWMEU3aGpWREtYaHplMW9aR2g5NW0wVlpncXN4MStGY3VIZjgvTnBIY3c9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D proxies: http: diff --git a/crawlers/tiktok/web/utils.py b/crawlers/tiktok/web/utils.py index 241b3de..8212727 100644 --- a/crawlers/tiktok/web/utils.py +++ b/crawlers/tiktok/web/utils.py @@ -104,8 +104,10 @@ class TokenManager: except Exception as e: # 返回虚假的msToken (Return a fake msToken) - logger.error("msToken API错误:{0}".format(e)) - logger.info("生成虚假的msToken") + logger.error("生成TikTok msToken API错误:{0}".format(e)) + logger.info("当前网络无法正常访问TikTok服务器,已经使用虚假msToken以继续运行。") + logger.info("并且TikTok相关API大概率无法正常使用,请在(/tiktok/web/config.yaml)中更新代理。") + logger.info("如果你不需要使用TikTok相关API,请忽略此消息。") return cls.gen_false_msToken() @classmethod diff --git a/crawlers/utils/logger.py b/crawlers/utils/logger.py index e8a31e6..3c4afcd 100644 --- a/crawlers/utils/logger.py +++ b/crawlers/utils/logger.py @@ -79,7 +79,7 @@ class LogManager(metaclass=Singleton): if getattr(self, "_initialized", False): # 防止重复初始化 return - self.logger = logging.getLogger("TikHub_Crawlers") + self.logger = logging.getLogger("Douyin_TikTok_Download_API_Crawlers") self.logger.setLevel(logging.INFO) self.log_dir = None self._initialized = True @@ -145,7 +145,7 @@ class LogManager(metaclass=Singleton): def log_setup(log_to_console=True): - logger = logging.getLogger("TikHub_Crawlers") + logger = logging.getLogger("Douyin_TikTok_Download_API_Crawlers") if logger.hasHandlers(): # logger已经被设置,不做任何操作 return logger diff --git a/start.sh b/start.sh index 6c40826..56939dc 100644 --- a/start.sh +++ b/start.sh @@ -1,11 +1,4 @@ #!/bin/sh -# Activating the virtual environment -# shellcheck disable=SC2039 -source /www/wwwroot/Douyin_TikTok_Download_API/venv/bin/activate - -# Starting the Python application -python start.py - -# Deactivating the virtual environment (optional, since the script is ending) -deactivate +# Starting the Python application directly using python3 +python3 start.py