Repository: ihmily/DouyinLiveRecorder Branch: main Commit: add187f8d8c7 Files: 48 Total size: 495.6 KB Directory structure: gitextract_a6x158yz/ ├── .dockerignore ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── bug.yml │ │ ├── bug_en.yml │ │ ├── feature.yml │ │ ├── feature_en.yml │ │ ├── question.yml │ │ └── question_en.yml │ ├── PULL_REQUEST_TEMPLATE.md │ └── workflows/ │ ├── build-image.yml │ ├── issue-translator.yml │ └── sync.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── StopRecording.vbs ├── config/ │ ├── URL_config.ini │ └── config.ini ├── demo.py ├── docker-compose.yaml ├── ffmpeg_install.py ├── i18n/ │ ├── en/ │ │ └── LC_MESSAGES/ │ │ └── .gitkeep │ └── zh_CN/ │ └── LC_MESSAGES/ │ ├── zh_CN.mo │ └── zh_CN.po ├── i18n.py ├── index.html ├── main.py ├── msg_push.py ├── pyproject.toml ├── requirements.txt └── src/ ├── __init__.py ├── ab_sign.py ├── http_clients/ │ ├── __init__.py │ ├── async_http.py │ └── sync_http.py ├── initializer.py ├── javascript/ │ ├── haixiu.js │ ├── laixiu.js │ ├── liveme.js │ ├── migu.js │ ├── taobao-sign.js │ └── x-bogus.js ├── logger.py ├── proxy.py ├── room.py ├── spider.py ├── stream.py └── utils.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .dockerignore ================================================ .github/workflows/build-image.yml .git .gitignore .dockerignore README.md LICENSE ================================================ FILE: .github/ISSUE_TEMPLATE/bug.yml ================================================ name: 🐛 Bug report description: 创建Bug报告以帮助项目改进。 title: 🐛[BUG] 请输入标题 labels: bug body: - type: markdown attributes: value: | 📝 **请在上方的`title`中填写一个简洁明了的标题**,格式建议为:🐛[Bug] 简短描述。 例如:🐛[Bug] B站某些直播间无法录制。 - type: checkboxes attributes: label: ⚠️ 确认是否已存在类似问题 description: > 🔍 [点击这里搜索历史issue](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) 请确保你的问题没有被报告过。 options: - label: 我已经搜索过issues,没有找到类似问题 required: true - type: dropdown attributes: label: 🔧 运行方式 description: 请选择你是如何运行程序的。 options: - 直接运行的exe文件 - 使用源代码运行 - 使用docker运行 validations: required: true - type: dropdown attributes: label: 🐍 如果是使用源代码运行,请选择你的Python环境版本 description: 请选择你运行程序的Python版本。 options: - Python 3.10 - Python 3.11 - Python 3.12 - Python 3.13 - Other (请在问题中说明) validations: required: false - type: dropdown attributes: label: 💻 请选择你的系统环境 description: 请选择你运行程序的具体系统版本。 options: - Windows 10 - Windows 11 - macOS - Ubuntu - CentOS - Fedora - Debian - Other (请在问题中说明) validations: required: true - type: checkboxes attributes: label: ⚠️ 确认是否已经重试多次 description: > 有时可能是你的设备或者网络问题导致的。 options: - label: 我已经尝试过多次,仍然出现问题 required: true - type: textarea attributes: label: 🕹 复现步骤 description: | **⚠️ 不能复现将会关闭issue.** 请按照以下格式填写: 1. 录制的直播间地址是... 2. 使用的录制格式是... 3. ... placeholder: | 1. ... 2. ... 3. ... validations: required: true - type: textarea attributes: label: 😯 问题描述 description: 详细描述出现的问题,或提供有关截图。 validations: required: true - type: textarea attributes: label: 📜 错误信息 description: 如果有,请贴出相关的日志错误信息或者截图。 validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/bug_en.yml ================================================ name: 🐛 (English)Bug report description: Create a bug report to help improve the project. title: 🐛[BUG] Please enter a title labels: bug body: - type: markdown attributes: value: | 📝 **Please fill in a concise and clear title in the `title` above**, the format is suggested as: 🐛[Bug] Short description. For example: 🐛[Bug] Unable to record certain TikTok live rooms. - type: checkboxes attributes: label: ⚠️ Confirm if similar issues exist description: > 🔍 [Click here to search historical issues](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) Please make sure your issue hasn't been reported before. options: - label: I have searched the issues and found no similar problems required: true - type: dropdown attributes: label: 🔧 How did you run the program? description: Please select how you ran the program. options: - Directly running the exe file - Running with source code - Running with docker validations: required: true - type: dropdown attributes: label: 🐍 If running with source code, please select your Python environment version description: Please select the Python version you used to run the program. options: - Python 3.10 - Python 3.11 - Python 3.12 - Python 3.13 - Other (please specify in the issue) validations: required: false - type: dropdown attributes: label: 💻 Please select your system environment description: Please select the specific system version you are running the program on. options: - Windows 10 - Windows 11 - macOS - Ubuntu - CentOS - Fedora - Debian - Other (please specify in the issue) validations: required: true - type: checkboxes attributes: label: ⚠️ Confirm if you have retried multiple times description: > Sometimes it might be due to your device or network issues. options: - label: I have tried multiple times and still encounter the problem required: true - type: textarea attributes: label: 🕹 Reproduction steps description: | **⚠️ Issues that cannot be reproduced will be closed.** Please fill in according to the following format: 1. The live room address I tried to record is... 2. The recording format I used is... 3. ... placeholder: | 1. ... 2. ... 3. ... validations: required: true - type: textarea attributes: label: 😯 Problem description description: Describe the problem in detail or provide relevant screenshots. validations: required: true - type: textarea attributes: label: 📜 Error information description: If available, please paste the relevant log error information or screenshots. validations: required: false ================================================ FILE: .github/ISSUE_TEMPLATE/feature.yml ================================================ name: 🚀 Feature request description: 提出你对项目的新想法或建议。 title: 🚀[Feature] 请输入标题 labels: enhancement body: - type: markdown attributes: value: | 📝 **请在上方的`title`中填写一个简洁明了的标题**,格式建议为:🚀[Feature] 简短描述。 例如:🚀[Feature] 添加xx直播录制。 - type: checkboxes attributes: label: ⚠️ 搜索是否存在类似issue description: > 🔍 [点击这里搜索历史issue](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) 使用关键词搜索,确保没有重复的issue。 options: - label: 我已经搜索过issues,没有发现相似issue required: true - type: textarea attributes: label: 📜 功能描述 description: 请详细描述你希望添加的功能,包括它的工作方式和预期效果。 placeholder: | 功能描述: - type: textarea attributes: label: 🌐 举例(可选) description: 如果可能,请提供功能相关的示例、截图或相关网址。 placeholder: | 直播间示例地址: `https://www.example.com/live/xxxx` - type: textarea attributes: label: 💡 动机 description: 描述你提出该feature的动机,以及没有这项feature对你的使用造成了怎样的影响。 placeholder: | 我需要这个功能是因为... ================================================ FILE: .github/ISSUE_TEMPLATE/feature_en.yml ================================================ name: 🚀 (English)Feature request description: Propose new ideas or suggestions for the project. title: 🚀[Feature] Please enter a title labels: enhancement body: - type: markdown attributes: value: | 📝 **Please fill in a concise and clear title in the `title` above**, the format is suggested as: 🚀[Feature] Short description. For example: 🚀[Feature] Add xx live recording. - type: checkboxes attributes: label: ⚠️ Search for similar issues description: > 🔍 [Click here to search historical issues](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) using keywords to ensure there are no duplicate issues. options: - label: I have searched the issues and found no similar issues required: true - type: textarea attributes: label: 📜 Feature description description: Please describe in detail the feature you would like to add, including how it should work and what its expected outcomes are. placeholder: | Feature description: - type: textarea attributes: label: 🌐 Example (Optional) description: If possible, provide examples, screenshots, or related URLs related to the feature. placeholder: | Live room example URL: `https://www.example.com/live/xxxx` - type: textarea attributes: label: 💡 Motivation description: Describe the motivation behind your feature request and how not having this feature impacts your use of the project. placeholder: | I need this feature because... ================================================ FILE: .github/ISSUE_TEMPLATE/question.yml ================================================ name: ❓ Question description: 对程序使用有疑问?在这里提出你的问题。 title: ❓[Question] 请输入标题 labels: question body: - type: markdown attributes: value: | 📝 **请在上方的`title`中填写一个简洁明了的问题标题**。这将帮助其他人快速理解你的问题。 例如:❓[Question] 如果设置单个直播间的录制清晰度。 - type: checkboxes attributes: label: ⚠️ 搜索是否存在类似问题 description: > 🔍 [点击这里搜索历史issue](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) 使用关键词搜索,看看是否已经有人问过类似的问题。 options: - label: 我已经搜索过issues,没有找到相似的问题 required: true - type: dropdown attributes: label: 🔧 运行方式 description: 请选择你是如何运行程序的。 options: - 直接运行的exe文件 - 使用源代码运行 - 使用docker运行 validations: required: true - type: dropdown attributes: label: 🐍 如果是使用源代码运行,请选择你的Python环境版本 description: 请选择你运行程序的Python版本。 options: - Python 3.10 - Python 3.11 - Python 3.12 - Python 3.13 - Other (请在问题中说明) validations: required: false - type: dropdown attributes: label: 💻 请选择你的系统环境 description: 请选择你运行程序的具体系统版本。 options: - Windows 10 - Windows 11 - macOS - Ubuntu - CentOS - Fedora - Debian - Other (请在问题中说明) validations: required: true - type: textarea attributes: label: 🤔 问题详情 description: 请提供与你的问题相关的所有详细信息。 placeholder: | 你的问题具体是关于什么? validations: required: true ================================================ FILE: .github/ISSUE_TEMPLATE/question_en.yml ================================================ name: ❓ (English)Question description: Have questions about using the program? Ask them here. title: ❓[Question] Please enter a title labels: question body: - type: markdown attributes: value: | 📝 **Please fill in a concise and clear question title in the `title` above**. This will help others quickly understand your question. For example: ❓[Question] How to set the recording quality for a single live room. - type: checkboxes attributes: label: ⚠️ Search for similar issues description: > 🔍 [Click here to search historical issues](https://github.com/ihmily/DouyinLiveRecorder/issues?q=is%3Aissue) see if your question has already been asked. options: - label: I have searched the issues and found no similar questions required: true - type: dropdown attributes: label: 🔧 How did you run the program? description: Please select how you ran the program. options: - Executable file run directly - Running with source code - Running with docker validations: required: true - type: dropdown attributes: label: 🐍 If running with source code, please select your Python environment version description: Please select the Python version you used to run the program. options: - Python 3.10 - Python 3.11 - Python 3.12 - Python 3.13 - Other (please specify in the question) validations: required: false - type: dropdown attributes: label: 💻 Please select your system environment description: Please select the specific system version you are running the program on. options: - Windows 10 - Windows 11 - macOS - Ubuntu - CentOS - Fedora - Debian - Other (please specify in the question) validations: required: true - type: textarea attributes: label: 🤔 Question details description: Please provide all the details relevant to your question. placeholder: | What is your question about? validations: required: true ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ ### 📜 标题(Title) **请提供这个Pull Request中提议的更改的简洁描述:** - ### 🔍 描述(Description) **请描述这个PR做了什么/为什么这些更改是必要的:** - ### 📝 类型(Type of Change) **这个PR引入了哪种类型的更改?(请勾选所有适用的选项)** - [ ] 修复Bug - [ ] 新功能 - [ ] 代码风格更新(格式化,局部变量) - [ ] 重构(改进代码结构) - [ ] 构建相关更改(依赖项,构建脚本等) - [ ] 其他:_请描述_ ### 🏗️ 测试(Testing) **请描述您已经进行的测试:** - **如果适用,请提供测试更改的说明:** - ### 📋 检查清单(Checklist) 在您创建这个PR之前,请确保以下所有框都被勾选,方法是在每个框中放置一个`x`: - [ ] 我已经阅读了**贡献指南**文档 - [ ] 我的更改没有产生新的警告 - [ ] 我已经添加了覆盖我更改的测试 - [ ] 我已经相应地更新了文档(如果适用) - [ ] 我遵循了这个项目的代码风格 **注意:** 这个PR在所有复选框被勾选之前不会被合并。 --- **感谢您的贡献!** ================================================ FILE: .github/workflows/build-image.yml ================================================ name: Build and Push Docker Image on: push: tags: - '*' workflow_dispatch: inputs: tag_name: description: 'Tag name for the Docker image' required: false default: 'latest' jobs: build_and_push: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Cache Docker layers uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} registry: docker.io - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile push: true tags: | ihmily/douyin-live-recorder:${{ github.event.inputs.tag_name || github.ref_name }} ihmily/douyin-live-recorder:latest platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache ================================================ FILE: .github/workflows/issue-translator.yml ================================================ name: Issue Translator on: issue_comment: types: [created] issues: types: [opened] jobs: build: runs-on: ubuntu-latest steps: - uses: usthe/issues-translate-action@v2.7 with: IS_MODIFY_TITLE: false CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. ================================================ FILE: .github/workflows/sync.yml ================================================ name: 'Upstream Sync' permissions: contents: write on: schedule: - cron: "0 0 * * *" # every day workflow_dispatch: # click the button on Github repo! inputs: sync_test_mode: # Adds a boolean option that appears during manual workflow run for easy test mode config description: 'Fork Sync Test Mode' type: boolean default: false jobs: sync_latest_from_upstream: runs-on: ubuntu-latest name: Sync latest commits from upstream repo if: ${{ github.event.repository.fork }} steps: # Step 1: run a standard checkout action, provided by github - name: Checkout target repo uses: actions/checkout@v3 with: # optional: set the branch to checkout, # sync action checks out your 'target_sync_branch' anyway ref: ${{ secrets.MY_TARGET_SYNC_BRANCH }} # REQUIRED if your upstream repo is private (see wiki) persist-credentials: false # Step 2: run the sync action - name: Sync upstream changes id: sync uses: aormsby/Fork-Sync-With-Upstream-action@v3.4.1 with: target_sync_branch: ${{ secrets.MY_TARGET_SYNC_BRANCH }} # need to set # REQUIRED 'target_repo_token' exactly like this! target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set upstream_sync_branch: main upstream_sync_repo: ihmily/DouyinLiveRecorder # Set test_mode true during manual dispatch to run tests instead of the true action!! test_mode: ${{ inputs.sync_test_mode }} # Step 3: Display a sample message based on the sync output var 'has_new_commits' - name: New commits found if: steps.sync.outputs.has_new_commits == 'true' run: echo "New commits were found to sync." - name: No new commits if: steps.sync.outputs.has_new_commits == 'false' run: echo "There were no new commits." - name: Show value of 'has_new_commits' run: echo ${{ steps.sync.outputs.has_new_commits }} - name: Sync check if: failure() run: | echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次" echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork." exit 1 ================================================ FILE: .gitignore ================================================ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # DouyinLiveRecord backup_config/ logs/ node/ node-v*.zip # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # poetry # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control poetry.lock # pdm # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. #pdm.lock # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it # in version control. # https://pdm.fming.dev/#use-with-ide .pdm.toml # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_debug/ # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ backup_config/ ================================================ FILE: Dockerfile ================================================ FROM python:3.11-slim WORKDIR /app COPY . /app RUN apt-get update && \ apt-get install -y curl gnupg && \ curl -sL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs RUN pip install --no-cache-dir -r requirements.txt RUN apt-get update && \ apt-get install -y ffmpeg tzdata && \ ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ dpkg-reconfigure -f noninteractive tzdata CMD ["python", "main.py"] ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2025 Hmily Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ ![video_spider](https://socialify.git.ci/ihmily/DouyinLiveRecorder/image?font=Inter&forks=1&language=1&owner=1&pattern=Circuit%20Board&stargazers=1&theme=Light) ## 💡简介 [![Python Version](https://img.shields.io/badge/python-3.11.6-blue.svg)](https://www.python.org/downloads/release/python-3116/) [![Supported Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20Linux-blue.svg)](https://github.com/ihmily/DouyinLiveRecorder) [![Docker Pulls](https://img.shields.io/docker/pulls/ihmily/douyin-live-recorder?label=Docker%20Pulls&color=blue&logo=docker)](https://hub.docker.com/r/ihmily/douyin-live-recorder/tags) ![GitHub issues](https://img.shields.io/github/issues/ihmily/DouyinLiveRecorder.svg) [![Latest Release](https://img.shields.io/github/v/release/ihmily/DouyinLiveRecorder)](https://github.com/ihmily/DouyinLiveRecorder/releases/latest) [![Downloads](https://img.shields.io/github/downloads/ihmily/DouyinLiveRecorder/total)](https://github.com/ihmily/DouyinLiveRecorder/releases/latest) 一款**简易**的可循环值守的直播录制工具,基于FFmpeg实现多平台直播源录制,支持自定义配置录制以及直播状态推送。 ## 😺已支持平台 - [x] 抖音 - [x] TikTok - [x] 快手 - [x] 虎牙 - [x] 斗鱼 - [x] YY - [x] B站 - [x] 小红书 - [x] bigo - [x] blued - [x] SOOP(原AfreecaTV) - [x] 网易cc - [x] 千度热播 - [x] PandaTV - [x] 猫耳FM - [x] Look直播 - [x] WinkTV - [x] TTingLive(原Flextv) - [x] PopkonTV - [x] TwitCasting - [x] 百度直播 - [x] 微博直播 - [x] 酷狗直播 - [x] TwitchTV - [x] LiveMe - [x] 花椒直播 - [x] 流星直播 - [x] ShowRoom - [x] Acfun - [x] 映客直播 - [x] 音播直播 - [x] 知乎直播 - [x] CHZZK - [x] 嗨秀直播 - [x] vv星球直播 - [x] 17Live - [x] 浪Live - [x] 畅聊直播 - [x] 飘飘直播 - [x] 六间房直播 - [x] 乐嗨直播 - [x] 花猫直播 - [x] Shopee - [x] Youtube - [x] 淘宝 - [x] 京东 - [x] Faceit - [x] 咪咕 - [x] 连接直播 - [x] 来秀直播 - [x] Picarto - [ ] 更多平台正在更新中 ## 🎈项目结构 ``` . └── DouyinLiveRecorder/ ├── /config -> (config record) ├── /logs -> (save runing log file) ├── /backup_config -> (backup file) ├── /douyinliverecorder -> (package) ├── initializer.py-> (check and install nodejs) ├── spider.py-> (get live data) ├── stream.py-> (get live stream address) ├── utils.py -> (contains utility functions) ├── logger.py -> (logger handdle) ├── room.py -> (get room info) ├── ab_sign.py-> (generate dy token) ├── /javascript -> (some decrypt code) ├── main.py -> (main file) ├── ffmpeg_install.py -> (ffmpeg install script) ├── demo.py -> (call package test demo) ├── msg_push.py -> (send live status update message) ├── ffmpeg.exe -> (record video) ├── index.html -> (play m3u8 and flv video) ├── requirements.txt -> (library dependencies) ├── docker-compose.yaml -> (Container Orchestration File) ├── Dockerfile -> (Application Build Recipe) ├── StopRecording.vbs -> (stop recording script on Windows) ... ``` ## 🌱使用说明 - 对于只想使用录制软件的小白用户,进入[Releases](https://github.com/ihmily/DouyinLiveRecorder/releases) 中下载最新发布的 zip压缩包即可,里面有打包好的录制软件。(有些电脑可能会报毒,直接忽略即可,如果下载时被浏览器屏蔽,请更换浏览器下载) - 压缩包解压后,在 `config` 文件夹内的 `URL_config.ini` 中添加录制直播间地址,一行一个直播间地址。如果要自定义配置录制,可以修改`config.ini` 文件,推荐将录制格式修改为`ts`。 - 以上步骤都做好后,就可以运行`DouyinLiveRecorder.exe` 程序进行录制了。录制的视频文件保存在同目录下的 `downloads` 文件夹内。 - 另外,如果需要录制TikTok、AfreecaTV等海外平台,请在配置文件中设置开启代理并添加proxy_addr链接 如:`127.0.0.1:7890` (这只是示例地址,具体根据实际填写)。 - 假如`URL_config.ini`文件中添加的直播间地址,有个别直播间暂时不想录制又不想移除链接,可以在对应直播间的链接开头加上`#`,那么将停止该直播间的监测以及录制。 - 软件默认录制清晰度为 `原画` ,如果要单独设置某个直播间的录制画质,可以在添加直播间地址时前面加上画质即可,如`超清,https://live.douyin.com/745964462470` 记得中间要有`,` 分隔。 - 如果要长时间挂着软件循环监测直播,最好循环时间设置长一点(咱也不差没录制到的那几分钟),避免因请求频繁导致被官方封禁IP 。 - 要停止直播录制,Windows平台可执行StopRecording.vbs脚本文件,或者在录制界面使用 `Ctrl+C ` 组合键中断录制,若要停止其中某个直播间的录制,可在`URL_config.ini`文件中的地址前加#,会自动停止对应直播间的录制并正常保存已录制的视频。 - 最后,欢迎右上角给本项目一个star,同时也非常乐意大家提交pr。   直播间链接示例: ``` 抖音: https://live.douyin.com/745964462470 https://v.douyin.com/iQFeBnt/ https://live.douyin.com/yall1102 (链接+抖音号) https://v.douyin.com/CeiU5cbX (主播主页地址) TikTok: https://www.tiktok.com/@pearlgaga88/live 快手: https://live.kuaishou.com/u/yall1102 虎牙: https://www.huya.com/52333 斗鱼: https://www.douyu.com/3637778?dyshid= https://www.douyu.com/topic/wzDBLS6?rid=4921614&dyshid= YY: https://www.yy.com/22490906/22490906 B站: https://live.bilibili.com/320 小红书(直播间分享地址): http://xhslink.com/xpJpfM bigo直播: https://www.bigo.tv/cn/716418802 buled直播: https://app.blued.cn/live?id=Mp6G2R SOOP: https://play.sooplive.co.kr/sw7love 网易cc: https://cc.163.com/583946984 千度热播: https://qiandurebo.com/web/video.php?roomnumber=33333 PandaTV: https://www.pandalive.co.kr/live/play/bara0109 猫耳FM: https://fm.missevan.com/live/868895007 Look直播: https://look.163.com/live?id=65108820&position=3 WinkTV: https://www.winktv.co.kr/live/play/anjer1004 FlexTV(TTinglive):: https://www.flextv.co.kr/channels/593127/live PopkonTV: https://www.popkontv.com/live/view?castId=wjfal007&partnerCode=P-00117 https://www.popkontv.com/channel/notices?mcid=wjfal007&mcPartnerCode=P-00117 TwitCasting: https://twitcasting.tv/c:uonq 百度直播: https://live.baidu.com/m/media/pclive/pchome/live.html?room_id=9175031377&tab_category 微博直播: https://weibo.com/l/wblive/p/show/1022:2321325026370190442592 酷狗直播: https://fanxing2.kugou.com/50428671?refer=2177&sourceFrom= TwitchTV: https://www.twitch.tv/gamerbee LiveMe: https://www.liveme.com/zh/v/17141543493018047815/index.html 花椒直播: https://www.huajiao.com/l/345096174 流星直播: https://www.7u66.com/100960 ShowRoom: https://www.showroom-live.com/room/profile?room_id=480206 (主播主页地址) Acfun: https://live.acfun.cn/live/179922 映客直播: https://www.inke.cn/liveroom/index.html?uid=22954469&id=1720860391070904 音播直播: https://live.ybw1666.com/800002949 知乎直播: https://www.zhihu.com/people/ac3a467005c5d20381a82230101308e9 (主播主页地址) CHZZK: https://chzzk.naver.com/live/458f6ec20b034f49e0fc6d03921646d2 嗨秀直播: https://www.haixiutv.com/6095106 VV星球直播: https://h5webcdn-pro.vvxqiu.com//activity/videoShare/videoShare.html?h5Server=https://h5p.vvxqiu.com&roomId=LP115924473&platformId=vvstar 17Live: https://17.live/en/live/6302408 浪Live: https://www.lang.live/en-US/room/3349463 畅聊直播: https://live.tlclw.com/106188 飘飘直播: https://m.pp.weimipopo.com/live/preview.html?uid=91648673&anchorUid=91625862&app=plpl 六间房直播: https://v.6.cn/634435 乐嗨直播: https://www.lehaitv.com/8059096 花猫直播: https://h.catshow168.com/live/preview.html?uid=19066357&anchorUid=18895331 Shopee: https://sg.shp.ee/GmpXeuf?uid=1006401066&session=802458 Youtube: https://www.youtube.com/watch?v=cS6zS5hi1w0 淘宝(需cookie): https://tbzb.taobao.com/live?liveId=532359023188 https://m.tb.cn/h.TWp0HTd 京东: https://3.cn/28MLBy-E Faceit: https://www.faceit.com/zh/players/Compl1/stream 连接直播: https://show.lailianjie.com/10000258 咪咕直播: https://www.miguvideo.com/p/live/120000541321 来秀直播: https://www.imkktv.com/h5/share/video.html?uid=1845195&roomId=1710496 Picarto: https://www.picarto.tv/cuteavalanche ```   ## 🎃源码运行 使用源码运行,可参考下面的步骤。 1.首先拉取或手动下载本仓库项目代码 ```bash git clone https://github.com/ihmily/DouyinLiveRecorder.git ``` 2.进入项目文件夹,安装依赖 ```bash cd DouyinLiveRecorder ``` > [!TIP] > - 不论你是否已安装 **Python>=3.10** 环境, 都推荐使用 [**uv**](https://github.com/astral-sh/uv) 运行, 因为它可以自动管理虚拟环境和方便地管理 **Python** 版本, **不过这完全是可选的**
> 使用以下命令安装 > ```bash > # 在 macOS 和 Linux 上安装 uv > curl -LsSf https://astral.sh/uv/install.sh | sh > ``` > ```powershell > # 在 Windows 上安装 uv > powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" > ``` > - 如果安装依赖速度太慢, 你可以考虑使用国内 pip 镜像源:
> 在 `pip` 命令使用 `-i` 参数指定, 如 `pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
> 或者在 `uv` 命令 `--index` 选项指定, 如 `uv sync --index https://pypi.tuna.tsinghua.edu.cn/simple`
如果已安装 Python>=3.10 环境 - :white_check_mark: 在虚拟环境中安装 (推荐) 1. 创建虚拟环境 - 使用系统已安装的 Python, 不使用 uv ```bash python -m venv .venv ``` - 使用 uv, 默认使用系统 Python, 你可以添加 `--python` 选项指定 Python 版本而不使用系统 Python [uv官方文档](https://docs.astral.sh/uv/concepts/python-versions/) ```bash uv venv ``` 2. 在终端激活虚拟环境 (在未安装 uv 或你想要手动激活虚拟环境时执行, 若已安装 uv, 可以跳过这一步, uv 会自动激活并使用虚拟环境) **Bash** 中 ```bash source .venv/Scripts/activate ``` **Powershell** 中 ```powershell .venv\Scripts\activate.ps1 ``` **Windows CMD** 中 ```bat .venv\Scripts\activate.bat ``` 3. 安装依赖 ```bash # 使用 pip (若安装太慢或失败, 可使用 `-i` 指定镜像源) pip3 install -U pip && pip3 install -r requirements.txt # 或者使用 uv (可使用 `--index` 指定镜像源) uv sync # 或者 uv pip sync requirements.txt ``` - :x: 在系统 Python 环境中安装 (不推荐) ```bash pip3 install -U pip && pip3 install -r requirements.txt ```
如果未安装 Python>=3.10 环境 你可以使用 [**uv**](https://github.com/astral-sh/uv) 安装依赖 ```bash # uv 将使用 3.10 及以上的最新 python 发行版自动创建并使用虚拟环境, 可使用 --python 选项指定 python 版本, 参见 https://docs.astral.sh/uv/reference/cli/#uv-sync--python 和 https://docs.astral.sh/uv/reference/cli/#uv-pip-sync--python uv sync # 或 uv pip sync requirements.txt ```
3.安装[FFmpeg](https://ffmpeg.org/download.html#build-linux),如果是Windows系统,这一步可跳过。对于Linux系统,执行以下命令安装 CentOS执行 ```bash yum install epel-release yum install ffmpeg ``` Ubuntu则执行 ```bash apt update apt install ffmpeg ``` macOS 执行 **如果已经安装 Homebrew 请跳过这一步** ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` ```bash brew install ffmpeg ``` 4.运行程序 ```python python main.py ``` 或 ```bash uv run main.py ``` 其中Linux系统请使用`python3 main.py` 运行。   ## 🐋容器运行 在运行命令之前,请确保您的机器上安装了 [Docker](https://docs.docker.com/get-docker/) 和 [Docker Compose](https://docs.docker.com/compose/install/) 1.快速启动 最简单方法是运行项目中的 [docker-compose.yaml](https://github.com/ihmily/DouyinLiveRecorder/blob/main/docker-compose.yaml) 文件,只需简单执行以下命令: ```bash docker-compose up ``` 可选 `-d` 在后台运行。 2.构建镜像(可选) 如果你只想简单的运行程序,则不需要做这一步。Docker镜像仓库中代码版本可能不是最新的,如果要运行本仓库主分支最新代码,可以本地自定义构建,通过修改 [docker-compose.yaml](https://github.com/ihmily/DouyinLiveRecorder/blob/main/docker-compose.yaml) 文件,如将镜像名修改为 `douyin-live-recorder:latest`,并取消 `# build: .` 注释,然后再执行 ```bash docker build -t douyin-live-recorder:latest . docker-compose up ``` 或者直接使用下面命令进行构建并启动 ```bash docker-compose -f docker-compose.yaml up ``` 3.停止容器实例 ```bash docker-compose stop ``` 4.注意事项 ①在docker容器内运行本程序之前,请先在配置文件中添加要录制的直播间地址。 ②在容器内时,如果手动中断容器运行停止录制,会导致正在录制的视频文件损坏! **无论哪种运行方式,为避免手动中断或者异常中断导致录制的视频文件损坏的情况,推荐使用 `ts` 格式保存**。   ## 🤖相关项目 - StreamCap: https://github.com/ihmily/StreamCap - streamget: https://github.com/ihmily/streamget   ## ❤️贡献者    [![Hmily](https://github.com/ihmily.png?size=50)](https://github.com/ihmily) [![iridescentGray](https://github.com/iridescentGray.png?size=50)](https://github.com/iridescentGray) [![annidy](https://github.com/annidy.png?size=50)](https://github.com/annidy) [![wwkk2580](https://github.com/wwkk2580.png?size=50)](https://github.com/wwkk2580) [![missuo](https://github.com/missuo.png?size=50)](https://github.com/missuo) xueli12 kaine1973 yinruiqing Max-Tortoise [![justdoiting](https://github.com/justdoiting.png?size=50)](https://github.com/justdoiting) [![dhbxs](https://github.com/dhbxs.png?size=50)](https://github.com/dhbxs) [![wujiyu115](https://github.com/wujiyu115.png?size=50)](https://github.com/wujiyu115) [![zhanghao333](https://github.com/zhanghao333.png?size=50)](https://github.com/zhanghao333) gyc0123    [![HoratioShaw](https://github.com/HoratioShaw.png?size=50)](https://github.com/HoratioShaw) [![nov30th](https://github.com/nov30th.png?size=50)](https://github.com/nov30th) [![727155455](https://github.com/727155455.png?size=50)](https://github.com/727155455) [![nixingshiguang](https://github.com/nixingshiguang.png?size=50)](https://github.com/nixingshiguang) [![1411430556](https://github.com/1411430556.png?size=50)](https://github.com/1411430556) [![Ovear](https://github.com/Ovear.png?size=50)](https://github.com/Ovear)   ## ⏳提交日志 - 20251024 - 修复抖音风控无法获取数据问题 - 新增soop.com录制支持 - 修复bigo录制 - 20250127 - 新增淘宝、京东、faceit直播录制 - 修复小红书直播流录制以及转码问题 - 修复畅聊、VV星球、flexTV直播录制 - 修复批量微信直播推送 - 新增email发送ssl和port配置 - 新增强制转h264配置 - 更新ffmpeg版本 - 重构包为异步函数! - 20241130 - 新增shopee、youtube直播录制 - 新增支持自定义m3u8、flv地址录制 - 新增自定义执行脚本,支持python、bat、bash等 - 修复YY直播、花椒直播和小红书直播录制 - 修复b站标题获取错误 - 修复log日志错误 - 20241030 - 新增嗨秀直播、vv星球直播、17Live、浪Live、SOOP、畅聊直播(原时光直播)、飘飘直播、六间房直播、乐嗨直播、花猫直播等10个平台直播录制 - 修复小红书直播录制,支持小红书作者主页地址录制直播 - 新增支持ntfy消息推送,以及新增支持批量推送多个地址(逗号分隔多个推送地址) - 修复Liveme直播录制、twitch直播录制 - 新增Windows平台一键停止录制VB脚本程序 - 20241005 - 新增邮箱和Bark推送 - 新增直播注释停止录制 - 优化分段录制 - 重构部分代码 - 20240928 - 新增知乎直播、CHZZK直播录制 - 修复音播直播录制 - 20240903 - 新增抖音双屏录制、音播直播录制 - 修复PandaTV、bigo直播录制 - 20240713 - 新增映客直播录制 - 20240705 - 新增时光直播录制 - 20240701 - 修复虎牙直播录制2分钟断流问题 - 新增自定义直播推送内容 - 20240621 - 新增Acfun、ShowRoom直播录制 - 修复微博录制、新增直播源线路 - 修复斗鱼直播60帧录制 - 修复酷狗直播录制 - 修复TikTok部分无法解析直播源 - 修复抖音无法录制连麦直播 - 20240510 - 修复部分虎牙直播间录制错误 - 20240508 - 修复花椒直播录制 - 更改文件路径解析方式 [@kaine1973](https://github.com/kaine1973) - 20240506 - 修复抖音录制画质解析bug - 修复虎牙录制 60帧最高画质问题 - 新增流星直播录制 - 20240427 - 新增LiveMe、花椒直播录制 - 20240425 - 新增TwitchTV直播录制 - 20240424 - 新增酷狗直播录制、优化PopkonTV直播录制 - 20240423 - 新增百度直播录制、微博直播录制 - 修复斗鱼录制直播回放的问题 - 新增直播源地址显示以及输出到日志文件设置 - 20240311 - 修复海外平台录制bug,增加画质选择,增强录制稳定性 - 修复虎牙录制bug (虎牙`一起看`频道 有特殊限制,有时无法录制) - 20240309 - 修复虎牙直播、小红书直播和B站直播录制 - 新增5个直播平台录制,包括winktv、flextv、look、popkontv、twitcasting - 新增部分海外平台账号密码配置,实现自动登录并更新配置文件中的cookie - 新增自定义配置需要使用代理录制的平台 - 新增只推送开播消息不进行录制设置 - 修复了一些bug - 20240209 - 优化AfreecaTV录制,新增账号密码登录获取cookie以及持久保存 - 修复了小红书直播因官方更新直播域名,导致无法录制直播的问题 - 修复了更新URL配置文件的bug - 最后,祝大家新年快乐!
点击展开更多提交日志 - 20240129 - 新增猫耳FM直播录制 - 20240127 - 新增千度热播直播录制、新增pandaTV(韩国)直播录制 - 新增telegram直播状态消息推送,修复了某些bug - 新增自定义设置不同直播间的录制画质(即每个直播间录制画质可不同) - 修改录制视频保存路径为 `downloads` 文件夹,并且分平台进行保存。 - 20240114 - 新增网易cc直播录制,优化ffmpeg参数,修改AfreecaTV输入直播地址格式 - 修改日志记录器 @[iridescentGray](https://github.com/iridescentGray) - 20240102 - 修复Linux上运行,新增docker配置文件 - 20231210 - 修复录制分段bug,修复bigo录制检测bug - 新增自定义修改录制主播名 - 新增AfreecaTV直播录制,修复某些可能会发生的bug - 20231207 - 新增blued直播录制,修复YY直播录制,新增直播结束消息推送 - 20231206 - 新增bigo直播录制 - 20231203 - 新增小红书直播录制(全网首发),目前小红书官方没有切换清晰度功能,因此直播录制也只有默认画质 - 小红书录制暂时无法循环监测,每次主播开启直播,都要重新获取一次链接 - 获取链接的方式为 将直播间转发到微信,在微信中打开后,复制页面的链接。 - 20231030 - 本次更新只是进行修复,没时间新增功能。 - 欢迎各位大佬提pr 帮忙更新维护 - 20230930 - 新增抖音从接口获取直播流,增强稳定性 - 修改快手获取直播流的方式,改用从官方接口获取 - 祝大家中秋节快乐! - 20230919 - 修复了快手版本更新后录制出错的问题,增加了其自动获取cookie(~~稳定性未知~~) - 修复了TikTok显示正在直播但不进行录制的问题 - 20230907 - 修复了因抖音官方更新了版本导致的录制出错以及短链接转换出错 - 修复B站无法录制原画视频的bug - 修改了配置文件字段,新增各平台自定义设置Cookie - 20230903 - 修复了TikTok录制时报644无法录制的问题 - 新增直播状态推送到钉钉和微信的功能,如有需要请看 [设置推送教程](https://d04vqdiqwr3.feishu.cn/docx/XFPwdDDvfobbzlxhmMYcvouynDh?from=from_copylink) - 最近比较忙,其他问题有时间再更新 - 20230816 - 修复斗鱼直播(官方更新了字段)和快手直播录制出错的问题 - 20230814 - 新增B站直播录制 - 写了一个在线播放M3U8和FLV视频的网页源码,打开即可食用 - 20230812 - 新增YY直播录制 - 20230808 - 修复主播重新开播无法再次录制的问题 - 20230807 - 新增了斗鱼直播录制 - 修复显示录制完成之后会重新开始录制的问题 - 20230805 - 新增了虎牙直播录制,其暂时只能用flv视频流进行录制 - Web API 新增了快手和虎牙这两个平台的直播流解析(TikTok要代理) - 20230804 - 新增了快手直播录制,优化了部分代码 - 上传了一个自动化获取抖音直播间页面Cookie的代码,可以用于录制 - 20230803 - 通宵更新 - 新增了国际版抖音TikTok的直播录制,去除冗余 简化了部分代码 - 20230724 - 新增了一个通过抖音直播间地址获取直播视频流链接的API接口,上传即可用
  ## 有问题可以提issue, 我会在这里持续添加更多直播平台的录制 欢迎Star #### ================================================ FILE: StopRecording.vbs ================================================ '********************************************************************************************/ '* File Name : StopRecording.vbs '* Created Date : 2024-10-15 01:50:30 '* Author : Hmily '* GitHub : http://github.com/ihmily '* Description : This script is designed to terminate the process of live recording '********************************************************************************************/ Dim objWMIService, colProcesses, objProcess Dim intResponse strComputer = "." On Error Resume Next intResponse = MsgBox("ȷҪкֱ̨¼ƽ", vbYesNo + vbQuestion, "ȷϽ") If intResponse = vbYes Then Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") If Err.Number <> 0 Then Err.Clear End If Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'ffmpeg.exe'") Set colProcesses2 = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'pythonw.exe'") Set colProcesses3 = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'DouyinLiveRecorder.exe'") If Err.Number <> 0 Then Err.Clear End If If Not objWMIService Is Nothing And Not colProcesses Is Nothing And Not colProcesses2 Is Nothing Then If colProcesses2.Count = 0 And colProcesses3.Count = 0 Then MsgBox "ûҵ¼ƳĽ", vbExclamation, "ʾϢ" WScript.Quit(1) Else For Each objProcess in colProcesses objProcess.Terminate() If Err.Number <> 0 Then objShell.Run "taskkill /f /im " & objProcess.Name, 0, True Err.Clear End If Next End If Else objShell.Run "taskkill /f /im " & objProcess.Name, 0, True End If MsgBox "ѳɹ¼ֱḶ̌" & vbCrLf & "رմ˴30Զֹͣ¼Ƴ", vbInformation, "ʾϢ" WScript.Sleep 10000 If colProcesses3.Count <> 0 Then Set colProcesses_ = colProcesses3 Else Set colProcesses_ = colProcesses2 End If For Each objProcess in colProcesses_ objProcess.Terminate() If Err.Number <> 0 Then objShell.Run "taskkill /f /im " & objProcess.Name, 0, True Err.Clear End If Next Else MsgBox "ȡ¼Ʋ", vbExclamation, "ʾϢ" End If On Error GoTo 0 Set objWMIService = Nothing Set colProcesses = Nothing Set colProcesses2 = Nothing Set colProcesses3 = Nothing Set objProcess = Nothing Set objShell = Nothing ================================================ FILE: config/URL_config.ini ================================================  ================================================ FILE: config/config.ini ================================================ [录制设置] language(zh_cn/en) = zh_cn 是否跳过代理检测(是/否) = 否 直播保存路径(不填则默认) = 保存文件夹是否以作者区分 = 是 保存文件夹是否以时间区分 = 否 保存文件夹是否以标题区分 = 否 保存文件名是否包含标题 = 否 是否去除名称中的表情符号 = 是 视频保存格式ts|mkv|flv|mp4|mp3音频|m4a音频 = ts 原画|超清|高清|标清|流畅 = 原画 是否使用代理ip(是/否) = 是 代理地址 = 同一时间访问网络的线程数 = 3 循环时间(秒) = 300 排队读取网址时间(秒) = 0 是否显示循环秒数 = 否 是否显示直播源地址 = 否 分段录制是否开启 = 是 是否强制启用https录制 = 否 录制空间剩余阈值(gb) = 1.0 视频分段时间(秒) = 1800 录制完成后自动转为mp4格式 = 是 mp4格式重新编码为h264 = 否 追加格式后删除原文件 = 是 生成时间字幕文件 = 否 是否录制完成后执行自定义脚本 = 否 自定义脚本执行命令 = 使用代理录制的平台(逗号分隔) = tiktok, sooplive, pandalive, winktv, flextv, popkontv, twitch, liveme, showroom, chzzk, shopee, shp, youtu 额外使用代理录制的平台(逗号分隔) = [推送配置] # 可选微信|钉钉|tg|邮箱|bark|ntfy|pushplus 可填多个 直播状态推送渠道 = 钉钉推送接口链接 = 微信推送接口链接 = bark推送接口链接 = bark推送中断级别 = active bark推送铃声 = 钉钉通知@对象(填手机号) = 钉钉通知@全体(是/否) = 否 tgapi令牌 = tg聊天id(个人或者群组id) = smtp邮件服务器 = 是否使用SMTP服务SSL加密(是/否) = SMTP邮件服务器端口 = 邮箱登录账号 = 发件人密码(授权码) = 发件人邮箱 = 发件人显示昵称 = 收件人邮箱 = ntfy推送地址 = https://ntfy.sh/xxxx ntfy推送标签 = tada ntfy推送邮箱 = pushplus推送token = 自定义推送标题 = 自定义开播推送内容 = 自定义关播推送内容 = 只推送通知不录制(是/否) = 否 直播推送检测频率(秒) = 1800 开播推送开启(是/否) = 是 关播推送开启(是/否)= 否 [Cookie] # 录制抖音必填 抖音cookie = ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986 快手cookie = tiktok_cookie = 虎牙cookie = 斗鱼cookie = yy_cookie = b站cookie = 小红书cookie = bigo_cookie = blued_cookie = sooplive_cookie = netease_cookie = 千度热播_cookie = pandatv_cookie = 猫耳fm_cookie = winktv_cookie = flextv_cookie = look_cookie = twitcasting_cookie = baidu_cookie = weibo_cookie = kugou_cookie = twitch_cookie = liveme_cookie = huajiao_cookie = liuxing_cookie = showroom_cookie = acfun_cookie = changliao_cookie = yinbo_cookie = yingke_cookie = zhihu_cookie = chzzk_cookie = haixiu_cookie = vvxqiu_cookie = 17live_cookie = langlive_cookie = pplive_cookie = 6room_cookie = lehaitv_cookie = huamao_cookie = shopee_cookie = youtube_cookie = taobao_cookie = jd_cookie = faceit_cookie = migu_cookie = lianjie_cookie = laixiu_cookie = picarto_cookie = [Authorization] popkontv_token = [账号密码] sooplive账号 = sooplive密码 = flextv账号 = flextv密码 = popkontv账号 = partner_code = P-00001 popkontv密码 = twitcasting账号类型 = normal twitcasting账号 = twitcasting密码 = ================================================ FILE: demo.py ================================================ # -*- coding: utf-8 -*- import asyncio from src.logger import logger from src import spider # 以下示例直播间链接不保证时效性,请自行查看链接是否能正常访问 # Please note that the following example live room links may not be up-to-date LIVE_STREAM_CONFIG = { "douyin": { "url": "https://live.douyin.com/745964462470", "func": spider.get_douyin_app_stream_data, }, "tiktok": { "url": "https://www.tiktok.com/@pearlgaga88/live", "func": spider.get_tiktok_stream_data, }, "kuaishou": { "url": "https://live.kuaishou.com/u/yall1102", "func": spider.get_kuaishou_stream_data, }, "huya": { "url": "https://www.huya.com/116", "func": spider.get_huya_app_stream_url, }, "douyu": { "url": "https://www.douyu.com/topic/wzDBLS6?rid=4921614&dyshid=", "func": spider.get_douyu_info_data, }, "yy": { "url": "https://www.yy.com/22490906/22490906", "func": spider.get_yy_stream_data, }, "bilibili": { "url": "https://live.bilibili.com/21593109", "func": spider.get_bilibili_stream_data, }, "xhs": { "url": "https://www.xiaohongshu.com/user/profile/6330049c000000002303c7ed?appuid=5f3f478a00000000010005b3", "func": spider.get_xhs_stream_url, }, "bigo": { "url": "https://www.bigo.tv/cn/716418802", "func": spider.get_bigo_stream_url, }, "blued": { "url": "https://app.blued.cn/live?id=Mp6G2R", "func": spider.get_blued_stream_url, }, "sooplive": { "url": "https://play.sooplive.co.kr/sw7love", "func": spider.get_sooplive_stream_data, }, "netease": { "url": "https://cc.163.com/583946984", "func": spider.get_netease_stream_data, }, "qiandurebo": { "url": "https://qiandurebo.com/web/video.php?roomnumber=33333", "func": spider.get_qiandurebo_stream_data, }, "pandatv": { "url": "https://www.pandalive.co.kr/live/play/bara0109", "func": spider.get_pandatv_stream_data, }, "maoerfm": { "url": "https://fm.missevan.com/live/868895007", "func": spider.get_maoerfm_stream_url, }, "winktv": { "url": "https://www.winktv.co.kr/live/play/anjer1004", "func": spider.get_winktv_stream_data, }, "flextv": { "url": "https://www.ttinglive.com/channels/685479/live", "func": spider.get_flextv_stream_data, }, "looklive": { "url": "https://look.163.com/live?id=65108820&position=3", "func": spider.get_looklive_stream_url, }, "popkontv": { "url": "https://www.popkontv.com/live/view?castId=wjfal007&partnerCode=P-00117", "func": spider.get_popkontv_stream_url, }, "twitcasting": { "url": "https://twitcasting.tv/c:uonq", "func": spider.get_twitcasting_stream_url, }, "baidu": { "url": "https://live.baidu.com/m/media/pclive/pchome/live.html?room_id=9175031377&tab_category", "func": spider.get_baidu_stream_data, }, "weibo": { "url": "https://weibo.com/u/7849520225", "func": spider.get_weibo_stream_data, }, "kugou": { "url": "https://fanxing2.kugou.com/50428671?refer=2177&sourceFrom=", "func": spider.get_kugou_stream_url, }, "twitchtv": { "url": "https://www.twitch.tv/gamerbee", "func": spider.get_twitchtv_stream_data, }, "liveme": { "url": "https://www.liveme.com/zh/v/17141937295821012854/index.html", "func": spider.get_liveme_stream_url, }, "huajiao": { "url": "https://www.huajiao.com/user/207446325", "func": spider.get_huajiao_stream_url, }, "showroom": { "url": "https://www.showroom-live.com/room/profile?room_id=511033", "func": spider.get_showroom_stream_data, }, "acfun": { "url": "https://live.acfun.cn/live/17912421", "func": spider.get_acfun_stream_data, }, "changliao": { "url": "https://www.tlclw.com/801044397", "func": spider.get_changliao_stream_url, }, "yingke": { "url": "https://www.inke.cn/liveroom/index.html?uid=710032101&id=1720857535354099", "func": spider.get_yingke_stream_url, }, "yinbo": { "url": "https://live.ybw1666.com/800008687", "func": spider.get_yinbo_stream_url, }, "zhihu": { "url": "https://www.zhihu.com/people/ac3a467005c5d20381a82230101308e9", "func": spider.get_zhihu_stream_url, }, "chzzk": { "url": "https://chzzk.naver.com/live/458f6ec20b034f49e0fc6d03921646d2", "func": spider.get_chzzk_stream_data, }, "haixiu": { "url": "https://www.haixiutv.com/6095106", "func": spider.get_haixiu_stream_url, }, "vvxqiu": { "url": "https://h5webcdnp.vvxqiu.com//activity/videoShare/videoShare.html?h5Server=https://h5p.vvxqiu.com&" "roomId=LP115664695&platformId=vvstar", "func": spider.get_vvxqiu_stream_url, }, "17live": { "url": "https://17.live/en/live/6302408", "func": spider.get_17live_stream_url, }, "langlive": { "url": "https://www.lang.live/en-US/room/3349463", "func": spider.get_langlive_stream_url, }, "pplive": { "url": "https://m.pp.weimipopo.com/live/preview.html?uid=91648673&anchorUid=91625862&app=plpl", "func": spider.get_pplive_stream_url, }, "6room": { "url": "https://v.6.cn/634435", "func": spider.get_6room_stream_url, }, "lehai": { "url": "https://www.lehaitv.com/8059096", "func": spider.get_haixiu_stream_url, }, "huamao": { "url": "https://h.catshow168.com/live/preview.html?uid=19066357&anchorUid=18895331", "func": spider.get_pplive_stream_url, }, "shopee": { "url": "https://sg.shp.ee/GmpXeuf?uid=1006401066&session=802458", "func": spider.get_shopee_stream_url, }, "youtube": { "url": "https://www.youtube.com/watch?v=cS6zS5hi1w0", "func": spider.get_youtube_stream_url, }, "taobao": { "url": "https://m.tb.cn/h.TWp0HTd", "func": spider.get_taobao_stream_url, }, "jd": { "url": "https://3.cn/28MLBy-E", "func": spider.get_jd_stream_url, }, "faceit": { "url": "https://www.faceit.com/zh/players/Compl1/stream", "func": spider.get_faceit_stream_data, }, "lianjie": { "url": "https://show.lailianjie.com/10000258", "func": spider.get_lianjie_stream_url, }, "migu": { "url": "https://www.miguvideo.com/p/live/120000541321", "func": spider.get_migu_stream_url, }, "laixiu": { "url": "https://www.imkktv.com/h5/share/video.html?uid=1845195&roomId=1710496", "func": spider.get_laixiu_stream_url, }, "picarto": { "url": "https://www.picarto.tv/cuteavalanche", "func": spider.get_picarto_stream_url, } } def test_live_stream(platform_name: str, proxy_addr=None, cookies=None) -> None: if platform_name in LIVE_STREAM_CONFIG: config = LIVE_STREAM_CONFIG[platform_name] try: stream_data = asyncio.run(config['func'](config['url'], proxy_addr=proxy_addr, cookies=cookies)) logger.debug(f"Stream data for {platform_name}: {stream_data}") except Exception as e: logger.error(f"Error fetching stream data for {platform_name}: {e}") else: logger.warning(f"No configuration found for platform: {platform_name}") if __name__ == "__main__": platform = "douyin" test_live_stream(platform) ================================================ FILE: docker-compose.yaml ================================================ version: '3.8' services: app: image: ihmily/douyin-live-recorder:latest environment: - TERM=xterm-256color tty: true stdin_open: true #build: . volumes: - ./config:/app/config - ./logs:/app/logs - ./backup_config:/app/backup_config - ./downloads:/app/downloads restart: always ================================================ FILE: ffmpeg_install.py ================================================ # -*- coding: utf-8 -*- """ Author: Hmily GitHub: https://github.com/ihmily Copyright (c) 2024 by Hmily, All Rights Reserved. """ import os import re import subprocess import sys import platform import zipfile from pathlib import Path import requests from tqdm import tqdm from src.logger import logger current_platform = platform.system() execute_dir = os.path.split(os.path.realpath(sys.argv[0]))[0] current_env_path = os.environ.get('PATH') ffmpeg_path = os.path.join(execute_dir, 'ffmpeg') def unzip_file(zip_path: str | Path, extract_to: str | Path, delete: bool = True) -> None: if not os.path.exists(extract_to): os.makedirs(extract_to) with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(extract_to) if delete and os.path.exists(zip_path): os.remove(zip_path) def get_lanzou_download_link(url: str, password: str | None = None) -> str | None: try: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Origin': 'https://wweb.lanzouv.com', 'Referer': 'https://wweb.lanzouv.com/iXncv0dly6mh', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', } response = requests.get(url, headers=headers) sign = re.search("var skdklds = '(.*?)';", response.text).group(1) data = { 'action': 'downprocess', 'sign': sign, 'p': password, 'kd': '1', } response = requests.post('https://wweb.lanzouv.com/ajaxm.php', headers=headers, data=data) json_data = response.json() download_url = json_data['dom'] + "/file/" + json_data['url'] response = requests.get(download_url, headers=headers) return response.url except Exception as e: logger.error(f"Failed to obtain ffmpeg download address. {e}") def install_ffmpeg_windows(): try: logger.warning("ffmpeg is not installed.") logger.debug("Installing the latest version of ffmpeg for Windows...") ffmpeg_url = get_lanzou_download_link('https://wweb.lanzouv.com/iHAc22ly3r3g', 'eots') if ffmpeg_url: full_file_name = 'ffmpeg_latest_build_20250124.zip' version = 'v20250124' zip_file_path = Path(execute_dir) / full_file_name if Path(zip_file_path).exists(): logger.debug("ffmpeg installation file already exists, start install...") else: response = requests.get(ffmpeg_url, stream=True) total_size = int(response.headers.get('Content-Length', 0)) block_size = 1024 with tqdm(total=total_size, unit="B", unit_scale=True, ncols=100, desc=f'Downloading ffmpeg ({version})') as t: with open(zip_file_path, 'wb') as f: for data in response.iter_content(block_size): t.update(len(data)) f.write(data) unzip_file(zip_file_path, execute_dir) os.environ['PATH'] = ffmpeg_path + os.pathsep + current_env_path result = subprocess.run(["ffmpeg", "-version"], capture_output=True) if result.returncode == 0: logger.debug('ffmpeg installation was successful') else: logger.error('ffmpeg installation failed. Please manually install ffmpeg by yourself') return True else: logger.error("Please manually install ffmpeg by yourself") except Exception as e: logger.error(f"type: {type(e).__name__}, ffmpeg installation failed {e}") def install_ffmpeg_mac(): logger.warning("ffmpeg is not installed.") logger.debug("Installing the stable version of ffmpeg for macOS...") try: result = subprocess.run(["brew", "install", "ffmpeg"], capture_output=True) if result.returncode == 0: logger.debug('ffmpeg installation was successful. Restart for changes to take effect.') return True else: logger.error("ffmpeg installation failed") except subprocess.CalledProcessError as e: logger.error(f"Failed to install ffmpeg using Homebrew. {e}") logger.error("Please install ffmpeg manually or check your Homebrew installation.") except Exception as e: logger.error(f"An unexpected error occurred: {e}") def install_ffmpeg_linux(): is_RHS = True try: logger.warning("ffmpeg is not installed.") logger.debug("Trying to install the stable version of ffmpeg") result = subprocess.run(['yum', '-y', 'update'], capture_output=True) if result.returncode != 0: logger.error("Failed to update package lists using yum.") return False result = subprocess.run(['yum', 'install', '-y', 'ffmpeg'], capture_output=True) if result.returncode == 0: logger.debug("ffmpeg installation was successful using yum. Restart for changes to take effect.") return True logger.error(result.stderr.decode('utf-8').strip()) except FileNotFoundError: logger.debug("yum command not found, trying to install using apt...") is_RHS = False except Exception as e: logger.error(f"An error occurred while trying to install ffmpeg using yum: {e}") if not is_RHS: try: logger.debug("Trying to install the stable version of ffmpeg for Linux using apt...") result = subprocess.run(['apt', 'update'], capture_output=True) if result.returncode != 0: logger.error("Failed to update package lists using apt") return False result = subprocess.run(['apt', 'install', '-y', 'ffmpeg'], capture_output=True) if result.returncode == 0: logger.debug("ffmpeg installation was successful using apt. Restart for changes to take effect.") return True else: logger.error(result.stderr.decode('utf-8').strip()) except FileNotFoundError: logger.error("apt command not found, unable to install ffmpeg. Please manually install ffmpeg by yourself") except Exception as e: logger.error(f"An error occurred while trying to install ffmpeg using apt: {e}") logger.error("Manual installation of ffmpeg is required. Please manually install ffmpeg by yourself.") return False def install_ffmpeg() -> bool: if current_platform == "Windows": return install_ffmpeg_windows() elif current_platform == "Linux": return install_ffmpeg_linux() elif current_platform == "Darwin": return install_ffmpeg_mac() else: logger.debug(f"ffmpeg auto installation is not supported on this platform: {current_platform}. " f"Please install ffmpeg manually.") return False def ensure_ffmpeg_installed(func): def wrapper(*args, **kwargs): try: result = subprocess.run(['ffmpeg', '-version'], capture_output=True) version = result.stdout.strip() if result.returncode == 0 and version: return func(*args, **kwargs) except FileNotFoundError: pass return False def wrapped_func(*args, **kwargs): if sys.version_info >= (3, 7): res = wrapper(*args, **kwargs) else: res = wrapper(*args, **kwargs) if not res: install_ffmpeg() res = wrapper(*args, **kwargs) if not res: raise RuntimeError("ffmpeg is not installed.") return func(*args, **kwargs) return wrapped_func def check_ffmpeg_installed() -> bool: try: result = subprocess.run(['ffmpeg', '-version'], capture_output=True) version = result.stdout.strip() if result.returncode == 0 and version: return True except FileNotFoundError: pass except OSError as e: print(f"OSError occurred: {e}. ffmpeg may not be installed correctly or is not available in the system PATH.") print("Please delete the ffmpeg and try to download and install again.") except Exception as e: print(f"An unexpected error occurred: {e}") return False def check_ffmpeg() -> bool: if not check_ffmpeg_installed(): return install_ffmpeg() return True ================================================ FILE: i18n/en/LC_MESSAGES/.gitkeep ================================================ ================================================ FILE: i18n/zh_CN/LC_MESSAGES/zh_CN.po ================================================ # DouyinLiveRecorder. # Copyright (C) 2024 Hmily # This file is distributed under the same license as the DouyinLiveRecorder package. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: 4.0.1\n" "POT-Creation-Date: 2024-10-20 00:00+0800\n" "PO-Revision-Date: 2024-11-09 03:05+0800\n" "Last-Translator: Hmily \n" "Language-Team: Chinese\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: zh_CN\n" "Plural-Forms: nplurals=1; plural=0;\n" #: douyinliverecorder/spider.py msgid "IP banned. Please change device or network." msgstr "IP被禁止 请更换设备或网络" msgid "The anchor did not start broadcasting." msgstr "主播并未开播" msgid "sooplive platform login successful! Starting to fetch live streaming data..." msgstr "sooplive平台登录成功!开始获取直播数据..." msgid "sooplive live stream failed to retrieve, the live stream just ended." msgstr "sooplive直播获取失败,该直播间刚结束直播" msgid "sooplive live stream retrieval failed, the live needs 19+, you are not logged in." msgstr "soop直播获取失败,该直播间需要年龄19+观看,您尚未登录" msgid "Attempting to log in to the sooplive live streaming platform with your account and password, please ensure it is configured." msgstr "正在尝试使用您的账号和密码登录soop直播平台,请确保已在config配置文件中配置" msgid "error message:Please check if the input sooplive live room address is correct." msgstr "错误信息:请检查输入的sooplive直播间地址是否正确" msgid "Please check if the FlexTV account and password in the configuration file are correct." msgstr "请检查配置文件中的FlexTV账号和密码是否正确" msgid "FlexTV live stream retrieval failed [not logged in]: 19+ live streams are only available for logged-in adults." msgstr "FlexTV直播获取失败[未登录]: 19+直播需要登录后是成人才可观看" msgid "Attempting to log in to the FlexTV live streaming platform, please ensure your account and password are correctly filled in the configuration file." msgstr "正在尝试登录FlexTV直播平台,请确保已在配置文件中填写好您的账号和密码" msgid "Logging into FlexTV platform..." msgstr "FlexTV平台登录中..." msgid "Logged into FlexTV platform successfully! Starting to fetch live streaming data..." msgstr "FlexTV平台登录成功!开始获取直播数据..." msgid "Look live currently only supports audio live streaming, not video live streaming!" msgstr "Look直播暂时只支持音频直播,不支持Look视频直播!" msgid "Failed to retrieve popkontv live stream [token does not exist or has expired]: Please log in to watch." msgstr "popkontv直播获取失败[token不存在或者已过期]: 请登录后观看" msgid "Attempting to log in to the popkontv live streaming platform, please ensure your account and password are correctly filled in the configuration file." msgstr "正在尝试登录popkontv直播平台,请确保已在配置文件中填写好您的账号和密码" msgid "Logging into popkontv platform..." msgstr "popkontv平台登录中..." msgid "Logged into popkontv platform successfully! Starting to fetch live streaming data..." msgstr "popkontv平台登录成功!开始获取直播数据..." msgid "Attempting to log in to TwitCasting..." msgstr "TwitCasting正在尝试登录..." msgid "TwitCasting login successful! Starting to fetch data..." msgstr "TwitCasting 登录成功!开始获取数据..." msgid "Failed to retrieve TwitCasting data, attempting to log in..." msgstr "获取TwitCasting数据失败,正在尝试登录..." msgid "Failed to retrieve live room data, the Huajiao live room address is not fixed, please manually change the address for recording." msgstr "获取直播间数据失败,花椒直播间地址是非固定的,请手动更换地址进行录制" msgid "Fetch shopee live data failed, please update the address of the live broadcast room and try again." msgstr "获取shopee直播间数据失败,请手动更换直播录制地址后重试" ================================================ FILE: i18n.py ================================================ import os import sys import gettext import inspect import builtins from pathlib import Path def init_gettext(locale_dir, locale_name): gettext.bindtextdomain('zh_CN', locale_dir) gettext.textdomain('zh_CN') os.environ['LANG'] = f'{locale_name}.utf8' return gettext.gettext execute_dir = os.path.split(os.path.realpath(sys.argv[0]))[0] if os.path.exists(Path(execute_dir) / '_internal/i18n'): locale_path = Path(execute_dir) / '_internal/i18n' else: locale_path = Path(execute_dir) / 'i18n' _tr = init_gettext(locale_path, 'zh_CN') original_print = builtins.print package_name = 'src' def translated_print(*args, **kwargs): for arg in args: if package_name in inspect.stack()[1].filename: translated_arg = _tr(str(arg)) else: translated_arg = str(arg) original_print(translated_arg, **kwargs) ================================================ FILE: index.html ================================================ M3U8 视频播放器

说明

M3U8文件格式

M3U8文件是采用UTF-8编码格式的M3U文件。M3U文件本身是一个纯文本索引文件,其核心功能是记录多媒体文件链接。当用户打开此类文件时,播放软件会根据索引查找相应的音视频文件网络地址,然后进行在线播放。

M3U最初设计用于播放音频文件,例如MP3。但随着时间推移,更多的播放器和软件开始使用M3U来播放视频文件列表,同时也支持在线流媒体音频源的指定。目前,许多播放器和软件都兼容M3U文件格式。

FLV文件格式(Flash Video Format)是Adobe公司开发的一种专门用于网页视频播放的文件格式。FLV格式的视频文件通常用于播放短视频和在线流媒体,可以嵌入到网页中供用户观看。FLV视频通常由Adobe Flash Player播放器播放,而其他第三方播放器也支持此格式。

================================================ FILE: main.py ================================================ # -*- encoding: utf-8 -*- """ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-17 23:52:05 Update: 2025-10-23 19:48:05 Copyright (c) 2023-2025 by Hmily, All Rights Reserved. Function: Record live stream video. """ import asyncio import os import sys import builtins import subprocess import signal import threading import time import datetime import re import shutil import random import uuid from pathlib import Path import urllib.request from urllib.error import URLError, HTTPError from typing import Any import configparser import httpx from src import spider, stream from src.proxy import ProxyDetector from src.utils import logger from src import utils from msg_push import ( dingtalk, xizhi, tg_bot, send_email, bark, ntfy, pushplus ) from ffmpeg_install import ( check_ffmpeg, ffmpeg_path, current_env_path ) version = "v4.0.7" platforms = ("\n国内站点:抖音|快手|虎牙|斗鱼|YY|B站|小红书|bigo|blued|网易CC|千度热播|猫耳FM|Look|TwitCasting|百度|微博|" "酷狗|花椒|流星|Acfun|畅聊|映客|音播|知乎|嗨秀|VV星球|17Live|浪Live|漂漂|六间房|乐嗨|花猫|淘宝|京东|咪咕|连接|来秀" "\n海外站点:TikTok|SOOP|PandaTV|WinkTV|FlexTV|PopkonTV|TwitchTV|LiveMe|ShowRoom|CHZZK|Shopee|" "Youtube|Faceit|Picarto") recording = set() error_count = 0 pre_max_request = 10 max_request_lock = threading.Lock() error_window = [] error_window_size = 10 error_threshold = 5 monitoring = 0 running_list = [] url_tuples_list = [] url_comments = [] text_no_repeat_url = [] create_var = locals() first_start = True exit_recording = False need_update_line_list = [] first_run = True not_record_list = [] start_display_time = datetime.datetime.now() global_proxy = False recording_time_list = {} script_path = os.path.split(os.path.realpath(sys.argv[0]))[0] config_file = f'{script_path}/config/config.ini' url_config_file = f'{script_path}/config/URL_config.ini' backup_dir = f'{script_path}/backup_config' text_encoding = 'utf-8-sig' rstr = r"[\/\\\:\*\??\"\<\>\|&#.。,, ~!· ]" default_path = f'{script_path}/downloads' os.makedirs(default_path, exist_ok=True) file_update_lock = threading.Lock() os_type = os.name clear_command = "cls" if os_type == 'nt' else "clear" color_obj = utils.Color() os.environ['PATH'] = ffmpeg_path + os.pathsep + current_env_path def signal_handler(_signal, _frame): sys.exit(0) signal.signal(signal.SIGTERM, signal_handler) def display_info() -> None: global start_display_time time.sleep(5) while True: try: sys.stdout.flush() time.sleep(5) if Path(sys.executable).name != 'pythonw.exe': os.system(clear_command) print(f"\r共监测{monitoring}个直播中", end=" | ") print(f"同一时间访问网络的线程数: {max_request}", end=" | ") print(f"是否开启代理录制: {'是' if use_proxy else '否'}", end=" | ") if split_video_by_time: print(f"录制分段开启: {split_time}秒", end=" | ") else: print("录制分段开启: 否", end=" | ") if create_time_file: print("是否生成时间文件: 是", end=" | ") print(f"录制视频质量为: {video_record_quality}", end=" | ") print(f"录制视频格式为: {video_save_type}", end=" | ") print(f"目前瞬时错误数为: {error_count}", end=" | ") now = time.strftime("%H:%M:%S", time.localtime()) print(f"当前时间: {now}") if len(recording) == 0: time.sleep(5) if monitoring == 0: print("\r没有正在监测和录制的直播") else: print(f"\r没有正在录制的直播 循环监测间隔时间:{delay_default}秒") else: now_time = datetime.datetime.now() print("x" * 60) no_repeat_recording = list(set(recording)) print(f"正在录制{len(no_repeat_recording)}个直播: ") for recording_live in no_repeat_recording: rt, qa = recording_time_list[recording_live] have_record_time = now_time - rt print(f"{recording_live}[{qa}] 正在录制中 {str(have_record_time).split('.')[0]}") # print('\n本软件已运行:'+str(now_time - start_display_time).split('.')[0]) print("x" * 60) start_display_time = now_time except Exception as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") def update_file(file_path: str, old_str: str, new_str: str, start_str: str = None) -> str | None: if old_str == new_str and start_str is None: return old_str with file_update_lock: file_data = [] with open(file_path, "r", encoding=text_encoding) as f: try: for text_line in f: if old_str in text_line: text_line = text_line.replace(old_str, new_str) if start_str: text_line = f'{start_str}{text_line}' if text_line not in file_data: file_data.append(text_line) except RuntimeError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") if ini_URL_content: with open(file_path, "w", encoding=text_encoding) as f2: f2.write(ini_URL_content) return old_str if file_data: with open(file_path, "w", encoding=text_encoding) as f: f.write(''.join(file_data)) return new_str def delete_line(file_path: str, del_line: str, delete_all: bool = False) -> None: with file_update_lock: with open(file_path, 'r+', encoding=text_encoding) as f: lines = f.readlines() f.seek(0) f.truncate() skip_line = False for txt_line in lines: if del_line in txt_line: if delete_all or not skip_line: skip_line = True continue else: skip_line = False f.write(txt_line) def get_startup_info(system_type: str): if system_type == 'nt': startup_info = subprocess.STARTUPINFO() startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: startup_info = None return startup_info def segment_video(converts_file_path: str, segment_save_file_path: str, segment_format: str, segment_time: str, is_original_delete: bool = True) -> None: try: if os.path.exists(converts_file_path) and os.path.getsize(converts_file_path) > 0: ffmpeg_command = [ "ffmpeg", "-i", converts_file_path, "-c:v", "copy", "-c:a", "copy", "-map", "0", "-f", "segment", "-segment_time", segment_time, "-segment_format", segment_format, "-reset_timestamps", "1", "-movflags", "+frag_keyframe+empty_moov", segment_save_file_path, ] _output = subprocess.check_output( ffmpeg_command, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type) ) if is_original_delete: time.sleep(1) if os.path.exists(converts_file_path): os.remove(converts_file_path) except subprocess.CalledProcessError as e: logger.error(f'Error occurred during conversion: {e}') except Exception as e: logger.error(f'An unknown error occurred: {e}') def converts_mp4(converts_file_path: str, is_original_delete: bool = True) -> None: try: if os.path.exists(converts_file_path) and os.path.getsize(converts_file_path) > 0: if converts_to_h264: color_obj.print_colored("正在转码为MP4格式并重新编码为h264\n", color_obj.YELLOW) ffmpeg_command = [ "ffmpeg", "-i", converts_file_path, "-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-vf", "format=yuv420p", "-c:a", "copy", "-f", "mp4", converts_file_path.rsplit('.', maxsplit=1)[0] + ".mp4", ] else: color_obj.print_colored("正在转码为MP4格式\n", color_obj.YELLOW) ffmpeg_command = [ "ffmpeg", "-i", converts_file_path, "-c:v", "copy", "-c:a", "copy", "-f", "mp4", converts_file_path.rsplit('.', maxsplit=1)[0] + ".mp4", ] _output = subprocess.check_output( ffmpeg_command, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type) ) if is_original_delete: time.sleep(1) if os.path.exists(converts_file_path): os.remove(converts_file_path) except subprocess.CalledProcessError as e: logger.error(f'Error occurred during conversion: {e}') except Exception as e: logger.error(f'An unknown error occurred: {e}') def converts_m4a(converts_file_path: str, is_original_delete: bool = True) -> None: try: if os.path.exists(converts_file_path) and os.path.getsize(converts_file_path) > 0: _output = subprocess.check_output([ "ffmpeg", "-i", converts_file_path, "-n", "-vn", "-c:a", "aac", "-bsf:a", "aac_adtstoasc", "-ab", "320k", converts_file_path.rsplit('.', maxsplit=1)[0] + ".m4a", ], stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type)) if is_original_delete: time.sleep(1) if os.path.exists(converts_file_path): os.remove(converts_file_path) except subprocess.CalledProcessError as e: logger.error(f'Error occurred during conversion: {e}') except Exception as e: logger.error(f'An unknown error occurred: {e}') def generate_subtitles(record_name: str, ass_filename: str, sub_format: str = 'srt') -> None: index_time = 0 today = datetime.datetime.now() re_datatime = today.strftime('%Y-%m-%d %H:%M:%S') def transform_int_to_time(seconds: int) -> str: m, s = divmod(seconds, 60) h, m = divmod(m, 60) return f"{h:02d}:{m:02d}:{s:02d}" while True: index_time += 1 txt = str(index_time) + "\n" + transform_int_to_time(index_time) + ',000 --> ' + transform_int_to_time( index_time + 1) + ',000' + "\n" + str(re_datatime) + "\n\n" with open(f"{ass_filename}.{sub_format.lower()}", 'a', encoding=text_encoding) as f: f.write(txt) if record_name not in recording: return time.sleep(1) today = datetime.datetime.now() re_datatime = today.strftime('%Y-%m-%d %H:%M:%S') def adjust_max_request() -> None: global max_request, error_count, pre_max_request, error_window preset = max_request while True: time.sleep(5) with max_request_lock: if error_window: error_rate = sum(error_window) / len(error_window) else: error_rate = 0 if error_rate > error_threshold: max_request = max(1, max_request - 1) elif error_rate < error_threshold / 2 and max_request < preset: max_request += 1 else: pass if pre_max_request != max_request: pre_max_request = max_request print(f"\r同一时间访问网络的线程数动态改为 {max_request}") error_window.append(error_count) if len(error_window) > error_window_size: error_window.pop(0) error_count = 0 def push_message(record_name: str, live_url: str, content: str) -> None: msg_title = push_message_title.strip() or "直播间状态更新通知" push_functions = { '微信': lambda: xizhi(xizhi_api_url, msg_title, content), '钉钉': lambda: dingtalk(dingtalk_api_url, content, dingtalk_phone_num, dingtalk_is_atall), '邮箱': lambda: send_email( email_host, login_email, email_password, sender_email, sender_name, to_email, msg_title, content, smtp_port, open_smtp_ssl ), 'TG': lambda: tg_bot(tg_chat_id, tg_token, content), 'BARK': lambda: bark( bark_msg_api, title=msg_title, content=content, level=bark_msg_level, sound=bark_msg_ring ), 'NTFY': lambda: ntfy( ntfy_api, title=msg_title, content=content, tags=ntfy_tags, action_url=live_url, email=ntfy_email ), 'PUSHPLUS': lambda: pushplus(pushplus_token, msg_title, content), } for platform, func in push_functions.items(): if platform in live_status_push.upper(): try: result = func() print(f'提示信息:已经将[{record_name}]直播状态消息推送至你的{platform},' f' 成功{len(result["success"])}, 失败{len(result["error"])}') except Exception as e: color_obj.print_colored(f"直播消息推送到{platform}失败: {e}", color_obj.RED) def run_script(command: str) -> None: try: process = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=get_startup_info(os_type) ) stdout, stderr = process.communicate() stdout_decoded = stdout.decode('utf-8') stderr_decoded = stderr.decode('utf-8') if stdout_decoded.strip(): print(stdout_decoded) if stderr_decoded.strip(): print(stderr_decoded) except PermissionError as e: logger.error(e) logger.error('脚本无执行权限!, 若是Linux环境, 请先执行:chmod +x your_script.sh 授予脚本可执行权限') except OSError as e: logger.error(e) logger.error('Please add `#!/bin/bash` at the beginning of your bash script file.') def clear_record_info(record_name: str, record_url: str) -> None: global monitoring recording.discard(record_name) if record_url in url_comments and record_url in running_list: running_list.remove(record_url) monitoring -= 1 color_obj.print_colored(f"[{record_name}]已经从录制列表中移除\n", color_obj.YELLOW) def direct_download_stream(source_url: str, save_path: str, record_name: str, live_url: str, platform: str) -> bool: try: with open(save_path, 'wb') as f: client = httpx.Client(timeout=None) headers = {} header_params = get_record_headers(platform, live_url) if header_params: key, value = header_params.split(":", 1) headers[key] = value with client.stream('GET', source_url, headers=headers, follow_redirects=True) as response: if response.status_code != 200: logger.error(f"请求直播流失败,状态码: {response.status_code}") return False downloaded = 0 chunk_size = 1024 * 16 for chunk in response.iter_bytes(chunk_size): if live_url in url_comments or exit_recording: color_obj.print_colored(f"[{record_name}]录制时已被注释或请求停止,下载中断", color_obj.YELLOW) clear_record_info(record_name, live_url) return False if chunk: f.write(chunk) downloaded += len(chunk) print() return True except Exception as e: logger.error(f"FLV下载错误: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") return False def check_subprocess(record_name: str, record_url: str, ffmpeg_command: list, save_type: str, script_command: str | None = None) -> bool: save_file_path = ffmpeg_command[-1] process = subprocess.Popen( ffmpeg_command, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type) ) subs_file_path = save_file_path.rsplit('.', maxsplit=1)[0] subs_thread_name = f'subs_{Path(subs_file_path).name}' if create_time_file and not split_video_by_time and '音频' not in save_type: create_var[subs_thread_name] = threading.Thread( target=generate_subtitles, args=(record_name, subs_file_path) ) create_var[subs_thread_name].daemon = True create_var[subs_thread_name].start() while process.poll() is None: if record_url in url_comments or exit_recording: color_obj.print_colored(f"[{record_name}]录制时已被注释,本条线程将会退出", color_obj.YELLOW) clear_record_info(record_name, record_url) # process.terminate() if os.name == 'nt': if process.stdin: process.stdin.write(b'q') process.stdin.close() else: process.send_signal(signal.SIGINT) process.wait() return True time.sleep(1) return_code = process.returncode stop_time = time.strftime('%Y-%m-%d %H:%M:%S') if return_code == 0: if converts_to_mp4 and save_type == 'TS': if split_video_by_time: file_paths = utils.get_file_paths(os.path.dirname(save_file_path)) prefix = os.path.basename(save_file_path).rsplit('_', maxsplit=1)[0] for path in file_paths: if prefix in path: threading.Thread(target=converts_mp4, args=(path, delete_origin_file)).start() else: threading.Thread(target=converts_mp4, args=(save_file_path, delete_origin_file)).start() print(f"\n{record_name} {stop_time} 直播录制完成\n") if script_command: logger.debug("开始执行脚本命令!") if "python" in script_command: params = [ f'--record_name "{record_name}"', f'--save_file_path "{save_file_path}"', f'--save_type {save_type}', f'--split_video_by_time {split_video_by_time}', f'--converts_to_mp4 {converts_to_mp4}', ] else: params = [ f'"{record_name.split(" ", maxsplit=1)[-1]}"', f'"{save_file_path}"', save_type, f'split_video_by_time:{split_video_by_time}', f'converts_to_mp4:{converts_to_mp4}' ] script_command = script_command.strip() + ' ' + ' '.join(params) run_script(script_command) logger.debug("脚本命令执行结束!") else: color_obj.print_colored(f"\n{record_name} {stop_time} 直播录制出错,返回码: {return_code}\n", color_obj.RED) recording.discard(record_name) return False def clean_name(input_text): cleaned_name = re.sub(rstr, "_", input_text.strip()).strip('_') cleaned_name = cleaned_name.replace("(", "(").replace(")", ")") if clean_emoji: cleaned_name = utils.remove_emojis(cleaned_name, '_').strip('_') return cleaned_name or '空白昵称' def get_quality_code(qn): QUALITY_MAPPING = { "原画": "OD", "蓝光": "BD", "超清": "UHD", "高清": "HD", "标清": "SD", "流畅": "LD" } return QUALITY_MAPPING.get(qn) def get_record_headers(platform, live_url): live_domain = '/'.join(live_url.split('/')[0:3]) record_headers = { 'PandaTV': 'origin:https://www.pandalive.co.kr', 'WinkTV': 'origin:https://www.winktv.co.kr', 'PopkonTV': 'origin:https://www.popkontv.com', 'FlexTV': 'origin:https://www.flextv.co.kr', '千度热播': 'referer:https://qiandurebo.com', '17Live': 'referer:https://17.live/en/live/6302408', '浪Live': 'referer:https://www.lang.live', 'shopee': f'origin:{live_domain}', 'Blued直播': 'referer:https://app.blued.cn' } return record_headers.get(platform) def is_flv_preferred_platform(link): return any(i in link for i in ["douyin", "tiktok"]) def select_source_url(link, stream_info): if is_flv_preferred_platform(link): codec = utils.get_query_params(stream_info.get('flv_url'), "codec") if codec and codec[0] == 'h265': logger.warning("FLV is not supported for h265 codec, use HLS source instead") else: return stream_info.get('flv_url') return stream_info.get('record_url') def start_record(url_data: tuple, count_variable: int = -1) -> None: global error_count while True: try: record_finished = False run_once = False start_pushed = False new_record_url = '' count_time = time.time() retry = 0 record_quality_zh, record_url, anchor_name = url_data record_quality = get_quality_code(record_quality_zh) proxy_address = proxy_addr platform = '未知平台' live_domain = '/'.join(record_url.split('/')[0:3]) if proxy_addr: proxy_address = None for platform in enable_proxy_platform_list: if platform and platform.strip() in record_url: proxy_address = proxy_addr break if not proxy_address: if extra_enable_proxy_platform_list: for pt in extra_enable_proxy_platform_list: if pt and pt.strip() in record_url: proxy_address = proxy_addr_bak or None # print(f'\r代理地址:{proxy_address}') # print(f'\r全局代理:{global_proxy}') while True: try: port_info = [] if record_url.find("douyin.com/") > -1: platform = '抖音直播' with semaphore: if 'v.douyin.com' not in record_url and '/user/' not in record_url: json_data = asyncio.run(spider.get_douyin_web_stream_data( url=record_url, proxy_addr=proxy_address, cookies=dy_cookie)) else: json_data = asyncio.run(spider.get_douyin_app_stream_data( url=record_url, proxy_addr=proxy_address, cookies=dy_cookie)) port_info = asyncio.run( stream.get_douyin_stream_url(json_data, record_quality, proxy_address)) elif record_url.find("https://www.tiktok.com/") > -1: platform = 'TikTok直播' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_tiktok_stream_data( url=record_url, proxy_addr=proxy_address, cookies=tiktok_cookie)) port_info = asyncio.run( stream.get_tiktok_stream_url(json_data, record_quality, proxy_address)) else: logger.error("错误信息: 网络异常,请检查网络是否能正常访问TikTok平台") elif record_url.find("https://live.kuaishou.com/") > -1: platform = '快手直播' with semaphore: json_data = asyncio.run(spider.get_kuaishou_stream_data( url=record_url, proxy_addr=proxy_address, cookies=ks_cookie)) port_info = asyncio.run(stream.get_kuaishou_stream_url(json_data, record_quality)) elif record_url.find("https://www.huya.com/") > -1: platform = '虎牙直播' with semaphore: if record_quality not in ['OD', 'BD', 'UHD']: json_data = asyncio.run(spider.get_huya_stream_data( url=record_url, proxy_addr=proxy_address, cookies=hy_cookie)) port_info = asyncio.run(stream.get_huya_stream_url(json_data, record_quality)) else: port_info = asyncio.run(spider.get_huya_app_stream_url( url=record_url, proxy_addr=proxy_address, cookies=hy_cookie )) elif record_url.find("https://www.douyu.com/") > -1: platform = '斗鱼直播' with semaphore: json_data = asyncio.run(spider.get_douyu_info_data( url=record_url, proxy_addr=proxy_address, cookies=douyu_cookie)) port_info = asyncio.run(stream.get_douyu_stream_url( json_data, video_quality=record_quality, cookies=douyu_cookie, proxy_addr=proxy_address )) elif record_url.find("https://www.yy.com/") > -1: platform = 'YY直播' with semaphore: json_data = asyncio.run(spider.get_yy_stream_data( url=record_url, proxy_addr=proxy_address, cookies=yy_cookie)) port_info = asyncio.run(stream.get_yy_stream_url(json_data)) elif record_url.find("https://live.bilibili.com/") > -1: platform = 'B站直播' with semaphore: json_data = asyncio.run(spider.get_bilibili_room_info( url=record_url, proxy_addr=proxy_address, cookies=bili_cookie)) port_info = asyncio.run(stream.get_bilibili_stream_url( json_data, video_quality=record_quality, cookies=bili_cookie, proxy_addr=proxy_address)) elif record_url.find("http://xhslink.com/") > -1 or \ record_url.find("https://www.xiaohongshu.com/") > -1: platform = '小红书直播' with semaphore: port_info = asyncio.run(spider.get_xhs_stream_url( record_url, proxy_addr=proxy_address, cookies=xhs_cookie)) retry += 1 elif record_url.find("www.bigo.tv/") > -1 or record_url.find("slink.bigovideo.tv/") > -1: platform = 'Bigo直播' with semaphore: port_info = asyncio.run(spider.get_bigo_stream_url( record_url, proxy_addr=proxy_address, cookies=bigo_cookie)) elif record_url.find("https://app.blued.cn/") > -1: platform = 'Blued直播' with semaphore: port_info = asyncio.run(spider.get_blued_stream_url( record_url, proxy_addr=proxy_address, cookies=blued_cookie)) elif record_url.find("sooplive.co.kr/") > -1 or record_url.find("sooplive.com/") > -1: platform = 'SOOP' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_sooplive_stream_data( url=record_url, proxy_addr=proxy_address, cookies=sooplive_cookie, username=sooplive_username, password=sooplive_password )) if json_data and json_data.get('new_cookies'): utils.update_config( config_file, 'Cookie', 'sooplive_cookie', json_data['new_cookies'] ) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问SOOP平台") elif record_url.find("cc.163.com/") > -1: platform = '网易CC直播' with semaphore: json_data = asyncio.run(spider.get_netease_stream_data( url=record_url, cookies=netease_cookie)) port_info = asyncio.run(stream.get_netease_stream_url(json_data, record_quality)) elif record_url.find("qiandurebo.com/") > -1: platform = '千度热播' with semaphore: port_info = asyncio.run(spider.get_qiandurebo_stream_data( url=record_url, proxy_addr=proxy_address, cookies=qiandurebo_cookie)) elif record_url.find("www.pandalive.co.kr/") > -1: platform = 'PandaTV' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_pandatv_stream_data( url=record_url, proxy_addr=proxy_address, cookies=pandatv_cookie )) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问PandaTV直播平台") elif record_url.find("fm.missevan.com/") > -1: platform = '猫耳FM直播' with semaphore: port_info = asyncio.run(spider.get_maoerfm_stream_url( url=record_url, proxy_addr=proxy_address, cookies=maoerfm_cookie)) elif record_url.find("www.winktv.co.kr/") > -1: platform = 'WinkTV' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_winktv_stream_data( url=record_url, proxy_addr=proxy_address, cookies=winktv_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问WinkTV直播平台") elif record_url.find("www.flextv.co.kr/") > -1 or record_url.find("www.ttinglive.com/") > -1: platform = 'FlexTV' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_flextv_stream_data( url=record_url, proxy_addr=proxy_address, cookies=flextv_cookie, username=flextv_username, password=flextv_password )) if json_data and json_data.get('new_cookies'): utils.update_config( config_file, 'Cookie', 'flextv_cookie', json_data['new_cookies'] ) if 'play_url_list' in json_data: port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: port_info = json_data else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问FlexTV直播平台") elif record_url.find("look.163.com/") > -1: platform = 'Look直播' with semaphore: port_info = asyncio.run(spider.get_looklive_stream_url( url=record_url, proxy_addr=proxy_address, cookies=look_cookie )) elif record_url.find("www.popkontv.com/") > -1: platform = 'PopkonTV' with semaphore: if global_proxy or proxy_address: port_info = asyncio.run(spider.get_popkontv_stream_url( url=record_url, proxy_addr=proxy_address, access_token=popkontv_access_token, username=popkontv_username, password=popkontv_password, partner_code=popkontv_partner_code )) if port_info and port_info.get('new_token'): utils.update_config( file_path=config_file, section='Authorization', key='popkontv_token', new_value=port_info['new_token'] ) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问PopkonTV直播平台") elif record_url.find("twitcasting.tv/") > -1: platform = 'TwitCasting' with semaphore: json_data = asyncio.run(spider.get_twitcasting_stream_url( url=record_url, proxy_addr=proxy_address, cookies=twitcasting_cookie, account_type=twitcasting_account_type, username=twitcasting_username, password=twitcasting_password )) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=False)) if port_info and port_info.get('new_cookies'): utils.update_config( file_path=config_file, section='Cookie', key='twitcasting_cookie', new_value=port_info['new_cookies'] ) elif record_url.find("live.baidu.com/") > -1: platform = '百度直播' with semaphore: json_data = asyncio.run(spider.get_baidu_stream_data( url=record_url, proxy_addr=proxy_address, cookies=baidu_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality)) elif record_url.find("weibo.com/") > -1: platform = '微博直播' with semaphore: json_data = asyncio.run(spider.get_weibo_stream_data( url=record_url, proxy_addr=proxy_address, cookies=weibo_cookie)) port_info = asyncio.run(stream.get_stream_url( json_data, record_quality, hls_extra_key='m3u8_url')) elif record_url.find("kugou.com/") > -1: platform = '酷狗直播' with semaphore: port_info = asyncio.run(spider.get_kugou_stream_url( url=record_url, proxy_addr=proxy_address, cookies=kugou_cookie)) elif record_url.find("www.twitch.tv/") > -1: platform = 'TwitchTV' with semaphore: if global_proxy or proxy_address: json_data = asyncio.run(spider.get_twitchtv_stream_data( url=record_url, proxy_addr=proxy_address, cookies=twitch_cookie )) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问TwitchTV直播平台") elif record_url.find("www.liveme.com/") > -1: if global_proxy or proxy_address: platform = 'LiveMe' with semaphore: port_info = asyncio.run(spider.get_liveme_stream_url( url=record_url, proxy_addr=proxy_address, cookies=liveme_cookie)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问LiveMe直播平台") elif record_url.find("www.huajiao.com/") > -1: platform = '花椒直播' with semaphore: port_info = asyncio.run(spider.get_huajiao_stream_url( url=record_url, proxy_addr=proxy_address, cookies=huajiao_cookie)) elif record_url.find("7u66.com/") > -1: platform = '流星直播' with semaphore: port_info = asyncio.run(spider.get_liuxing_stream_url( url=record_url, proxy_addr=proxy_address, cookies=liuxing_cookie)) elif record_url.find("showroom-live.com/") > -1: platform = 'ShowRoom' with semaphore: json_data = asyncio.run(spider.get_showroom_stream_data( url=record_url, proxy_addr=proxy_address, cookies=showroom_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) elif record_url.find("live.acfun.cn/") > -1 or record_url.find("m.acfun.cn/") > -1: platform = 'Acfun' with semaphore: json_data = asyncio.run(spider.get_acfun_stream_data( url=record_url, proxy_addr=proxy_address, cookies=acfun_cookie)) port_info = asyncio.run(stream.get_stream_url( json_data, record_quality, url_type='flv', flv_extra_key='url')) elif record_url.find("live.tlclw.com/") > -1: platform = '畅聊直播' with semaphore: port_info = asyncio.run(spider.get_changliao_stream_url( url=record_url, proxy_addr=proxy_address, cookies=changliao_cookie)) elif record_url.find("ybw1666.com/") > -1: platform = '音播直播' with semaphore: port_info = asyncio.run(spider.get_yinbo_stream_url( url=record_url, proxy_addr=proxy_address, cookies=yinbo_cookie)) elif record_url.find("www.inke.cn/") > -1: platform = '映客直播' with semaphore: port_info = asyncio.run(spider.get_yingke_stream_url( url=record_url, proxy_addr=proxy_address, cookies=yingke_cookie)) elif record_url.find("www.zhihu.com/") > -1: platform = '知乎直播' with semaphore: port_info = asyncio.run(spider.get_zhihu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=zhihu_cookie)) elif record_url.find("chzzk.naver.com/") > -1: platform = 'CHZZK' with semaphore: json_data = asyncio.run(spider.get_chzzk_stream_data( url=record_url, proxy_addr=proxy_address, cookies=chzzk_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) elif record_url.find("www.haixiutv.com/") > -1: platform = '嗨秀直播' with semaphore: port_info = asyncio.run(spider.get_haixiu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=haixiu_cookie)) elif record_url.find("vvxqiu.com/") > -1: platform = 'VV星球' with semaphore: port_info = asyncio.run(spider.get_vvxqiu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=vvxqiu_cookie)) elif record_url.find("17.live/") > -1: platform = '17Live' with semaphore: port_info = asyncio.run(spider.get_17live_stream_url( url=record_url, proxy_addr=proxy_address, cookies=yiqilive_cookie)) elif record_url.find("www.lang.live/") > -1: platform = '浪Live' with semaphore: port_info = asyncio.run(spider.get_langlive_stream_url( url=record_url, proxy_addr=proxy_address, cookies=langlive_cookie)) elif record_url.find("m.pp.weimipopo.com/") > -1: platform = '漂漂直播' with semaphore: port_info = asyncio.run(spider.get_pplive_stream_url( url=record_url, proxy_addr=proxy_address, cookies=pplive_cookie)) elif record_url.find(".6.cn/") > -1: platform = '六间房直播' with semaphore: port_info = asyncio.run(spider.get_6room_stream_url( url=record_url, proxy_addr=proxy_address, cookies=six_room_cookie)) elif record_url.find("lehaitv.com/") > -1: platform = '乐嗨直播' with semaphore: port_info = asyncio.run(spider.get_haixiu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=lehaitv_cookie)) elif record_url.find("h.catshow168.com/") > -1: platform = '花猫直播' with semaphore: port_info = asyncio.run(spider.get_pplive_stream_url( url=record_url, proxy_addr=proxy_address, cookies=huamao_cookie)) elif record_url.find("live.shopee") > -1 or record_url.find("shp.ee/") > -1: platform = 'shopee' with semaphore: port_info = asyncio.run(spider.get_shopee_stream_url( url=record_url, proxy_addr=proxy_address, cookies=shopee_cookie)) if port_info.get('uid'): new_record_url = record_url.split('?')[0] + '?' + str(port_info['uid']) elif record_url.find("www.youtube.com/") > -1 or record_url.find("youtu.be/") > -1: platform = 'Youtube' with semaphore: json_data = asyncio.run(spider.get_youtube_stream_url( url=record_url, proxy_addr=proxy_address, cookies=youtube_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) elif record_url.find("tb.cn") > -1: platform = '淘宝直播' with semaphore: json_data = asyncio.run(spider.get_taobao_stream_url( url=record_url, proxy_addr=proxy_address, cookies=taobao_cookie)) port_info = asyncio.run(stream.get_stream_url( json_data, record_quality, url_type='all', hls_extra_key='hlsUrl', flv_extra_key='flvUrl' )) elif record_url.find("3.cn") > -1 or record_url.find("m.jd.com") > -1: platform = '京东直播' with semaphore: port_info = asyncio.run(spider.get_jd_stream_url( url=record_url, proxy_addr=proxy_address, cookies=jd_cookie)) elif record_url.find("faceit.com/") > -1: platform = 'faceit' with semaphore: if global_proxy or proxy_address: with semaphore: json_data = asyncio.run(spider.get_faceit_stream_data( url=record_url, proxy_addr=proxy_address, cookies=faceit_cookie)) port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=True)) else: logger.error("错误信息: 网络异常,请检查本网络是否能正常访问faceit直播平台") elif record_url.find("www.miguvideo.com") > -1 or record_url.find("m.miguvideo.com") > -1: platform = '咪咕直播' with semaphore: port_info = asyncio.run(spider.get_migu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=migu_cookie)) elif record_url.find("show.lailianjie.com") > -1: platform = '连接直播' with semaphore: port_info = asyncio.run(spider.get_lianjie_stream_url( url=record_url, proxy_addr=proxy_address, cookies=lianjie_cookie)) elif record_url.find("www.imkktv.com") > -1: platform = '来秀直播' with semaphore: port_info = asyncio.run(spider.get_laixiu_stream_url( url=record_url, proxy_addr=proxy_address, cookies=laixiu_cookie)) elif record_url.find("www.picarto.tv") > -1: platform = 'Picarto' with semaphore: port_info = asyncio.run(spider.get_picarto_stream_url( url=record_url, proxy_addr=proxy_address, cookies=picarto_cookie)) elif record_url.find(".m3u8") > -1 or record_url.find(".flv") > -1: platform = '自定义录制直播' port_info = { "anchor_name": platform + '_' + str(uuid.uuid4())[:8], "is_live": True, "record_url": record_url, } if '.flv' in record_url: port_info['flv_url'] = record_url else: port_info['m3u8_url'] = record_url else: logger.error(f'{record_url} {platform}直播地址') return if anchor_name: if '主播:' in anchor_name: anchor_split: list = anchor_name.split('主播:') if len(anchor_split) > 1 and anchor_split[1].strip(): anchor_name = anchor_split[1].strip() else: anchor_name = port_info.get("anchor_name", '') else: anchor_name = port_info.get("anchor_name", '') if not port_info.get("anchor_name", ''): print(f'序号{count_variable} 网址内容获取失败,进行重试中...获取失败的地址是:{url_data}') with max_request_lock: error_count += 1 error_window.append(1) else: anchor_name = clean_name(anchor_name) record_name = f'序号{count_variable} {anchor_name}' if record_url in url_comments: print(f"[{anchor_name}]已被注释,本条线程将会退出") clear_record_info(record_name, record_url) return if not url_data[-1] and run_once is False: if new_record_url: need_update_line_list.append( f'{record_url}|{new_record_url},主播: {anchor_name.strip()}') not_record_list.append(new_record_url) else: need_update_line_list.append(f'{record_url}|{record_url},主播: {anchor_name.strip()}') run_once = True push_at = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S') if port_info['is_live'] is False: print(f"\r{record_name} 等待直播... ") if start_pushed: if over_show_push: push_content = "直播间状态更新:[直播间名称] 直播已结束!时间:[时间]" if over_push_message_text: push_content = over_push_message_text push_content = (push_content.replace('[直播间名称]', record_name). replace('[时间]', push_at)) threading.Thread( target=push_message, args=(record_name, record_url, push_content.replace(r'\n', '\n')), daemon=True ).start() start_pushed = False else: content = f"\r{record_name} 正在直播中..." print(content) if live_status_push and not start_pushed: if begin_show_push: push_content = "直播间状态更新:[直播间名称] 正在直播中,时间:[时间]" if begin_push_message_text: push_content = begin_push_message_text push_content = (push_content.replace('[直播间名称]', record_name). replace('[时间]', push_at)) threading.Thread( target=push_message, args=(record_name, record_url, push_content.replace(r'\n', '\n')), daemon=True ).start() start_pushed = True if disable_record: time.sleep(push_check_seconds) continue real_url = select_source_url(record_url, port_info) full_path = f'{default_path}/{platform}' if real_url: now = datetime.datetime.today().strftime("%Y-%m-%d_%H-%M-%S") live_title = port_info.get('title') title_in_name = '' if live_title: live_title = clean_name(live_title) title_in_name = live_title + '_' if filename_by_title else '' try: if len(video_save_path) > 0: if not video_save_path.endswith(('/', '\\')): full_path = f'{video_save_path}/{platform}' else: full_path = f'{video_save_path}{platform}' full_path = full_path.replace("\\", '/') if folder_by_author: full_path = f'{full_path}/{anchor_name}' if folder_by_time: full_path = f'{full_path}/{now[:10]}' if folder_by_title and port_info.get('title'): if folder_by_time: full_path = f'{full_path}/{live_title}_{anchor_name}' else: full_path = f'{full_path}/{now[:10]}_{live_title}' if not os.path.exists(full_path): os.makedirs(full_path) except Exception as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") if platform != '自定义录制直播': if enable_https_recording and real_url.startswith("http://"): real_url = real_url.replace("http://", "https://") http_record_list = ['shopee', "migu"] if platform in http_record_list: real_url = real_url.replace("https://", "http://") user_agent = ("Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (" "KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile " "Safari/537.36") rw_timeout = "15000000" analyzeduration = "20000000" probesize = "10000000" bufsize = "8000k" max_muxing_queue_size = "1024" for pt_host in overseas_platform_host: if pt_host in record_url: rw_timeout = "50000000" analyzeduration = "40000000" probesize = "20000000" bufsize = "15000k" max_muxing_queue_size = "2048" break ffmpeg_command = [ 'ffmpeg', "-y", "-v", "verbose", "-rw_timeout", rw_timeout, "-loglevel", "error", "-hide_banner", "-user_agent", user_agent, "-protocol_whitelist", "rtmp,crypto,file,http,https,tcp,tls,udp,rtp,httpproxy", "-thread_queue_size", "1024", "-analyzeduration", analyzeduration, "-probesize", probesize, "-fflags", "+discardcorrupt", "-re", "-i", real_url, "-bufsize", bufsize, "-sn", "-dn", "-reconnect_delay_max", "60", "-reconnect_streamed", "-reconnect_at_eof", "-max_muxing_queue_size", max_muxing_queue_size, "-correct_ts_overflow", "1", "-avoid_negative_ts", "1" ] headers = get_record_headers(platform, record_url) if headers: ffmpeg_command.insert(11, "-headers") ffmpeg_command.insert(12, headers) if proxy_address: ffmpeg_command.insert(1, "-http_proxy") ffmpeg_command.insert(2, proxy_address) recording.add(record_name) start_record_time = datetime.datetime.now() recording_time_list[record_name] = [start_record_time, record_quality_zh] rec_info = f"\r{anchor_name} 准备开始录制视频: {full_path}" if show_url: re_plat = ('WinkTV', 'PandaTV', 'ShowRoom', 'CHZZK', 'Youtube') if platform in re_plat: logger.info( f"{platform} | {anchor_name} | 直播源地址: {port_info.get('m3u8_url')}") else: logger.info( f"{platform} | {anchor_name} | 直播源地址: {real_url}") only_flv_record = False only_flv_platform_list = ['shopee', '花椒直播'] if platform in only_flv_platform_list: logger.debug(f"提示: {platform} 将强制使用FLV格式录制") only_flv_record = True only_audio_record = False only_audio_platform_list = ['猫耳FM直播', 'Look直播'] if platform in only_audio_platform_list: only_audio_record = True record_save_type = video_save_type if is_flv_preferred_platform(record_url) and port_info.get('flv_url'): codec = utils.get_query_params(port_info['flv_url'], "codec") if codec and codec[0] == 'h265': logger.warning("FLV is not supported for h265 codec, use TS format instead") record_save_type = "TS" if only_audio_record or any(i in record_save_type for i in ['MP3', 'M4A']): try: now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) extension = "mp3" if "m4a" not in record_save_type.lower() else "m4a" name_format = "_%03d" if split_video_by_time else "" save_file_path = (f"{full_path}/{anchor_name}_{title_in_name}{now}" f"{name_format}.{extension}") if split_video_by_time: print(f'\r{anchor_name} 准备开始录制音频: {save_file_path}') if "MP3" in record_save_type: command = [ "-map", "0:a", "-c:a", "libmp3lame", "-ab", "320k", "-f", "segment", "-segment_time", split_time, "-reset_timestamps", "1", save_file_path, ] else: command = [ "-map", "0:a", "-c:a", "aac", "-bsf:a", "aac_adtstoasc", "-ab", "320k", "-f", "segment", "-segment_time", split_time, "-segment_format", 'mpegts', "-reset_timestamps", "1", save_file_path, ] else: if "MP3" in record_save_type: command = [ "-map", "0:a", "-c:a", "libmp3lame", "-ab", "320k", save_file_path, ] else: command = [ "-map", "0:a", "-c:a", "aac", "-bsf:a", "aac_adtstoasc", "-ab", "320k", "-movflags", "+faststart", save_file_path, ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: return except subprocess.CalledProcessError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) if only_flv_record: logger.info(f"Use Direct Downloader to Download FLV Stream: {record_url}") filename = anchor_name + f'_{title_in_name}' + now + '.flv' save_file_path = f'{full_path}/{filename}' print(f'{rec_info}/{filename}') subs_file_path = save_file_path.rsplit('.', maxsplit=1)[0] subs_thread_name = f'subs_{Path(subs_file_path).name}' if create_time_file: create_var[subs_thread_name] = threading.Thread( target=generate_subtitles, args=(record_name, subs_file_path) ) create_var[subs_thread_name].daemon = True create_var[subs_thread_name].start() try: flv_url = port_info.get('flv_url') if flv_url: recording.add(record_name) start_record_time = datetime.datetime.now() recording_time_list[record_name] = [start_record_time, record_quality_zh] download_success = direct_download_stream( flv_url, save_file_path, record_name, record_url, platform ) if download_success: record_finished = True print( f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制完成\n") recording.discard(record_name) else: logger.debug("未找到FLV直播流,跳过录制") except Exception as e: clear_record_info(record_name, record_url) color_obj.print_colored( f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制出错,请检查网络\n", color_obj.RED) logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) elif record_save_type == "FLV": filename = anchor_name + f'_{title_in_name}' + now + ".flv" print(f'{rec_info}/{filename}') save_file_path = full_path + '/' + filename try: if split_video_by_time: now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) save_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.flv" command = [ "-map", "0", "-c:v", "copy", "-c:a", "copy", "-bsf:a", "aac_adtstoasc", "-f", "segment", "-segment_time", split_time, "-segment_format", "flv", "-reset_timestamps", "1", save_file_path ] else: command = [ "-map", "0", "-c:v", "copy", "-c:a", "copy", "-bsf:a", "aac_adtstoasc", "-f", "flv", "{path}".format(path=save_file_path), ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: return except subprocess.CalledProcessError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) try: if converts_to_mp4: seg_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.mp4" if split_video_by_time: segment_video( save_file_path, seg_file_path, segment_format='mp4', segment_time=split_time, is_original_delete=delete_origin_file ) else: threading.Thread( target=converts_mp4, args=(save_file_path, delete_origin_file) ).start() else: seg_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.flv" if split_video_by_time: segment_video( save_file_path, seg_file_path, segment_format='flv', segment_time=split_time, is_original_delete=delete_origin_file ) except Exception as e: logger.error(f"转码失败: {e} ") elif record_save_type == "MKV": filename = anchor_name + f'_{title_in_name}' + now + ".mkv" print(f'{rec_info}/{filename}') save_file_path = full_path + '/' + filename try: if split_video_by_time: now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) save_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.mkv" command = [ "-flags", "global_header", "-c:v", "copy", "-c:a", "aac", "-map", "0", "-f", "segment", "-segment_time", split_time, "-segment_format", "matroska", "-reset_timestamps", "1", save_file_path, ] else: command = [ "-flags", "global_header", "-map", "0", "-c:v", "copy", "-c:a", "copy", "-f", "matroska", "{path}".format(path=save_file_path), ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: return except subprocess.CalledProcessError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) elif record_save_type == "MP4": filename = anchor_name + f'_{title_in_name}' + now + ".mp4" print(f'{rec_info}/{filename}') save_file_path = full_path + '/' + filename try: if split_video_by_time: now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) save_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.mp4" command = [ "-c:v", "copy", "-c:a", "aac", "-map", "0", "-f", "segment", "-segment_time", split_time, "-segment_format", "mp4", "-reset_timestamps", "1", "-movflags", "+frag_keyframe+empty_moov", save_file_path, ] else: command = [ "-map", "0", "-c:v", "copy", "-c:a", "copy", "-f", "mp4", save_file_path, ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: return except subprocess.CalledProcessError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) else: if split_video_by_time: now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()) filename = anchor_name + f'_{title_in_name}' + now + ".ts" print(f'{rec_info}/{filename}') try: save_file_path = f"{full_path}/{anchor_name}_{title_in_name}{now}_%03d.ts" command = [ "-c:v", "copy", "-c:a", "copy", "-map", "0", "-f", "segment", "-segment_time", split_time, "-segment_format", 'mpegts', "-reset_timestamps", "1", save_file_path, ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: if converts_to_mp4: file_paths = utils.get_file_paths(os.path.dirname(save_file_path)) prefix = os.path.basename(save_file_path).rsplit('_', maxsplit=1)[0] for path in file_paths: if prefix in path: try: threading.Thread( target=converts_mp4, args=(path, delete_origin_file) ).start() except subprocess.CalledProcessError as e: logger.error(f"转码失败: {e} ") return except subprocess.CalledProcessError as e: logger.error( f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) else: filename = anchor_name + f'_{title_in_name}' + now + ".ts" print(f'{rec_info}/{filename}') save_file_path = full_path + '/' + filename try: command = [ "-c:v", "copy", "-c:a", "copy", "-map", "0", "-f", "mpegts", save_file_path, ] ffmpeg_command.extend(command) comment_end = check_subprocess( record_name, record_url, ffmpeg_command, record_save_type, custom_script ) if comment_end: threading.Thread( target=converts_mp4, args=(save_file_path, delete_origin_file) ).start() return except subprocess.CalledProcessError as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) count_time = time.time() except Exception as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) num = random.randint(-5, 5) + delay_default if num < 0: num = 0 x = num if error_count > 20: x = x + 60 color_obj.print_colored("\r瞬时错误太多,延迟加60秒", color_obj.YELLOW) # 这里是.如果录制结束后,循环时间会暂时变成30s后检测一遍. 这样一定程度上防止主播卡顿造成少录 # 当30秒过后检测一遍后. 会回归正常设置的循环秒数 if record_finished: count_time_end = time.time() - count_time if count_time_end < 60: x = 30 record_finished = False else: x = num # 这里是正常循环 while x: x = x - 1 if loop_time: print(f'\r{anchor_name}循环等待{x}秒 ', end="") time.sleep(1) if loop_time: print('\r检测直播间中...', end="") except Exception as e: logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 error_window.append(1) time.sleep(2) def backup_file(file_path: str, backup_dir_path: str, limit_counts: int = 6) -> None: try: if not os.path.exists(backup_dir_path): os.makedirs(backup_dir_path) timestamp = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') backup_file_name = os.path.basename(file_path) + '_' + timestamp backup_file_path = os.path.join(backup_dir_path, backup_file_name).replace("\\", "/") shutil.copy2(file_path, backup_file_path) files = os.listdir(backup_dir_path) _files = [f for f in files if f.startswith(os.path.basename(file_path))] _files.sort(key=lambda x: os.path.getmtime(os.path.join(backup_dir_path, x))) while len(_files) > limit_counts: oldest_file = _files[0] os.remove(os.path.join(backup_dir_path, oldest_file)) _files = _files[1:] except Exception as e: logger.error(f'\r备份配置文件 {file_path} 失败:{str(e)}') def backup_file_start() -> None: config_md5 = '' url_config_md5 = '' while True: try: if os.path.exists(config_file): new_config_md5 = utils.check_md5(config_file) if new_config_md5 != config_md5: backup_file(config_file, backup_dir) config_md5 = new_config_md5 if os.path.exists(url_config_file): new_url_config_md5 = utils.check_md5(url_config_file) if new_url_config_md5 != url_config_md5: backup_file(url_config_file, backup_dir) url_config_md5 = new_url_config_md5 time.sleep(600) except Exception as e: logger.error(f"备份配置文件失败, 错误信息: {e}") def check_ffmpeg_existence() -> bool: try: result = subprocess.run(['ffmpeg', '-version'], check=True, capture_output=True, text=True) if result.returncode == 0: lines = result.stdout.splitlines() version_line = lines[0] built_line = lines[1] print(version_line) print(built_line) except subprocess.CalledProcessError as e: logger.error(e) except FileNotFoundError: pass finally: if check_ffmpeg(): time.sleep(1) return True return False # --------------------------初始化程序------------------------------------- print("-----------------------------------------------------") print("| DouyinLiveRecorder |") print("-----------------------------------------------------") print(f"版本号: {version}") print("GitHub: https://github.com/ihmily/DouyinLiveRecorder") print(f'支持平台: {platforms}') print('.....................................................') if not check_ffmpeg_existence(): logger.error("缺少ffmpeg无法进行录制,程序退出") sys.exit(1) os.makedirs(os.path.dirname(config_file), exist_ok=True) t3 = threading.Thread(target=backup_file_start, args=(), daemon=True) t3.start() utils.remove_duplicate_lines(url_config_file) def read_config_value(config_parser: configparser.RawConfigParser, section: str, option: str, default_value: Any) \ -> Any: try: config_parser.read(config_file, encoding=text_encoding) if '录制设置' not in config_parser.sections(): config_parser.add_section('录制设置') if '推送配置' not in config_parser.sections(): config_parser.add_section('推送配置') if 'Cookie' not in config_parser.sections(): config_parser.add_section('Cookie') if 'Authorization' not in config_parser.sections(): config_parser.add_section('Authorization') if '账号密码' not in config_parser.sections(): config_parser.add_section('账号密码') return config_parser.get(section, option) except (configparser.NoSectionError, configparser.NoOptionError): config_parser.set(section, option, str(default_value)) with open(config_file, 'w', encoding=text_encoding) as f: config_parser.write(f) return default_value options = {"是": True, "否": False} config = configparser.RawConfigParser() language = read_config_value(config, '录制设置', 'language(zh_cn/en)', "zh_cn") skip_proxy_check = options.get(read_config_value(config, '录制设置', '是否跳过代理检测(是/否)', "否"), False) if language and 'en' not in language.lower(): from i18n import translated_print builtins.print = translated_print try: if skip_proxy_check: global_proxy = True else: print('系统代理检测中,请耐心等待...') response_g = urllib.request.urlopen("https://www.google.com/", timeout=15) global_proxy = True print('\r全局/规则网络代理已开启√') pd = ProxyDetector() if pd.is_proxy_enabled(): proxy_info = pd.get_proxy_info() print("System Proxy: http://{}:{}".format(proxy_info.ip, proxy_info.port)) except HTTPError as err: print(f"HTTP error occurred: {err.code} - {err.reason}") except URLError: color_obj.print_colored("INFO:未检测到全局/规则网络代理,请检查代理配置(若无需录制海外直播请忽略此条提示)", color_obj.YELLOW) except Exception as err: print("An unexpected error occurred:", err) while True: try: if not os.path.isfile(config_file): with open(config_file, 'w', encoding=text_encoding) as file: pass ini_URL_content = '' if os.path.isfile(url_config_file): with open(url_config_file, 'r', encoding=text_encoding) as file: ini_URL_content = file.read().strip() if not ini_URL_content.strip(): input_url = input('请输入要录制的主播直播间网址(尽量使用PC网页端的直播间地址):\n') with open(url_config_file, 'w', encoding=text_encoding) as file: file.write(input_url) except OSError as err: logger.error(f"发生 I/O 错误: {err}") video_save_path = read_config_value(config, '录制设置', '直播保存路径(不填则默认)', "") folder_by_author = options.get(read_config_value(config, '录制设置', '保存文件夹是否以作者区分', "是"), False) folder_by_time = options.get(read_config_value(config, '录制设置', '保存文件夹是否以时间区分', "否"), False) folder_by_title = options.get(read_config_value(config, '录制设置', '保存文件夹是否以标题区分', "否"), False) filename_by_title = options.get(read_config_value(config, '录制设置', '保存文件名是否包含标题', "否"), False) clean_emoji = options.get(read_config_value(config, '录制设置', '是否去除名称中的表情符号', "是"), True) video_save_type = read_config_value(config, '录制设置', '视频保存格式ts|mkv|flv|mp4|mp3音频|m4a音频', "ts") video_record_quality = read_config_value(config, '录制设置', '原画|超清|高清|标清|流畅', "原画") use_proxy = options.get(read_config_value(config, '录制设置', '是否使用代理ip(是/否)', "是"), False) proxy_addr_bak = read_config_value(config, '录制设置', '代理地址', "") proxy_addr = None if not use_proxy else proxy_addr_bak max_request = int(read_config_value(config, '录制设置', '同一时间访问网络的线程数', 3)) semaphore = threading.Semaphore(max_request) delay_default = int(read_config_value(config, '录制设置', '循环时间(秒)', 120)) local_delay_default = int(read_config_value(config, '录制设置', '排队读取网址时间(秒)', 0)) loop_time = options.get(read_config_value(config, '录制设置', '是否显示循环秒数', "否"), False) show_url = options.get(read_config_value(config, '录制设置', '是否显示直播源地址', "否"), False) split_video_by_time = options.get(read_config_value(config, '录制设置', '分段录制是否开启', "否"), False) enable_https_recording = options.get(read_config_value(config, '录制设置', '是否强制启用https录制', "否"), False) disk_space_limit = float(read_config_value(config, '录制设置', '录制空间剩余阈值(gb)', 1.0)) split_time = str(read_config_value(config, '录制设置', '视频分段时间(秒)', 1800)) converts_to_mp4 = options.get(read_config_value(config, '录制设置', '录制完成后自动转为mp4格式', "否"), False) converts_to_h264 = options.get(read_config_value(config, '录制设置', 'mp4格式重新编码为h264', "否"), False) delete_origin_file = options.get(read_config_value(config, '录制设置', '追加格式后删除原文件', "否"), False) create_time_file = options.get(read_config_value(config, '录制设置', '生成时间字幕文件', "否"), False) is_run_script = options.get(read_config_value(config, '录制设置', '是否录制完成后执行自定义脚本', "否"), False) custom_script = read_config_value(config, '录制设置', '自定义脚本执行命令', "") if is_run_script else None enable_proxy_platform = read_config_value( config, '录制设置', '使用代理录制的平台(逗号分隔)', 'tiktok, soop, pandalive, winktv, flextv, popkontv, twitch, liveme, showroom, chzzk, shopee, shp, youtu, faceit' ) enable_proxy_platform_list = enable_proxy_platform.replace(',', ',').split(',') if enable_proxy_platform else None extra_enable_proxy = read_config_value(config, '录制设置', '额外使用代理录制的平台(逗号分隔)', '') extra_enable_proxy_platform_list = extra_enable_proxy.replace(',', ',').split(',') if extra_enable_proxy else None live_status_push = read_config_value(config, '推送配置', '直播状态推送渠道', "") dingtalk_api_url = read_config_value(config, '推送配置', '钉钉推送接口链接', "") xizhi_api_url = read_config_value(config, '推送配置', '微信推送接口链接', "") bark_msg_api = read_config_value(config, '推送配置', 'bark推送接口链接', "") bark_msg_level = read_config_value(config, '推送配置', 'bark推送中断级别', "active") bark_msg_ring = read_config_value(config, '推送配置', 'bark推送铃声', "bell") dingtalk_phone_num = read_config_value(config, '推送配置', '钉钉通知@对象(填手机号)', "") dingtalk_is_atall = options.get(read_config_value(config, '推送配置', '钉钉通知@全体(是/否)', "否"), False) tg_token = read_config_value(config, '推送配置', 'tgapi令牌', "") tg_chat_id = read_config_value(config, '推送配置', 'tg聊天id(个人或者群组id)', "") email_host = read_config_value(config, '推送配置', 'SMTP邮件服务器', "") open_smtp_ssl = options.get(read_config_value(config, '推送配置', '是否使用SMTP服务SSL加密(是/否)', "是"), True) smtp_port = read_config_value(config, '推送配置', 'SMTP邮件服务器端口', "") login_email = read_config_value(config, '推送配置', '邮箱登录账号', "") email_password = read_config_value(config, '推送配置', '发件人密码(授权码)', "") sender_email = read_config_value(config, '推送配置', '发件人邮箱', "") sender_name = read_config_value(config, '推送配置', '发件人显示昵称', "") to_email = read_config_value(config, '推送配置', '收件人邮箱', "") ntfy_api = read_config_value(config, '推送配置', 'ntfy推送地址', "") ntfy_tags = read_config_value(config, '推送配置', 'ntfy推送标签', "tada") ntfy_email = read_config_value(config, '推送配置', 'ntfy推送邮箱', "") pushplus_token = read_config_value(config, '推送配置', 'pushplus推送token', "") push_message_title = read_config_value(config, '推送配置', '自定义推送标题', "直播间状态更新通知") begin_push_message_text = read_config_value(config, '推送配置', '自定义开播推送内容', "") over_push_message_text = read_config_value(config, '推送配置', '自定义关播推送内容', "") disable_record = options.get(read_config_value(config, '推送配置', '只推送通知不录制(是/否)', "否"), False) push_check_seconds = int(read_config_value(config, '推送配置', '直播推送检测频率(秒)', 1800)) begin_show_push = options.get(read_config_value(config, '推送配置', '开播推送开启(是/否)', "是"), True) over_show_push = options.get(read_config_value(config, '推送配置', '关播推送开启(是/否)', "否"), False) sooplive_username = read_config_value(config, '账号密码', 'sooplive账号', '') sooplive_password = read_config_value(config, '账号密码', 'sooplive密码', '') flextv_username = read_config_value(config, '账号密码', 'flextv账号', '') flextv_password = read_config_value(config, '账号密码', 'flextv密码', '') popkontv_username = read_config_value(config, '账号密码', 'popkontv账号', '') popkontv_partner_code = read_config_value(config, '账号密码', 'partner_code', 'P-00001') popkontv_password = read_config_value(config, '账号密码', 'popkontv密码', '') twitcasting_account_type = read_config_value(config, '账号密码', 'twitcasting账号类型', 'normal') twitcasting_username = read_config_value(config, '账号密码', 'twitcasting账号', '') twitcasting_password = read_config_value(config, '账号密码', 'twitcasting密码', '') popkontv_access_token = read_config_value(config, 'Authorization', 'popkontv_token', '') dy_cookie = read_config_value(config, 'Cookie', '抖音cookie', '') ks_cookie = read_config_value(config, 'Cookie', '快手cookie', '') tiktok_cookie = read_config_value(config, 'Cookie', 'tiktok_cookie', '') hy_cookie = read_config_value(config, 'Cookie', '虎牙cookie', '') douyu_cookie = read_config_value(config, 'Cookie', '斗鱼cookie', '') yy_cookie = read_config_value(config, 'Cookie', 'yy_cookie', '') bili_cookie = read_config_value(config, 'Cookie', 'B站cookie', '') xhs_cookie = read_config_value(config, 'Cookie', '小红书cookie', '') bigo_cookie = read_config_value(config, 'Cookie', 'bigo_cookie', '') blued_cookie = read_config_value(config, 'Cookie', 'blued_cookie', '') sooplive_cookie = read_config_value(config, 'Cookie', 'sooplive_cookie', '') netease_cookie = read_config_value(config, 'Cookie', 'netease_cookie', '') qiandurebo_cookie = read_config_value(config, 'Cookie', '千度热播_cookie', '') pandatv_cookie = read_config_value(config, 'Cookie', 'pandatv_cookie', '') maoerfm_cookie = read_config_value(config, 'Cookie', '猫耳fm_cookie', '') winktv_cookie = read_config_value(config, 'Cookie', 'winktv_cookie', '') flextv_cookie = read_config_value(config, 'Cookie', 'flextv_cookie', '') look_cookie = read_config_value(config, 'Cookie', 'look_cookie', '') twitcasting_cookie = read_config_value(config, 'Cookie', 'twitcasting_cookie', '') baidu_cookie = read_config_value(config, 'Cookie', 'baidu_cookie', '') weibo_cookie = read_config_value(config, 'Cookie', 'weibo_cookie', '') kugou_cookie = read_config_value(config, 'Cookie', 'kugou_cookie', '') twitch_cookie = read_config_value(config, 'Cookie', 'twitch_cookie', '') liveme_cookie = read_config_value(config, 'Cookie', 'liveme_cookie', '') huajiao_cookie = read_config_value(config, 'Cookie', 'huajiao_cookie', '') liuxing_cookie = read_config_value(config, 'Cookie', 'liuxing_cookie', '') showroom_cookie = read_config_value(config, 'Cookie', 'showroom_cookie', '') acfun_cookie = read_config_value(config, 'Cookie', 'acfun_cookie', '') changliao_cookie = read_config_value(config, 'Cookie', 'changliao_cookie', '') yinbo_cookie = read_config_value(config, 'Cookie', 'yinbo_cookie', '') yingke_cookie = read_config_value(config, 'Cookie', 'yingke_cookie', '') zhihu_cookie = read_config_value(config, 'Cookie', 'zhihu_cookie', '') chzzk_cookie = read_config_value(config, 'Cookie', 'chzzk_cookie', '') haixiu_cookie = read_config_value(config, 'Cookie', 'haixiu_cookie', '') vvxqiu_cookie = read_config_value(config, 'Cookie', 'vvxqiu_cookie', '') yiqilive_cookie = read_config_value(config, 'Cookie', '17live_cookie', '') langlive_cookie = read_config_value(config, 'Cookie', 'langlive_cookie', '') pplive_cookie = read_config_value(config, 'Cookie', 'pplive_cookie', '') six_room_cookie = read_config_value(config, 'Cookie', '6room_cookie', '') lehaitv_cookie = read_config_value(config, 'Cookie', 'lehaitv_cookie', '') huamao_cookie = read_config_value(config, 'Cookie', 'huamao_cookie', '') shopee_cookie = read_config_value(config, 'Cookie', 'shopee_cookie', '') youtube_cookie = read_config_value(config, 'Cookie', 'youtube_cookie', '') taobao_cookie = read_config_value(config, 'Cookie', 'taobao_cookie', '') jd_cookie = read_config_value(config, 'Cookie', 'jd_cookie', '') faceit_cookie = read_config_value(config, 'Cookie', 'faceit_cookie', '') migu_cookie = read_config_value(config, 'Cookie', 'migu_cookie', '') lianjie_cookie = read_config_value(config, 'Cookie', 'lianjie_cookie', '') laixiu_cookie = read_config_value(config, 'Cookie', 'laixiu_cookie', '') picarto_cookie = read_config_value(config, 'Cookie', 'picarto_cookie', '') video_save_type_list = ("FLV", "MKV", "TS", "MP4", "MP3音频", "M4A音频", "MP3", "M4A") if video_save_type and video_save_type.upper() in video_save_type_list: video_save_type = video_save_type.upper() else: video_save_type = "TS" check_path = video_save_path or default_path if utils.check_disk_capacity(check_path, show=first_run) < disk_space_limit: exit_recording = True if not recording: logger.warning(f"Disk space remaining is below {disk_space_limit} GB. " f"Exiting program due to the disk space limit being reached.") sys.exit(-1) def contains_url(string: str) -> bool: pattern = r"(https?://)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(:\d+)?(/.*)?" return re.search(pattern, string) is not None try: url_comments, line_list, url_line_list = [[] for _ in range(3)] with (open(url_config_file, "r", encoding=text_encoding, errors='ignore') as file): for origin_line in file: if origin_line in line_list: delete_line(url_config_file, origin_line) line_list.append(origin_line) line = origin_line.strip() if len(line) < 18: continue line_spilt = line.split('主播: ') if len(line_spilt) > 2: line = update_file(url_config_file, line, f'{line_spilt[0]}主播: {line_spilt[-1]}') is_comment_line = line.startswith("#") if is_comment_line: line = line.lstrip('#') if re.search('[,,]', line): split_line = re.split('[,,]', line) else: split_line = [line, ''] if len(split_line) == 1: url = split_line[0] quality, name = [video_record_quality, ''] elif len(split_line) == 2: if contains_url(split_line[0]): quality = video_record_quality url, name = split_line else: quality, url = split_line name = '' else: quality, url, name = split_line if quality not in ("原画", "蓝光", "超清", "高清", "标清", "流畅"): quality = '原画' if url not in url_line_list: url_line_list.append(url) else: delete_line(url_config_file, origin_line) url = 'https://' + url if '://' not in url else url url_host = url.split('/')[2] platform_host = [ 'live.douyin.com', 'v.douyin.com', 'www.douyin.com', 'live.kuaishou.com', 'www.huya.com', 'www.douyu.com', 'www.yy.com', 'live.bilibili.com', 'www.redelight.cn', 'www.xiaohongshu.com', 'xhslink.com', 'www.bigo.tv', 'slink.bigovideo.tv', 'app.blued.cn', 'cc.163.com', 'qiandurebo.com', 'fm.missevan.com', 'look.163.com', 'twitcasting.tv', 'live.baidu.com', 'weibo.com', 'fanxing.kugou.com', 'fanxing2.kugou.com', 'mfanxing.kugou.com', 'www.huajiao.com', 'www.7u66.com', 'wap.7u66.com', 'live.acfun.cn', 'm.acfun.cn', 'live.tlclw.com', 'wap.tlclw.com', 'live.ybw1666.com', 'wap.ybw1666.com', 'www.inke.cn', 'www.zhihu.com', 'www.haixiutv.com', "h5webcdnp.vvxqiu.com", "17.live", 'www.lang.live', "m.pp.weimipopo.com", "v.6.cn", "m.6.cn", 'www.lehaitv.com', 'h.catshow168.com', 'e.tb.cn', 'huodong.m.taobao.com', '3.cn', 'eco.m.jd.com', 'www.miguvideo.com', 'm.miguvideo.com', 'show.lailianjie.com', 'www.imkktv.com', 'www.picarto.tv' ] overseas_platform_host = [ 'www.tiktok.com', 'play.sooplive.co.kr', 'm.sooplive.co.kr', 'www.sooplive.com', 'm.sooplive.com', 'www.pandalive.co.kr', 'www.winktv.co.kr', 'www.flextv.co.kr', 'www.ttinglive.com', 'www.popkontv.com', 'www.twitch.tv', 'www.liveme.com', 'www.showroom-live.com', 'chzzk.naver.com', 'm.chzzk.naver.com', 'live.shopee.', '.shp.ee', 'www.youtube.com', 'youtu.be', 'www.faceit.com' ] platform_host.extend(overseas_platform_host) clean_url_host_list = ( "live.douyin.com", "live.bilibili.com", "www.huajiao.com", "www.zhihu.com", "www.huya.com", "chzzk.naver.com", "www.liveme.com", "www.haixiutv.com", "v.6.cn", "m.6.cn", 'www.lehaitv.com' ) if 'live.shopee.' in url_host or '.shp.ee' in url_host: url_host = 'live.shopee.' if 'live.shopee.' in url_host else '.shp.ee' if url_host in platform_host or any(ext in url for ext in (".flv", ".m3u8")): if url_host in clean_url_host_list: url = update_file(url_config_file, old_str=url, new_str=url.split('?')[0]) if 'xiaohongshu' in url: host_id = re.search('&host_id=(.*?)(?=&|$)', url) if host_id: new_url = url.split('?')[0] + f'?host_id={host_id.group(1)}' url = update_file(url_config_file, old_str=url, new_str=new_url) url_comments = [i for i in url_comments if url not in i] if is_comment_line: url_comments.append(url) else: new_line = (quality, url, name) url_tuples_list.append(new_line) else: if not origin_line.startswith('#'): color_obj.print_colored(f"\r{origin_line.strip()} 本行包含未知链接.此条跳过", color_obj.YELLOW) update_file(url_config_file, old_str=origin_line, new_str=origin_line, start_str='#') while len(need_update_line_list): a = need_update_line_list.pop() replace_words = a.split('|') if replace_words[0] != replace_words[1]: if replace_words[1].startswith("#"): start_with = '#' new_word = replace_words[1][1:] else: start_with = None new_word = replace_words[1] update_file(url_config_file, old_str=replace_words[0], new_str=new_word, start_str=start_with) text_no_repeat_url = list(set(url_tuples_list)) if len(text_no_repeat_url) > 0: for url_tuple in text_no_repeat_url: monitoring = len(running_list) if url_tuple[1] in not_record_list: continue if url_tuple[1] not in running_list: print(f"\r{'新增' if not first_start else '传入'}地址: {url_tuple[1]}") monitoring += 1 args = [url_tuple, monitoring] create_var[f'thread_{monitoring}'] = threading.Thread(target=start_record, args=args) create_var[f'thread_{monitoring}'].daemon = True create_var[f'thread_{monitoring}'].start() running_list.append(url_tuple[1]) time.sleep(local_delay_default) url_tuples_list = [] first_start = False except Exception as err: logger.error(f"错误信息: {err} 发生错误的行数: {err.__traceback__.tb_lineno}") if first_run: t = threading.Thread(target=display_info, args=(), daemon=True) t.start() t2 = threading.Thread(target=adjust_max_request, args=(), daemon=True) t2.start() first_run = False time.sleep(3) ================================================ FILE: msg_push.py ================================================ # -*- coding: utf-8 -*- """ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-09-03 19:18:36 Update: 2025-01-23 17:16:12 Copyright (c) 2023-2024 by Hmily, All Rights Reserved. """ from typing import Dict, Any import json import base64 import urllib.request import urllib.error import smtplib from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText no_proxy_handler = urllib.request.ProxyHandler({}) opener = urllib.request.build_opener(no_proxy_handler) headers: Dict[str, str] = {'Content-Type': 'application/json'} def dingtalk(url: str, content: str, number: str = None, is_atall: bool = False) -> Dict[str, Any]: success = [] error = [] api_list = url.replace(',', ',').split(',') if url.strip() else [] for api in api_list: json_data = { 'msgtype': 'text', 'text': { 'content': content, }, "at": { "atMobiles": [ number ], "isAtAll": is_atall }, } try: data = json.dumps(json_data).encode('utf-8') req = urllib.request.Request(api, data=data, headers=headers) response = opener.open(req, timeout=10) json_str = response.read().decode('utf-8') json_data = json.loads(json_str) if json_data['errcode'] == 0: success.append(api) else: error.append(api) print(f'钉钉推送失败, 推送地址:{api}, {json_data["errmsg"]}') except Exception as e: error.append(api) print(f'钉钉推送失败, 推送地址:{api}, 错误信息:{e}') return {"success": success, "error": error} def xizhi(url: str, title: str, content: str) -> Dict[str, Any]: success = [] error = [] api_list = url.replace(',', ',').split(',') if url.strip() else [] for api in api_list: json_data = { 'title': title, 'content': content } try: data = json.dumps(json_data).encode('utf-8') req = urllib.request.Request(api, data=data, headers=headers) response = opener.open(req, timeout=10) json_str = response.read().decode('utf-8') json_data = json.loads(json_str) if json_data['code'] == 200: success.append(api) else: error.append(api) print(f'微信推送失败, 推送地址:{api}, 失败信息:{json_data["msg"]}') except Exception as e: error.append(api) print(f'微信推送失败, 推送地址:{api}, 错误信息:{e}') return {"success": success, "error": error} def send_email(email_host: str, login_email: str, email_pass: str, sender_email: str, sender_name: str, to_email: str, title: str, content: str, smtp_port: str = None, open_ssl: bool = True) -> Dict[str, Any]: receivers = to_email.replace(',', ',').split(',') if to_email.strip() else [] try: message = MIMEMultipart() send_name = base64.b64encode(sender_name.encode("utf-8")).decode() message['From'] = f'=?UTF-8?B?{send_name}?= <{sender_email}>' message['Subject'] = Header(title, 'utf-8') if len(receivers) == 1: message['To'] = receivers[0] t_apart = MIMEText(content, 'plain', 'utf-8') message.attach(t_apart) if open_ssl: smtp_port = int(smtp_port) or 465 smtp_obj = smtplib.SMTP_SSL(email_host, smtp_port) else: smtp_port = int(smtp_port) or 25 smtp_obj = smtplib.SMTP(email_host, smtp_port) smtp_obj.login(login_email, email_pass) smtp_obj.sendmail(sender_email, receivers, message.as_string()) return {"success": receivers, "error": []} except smtplib.SMTPException as e: print(f'邮件推送失败, 推送邮箱:{to_email}, 错误信息:{e}') return {"success": [], "error": receivers} def tg_bot(chat_id: int, token: str, content: str) -> Dict[str, Any]: try: json_data = { "chat_id": chat_id, 'text': content } url = f'https://api.telegram.org/bot{token}/sendMessage' data = json.dumps(json_data).encode('utf-8') req = urllib.request.Request(url, data=data, headers=headers) response = urllib.request.urlopen(req, timeout=15) json_str = response.read().decode('utf-8') _json_data = json.loads(json_str) return {"success": [1], "error": []} except Exception as e: print(f'tg推送失败, 聊天ID:{chat_id}, 错误信息:{e}') return {"success": [], "error": [1]} def bark(api: str, title: str = "message", content: str = 'test', level: str = "active", badge: int = 1, auto_copy: int = 1, sound: str = "", icon: str = "", group: str = "", is_archive: int = 1, url: str = "") -> Dict[str, Any]: success = [] error = [] api_list = api.replace(',', ',').split(',') if api.strip() else [] for _api in api_list: json_data = { "title": title, "body": content, "level": level, "badge": badge, "autoCopy": auto_copy, "sound": sound, "icon": icon, "group": group, "isArchive": is_archive, "url": url } try: data = json.dumps(json_data).encode('utf-8') req = urllib.request.Request(_api, data=data, headers=headers) response = opener.open(req, timeout=10) json_str = response.read().decode("utf-8") json_data = json.loads(json_str) if json_data['code'] == 200: success.append(_api) else: error.append(_api) print(f'Bark推送失败, 推送地址:{_api}, 失败信息:{json_data["message"]}') except Exception as e: error.append(api) print(f'Bark推送失败, 推送地址:{_api}, 错误信息:{e}') return {"success": success, "error": error} def ntfy(api: str, title: str = "message", content: str = 'test', tags: str = 'tada', priority: int = 3, action_url: str = "", attach: str = "", filename: str = "", click: str = "", icon: str = "", delay: str = "", email: str = "", call: str = "") -> Dict[str, Any]: success = [] error = [] api_list = api.replace(',', ',').split(',') if api.strip() else [] tags = tags.replace(',', ',').split(',') if tags else ['partying_face'] actions = [{"action": "view", "label": "view live", "url": action_url}] if action_url else [] for _api in api_list: server, topic = _api.rsplit('/', maxsplit=1) json_data = { "topic": topic, "title": title, "message": content, "tags": tags, "priority": priority, "attach": attach, "filename": filename, "click": click, "actions": actions, "markdown": False, "icon": icon, "delay": delay, "email": email, "call": call } try: data = json.dumps(json_data, ensure_ascii=False).encode('utf-8') req = urllib.request.Request(server, data=data, headers=headers) response = opener.open(req, timeout=10) json_str = response.read().decode("utf-8") json_data = json.loads(json_str) if "error" not in json_data: success.append(_api) else: error.append(_api) print(f'ntfy推送失败, 推送地址:{_api}, 失败信息:{json_data["error"]}') except urllib.error.HTTPError as e: error.append(_api) error_msg = e.read().decode("utf-8") print(f'ntfy推送失败, 推送地址:{_api}, 错误信息:{json.loads(error_msg)["error"]}') except Exception as e: error.append(api) print(f'ntfy推送失败, 推送地址:{_api}, 错误信息:{e}') return {"success": success, "error": error} def pushplus(token: str, title: str, content: str) -> Dict[str, Any]: """ PushPlus推送通知 API文档: https://www.pushplus.plus/doc/ """ success = [] error = [] token_list = token.replace(',', ',').split(',') if token.strip() else [] for _token in token_list: json_data = { 'token': _token, 'title': title, 'content': content } try: url = 'https://www.pushplus.plus/send' data = json.dumps(json_data).encode('utf-8') req = urllib.request.Request(url, data=data, headers=headers) response = opener.open(req, timeout=10) json_str = response.read().decode('utf-8') json_data = json.loads(json_str) if json_data.get('code') == 200: success.append(_token) else: error.append(_token) print(f'PushPlus推送失败, Token:{_token}, 失败信息:{json_data.get("msg", "未知错误")}') except Exception as e: error.append(_token) print(f'PushPlus推送失败, Token:{_token}, 错误信息:{e}') return {"success": success, "error": error} if __name__ == '__main__': send_title = '直播通知' # 标题 send_content = '张三 开播了!' # 推送内容 # 钉钉推送通知 webhook_api = '' # 替换成自己Webhook链接,参考文档:https://open.dingtalk.com/document/robots/custom-robot-access phone_number = '' # 被@用户的手机号码 is_atall = '' # 是否@全体 # dingtalk(webhook_api, send_content, phone_number) # 微信推送通知 # 替换成自己的单点推送接口,获取地址:https://xz.qqoq.net/#/admin/one # 当然也可以使用其他平台API 如server酱 使用方法一样 xizhi_api = 'https://xizhi.qqoq.net/xxxxxxxxx.send' # xizhi(xizhi_api, send_content) # telegram推送通知 tg_token = '' # tg搜索"BotFather"获取的token值 tg_chat_id = 000000 # tg搜索"userinfobot"获取的chat_id值,即可发送推送消息给你自己,如果下面的是群组id则发送到群 # tg_bot(tg_chat_id, tg_token, send_content) # email_message( # email_host="smtp.qq.com", # login_email="", # email_pass="", # sender_email="", # sender_name="", # to_email="", # title="", # content="", # ) bark_url = 'https://xxx.xxx.com/key/' # bark(bark_url, send_title, send_content) ntfy( api="https://ntfy.sh/xxxxx", title="直播推送", content="xxx已开播", ) # PushPlus推送通知 pushplus_token = '' # 替换成自己的PushPlus Token,获取地址:https://www.pushplus.plus/ # pushplus(pushplus_token, send_title, send_content) ================================================ FILE: pyproject.toml ================================================ [project] name = "DouyinLiveRecorder" version = "4.0.7" description = "可循环值守和多人录制的直播录制软件, 支持抖音、TikTok、Youtube、快手、虎牙、斗鱼、B站、小红书、pandatv、sooplive、flextv、popkontv、twitcasting、winktv、百度、微博、酷狗、17Live、Twitch、Acfun、CHZZK、shopee等40+平台直播录制" readme = "README.md" authors = [{name = "Hmily"}] license = { text = "MIT" } requires-python = ">=3.10" dependencies = [ "requests>=2.31.0", "loguru>=0.7.3", "pycryptodome>=3.20.0", "distro>=1.9.0", "tqdm>=4.67.1", "httpx[http2]>=0.28.1", "PyExecJS>=1.5.1" ] [project.urls] "Homepage" = "https://github.com/ihmily/DouyinLiveRecorder" "Documentation" = "https://github.com/ihmily/DouyinLiveRecorder" "Repository" = "https://github.com/ihmily/DouyinLiveRecorder" "Issues" = "https://github.com/ihmily/DouyinLiveRecorder/issues" ================================================ FILE: requirements.txt ================================================ requests>=2.31.0 loguru>=0.7.3 pycryptodome>=3.20.0 distro>=1.9.0 tqdm>=4.67.1 httpx[http2]>=0.28.1 PyExecJS>=1.5.1 ================================================ FILE: src/__init__.py ================================================ import os import sys from pathlib import Path from .initializer import check_node current_file_path = Path(__file__).resolve() current_dir = current_file_path.parent JS_SCRIPT_PATH = current_dir / 'javascript' execute_dir = os.path.split(os.path.realpath(sys.argv[0]))[0] node_execute_dir = Path(execute_dir) / 'node' current_env_path = os.environ.get('PATH') os.environ['PATH'] = str(node_execute_dir) + os.pathsep + current_env_path check_node() ================================================ FILE: src/ab_sign.py ================================================ # -*- encoding: utf-8 -*- import math import time def rc4_encrypt(plaintext: str, key: str) -> str: # 初始化状态数组 s = list(range(256)) # 使用密钥对状态数组进行置换 j = 0 for i in range(256): j = (j + s[i] + ord(key[i % len(key)])) % 256 s[i], s[j] = s[j], s[i] # 生成密钥流并加密 i = j = 0 result = [] for char in plaintext: i = (i + 1) % 256 j = (j + s[i]) % 256 s[i], s[j] = s[j], s[i] t = (s[i] + s[j]) % 256 result.append(chr(s[t] ^ ord(char))) return ''.join(result) def left_rotate(x: int, n: int) -> int: n %= 32 return ((x << n) | (x >> (32 - n))) & 0xFFFFFFFF def get_t_j(j: int) -> int: if 0 <= j < 16: return 2043430169 # 0x79CC4519 elif 16 <= j < 64: return 2055708042 # 0x7A879D8A else: raise ValueError("invalid j for constant Tj") def ff_j(j: int, x: int, y: int, z: int) -> int: if 0 <= j < 16: return (x ^ y ^ z) & 0xFFFFFFFF elif 16 <= j < 64: return ((x & y) | (x & z) | (y & z)) & 0xFFFFFFFF else: raise ValueError("invalid j for bool function FF") def gg_j(j: int, x: int, y: int, z: int) -> int: if 0 <= j < 16: return (x ^ y ^ z) & 0xFFFFFFFF elif 16 <= j < 64: return ((x & y) | (~x & z)) & 0xFFFFFFFF else: raise ValueError("invalid j for bool function GG") class SM3: def __init__(self): self.reg = [] self.chunk = [] self.size = 0 self.reset() def reset(self): # 初始化寄存器值 - 修正为与JS版本相同的值 self.reg = [ 1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214 ] self.chunk = [] self.size = 0 def write(self, data): # 将输入转换为字节数组 if isinstance(data, str): # 直接转换为UTF-8字节列表 a = list(data.encode('utf-8')) else: a = data self.size += len(a) f = 64 - len(self.chunk) if len(a) < f: # 如果数据长度小于剩余空间,直接添加 self.chunk.extend(a) else: # 否则分块处理 self.chunk.extend(a[:f]) while len(self.chunk) >= 64: self._compress(self.chunk) if f < len(a): self.chunk = a[f:min(f + 64, len(a))] else: self.chunk = [] f += 64 def _fill(self): # 计算比特长度 bit_length = 8 * self.size # 添加填充位 padding_pos = len(self.chunk) self.chunk.append(0x80) padding_pos = (padding_pos + 1) % 64 # 如果剩余空间不足8字节,则填充到下一个块 if 64 - padding_pos < 8: padding_pos -= 64 # 填充0直到剩余8字节用于存储长度 while padding_pos < 56: self.chunk.append(0) padding_pos += 1 # 添加消息长度(高32位) high_bits = bit_length // 4294967296 for i in range(4): self.chunk.append((high_bits >> (8 * (3 - i))) & 0xFF) # 添加消息长度(低32位) for i in range(4): self.chunk.append((bit_length >> (8 * (3 - i))) & 0xFF) def _compress(self, data): if len(data) < 64: raise ValueError("compress error: not enough data") else: # 消息扩展 w = [0] * 132 # 将字节数组转换为字 for t in range(16): w[t] = (data[4 * t] << 24) | (data[4 * t + 1] << 16) | (data[4 * t + 2] << 8) | data[4 * t + 3] w[t] &= 0xFFFFFFFF # 消息扩展 for j in range(16, 68): a = w[j - 16] ^ w[j - 9] ^ left_rotate(w[j - 3], 15) a = a ^ left_rotate(a, 15) ^ left_rotate(a, 23) w[j] = (a ^ left_rotate(w[j - 13], 7) ^ w[j - 6]) & 0xFFFFFFFF # 计算w' for j in range(64): w[j + 68] = (w[j] ^ w[j + 4]) & 0xFFFFFFFF # 压缩 a, b, c, d, e, f, g, h = self.reg for j in range(64): ss1 = left_rotate((left_rotate(a, 12) + e + left_rotate(get_t_j(j), j)) & 0xFFFFFFFF, 7) ss2 = ss1 ^ left_rotate(a, 12) tt1 = (ff_j(j, a, b, c) + d + ss2 + w[j + 68]) & 0xFFFFFFFF tt2 = (gg_j(j, e, f, g) + h + ss1 + w[j]) & 0xFFFFFFFF d = c c = left_rotate(b, 9) b = a a = tt1 h = g g = left_rotate(f, 19) f = e e = (tt2 ^ left_rotate(tt2, 9) ^ left_rotate(tt2, 17)) & 0xFFFFFFFF # 更新寄存器 self.reg[0] ^= a self.reg[1] ^= b self.reg[2] ^= c self.reg[3] ^= d self.reg[4] ^= e self.reg[5] ^= f self.reg[6] ^= g self.reg[7] ^= h def sum(self, data=None, output_format=None): """ 计算哈希值 """ # 如果提供了输入,则重置并写入 if data is not None: self.reset() self.write(data) self._fill() # 分块压缩 for f in range(0, len(self.chunk), 64): self._compress(self.chunk[f:f + 64]) if output_format == 'hex': # 十六进制输出 result = ''.join(f'{val:08x}' for val in self.reg) else: # 字节数组输出 result = [] for f in range(8): c = self.reg[f] result.append((c >> 24) & 0xFF) result.append((c >> 16) & 0xFF) result.append((c >> 8) & 0xFF) result.append(c & 0xFF) self.reset() return result def result_encrypt(long_str: str, num: str | None = None) -> str: # 魔改base64编码表 encoding_tables = { "s0": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", "s1": "Dkdpgh4ZKsQB80/Mfvw36XI1R25+WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=", "s2": "Dkdpgh4ZKsQB80/Mfvw36XI1R25-WUAlEi7NLboqYTOPuzmFjJnryx9HVGcaStCe=", "s3": "ckdp1h4ZKsUB80/Mfvw36XIgR25+WQAlEi7NLboqYTOPuzmFjJnryx9HVGDaStCe", "s4": "Dkdpgh2ZmsQB80/MfvV36XI1R45-WUAlEixNLwoqYTOPuzKFjJnry79HbGcaStCe" } # 位移常量 masks = [16515072, 258048, 4032, 63] # 对应 0, 1, 2 的掩码,添加63作为第四个掩码 shifts = [18, 12, 6, 0] # 对应的位移量 encoding_table = encoding_tables[num] result = "" round_num = 0 long_int = get_long_int(round_num, long_str) total_chars = math.ceil(len(long_str) / 3 * 4) for i in range(total_chars): # 每4个字符处理一组3字节 if i // 4 != round_num: round_num += 1 long_int = get_long_int(round_num, long_str) # 计算当前位置的索引 index = i % 4 # 使用掩码和位移提取6位值 char_index = (long_int & masks[index]) >> shifts[index] result += encoding_table[char_index] return result def get_long_int(round_num: int, long_str: str) -> int: round_num = round_num * 3 # 获取字符串中的字符,如果超出范围则使用0 char1 = ord(long_str[round_num]) if round_num < len(long_str) else 0 char2 = ord(long_str[round_num + 1]) if round_num + 1 < len(long_str) else 0 char3 = ord(long_str[round_num + 2]) if round_num + 2 < len(long_str) else 0 return (char1 << 16) | (char2 << 8) | char3 def gener_random(random_num: int, option: list[int]) -> list[int]: byte1 = random_num & 255 byte2 = (random_num >> 8) & 255 return [ (byte1 & 170) | (option[0] & 85), # 偶数位与option[0]的奇数位合并 (byte1 & 85) | (option[0] & 170), # 奇数位与option[0]的偶数位合并 (byte2 & 170) | (option[1] & 85), # 偶数位与option[1]的奇数位合并 (byte2 & 85) | (option[1] & 170), # 奇数位与option[1]的偶数位合并 ] def generate_random_str() -> str: """ 生成随机字符串 Returns: 随机字符串 """ # 使用与JS版本相同的固定随机值 random_values = [0.123456789, 0.987654321, 0.555555555] # 生成三组随机字节并合并 random_bytes = [] random_bytes.extend(gener_random(int(random_values[0] * 10000), [3, 45])) random_bytes.extend(gener_random(int(random_values[1] * 10000), [1, 0])) random_bytes.extend(gener_random(int(random_values[2] * 10000), [1, 5])) return ''.join(chr(b) for b in random_bytes) def generate_rc4_bb_str(url_search_params: str, user_agent: str, window_env_str: str, suffix: str = "cus", arguments: list[int] | None = None) -> str: if arguments is None: arguments = [0, 1, 14] sm3 = SM3() start_time = int(time.time() * 1000) # 三次加密处理 # 1: url_search_params两次sm3之的结果 url_search_params_list = sm3.sum(sm3.sum(url_search_params + suffix)) # 2: 对后缀两次sm3之的结果 cus = sm3.sum(sm3.sum(suffix)) # 3: 对ua处理之后的结果 ua_key = chr(0) + chr(1) + chr(14) # [1/256, 1, 14] ua = sm3.sum(result_encrypt( rc4_encrypt(user_agent, ua_key), "s3" )) end_time = start_time + 100 # 构建配置对象 b = { 8: 3, 10: end_time, 15: { "aid": 6383, "pageId": 110624, "boe": False, "ddrt": 7, "paths": { "include": [{} for _ in range(7)], "exclude": [] }, "track": { "mode": 0, "delay": 300, "paths": [] }, "dump": True, "rpU": "hwj" }, 16: start_time, 18: 44, 19: [1, 0, 1, 5], } def split_to_bytes(num: int) -> list[int]: return [ (num >> 24) & 255, (num >> 16) & 255, (num >> 8) & 255, num & 255 ] # 处理时间戳 start_time_bytes = split_to_bytes(b[16]) b[20] = start_time_bytes[0] b[21] = start_time_bytes[1] b[22] = start_time_bytes[2] b[23] = start_time_bytes[3] b[24] = int(b[16] / 256 / 256 / 256 / 256) & 255 b[25] = int(b[16] / 256 / 256 / 256 / 256 / 256) & 255 # 处理Arguments参数 arg0_bytes = split_to_bytes(arguments[0]) b[26] = arg0_bytes[0] b[27] = arg0_bytes[1] b[28] = arg0_bytes[2] b[29] = arg0_bytes[3] b[30] = int(arguments[1] / 256) & 255 b[31] = (arguments[1] % 256) & 255 arg1_bytes = split_to_bytes(arguments[1]) b[32] = arg1_bytes[0] b[33] = arg1_bytes[1] arg2_bytes = split_to_bytes(arguments[2]) b[34] = arg2_bytes[0] b[35] = arg2_bytes[1] b[36] = arg2_bytes[2] b[37] = arg2_bytes[3] # 处理加密结果 b[38] = url_search_params_list[21] b[39] = url_search_params_list[22] b[40] = cus[21] b[41] = cus[22] b[42] = ua[23] b[43] = ua[24] # 处理结束时间 end_time_bytes = split_to_bytes(b[10]) b[44] = end_time_bytes[0] b[45] = end_time_bytes[1] b[46] = end_time_bytes[2] b[47] = end_time_bytes[3] b[48] = b[8] b[49] = int(b[10] / 256 / 256 / 256 / 256) & 255 b[50] = int(b[10] / 256 / 256 / 256 / 256 / 256) & 255 # 处理配置项 b[51] = b[15]['pageId'] page_id_bytes = split_to_bytes(b[15]['pageId']) b[52] = page_id_bytes[0] b[53] = page_id_bytes[1] b[54] = page_id_bytes[2] b[55] = page_id_bytes[3] b[56] = b[15]['aid'] b[57] = b[15]['aid'] & 255 b[58] = (b[15]['aid'] >> 8) & 255 b[59] = (b[15]['aid'] >> 16) & 255 b[60] = (b[15]['aid'] >> 24) & 255 # 处理环境信息 window_env_list = [ord(char) for char in window_env_str] b[64] = len(window_env_list) b[65] = b[64] & 255 b[66] = (b[64] >> 8) & 255 b[69] = 0 b[70] = 0 b[71] = 0 # 计算校验和 b[72] = b[18] ^ b[20] ^ b[26] ^ b[30] ^ b[38] ^ b[40] ^ b[42] ^ b[21] ^ b[27] ^ b[31] ^ \ b[35] ^ b[39] ^ b[41] ^ b[43] ^ b[22] ^ b[28] ^ b[32] ^ b[36] ^ b[23] ^ b[29] ^ \ b[33] ^ b[37] ^ b[44] ^ b[45] ^ b[46] ^ b[47] ^ b[48] ^ b[49] ^ b[50] ^ b[24] ^ \ b[25] ^ b[52] ^ b[53] ^ b[54] ^ b[55] ^ b[57] ^ b[58] ^ b[59] ^ b[60] ^ b[65] ^ \ b[66] ^ b[70] ^ b[71] # 构建最终字节数组 bb = [ b[18], b[20], b[52], b[26], b[30], b[34], b[58], b[38], b[40], b[53], b[42], b[21], b[27], b[54], b[55], b[31], b[35], b[57], b[39], b[41], b[43], b[22], b[28], b[32], b[60], b[36], b[23], b[29], b[33], b[37], b[44], b[45], b[59], b[46], b[47], b[48], b[49], b[50], b[24], b[25], b[65], b[66], b[70], b[71] ] bb.extend(window_env_list) bb.append(b[72]) return rc4_encrypt( ''.join(chr(byte) for byte in bb), chr(121) ) def ab_sign(url_search_params: str, user_agent: str) -> str: window_env_str = "1920|1080|1920|1040|0|30|0|0|1872|92|1920|1040|1857|92|1|24|Win32" # 1. 生成随机字符串前缀 # 2. 生成RC4加密的主体部分 # 3. 对结果进行最终加密并添加等号后缀 return result_encrypt( generate_random_str() + generate_rc4_bb_str(url_search_params, user_agent, window_env_str), "s4" ) + "=" ================================================ FILE: src/http_clients/__init__.py ================================================ ================================================ FILE: src/http_clients/async_http.py ================================================ # -*- coding: utf-8 -*- import httpx from typing import Dict, Any from .. import utils OptionalStr = str | None OptionalDict = Dict[str, Any] | None async def async_req( url: str, proxy_addr: OptionalStr = None, headers: OptionalDict = None, data: dict | bytes | None = None, json_data: dict | list | None = None, timeout: int = 20, redirect_url: bool = False, return_cookies: bool = False, include_cookies: bool = False, abroad: bool = False, content_conding: str = 'utf-8', verify: bool = False, http2: bool = True ) -> OptionalDict | OptionalStr | tuple: if headers is None: headers = {} try: proxy_addr = utils.handle_proxy_addr(proxy_addr) if data or json_data: async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify, http2=http2) as client: response = await client.post(url, data=data, json=json_data, headers=headers) else: async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify, http2=http2) as client: response = await client.get(url, headers=headers, follow_redirects=True) if redirect_url: return str(response.url) elif return_cookies: cookies_dict = {name: value for name, value in response.cookies.items()} return (response.text, cookies_dict) if include_cookies else cookies_dict else: resp_str = response.text except Exception as e: resp_str = str(e) return resp_str async def get_response_status(url: str, proxy_addr: OptionalStr = None, headers: OptionalDict = None, timeout: int = 10, abroad: bool = False, verify: bool = False, http2=False) -> bool: try: proxy_addr = utils.handle_proxy_addr(proxy_addr) async with httpx.AsyncClient(proxy=proxy_addr, timeout=timeout, verify=verify) as client: response = await client.head(url, headers=headers, follow_redirects=True) return response.status_code == 200 except Exception as e: print(e) return False ================================================ FILE: src/http_clients/sync_http.py ================================================ # -*- coding: utf-8 -*- import gzip import urllib.parse import urllib.error import requests import ssl import json import urllib.request no_proxy_handler = urllib.request.ProxyHandler({}) opener = urllib.request.build_opener(no_proxy_handler) ssl_context = ssl.create_default_context() ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE OptionalStr = str | None OptionalDict = dict | None def sync_req( url: str, proxy_addr: OptionalStr = None, headers: OptionalDict = None, data: dict | bytes | None = None, json_data: dict | list | None = None, timeout: int = 20, redirect_url: bool = False, abroad: bool = False, content_conding: str = 'utf-8' ) -> str: if headers is None: headers = {} try: if proxy_addr: proxies = { 'http': proxy_addr, 'https': proxy_addr } if data or json_data: response = requests.post( url, data=data, json=json_data, headers=headers, proxies=proxies, timeout=timeout ) else: response = requests.get(url, headers=headers, proxies=proxies, timeout=timeout) if redirect_url: return response.url resp_str = response.text else: if data and not isinstance(data, bytes): data = urllib.parse.urlencode(data).encode(content_conding) if json_data and isinstance(json_data, (dict, list)): data = json.dumps(json_data).encode(content_conding) req = urllib.request.Request(url, data=data, headers=headers) try: if abroad: response = urllib.request.urlopen(req, timeout=timeout) else: response = opener.open(req, timeout=timeout) if redirect_url: return response.url content_encoding = response.info().get('Content-Encoding') try: if content_encoding == 'gzip': with gzip.open(response, 'rt', encoding=content_conding) as gzipped: resp_str = gzipped.read() else: resp_str = response.read().decode(content_conding) finally: response.close() except urllib.error.HTTPError as e: if e.code == 400: resp_str = e.read().decode(content_conding) else: raise except urllib.error.URLError as e: print(f"URL Error: {e}") raise except Exception as e: print(f"An error occurred: {e}") raise except Exception as e: resp_str = str(e) return resp_str ================================================ FILE: src/initializer.py ================================================ # -*- coding: utf-8 -*- """ Author: Hmily GitHub:https://github.com/ihmily Copyright (c) 2024 by Hmily, All Rights Reserved. """ import os import subprocess import sys import platform import zipfile from pathlib import Path import requests import re import distro from tqdm import tqdm from .logger import logger current_platform = platform.system() execute_dir = os.path.split(os.path.realpath(sys.argv[0]))[0] current_env_path = os.environ.get('PATH') def unzip_file(zip_path: str | Path, extract_to: str | Path, delete: bool = True) -> None: if not os.path.exists(extract_to): os.makedirs(extract_to) with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(extract_to) if delete and os.path.exists(zip_path): os.remove(zip_path) def install_nodejs_windows(): try: logger.warning("Node.js is not installed.") logger.debug("Installing the stable version of Node.js for Windows...") response = requests.get('https://nodejs.cn/download/') if response.status_code == 200: match = re.search('https://npmmirror.com/mirrors/node/(v.*?)/node-(v.*?)-x64.msi', response.text) if match: version = match.group(1) system_bit = 'x64' if '32' not in platform.machine() else 'x86' url = f'https://npmmirror.com/mirrors/node/{version}/node-{version}-win-{system_bit}.zip' else: logger.error("Failed to retrieve the download URL for the latest version of Node.js...") return full_file_name = url.rsplit('/', maxsplit=1)[-1] zip_file_path = Path(execute_dir) / full_file_name if Path(zip_file_path).exists(): logger.debug("Node.js installation file already exists, start install...") else: response = requests.get(url, stream=True) total_size = int(response.headers.get('Content-Length', 0)) block_size = 1024 with tqdm(total=total_size, unit="B", unit_scale=True, ncols=100, desc=f'Downloading Node.js ({version})') as t: with open(zip_file_path, 'wb') as f: for data in response.iter_content(block_size): t.update(len(data)) f.write(data) unzip_file(zip_file_path, execute_dir) extract_dir_path = str(zip_file_path).rsplit('.', maxsplit=1)[0] f_path, f_name = os.path.splitext(zip_file_path) new_extract_dir_path = Path(f_path).parent / 'node' if Path(extract_dir_path).exists() and not Path(new_extract_dir_path).exists(): os.rename(extract_dir_path, new_extract_dir_path) os.environ['PATH'] = execute_dir + '/node' + os.pathsep + current_env_path result = subprocess.run(["node", "-v"], capture_output=True) if result.returncode == 0: logger.debug('Node.js installation was successful. Restart for changes to take effect') else: logger.debug('Node.js installation failed') return True else: logger.error("Failed to retrieve the Node.js version page") except Exception as e: logger.error(f"type: {type(e).__name__}, Node.js installation failed {e}") def install_nodejs_centos(): try: logger.warning("Node.js is not installed.") logger.debug("Installing the latest version of Node.js for CentOS...") result = subprocess.run('curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm/setup_lts.x | ' 'bash -', shell=True, capture_output=True) if result.returncode != 0: logger.error("Failed to run NodeSource installation script") return result = subprocess.run(['yum', 'install', '-y', 'epel-release'], capture_output=True) if result.returncode != 0: logger.error("Failed to install EPEL repository") return result = subprocess.run(['yum', 'install', '-y', 'nodejs'], capture_output=True) if result.returncode == 0: logger.debug('Node.js installation was successful. Restart for changes to take effect.') return True else: logger.error("Node.js installation failed") except Exception as e: logger.error(f"type: {type(e).__name__}, Node.js installation failed {e}") def install_nodejs_ubuntu(): try: logger.warning("Node.js is not installed.") logger.debug("Installing the latest version of Node.js for Ubuntu...") install_script = 'curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -' result = subprocess.run(install_script, shell=True, capture_output=True) if result.returncode != 0: logger.error("Failed to run NodeSource installation script") return install_command = ['apt', 'install', '-y', 'nodejs'] result = subprocess.run(install_command, capture_output=True) if result.returncode == 0: logger.debug('Node.js installation was successful. Restart for changes to take effect.') return True else: logger.error("Node.js installation failed") except Exception as e: logger.error(f"type: {type(e).__name__}, Node.js installation failed, {e}") def install_nodejs_mac(): logger.warning("Node.js is not installed.") logger.debug("Installing the latest version of Node.js for macOS...") try: result = subprocess.run(["brew", "install", "node"], capture_output=True) if result.returncode == 0: logger.debug('Node.js installation was successful. Restart for changes to take effect.') return True else: logger.error("Node.js installation failed") except subprocess.CalledProcessError as e: logger.error(f"Failed to install Node.js using Homebrew. {e}") logger.error("Please install Node.js manually or check your Homebrew installation.") except Exception as e: logger.error(f"An unexpected error occurred: {e}") def get_package_manager(): dist_id = distro.id() if dist_id in ["centos", "fedora", "rhel", "amzn", "oracle", "scientific", "opencloudos", "alinux"]: return "RHS" else: return "DBS" def install_nodejs() -> bool: if current_platform == "Windows": return install_nodejs_windows() elif current_platform == "Linux": os_type = get_package_manager() if os_type == "RHS": return install_nodejs_centos() else: return install_nodejs_ubuntu() elif current_platform == "Darwin": return install_nodejs_mac() else: logger.debug(f"Node.js auto installation is not supported on this platform: {current_platform}. " f"Please install Node.js manually.") return False def ensure_nodejs_installed(func): def wrapper(*args, **kwargs): try: result = subprocess.run(['node', '-v'], capture_output=True) version = result.stdout.strip() if result.returncode == 0 and version: return func(*args, **kwargs) except FileNotFoundError: pass return False def wrapped_func(*args, **kwargs): if sys.version_info >= (3, 7): res = wrapper(*args, **kwargs) else: res = wrapper(*args, **kwargs) if not res: install_nodejs() res = wrapper(*args, **kwargs) if not res: raise RuntimeError("Node.js is not installed.") return func(*args, **kwargs) return wrapped_func def check_nodejs_installed() -> bool: try: result = subprocess.run(['node', '-v'], capture_output=True) version = result.stdout.strip() if result.returncode == 0 and version: return True except FileNotFoundError: pass return False def check_node() -> bool: if not check_nodejs_installed(): return install_nodejs() ================================================ FILE: src/javascript/haixiu.js ================================================ var closeGeetest = !1, _a123 = "haija1c7", _b2x = "xiuhc2a6", _c3y = "anchc3a5", _dx34 = "famic7a2", _hf_constants1 = "sowh1e", _hf_constants2 = "1000ha", _hf_constants3 = "butr12", _hf_constants4 = "2000h5", _gf_constants1 = "lehaaj", _gf_constants2 = "1000ax", _gf_constants3 = "lehaData" let CryptoJS = null; function EnmoliParamter() { this._a123 = eval("_hf_constants1"), this._b2x = eval("_hf_constants2"), this._c3y = eval("_hf_constants3"), this._dx34 = eval("_hf_constants4"), this.getA123 = function() { return this._a123 } , this.getB2X = function() { return this._b2x } , this.getC3Y = function() { return this._c3y } , this.getDX34 = function() { return this._dx34 } } EnmoliParamter.prototype = { aa: function(e, t) { if (e === t) return e; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e; if (e.arity === t.arity && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ac: function(e, t) { if (e === t) return e; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e; if (e.id === t.id && (e = CryptoJS.MD5(e) + ""), e.arity1 === t.arity && e.string2 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ad: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e; if (e.arity2 === t.arity && e.string3 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ae: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity3 === t.arity && e.string4 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, af: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity4 === t.arity && e.string5 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ah: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e; if (e.arity6 === t.arity && e.string9 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ai: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e; if (e.arity2 === t.arity5 && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, aj: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity44 === t.arity42 && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ak: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity21 === t.arity322 && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, ax: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity22 === t.arity32 && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, az: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity42 === t.arity57 && e.string2 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return e }, are_similar: function(e, t) { if (e === t) return !0; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return !0; return !0 } return e } if (Array.isArray(t)) return e; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity === t.arity && e.string === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third); case "function": case "regexp": return e; default: return !0 } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e.second.string === t.second.string && "(string)" === t.second.id; if ("[" === e.id && "infix" === e.arity && "." === t.id) return e.second.string === t.second.string && "(string)" === e.second.id } return !1 }, ayz: function(e, t) { if (e === t) return e; if (Array.isArray(e)) { if (Array.isArray(t) && e.length === t.length) { var i; for (i = 0; i < e.length; i += 1) if (!this.are_similar(e[i], t[i])) return e; return e } return e } if (Array.isArray(t)) return t; if ("(number)" === e.id && "(number)" === t.id) return e.number === t.number; if (e.arity42 === t.arity57 && e.string2 === t.string) switch (e.arity) { case "prefix": case "suffix": case "infix": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second); case "ternary": return this.are_similar(e.first, t.first) && this.are_similar(e.second, t.second) && this.are_similar(e.third, t.third) } else { if ("." === e.id && "[" === t.id && "infix" === t.arity) return e; if ("[" === e.id && "infix" === e.arity && "." === t.id) return t } return this.getA123().substring(4) + this.getB2X().substring(4) + this.getC3Y().substring(4) + this.getDX34().substring(4) } } function EnmoliSubmiter() {} EnmoliSubmiter.prototype = { bsq: function(e) { var t = this.pf(e) , i = this.as(t); return this.brm(i) }, pf: function(e) { var t = {}; for (var i in e) "" !== e[i] && (t[i] = e[i]); return t }, as: function(e) { for (var t = {}, i = Object.keys(e).sort(), o = 0; o < i.length; o++) { var n = i[o]; t[n] = e[n] } return t }, brm: function(e) { var t = this.cls(e) , i = new EnmoliParamter; return this.pt(t, i.ayz(t, "showselfAnchorVisitorParameters")) }, cls: function(e) { var t = ""; for (var i in e) t = t + i + "=" + e[i] + "&"; return t = t.substring(0, t.length - 1) }, pt: function(e, t) { var i = new EnmoliParamter; return e += t, i.az(i.ax(i.ak(i.aj(i.ai(i.ah(i.af(i.ae(i.ad(i.ac(i.aa(e, e + "01" + t), e + "escape" + t), e + "same"), e + "visitor"), "anchor"), e + "person"), e + "ax" + t), "ae" + t), e + "ax" + t), e + "inspect" + t), "af" + t) }, bnu: function(e, t) { for (var i = e.split("&"), o = 0; o < i.length; o++) { var n = i[o].split("="); 2 == n.length && (t[n[0]] = encodeURIComponent($.trim(n[1])).toString()) } }, bn: function(e, t) { for (var i in e) "object" == typeof e[i] ? t[i] = encodeURIComponent($.trim(JSON.stringify(e[i]))).toString() : t[i] = encodeURIComponent($.trim(e[i])).toString() } } var enmoliSubmiter = new EnmoliSubmiter(); function sign(options, cryptoJSPath){ CryptoJS = require(cryptoJSPath); return enmoliSubmiter.bsq(options); } module.exports = { sign }; // const options = { // "accessToken": "pLXSC%252FXJ0asc1I21tVL5FYZhNJn2Zg6d7m94umCnpgL%252BuVm31GQvyw%253D%253D", // "tku": "3000006", // "c": "10138100100000", // "_st1": "1728621076958" // } // const cryptoJSPath = './crypto-js.min.js' // console.log(sign(options, cryptoJSPath)) ================================================ FILE: src/javascript/laixiu.js ================================================ function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function calculateSign() { const a = new Date().getTime(); const s = generateUUID().replace(/-/g, ""); const u = 'kk792f28d6ff1f34ec702c08626d454b39pro'; const input = "web" + s + a + u; const hash = CryptoJS.MD5(input).toString(); return { timestamp: a, imei: s, requestId: hash, inputString: input }; } function sign(cryptoJSPath) { CryptoJS = require(cryptoJSPath); return calculateSign(); } module.exports = { sign }; ================================================ FILE: src/javascript/liveme.js ================================================ /** * @author Hmily * @createTime 2024-10-10 */ const id = 1; const r = `${new Date().getTime()}${id}` const Am = "LM6000101139961122666757"; const rl = "undefined" function createRandom(length = 32) { let result = ""; const characters = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; for (let i = 0; i < length; ++i) { const randomIndex = Math.floor(Math.random() * characters.length); result += characters.charAt(randomIndex); } return result; } function createSignature(input = "4l4m5") { let signature = ""; let number = 0; for (let i = 0; i < input.length; ++i) { const charCode = input.charCodeAt(i); if (charCode >= 48 && charCode <= 57) { number = number * 10 + (charCode - 48); } else { if (number !== 0) { signature += createRandom(number); number = 0; } signature += String.fromCharCode(charCode); } } if (number !== 0) { signature += createRandom(number); } return signature; } function oC(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e } var Tm = { exports: {} } , Sm = { exports: {} }; (function() { var e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" , t = { rotl: function(n, r) { return n << r | n >>> 32 - r }, rotr: function(n, r) { return n << 32 - r | n >>> r }, endian: function(n) { if (n.constructor == Number) return t.rotl(n, 8) & 16711935 | t.rotl(n, 24) & 4278255360; for (var r = 0; r < n.length; r++) n[r] = t.endian(n[r]); return n }, randomBytes: function(n) { for (var r = []; n > 0; n--) r.push(Math.floor(Math.random() * 256)); return r }, bytesToWords: function(n) { for (var r = [], s = 0, o = 0; s < n.length; s++, o += 8) r[o >>> 5] |= n[s] << 24 - o % 32; return r }, wordsToBytes: function(n) { for (var r = [], s = 0; s < n.length * 32; s += 8) r.push(n[s >>> 5] >>> 24 - s % 32 & 255); return r }, bytesToHex: function(n) { for (var r = [], s = 0; s < n.length; s++) r.push((n[s] >>> 4).toString(16)), r.push((n[s] & 15).toString(16)); return r.join("") }, hexToBytes: function(n) { for (var r = [], s = 0; s < n.length; s += 2) r.push(parseInt(n.substr(s, 2), 16)); return r }, bytesToBase64: function(n) { for (var r = [], s = 0; s < n.length; s += 3) for (var o = n[s] << 16 | n[s + 1] << 8 | n[s + 2], i = 0; i < 4; i++) s * 8 + i * 6 <= n.length * 8 ? r.push(e.charAt(o >>> 6 * (3 - i) & 63)) : r.push("="); return r.join("") }, base64ToBytes: function(n) { n = n.replace(/[^A-Z0-9+\/]/ig, ""); for (var r = [], s = 0, o = 0; s < n.length; o = ++s % 4) o != 0 && r.push((e.indexOf(n.charAt(s - 1)) & Math.pow(2, -2 * o + 8) - 1) << o * 2 | e.indexOf(n.charAt(s)) >>> 6 - o * 2); return r } }; Sm.exports = t } )(); var iC = Sm.exports , nl = { utf8: { stringToBytes: function(e) { return nl.bin.stringToBytes(unescape(encodeURIComponent(e))) }, bytesToString: function(e) { return decodeURIComponent(escape(nl.bin.bytesToString(e))) } }, bin: { stringToBytes: function(e) { for (var t = [], n = 0; n < e.length; n++) t.push(e.charCodeAt(n) & 255); return t }, bytesToString: function(e) { for (var t = [], n = 0; n < e.length; n++) t.push(String.fromCharCode(e[n])); return t.join("") } } }, sd = nl; var aC = function(e) { return e != null && (Cm(e) || lC(e) || !!e._isBuffer) }; function Cm(e) { return !!e.constructor && typeof e.constructor.isBuffer == "function" && e.constructor.isBuffer(e) } function lC(e) { return typeof e.readFloatLE == "function" && typeof e.slice == "function" && Cm(e.slice(0, 0)) } (function() { var e = iC , t = sd.utf8 , n = aC , r = sd.bin , s = function(o, i) { o.constructor == String ? i && i.encoding === "binary" ? o = r.stringToBytes(o) : o = t.stringToBytes(o) : n(o) ? o = Array.prototype.slice.call(o, 0) : !Array.isArray(o) && o.constructor !== Uint8Array && (o = o.toString()); for (var a = e.bytesToWords(o), l = o.length * 8, c = 1732584193, u = -271733879, f = -1732584194, d = 271733878, m = 0; m < a.length; m++) a[m] = (a[m] << 8 | a[m] >>> 24) & 16711935 | (a[m] << 24 | a[m] >>> 8) & 4278255360; a[l >>> 5] |= 128 << l % 32, a[(l + 64 >>> 9 << 4) + 14] = l; for (var v = s._ff, w = s._gg, R = s._hh, y = s._ii, m = 0; m < a.length; m += 16) { var b = c , _ = u , g = f , C = d; c = v(c, u, f, d, a[m + 0], 7, -680876936), d = v(d, c, u, f, a[m + 1], 12, -389564586), f = v(f, d, c, u, a[m + 2], 17, 606105819), u = v(u, f, d, c, a[m + 3], 22, -1044525330), c = v(c, u, f, d, a[m + 4], 7, -176418897), d = v(d, c, u, f, a[m + 5], 12, 1200080426), f = v(f, d, c, u, a[m + 6], 17, -1473231341), u = v(u, f, d, c, a[m + 7], 22, -45705983), c = v(c, u, f, d, a[m + 8], 7, 1770035416), d = v(d, c, u, f, a[m + 9], 12, -1958414417), f = v(f, d, c, u, a[m + 10], 17, -42063), u = v(u, f, d, c, a[m + 11], 22, -1990404162), c = v(c, u, f, d, a[m + 12], 7, 1804603682), d = v(d, c, u, f, a[m + 13], 12, -40341101), f = v(f, d, c, u, a[m + 14], 17, -1502002290), u = v(u, f, d, c, a[m + 15], 22, 1236535329), c = w(c, u, f, d, a[m + 1], 5, -165796510), d = w(d, c, u, f, a[m + 6], 9, -1069501632), f = w(f, d, c, u, a[m + 11], 14, 643717713), u = w(u, f, d, c, a[m + 0], 20, -373897302), c = w(c, u, f, d, a[m + 5], 5, -701558691), d = w(d, c, u, f, a[m + 10], 9, 38016083), f = w(f, d, c, u, a[m + 15], 14, -660478335), u = w(u, f, d, c, a[m + 4], 20, -405537848), c = w(c, u, f, d, a[m + 9], 5, 568446438), d = w(d, c, u, f, a[m + 14], 9, -1019803690), f = w(f, d, c, u, a[m + 3], 14, -187363961), u = w(u, f, d, c, a[m + 8], 20, 1163531501), c = w(c, u, f, d, a[m + 13], 5, -1444681467), d = w(d, c, u, f, a[m + 2], 9, -51403784), f = w(f, d, c, u, a[m + 7], 14, 1735328473), u = w(u, f, d, c, a[m + 12], 20, -1926607734), c = R(c, u, f, d, a[m + 5], 4, -378558), d = R(d, c, u, f, a[m + 8], 11, -2022574463), f = R(f, d, c, u, a[m + 11], 16, 1839030562), u = R(u, f, d, c, a[m + 14], 23, -35309556), c = R(c, u, f, d, a[m + 1], 4, -1530992060), d = R(d, c, u, f, a[m + 4], 11, 1272893353), f = R(f, d, c, u, a[m + 7], 16, -155497632), u = R(u, f, d, c, a[m + 10], 23, -1094730640), c = R(c, u, f, d, a[m + 13], 4, 681279174), d = R(d, c, u, f, a[m + 0], 11, -358537222), f = R(f, d, c, u, a[m + 3], 16, -722521979), u = R(u, f, d, c, a[m + 6], 23, 76029189), c = R(c, u, f, d, a[m + 9], 4, -640364487), d = R(d, c, u, f, a[m + 12], 11, -421815835), f = R(f, d, c, u, a[m + 15], 16, 530742520), u = R(u, f, d, c, a[m + 2], 23, -995338651), c = y(c, u, f, d, a[m + 0], 6, -198630844), d = y(d, c, u, f, a[m + 7], 10, 1126891415), f = y(f, d, c, u, a[m + 14], 15, -1416354905), u = y(u, f, d, c, a[m + 5], 21, -57434055), c = y(c, u, f, d, a[m + 12], 6, 1700485571), d = y(d, c, u, f, a[m + 3], 10, -1894986606), f = y(f, d, c, u, a[m + 10], 15, -1051523), u = y(u, f, d, c, a[m + 1], 21, -2054922799), c = y(c, u, f, d, a[m + 8], 6, 1873313359), d = y(d, c, u, f, a[m + 15], 10, -30611744), f = y(f, d, c, u, a[m + 6], 15, -1560198380), u = y(u, f, d, c, a[m + 13], 21, 1309151649), c = y(c, u, f, d, a[m + 4], 6, -145523070), d = y(d, c, u, f, a[m + 11], 10, -1120210379), f = y(f, d, c, u, a[m + 2], 15, 718787259), u = y(u, f, d, c, a[m + 9], 21, -343485551), c = c + b >>> 0, u = u + _ >>> 0, f = f + g >>> 0, d = d + C >>> 0 } return e.endian([c, u, f, d]) }; s._ff = function(o, i, a, l, c, u, f) { var d = o + (i & a | ~i & l) + (c >>> 0) + f; return (d << u | d >>> 32 - u) + i } , s._gg = function(o, i, a, l, c, u, f) { var d = o + (i & l | a & ~l) + (c >>> 0) + f; return (d << u | d >>> 32 - u) + i } , s._hh = function(o, i, a, l, c, u, f) { var d = o + (i ^ a ^ l) + (c >>> 0) + f; return (d << u | d >>> 32 - u) + i } , s._ii = function(o, i, a, l, c, u, f) { var d = o + (a ^ (i | ~l)) + (c >>> 0) + f; return (d << u | d >>> 32 - u) + i } , s._blocksize = 16, s._digestsize = 16, Tm.exports = function(o, i) { if (o == null) throw new Error("Illegal argument " + o); var a = e.wordsToBytes(s(o, i)); return i && i.asBytes ? a : i && i.asString ? r.bytesToString(a) : e.bytesToHex(a) } } )(); var cC = Tm.exports; var t = { utf8: { stringToBytes: function(e) { return nl.bin.stringToBytes(unescape(encodeURIComponent(e))) }, bytesToString: function(e) { return decodeURIComponent(escape(nl.bin.bytesToString(e))) } }, bin: { stringToBytes: function(e) { for (var t = [], n = 0; n < e.length; n++) t.push(e.charCodeAt(n) & 255); return t }, bytesToString: function(e) { for (var t = [], n = 0; n < e.length; n++) t.push(String.fromCharCode(e[n])); return t.join("") } } }; const hC = (e, t, n=!1) => { if (t.params) { const o = {}; Object.keys(t.params).forEach(i => { t.params[i] !== void 0 && t.params[i] !== null && (o[i] = t.params[i]) } ), t.params = o } let r = {}; const s = t.method.toLowerCase(); if (s === "get") t.params = Object.assign({}, e, t.params || {}); else if (s === "post") if (typeof t.data == "string") { let o; t.data.split("&").forEach(i => { o = i.split("="), r[o[0]] = o[1] } ), r = Object.assign({}, e, r), t.data = Object.keys(r).map(i => `${i}=${r[i]}`).join("&") } else r = Object.assign(r, e, t.data || {}), t.data = r; return n ? t : (r = Object.assign({}, t.params, r), r) } const Rm = oC(cC); const s = Rm(r); pC = e => { let t = Object.keys(e).sort().map(n => { function r(s) { return Array.isArray(s) ? s.join(",") : typeof s === "object" ? JSON.stringify(s) : s } return n + r(e[n]) } ).join(""); return t += Am + e.lm_s_ts + rl, Rm(t) } // final encryption function let CryptoJS = null; lm_s_key = atob('ZGQ0NmRiYjQ0MmI2ZTRiYTgxN2Q2MzQ3ZDJkZGY0OTM='); function requestSign(signParams, cryptoJSPath) { let sKey = Object.keys(signParams).sort().map(key => { function getValue(val) { if (Array.isArray(val)) { return val.join(','); } if (typeof val === 'object') { return JSON.stringify(val); } return val; } return key + getValue(signParams[key]); }).join(''); sKey += signParams.lm_s_id + signParams.lm_s_ts + lm_s_key; console.log(`sKey: ${sKey}`); CryptoJS = require(cryptoJSPath); return CryptoJS.MD5(sKey).toString(); } function sign(videoid, cryptoJSPath, platform='web'){ const vali = createSignature(); const data_e = { lm_s_id: Am, lm_s_ts: r, lm_s_str: s, lm_s_ver: 1, h5: 1 }; /* data_e example value const data_e = { lm_s_id: Am, lm_s_ts: "17284909009151", lm_s_str: "88f9777231dc2d6ac462a1d7ebf5f54e", lm_s_ver: 1, h5: 1 }; */ console.log("data_e:",data_e); data_i = { ...data_e, _time: new Date().valueOf(), thirdchannel: 6, videoid: videoid, area: 'zh', vali: vali } console.log("data_i:",data_i); // fake lm_s_sign param value let lm_s_sign = pC(data_i); console.log(`fake lm_s_sign: ${lm_s_sign}`); //finnal request params /* signParams = { "alias": "liveme", "tongdun_black_box": "iWPU21728483558afruvSVo6x0", "os": "android", "lm_s_id": "LM6000101139961122666757", "lm_s_ts": "17284909009151", "lm_s_str": "88f9777231dc2d6ac462a1d7ebf5f54e", "lm_s_ver": 1, "h5": 1, "_time": 1728490664651, "thirdchannel": 6, "videoid": "17284844223282059697", "area": "zh", "vali": "zH8SlBwnCm4AZWp" }# //result: 4eaf71a1ec19b49b7267e4d16e007105 */ signParams = { "alias": "liveme", "tongdun_black_box": "", "os": platform, ...data_i } console.log("signParams: ", signParams); lm_s_sign = requestSign(signParams, cryptoJSPath); console.log(`\x1b[32mfinal lm_s_sign: \x1b[0m${lm_s_sign}\n`); data = { ...signParams, lm_s_sign } return data; } module.exports = { sign }; ================================================ FILE: src/javascript/migu.js ================================================ /** * Function to get the ddCalcu parameter value * @param {string} inputUrl - The original URL before encryption * @returns {Promise} - Returns the calculated ddCalcu value */ async function getDdCalcu(inputUrl) { let wasmInstance = null; let memory_p = null; // Uint8Array view let memory_h = null; // Uint32Array view // Fixed parameter const f = 'PBTxuWiTEbUPPFcpyxs0ww=='; // Utility function: Convert string to UTF-8 in memory function stringToUTF8(string, offset) { const encoder = new TextEncoder(); const encoded = encoder.encode(string); for (let i = 0; i < encoded.length; i++) { memory_p[offset + i] = encoded[i]; } memory_p[offset + encoded.length] = 0; // Null-terminate } // Utility function: Read UTF-8 string from memory address function UTF8ToString(offset) { let s = ''; let i = 0; while (memory_p[offset + i]) { s += String.fromCharCode(memory_p[offset + i]); i++; } return s; } // WASM import function stubs function a(e, t, r, n) { let s = 0; for (let i = 0; i < r; i++) { const d = memory_h[t + 4 >> 2]; t += 8; s += d; } memory_h[n >> 2] = s; return 0; } function b() {} function c() {} // Step 1: Retrieve playerVersion const settingsResp = await fetch('https://app-sc.miguvideo.com/common/v1/settings/H5_DetailPage'); const settingsData = await settingsResp.json(); const playerVersion = JSON.parse(settingsData.body.paramValue).playerVersion; // Step 2: Load WASM module const wasmUrl = `https://www.miguvideo.com/mgs/player/prd/${playerVersion}/dist/mgprtcl.wasm`; const wasmResp = await fetch(wasmUrl); if (!wasmResp.ok) throw new Error("Failed to download WASM"); const wasmBuffer = await wasmResp.arrayBuffer(); const importObject = { a: { a, b, c } }; const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject); wasmInstance = instance; const memory = wasmInstance.exports.d; memory_p = new Uint8Array(memory.buffer); memory_h = new Uint32Array(memory.buffer); const exports = { CallInterface1: wasmInstance.exports.h, CallInterface2: wasmInstance.exports.i, CallInterface3: wasmInstance.exports.j, CallInterface4: wasmInstance.exports.k, CallInterface6: wasmInstance.exports.m, CallInterface7: wasmInstance.exports.n, CallInterface8: wasmInstance.exports.o, CallInterface9: wasmInstance.exports.p, CallInterface10: wasmInstance.exports.q, CallInterface11: wasmInstance.exports.r, CallInterface14: wasmInstance.exports.t, malloc: wasmInstance.exports.u, }; const parsedUrl = new URL(inputUrl); const query = Object.fromEntries(parsedUrl.searchParams); const o = query.userid || ''; const a_val = query.timestamp || ''; const s = query.ProgramID || ''; const u = query.Channel_ID || ''; const v = query.puData || ''; // Allocate memory const d = exports.malloc(o.length + 1); const h = exports.malloc(a_val.length + 1); const y = exports.malloc(s.length + 1); const m = exports.malloc(u.length + 1); const g = exports.malloc(v.length + 1); const b_val = exports.malloc(f.length + 1); const E = exports.malloc(128); const T = exports.malloc(128); // Write data to memory stringToUTF8(o, d); stringToUTF8(a_val, h); stringToUTF8(s, y); stringToUTF8(u, m); stringToUTF8(v, g); stringToUTF8(f, b_val); // Call interface functions const S = exports.CallInterface6(); // Create context exports.CallInterface1(S, y, s.length); exports.CallInterface10(S, h, a_val.length); exports.CallInterface9(S, d, o.length); exports.CallInterface3(S, 0, 0); exports.CallInterface11(S, 0, 0); exports.CallInterface8(S, g, v.length); exports.CallInterface2(S, m, u.length); exports.CallInterface14(S, b_val, f.length, T, 128); const w = UTF8ToString(T); const I = exports.malloc(w.length + 1); stringToUTF8(w, I); exports.CallInterface7(S, I, w.length); exports.CallInterface4(S, E, 128); return UTF8ToString(E); } const url = process.argv[2]; getDdCalcu(url).then(result => { console.log(result); }).catch(err => { console.error(err); process.exit(1); }); ================================================ FILE: src/javascript/taobao-sign.js ================================================ function sign(e) { function t(e, t) { return e << t | e >>> 32 - t } function o(e, t) { var o, n, r, i, a; return r = 2147483648 & e, i = 2147483648 & t, a = (1073741823 & e) + (1073741823 & t), (o = 1073741824 & e) & (n = 1073741824 & t) ? 2147483648 ^ a ^ r ^ i : o | n ? 1073741824 & a ? 3221225472 ^ a ^ r ^ i : 1073741824 ^ a ^ r ^ i : a ^ r ^ i } function n(e, n, r, i, a, s, u) { return o(t(e = o(e, o(o(function(e, t, o) { return e & t | ~e & o }(n, r, i), a), u)), s), n) } function r(e, n, r, i, a, s, u) { return o(t(e = o(e, o(o(function(e, t, o) { return e & o | t & ~o }(n, r, i), a), u)), s), n) } function i(e, n, r, i, a, s, u) { return o(t(e = o(e, o(o(function(e, t, o) { return e ^ t ^ o }(n, r, i), a), u)), s), n) } function a(e, n, r, i, a, s, u) { return o(t(e = o(e, o(o(function(e, t, o) { return t ^ (e | ~o) }(n, r, i), a), u)), s), n) } function s(e) { var t, o = "", n = ""; for (t = 0; 3 >= t; t++) o += (n = "0" + (e >>> 8 * t & 255).toString(16)).substr(n.length - 2, 2); return o } var u, l, d, c, p, f, h, m, y, g; for (g = function(e) { for (var t = e.length, o = t + 8, n = 16 * ((o - o % 64) / 64 + 1), r = Array(n - 1), i = 0, a = 0; t > a; ) i = a % 4 * 8, r[(a - a % 4) / 4] |= e.charCodeAt(a) << i, a++; return i = a % 4 * 8, r[(a - a % 4) / 4] |= 128 << i, r[n - 2] = t << 3, r[n - 1] = t >>> 29, r }(e = function(e) { var t = String.fromCharCode; e = e.replace(/\r\n/g, "\n"); for (var o, n = "", r = 0; r < e.length; r++) 128 > (o = e.charCodeAt(r)) ? n += t(o) : o > 127 && 2048 > o ? (n += t(o >> 6 | 192), n += t(63 & o | 128)) : (n += t(o >> 12 | 224), n += t(o >> 6 & 63 | 128), n += t(63 & o | 128)); return n }(e)), f = 1732584193, h = 4023233417, m = 2562383102, y = 271733878, u = 0; u < g.length; u += 16) l = f, d = h, c = m, p = y, h = a(h = a(h = a(h = a(h = i(h = i(h = i(h = i(h = r(h = r(h = r(h = r(h = n(h = n(h = n(h = n(h, m = n(m, y = n(y, f = n(f, h, m, y, g[u + 0], 7, 3614090360), h, m, g[u + 1], 12, 3905402710), f, h, g[u + 2], 17, 606105819), y, f, g[u + 3], 22, 3250441966), m = n(m, y = n(y, f = n(f, h, m, y, g[u + 4], 7, 4118548399), h, m, g[u + 5], 12, 1200080426), f, h, g[u + 6], 17, 2821735955), y, f, g[u + 7], 22, 4249261313), m = n(m, y = n(y, f = n(f, h, m, y, g[u + 8], 7, 1770035416), h, m, g[u + 9], 12, 2336552879), f, h, g[u + 10], 17, 4294925233), y, f, g[u + 11], 22, 2304563134), m = n(m, y = n(y, f = n(f, h, m, y, g[u + 12], 7, 1804603682), h, m, g[u + 13], 12, 4254626195), f, h, g[u + 14], 17, 2792965006), y, f, g[u + 15], 22, 1236535329), m = r(m, y = r(y, f = r(f, h, m, y, g[u + 1], 5, 4129170786), h, m, g[u + 6], 9, 3225465664), f, h, g[u + 11], 14, 643717713), y, f, g[u + 0], 20, 3921069994), m = r(m, y = r(y, f = r(f, h, m, y, g[u + 5], 5, 3593408605), h, m, g[u + 10], 9, 38016083), f, h, g[u + 15], 14, 3634488961), y, f, g[u + 4], 20, 3889429448), m = r(m, y = r(y, f = r(f, h, m, y, g[u + 9], 5, 568446438), h, m, g[u + 14], 9, 3275163606), f, h, g[u + 3], 14, 4107603335), y, f, g[u + 8], 20, 1163531501), m = r(m, y = r(y, f = r(f, h, m, y, g[u + 13], 5, 2850285829), h, m, g[u + 2], 9, 4243563512), f, h, g[u + 7], 14, 1735328473), y, f, g[u + 12], 20, 2368359562), m = i(m, y = i(y, f = i(f, h, m, y, g[u + 5], 4, 4294588738), h, m, g[u + 8], 11, 2272392833), f, h, g[u + 11], 16, 1839030562), y, f, g[u + 14], 23, 4259657740), m = i(m, y = i(y, f = i(f, h, m, y, g[u + 1], 4, 2763975236), h, m, g[u + 4], 11, 1272893353), f, h, g[u + 7], 16, 4139469664), y, f, g[u + 10], 23, 3200236656), m = i(m, y = i(y, f = i(f, h, m, y, g[u + 13], 4, 681279174), h, m, g[u + 0], 11, 3936430074), f, h, g[u + 3], 16, 3572445317), y, f, g[u + 6], 23, 76029189), m = i(m, y = i(y, f = i(f, h, m, y, g[u + 9], 4, 3654602809), h, m, g[u + 12], 11, 3873151461), f, h, g[u + 15], 16, 530742520), y, f, g[u + 2], 23, 3299628645), m = a(m, y = a(y, f = a(f, h, m, y, g[u + 0], 6, 4096336452), h, m, g[u + 7], 10, 1126891415), f, h, g[u + 14], 15, 2878612391), y, f, g[u + 5], 21, 4237533241), m = a(m, y = a(y, f = a(f, h, m, y, g[u + 12], 6, 1700485571), h, m, g[u + 3], 10, 2399980690), f, h, g[u + 10], 15, 4293915773), y, f, g[u + 1], 21, 2240044497), m = a(m, y = a(y, f = a(f, h, m, y, g[u + 8], 6, 1873313359), h, m, g[u + 15], 10, 4264355552), f, h, g[u + 6], 15, 2734768916), y, f, g[u + 13], 21, 1309151649), m = a(m, y = a(y, f = a(f, h, m, y, g[u + 4], 6, 4149444226), h, m, g[u + 11], 10, 3174756917), f, h, g[u + 2], 15, 718787259), y, f, g[u + 9], 21, 3951481745), f = o(f, l), h = o(h, d), m = o(m, c), y = o(y, p); return (s(f) + s(h) + s(m) + s(y)).toLowerCase() } // 正确sign值:05748e8359cd3e6deaab02d15caafc11 // var sg =sign('5655b7041ca049730330701082886efd&1719411639403&12574478&{"componentKey":"wp_pc_shop_basic_info","params":"{\\"memberId\\":\\"b2b-22133374292418351a\\"}"}') // console.log(sg) ================================================ FILE: src/javascript/x-bogus.js ================================================ var window = null; function _0x5cd844(e) { var b = { exports: {} }; return e(b, b.exports), b.exports } jsvmp = function(e, b, a) { function f(e, b, a) { return (f = function() { if ("undefined" == typeof Reflect || !Reflect.construct || Reflect.construct.sham) return !1; if ("function" == typeof Proxy) return !0; try { return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0 } catch (e) { return !1 } }() ? Reflect.construct : function(e, b, a) { var f = [null]; f.push.apply(f, b); var c = new(Function.bind.apply(e, f)); return a && function(e, b) { (Object.setPrototypeOf || function(e, b) { return e.__proto__ = b, e })(e, b) }(c, a.prototype), c }).apply(null, arguments) } function c(e) { return function(e) { if (Array.isArray(e)) { for (var b = 0, a = new Array(e.length); b < e.length; b++) a[b] = e[b]; return a } }(e) || function(e) { if (Symbol.iterator in Object(e) || "[object Arguments]" === Object.prototype.toString.call(e)) return Array.from(e) }(e) || function() { throw new TypeError("Invalid attempt to spread non-iterable instance") }() } for (var r = [], t = 0, d = [], i = 0, n = function(e, b) { var a = e[b++], f = e[b], c = parseInt("" + a + f, 16); if (c >> 7 == 0) return [1, c]; if (c >> 6 == 2) { var r = parseInt("" + e[++b] + e[++b], 16); return c &= 63, [2, r = (c <<= 8) + r] } if (c >> 6 == 3) { var t = parseInt("" + e[++b] + e[++b], 16), d = parseInt("" + e[++b] + e[++b], 16); return c &= 63, [3, d = (c <<= 16) + (t <<= 8) + d] } }, s = function(e, b) { var a = parseInt("" + e[b] + e[b + 1], 16); return a > 127 ? -256 + a : a }, o = function(e, b) { var a = parseInt("" + e[b] + e[b + 1] + e[b + 2] + e[b + 3], 16); return a > 32767 ? -65536 + a : a }, l = function(e, b) { var a = parseInt("" + e[b] + e[b + 1] + e[b + 2] + e[b + 3] + e[b + 4] + e[b + 5] + e[b + 6] + e[b + 7], 16); return a > 2147483647 ? 0 + a : a }, _ = function(e, b) { return parseInt("" + e[b] + e[b + 1], 16) }, x = function(e, b) { return parseInt("" + e[b] + e[b + 1] + e[b + 2] + e[b + 3], 16) }, u = u || this || window, h = (e.length, 0), p = "", y = h; y < h + 16; y++) { var v = "" + e[y++] + e[y]; v = parseInt(v, 16), p += String.fromCharCode(v) } if ("HNOJ@?RC" != p) throw new Error("error magic number " + p); parseInt("" + e[h += 16] + e[h + 1], 16), h += 8, t = 0; for (var g = 0; g < 4; g++) { var w = h + 2 * g, A = parseInt("" + e[w++] + e[w], 16); t += (3 & A) << 2 * g } h += 16; var C = parseInt("" + e[h += 8] + e[h + 1] + e[h + 2] + e[h + 3] + e[h + 4] + e[h + 5] + e[h + 6] + e[h + 7], 16), m = C, S = h += 8, z = x(e, h += C); z[1], h += 4, r = { p: [], q: [] }; for (var B = 0; B < z; B++) { for (var R = n(e, h), q = h += 2 * R[0], I = r.p.length, k = 0; k < R[1]; k++) { var j = n(e, q); r.p.push(j[1]), q += 2 * j[0] } h = q, r.q.push([I, r.p.length]) } var O = { 5: 1, 6: 1, 70: 1, 22: 1, 23: 1, 37: 1, 73: 1 }, U = { 72: 1 }, D = { 74: 1 }, N = { 11: 1, 12: 1, 24: 1, 26: 1, 27: 1, 31: 1 }, J = { 10: 1 }, L = { 2: 1, 29: 1, 30: 1, 20: 1 }, T = [], E = []; function M(e, b, a) { for (var f = b; f < b + a;) { var c = _(e, f); T[f] = c, f += 2, U[c] ? (E[f] = s(e, f), f += 2) : O[c] ? (E[f] = o(e, f), f += 4) : D[c] ? (E[f] = l(e, f), f += 8) : N[c] ? (E[f] = _(e, f), f += 2) : J[c] ? (E[f] = x(e, f), f += 4) : L[c] && (E[f] = x(e, f), f += 4) } } return F(e, S, m / 2, [], b, a); function P(e, b, a, n, h, p, y, v) { null == p && (p = this); var g, w, A, C, m = [], S = 0; y && (w = y); var z, B, R = b, q = R + 2 * a; if (!v) for (; R < q;) { var I = parseInt("" + e[R] + e[R + 1], 16); R += 2; var j = 3 & (z = 13 * I % 241); if (z >>= 2, j < 1) if (j = 3 & z, z >>= 2, j < 1) { if ((j = z) < 1) return [1, m[S--]]; j < 5 ? (w = m[S--], m[S] = m[S] * w) : j < 7 ? (w = m[S--], m[S] = m[S] != w) : j < 14 ? (A = m[S--], C = m[S--], (j = m[S--]).x === P ? j.y >= 1 ? m[++S] = F(e, j.c, j.l, A, j.z, C, null, 1) : (m[++S] = F(e, j.c, j.l, A, j.z, C, null, 0), j.y++) : m[++S] = j.apply(C, A)) : j < 16 && (B = o(e, R), (g = function b() { var a = arguments; return b.y > 0 || b.y++, F(e, b.c, b.l, a, b.z, this, null, 0) }).c = R + 4, g.l = B - 2, g.x = P, g.y = 0, g.z = h, m[S] = g, R += 2 * B - 2) } else if (j < 2)(j = z) > 8 ? (w = m[S--], m[S] = typeof w) : j > 4 ? m[S -= 1] = m[S][m[S + 1]] : j > 2 && (A = m[S--], (j = m[S]).x === P ? j.y >= 1 ? m[S] = F(e, j.c, j.l, [A], j.z, C, null, 1) : (m[S] = F(e, j.c, j.l, [A], j.z, C, null, 0), j.y++) : m[S] = j(A)); else if (j < 3) { if ((j = z) < 9) { for (w = m[S--], B = x(e, R), j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); R += 4, m[S--][j] = w } else if (j < 13) throw m[S--] } else(j = z) < 1 ? m[++S] = null : j < 3 ? (w = m[S--], m[S] = m[S] >= w) : j < 12 && (m[++S] = void 0); else if (j < 2) if (j = 3 & z, z >>= 2, j < 1) if ((j = z) < 5) { B = o(e, R); try { if (d[i][2] = 1, 1 == (w = P(e, R + 4, B - 3, [], h, p, null, 0))[0]) return w } catch (b) { if (d[i] && d[i][1] && 1 == (w = P(e, d[i][1][0], d[i][1][1], [], h, p, b, 0))[0]) return w } finally { if (d[i] && d[i][0] && 1 == (w = P(e, d[i][0][0], d[i][0][1], [], h, p, null, 0))[0]) return w; d[i] = 0, i-- } R += 2 * B - 2 } else j < 7 ? (B = _(e, R), R += 2, m[S -= B] = 0 === B ? new m[S] : f(m[S], c(m.slice(S + 1, S + B + 1)))) : j < 9 && (w = m[S--], m[S] = m[S] & w); else if (j < 2) if ((j = z) > 12) m[++S] = s(e, R), R += 2; else if (j > 10) w = m[S--], m[S] = m[S] << w; else if (j > 8) { for (B = x(e, R), j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); R += 4, m[S] = m[S][j] } else j > 6 && (A = m[S--], w = delete m[S--][A]); else if (j < 3)(j = z) < 2 ? m[++S] = w : j < 11 ? (w = m[S -= 2][m[S + 1]] = m[S + 2], S--) : j < 13 && (w = m[S], m[++S] = w); else if ((j = z) > 12) m[++S] = p; else if (j > 5) w = m[S--], m[S] = m[S] !== w; else if (j > 3) w = m[S--], m[S] = m[S] / w; else if (j > 1) { if ((B = o(e, R)) < 0) { v = 1, M(e, b, 2 * a), R += 2 * B - 2; break } R += 2 * B - 2 } else j > -1 && (m[S] = !m[S]); else if (j < 3) if (j = 3 & z, z >>= 2, j < 1)(j = z) > 13 ? (m[++S] = o(e, R), R += 4) : j > 11 ? (w = m[S--], m[S] = m[S] >> w) : j > 9 ? (B = _(e, R), R += 2, w = m[S--], h[B] = w) : j > 7 ? (B = x(e, R), R += 4, A = S + 1, m[S -= B - 1] = B ? m.slice(S, A) : []) : j > 0 && (w = m[S--], m[S] = m[S] > w); else if (j < 2)(j = z) > 12 ? (w = m[S - 1], A = m[S], m[++S] = w, m[++S] = A) : j > 3 ? (w = m[S--], m[S] = m[S] == w) : j > 1 ? (w = m[S--], m[S] = m[S] + w) : j > -1 && (m[++S] = u); else if (j < 3) { if ((j = z) > 13) m[++S] = !1; else if (j > 6) w = m[S--], m[S] = m[S] instanceof w; else if (j > 4) w = m[S--], m[S] = m[S] % w; else if (j > 2) if (m[S--]) R += 4; else { if ((B = o(e, R)) < 0) { v = 1, M(e, b, 2 * a), R += 2 * B - 2; break } R += 2 * B - 2 } else if (j > 0) { for (B = x(e, R), w = "", k = r.q[B][0]; k < r.q[B][1]; k++) w += String.fromCharCode(t ^ r.p[k]); m[++S] = w, R += 4 } } else(j = z) > 7 ? (w = m[S--], m[S] = m[S] | w) : j > 5 ? (B = _(e, R), R += 2, m[++S] = h["$" + B]) : j > 3 && (B = o(e, R), d[i][0] && !d[i][2] ? d[i][1] = [R + 4, B - 3] : d[i++] = [0, [R + 4, B - 3], 0], R += 2 * B - 2); else if (j = 3 & z, z >>= 2, j > 2)(j = z) > 13 ? (m[++S] = l(e, R), R += 8) : j > 11 ? (w = m[S--], m[S] = m[S] >>> w) : j > 9 ? m[++S] = !0 : j > 7 ? (B = _(e, R), R += 2, m[S] = m[S][B]) : j > 0 && (w = m[S--], m[S] = m[S] < w); else if (j > 1)(j = z) > 10 ? (B = o(e, R), d[++i] = [ [R + 4, B - 3], 0, 0 ], R += 2 * B - 2) : j > 8 ? (w = m[S--], m[S] = m[S] ^ w) : j > 6 && (w = m[S--]); else if (j > 0) { if ((j = z) > 7) w = m[S--], m[S] = m[S] in w; else if (j > 5) m[S] = ++m[S]; else if (j > 3) B = _(e, R), R += 2, w = h[B], m[++S] = w; else if (j > 1) { var O = 0, U = m[S].length, D = m[S]; m[++S] = function() { var e = O < U; if (e) { var b = D[O++]; m[++S] = b } m[++S] = e } } } else if ((j = z) > 13) w = m[S], m[S] = m[S - 1], m[S - 1] = w; else if (j > 4) w = m[S--], m[S] = m[S] === w; else if (j > 2) w = m[S--], m[S] = m[S] - w; else if (j > 0) { for (B = x(e, R), j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); j = +j, R += 4, m[++S] = j } } if (v) for (; R < q;) if (I = T[R], R += 2, j = 3 & (z = 13 * I % 241), z >>= 2, j > 2) if (j = 3 & z, z >>= 2, j > 2)(j = z) < 2 ? (w = m[S--], m[S] = m[S] < w) : j < 9 ? (B = E[R], R += 2, m[S] = m[S][B]) : j < 11 ? m[++S] = !0 : j < 13 ? (w = m[S--], m[S] = m[S] >>> w) : j < 15 && (m[++S] = E[R], R += 8); else if (j > 1)(j = z) < 6 || (j < 8 ? w = m[S--] : j < 10 ? (w = m[S--], m[S] = m[S] ^ w) : j < 12 && (B = E[R], d[++i] = [ [R + 4, B - 3], 0, 0 ], R += 2 * B - 2)); else if (j > 0)(j = z) > 7 ? (w = m[S--], m[S] = m[S] in w) : j > 5 ? m[S] = ++m[S] : j > 3 ? (B = E[R], R += 2, w = h[B], m[++S] = w) : j > 1 && (O = 0, U = m[S].length, D = m[S], m[++S] = function() { var e = O < U; if (e) { var b = D[O++]; m[++S] = b } m[++S] = e }); else if ((j = z) < 2) { for (B = E[R], j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); j = +j, R += 4, m[++S] = j } else j < 4 ? (w = m[S--], m[S] = m[S] - w) : j < 6 ? (w = m[S--], m[S] = m[S] === w) : j < 15 && (w = m[S], m[S] = m[S - 1], m[S - 1] = w); else if (j > 1) if (j = 3 & z, z >>= 2, j < 1)(j = z) > 13 ? (m[++S] = E[R], R += 4) : j > 11 ? (w = m[S--], m[S] = m[S] >> w) : j > 9 ? (B = E[R], R += 2, w = m[S--], h[B] = w) : j > 7 ? (B = E[R], R += 4, A = S + 1, m[S -= B - 1] = B ? m.slice(S, A) : []) : j > 0 && (w = m[S--], m[S] = m[S] > w); else if (j < 2)(j = z) < 1 ? m[++S] = u : j < 3 ? (w = m[S--], m[S] = m[S] + w) : j < 5 ? (w = m[S--], m[S] = m[S] == w) : j < 14 && (w = m[S - 1], A = m[S], m[++S] = w, m[++S] = A); else if (j < 3) { if ((j = z) > 13) m[++S] = !1; else if (j > 6) w = m[S--], m[S] = m[S] instanceof w; else if (j > 4) w = m[S--], m[S] = m[S] % w; else if (j > 2) m[S--] ? R += 4 : R += 2 * (B = E[R]) - 2; else if (j > 0) { for (B = E[R], w = "", k = r.q[B][0]; k < r.q[B][1]; k++) w += String.fromCharCode(t ^ r.p[k]); m[++S] = w, R += 4 } } else(j = z) > 7 ? (w = m[S--], m[S] = m[S] | w) : j > 5 ? (B = E[R], R += 2, m[++S] = h["$" + B]) : j > 3 && (B = E[R], d[i][0] && !d[i][2] ? d[i][1] = [R + 4, B - 3] : d[i++] = [0, [R + 4, B - 3], 0], R += 2 * B - 2); else if (j > 0) if (j = 3 & z, z >>= 2, j < 1) { if ((j = z) > 9); else if (j > 7) w = m[S--], m[S] = m[S] & w; else if (j > 5) B = E[R], R += 2, m[S -= B] = 0 === B ? new m[S] : f(m[S], c(m.slice(S + 1, S + B + 1))); else if (j > 3) { B = E[R]; try { if (d[i][2] = 1, 1 == (w = P(e, R + 4, B - 3, [], h, p, null, 0))[0]) return w } catch (b) { if (d[i] && d[i][1] && 1 == (w = P(e, d[i][1][0], d[i][1][1], [], h, p, b, 0))[0]) return w } finally { if (d[i] && d[i][0] && 1 == (w = P(e, d[i][0][0], d[i][0][1], [], h, p, null, 0))[0]) return w; d[i] = 0, i-- } R += 2 * B - 2 } } else if (j < 2) if ((j = z) < 8) A = m[S--], w = delete m[S--][A]; else if (j < 10) { for (B = E[R], j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); R += 4, m[S] = m[S][j] } else j < 12 ? (w = m[S--], m[S] = m[S] << w) : j < 14 && (m[++S] = E[R], R += 2); else j < 3 ? (j = z) < 2 ? m[++S] = w : j < 11 ? (w = m[S -= 2][m[S + 1]] = m[S + 2], S--) : j < 13 && (w = m[S], m[++S] = w) : (j = z) > 12 ? m[++S] = p : j > 5 ? (w = m[S--], m[S] = m[S] !== w) : j > 3 ? (w = m[S--], m[S] = m[S] / w) : j > 1 ? R += 2 * (B = E[R]) - 2 : j > -1 && (m[S] = !m[S]); else if (j = 3 & z, z >>= 2, j < 1) { if ((j = z) < 1) return [1, m[S--]]; j < 5 ? (w = m[S--], m[S] = m[S] * w) : j < 7 ? (w = m[S--], m[S] = m[S] != w) : j < 14 ? (A = m[S--], C = m[S--], (j = m[S--]).x === P ? j.y >= 1 ? m[++S] = F(e, j.c, j.l, A, j.z, C, null, 1) : (m[++S] = F(e, j.c, j.l, A, j.z, C, null, 0), j.y++) : m[++S] = j.apply(C, A)) : j < 16 && (B = E[R], (g = function b() { var a = arguments; return b.y > 0 || b.y++, F(e, b.c, b.l, a, b.z, this, null, 0) }).c = R + 4, g.l = B - 2, g.x = P, g.y = 0, g.z = h, m[S] = g, R += 2 * B - 2) } else if (j < 2)(j = z) > 8 ? (w = m[S--], m[S] = typeof w) : j > 4 ? m[S -= 1] = m[S][m[S + 1]] : j > 2 && (A = m[S--], (j = m[S]).x === P ? j.y >= 1 ? m[S] = F(e, j.c, j.l, [A], j.z, C, null, 1) : (m[S] = F(e, j.c, j.l, [A], j.z, C, null, 0), j.y++) : m[S] = j(A)); else if (j < 3) { if ((j = z) < 9) { for (w = m[S--], B = E[R], j = "", k = r.q[B][0]; k < r.q[B][1]; k++) j += String.fromCharCode(t ^ r.p[k]); R += 4, m[S--][j] = w } else if (j < 13) throw m[S--] } else(j = z) < 1 ? m[++S] = null : j < 3 ? (w = m[S--], m[S] = m[S] >= w) : j < 12 && (m[++S] = void 0); return [0, null] } function F(e, b, a, f, c, r, t, d) { null == r && (r = this), c && !c.d && (c.d = 0, c.$0 = c, c[1] = {}); var i, n, s = {}, o = s.d = c ? c.d + 1 : 0; for (s["$" + o] = s, n = 0; n < o; n++) s[i = "$" + n] = c[i]; for (n = 0, o = s.length = f.length; n < o; n++) s[n] = f[n]; return d && !T[b] && M(e, b, 2 * a), T[b] ? P(e, b, a, 0, s, r, null, 1)[1] : P(e, b, a, 0, s, r, null, 0)[1] } }; var _0x397dc7 = "undefined" != typeof globalThis ? globalThis : void 0 !== window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : {}, _0x124d1a = _0x5cd844(function(_0x770f81) { ! function() { var _0x250d36 = "input is invalid type", _0x4cfaee = !1, _0x1702f9 = {}, _0x5ccbb3 = !_0x4cfaee && "object" == typeof self, _0x54d876 = !_0x1702f9.JS_MD5_NO_NODE_JS && "object" == typeof process && process.versions && process.versions.node, _0x185caf; _0x54d876 ? _0x1702f9 = _0x397dc7 : _0x5ccbb3 && (_0x1702f9 = self); var _0x17dcbf = !_0x1702f9.JS_MD5_NO_COMMON_JS && _0x770f81.exports, _0x554fed = !1, _0x2de28f = !_0x1702f9.JS_MD5_NO_ARRAY_BUFFER && "undefined" != typeof ArrayBuffer, _0x3a9a1b = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], _0x465562 = [128, 32768, 8388608, -2147483648], _0x20b37e = [0, 8, 16, 24], _0x323604 = ["hex", "array", "digest", "buffer", "arrayBuffer", "base64"], _0x2c185e = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"], _0x4b59e0 = []; if (_0x2de28f) { var _0x395837 = new ArrayBuffer(68); _0x185caf = new Uint8Array(_0x395837), _0x4b59e0 = new Uint32Array(_0x395837) }!_0x1702f9.JS_MD5_NO_NODE_JS && Array.isArray || (Array.isArray = function(e) { return "[object Array]" === Object.prototype.toString.call(e) }), _0x2de28f && (_0x1702f9.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) && (ArrayBuffer.isView = function(e) { return "object" == typeof e && e.buffer && e.buffer.constructor === ArrayBuffer }); var _0x4e9930 = function(e) { return function(b) { return new _0x5887c8(!0).update(b)[e]() } }, _0x38ba77 = function() { var e = _0x4e9930("hex"); _0x54d876 && (e = _0x474989(e)), e.create = function() { return new _0x5887c8 }, e.update = function(b) { return e.create().update(b) }; for (var b = 0; b < _0x323604.length; ++b) { var a = _0x323604[b]; e[a] = _0x4e9930(a) } return e }, _0x474989 = function(_0x57eeaa) { var _0x114910, _0x226465 = eval("require('crypto');"), _0x1f6ae0 = eval("require('buffer')['Buffer'];"); return function(e) { if ("string" == typeof e) return _0x226465.createHash("md5").update(e, "utf8").digest("hex"); if (null == e) throw _0x250d36; return e.constructor === ArrayBuffer && (e = new Uint8Array(e)), Array.isArray(e) || ArrayBuffer.isView(e) || e.constructor === _0x1f6ae0 ? _0x226465.createHash("md5").update(new _0x1f6ae0.from(e)).digest("hex") : _0x57eeaa(e) } }; function _0x5887c8(e) { if (e) _0x4b59e0[0] = _0x4b59e0[16] = _0x4b59e0[1] = _0x4b59e0[2] = _0x4b59e0[3] = _0x4b59e0[4] = _0x4b59e0[5] = _0x4b59e0[6] = _0x4b59e0[7] = _0x4b59e0[8] = _0x4b59e0[9] = _0x4b59e0[10] = _0x4b59e0[11] = _0x4b59e0[12] = _0x4b59e0[13] = _0x4b59e0[14] = _0x4b59e0[15] = 0, this.blocks = _0x4b59e0, this.buffer8 = _0x185caf; else if (_0x2de28f) { var b = new ArrayBuffer(68); this.buffer8 = new Uint8Array(b), this.blocks = new Uint32Array(b) } else this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0, this.finalized = this.hashed = !1, this.first = !0 } _0x5887c8.prototype.update = function(e) { if (!this.finalized) { var b, a = typeof e; if ("string" !== a) { if ("object" !== a || null === e) throw _0x250d36; if (_0x2de28f && e.constructor === ArrayBuffer) e = new Uint8Array(e); else if (!(Array.isArray(e) || _0x2de28f && ArrayBuffer.isView(e))) throw _0x250d36; b = !0 } for (var f, c, r = 0, t = e.length, d = this.blocks, i = this.buffer8; r < t;) { if (this.hashed && (this.hashed = !1, d[0] = d[16], d[16] = d[1] = d[2] = d[3] = d[4] = d[5] = d[6] = d[7] = d[8] = d[9] = d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = 0), b) if (_0x2de28f) for (c = this.start; r < t && c < 64; ++r) i[c++] = e[r]; else for (c = this.start; r < t && c < 64; ++r) d[c >> 2] |= e[r] << _0x20b37e[3 & c++]; else if (_0x2de28f) for (c = this.start; r < t && c < 64; ++r)(f = e.charCodeAt(r)) < 128 ? i[c++] = f : f < 2048 ? (i[c++] = 192 | f >> 6, i[c++] = 128 | 63 & f) : f < 55296 || f >= 57344 ? (i[c++] = 224 | f >> 12, i[c++] = 128 | f >> 6 & 63, i[c++] = 128 | 63 & f) : (f = 65536 + ((1023 & f) << 10 | 1023 & e.charCodeAt(++r)), i[c++] = 240 | f >> 18, i[c++] = 128 | f >> 12 & 63, i[c++] = 128 | f >> 6 & 63, i[c++] = 128 | 63 & f); else for (c = this.start; r < t && c < 64; ++r)(f = e.charCodeAt(r)) < 128 ? d[c >> 2] |= f << _0x20b37e[3 & c++] : f < 2048 ? (d[c >> 2] |= (192 | f >> 6) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | 63 & f) << _0x20b37e[3 & c++]) : f < 55296 || f >= 57344 ? (d[c >> 2] |= (224 | f >> 12) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | f >> 6 & 63) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | 63 & f) << _0x20b37e[3 & c++]) : (f = 65536 + ((1023 & f) << 10 | 1023 & e.charCodeAt(++r)), d[c >> 2] |= (240 | f >> 18) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | f >> 12 & 63) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | f >> 6 & 63) << _0x20b37e[3 & c++], d[c >> 2] |= (128 | 63 & f) << _0x20b37e[3 & c++]); this.lastByteIndex = c, this.bytes += c - this.start, c >= 64 ? (this.start = c - 64, this.hash(), this.hashed = !0) : this.start = c } return this.bytes > 4294967295 && (this.hBytes += this.bytes / 4294967296 << 0, this.bytes = this.bytes % 4294967296), this } }, _0x5887c8.prototype.finalize = function() { if (!this.finalized) { this.finalized = !0; var e = this.blocks, b = this.lastByteIndex; e[b >> 2] |= _0x465562[3 & b], b >= 56 && (this.hashed || this.hash(), e[0] = e[16], e[16] = e[1] = e[2] = e[3] = e[4] = e[5] = e[6] = e[7] = e[8] = e[9] = e[10] = e[11] = e[12] = e[13] = e[14] = e[15] = 0), e[14] = this.bytes << 3, e[15] = this.hBytes << 3 | this.bytes >>> 29, this.hash() } }, _0x5887c8.prototype.hash = function() { var e, b, a, f, c, r, t = this.blocks; this.first ? b = ((b = ((e = ((e = t[0] - 680876937) << 7 | e >>> 25) - 271733879 << 0) ^ (a = ((a = (-271733879 ^ (f = ((f = (-1732584194 ^ 2004318071 & e) + t[1] - 117830708) << 12 | f >>> 20) + e << 0) & (-271733879 ^ e)) + t[2] - 1126478375) << 17 | a >>> 15) + f << 0) & (f ^ e)) + t[3] - 1316259209) << 22 | b >>> 10) + a << 0 : (e = this.h0, b = this.h1, a = this.h2, b = ((b += ((e = ((e += ((f = this.h3) ^ b & (a ^ f)) + t[0] - 680876936) << 7 | e >>> 25) + b << 0) ^ (a = ((a += (b ^ (f = ((f += (a ^ e & (b ^ a)) + t[1] - 389564586) << 12 | f >>> 20) + e << 0) & (e ^ b)) + t[2] + 606105819) << 17 | a >>> 15) + f << 0) & (f ^ e)) + t[3] - 1044525330) << 22 | b >>> 10) + a << 0), b = ((b += ((e = ((e += (f ^ b & (a ^ f)) + t[4] - 176418897) << 7 | e >>> 25) + b << 0) ^ (a = ((a += (b ^ (f = ((f += (a ^ e & (b ^ a)) + t[5] + 1200080426) << 12 | f >>> 20) + e << 0) & (e ^ b)) + t[6] - 1473231341) << 17 | a >>> 15) + f << 0) & (f ^ e)) + t[7] - 45705983) << 22 | b >>> 10) + a << 0, b = ((b += ((e = ((e += (f ^ b & (a ^ f)) + t[8] + 1770035416) << 7 | e >>> 25) + b << 0) ^ (a = ((a += (b ^ (f = ((f += (a ^ e & (b ^ a)) + t[9] - 1958414417) << 12 | f >>> 20) + e << 0) & (e ^ b)) + t[10] - 42063) << 17 | a >>> 15) + f << 0) & (f ^ e)) + t[11] - 1990404162) << 22 | b >>> 10) + a << 0, b = ((b += ((e = ((e += (f ^ b & (a ^ f)) + t[12] + 1804603682) << 7 | e >>> 25) + b << 0) ^ (a = ((a += (b ^ (f = ((f += (a ^ e & (b ^ a)) + t[13] - 40341101) << 12 | f >>> 20) + e << 0) & (e ^ b)) + t[14] - 1502002290) << 17 | a >>> 15) + f << 0) & (f ^ e)) + t[15] + 1236535329) << 22 | b >>> 10) + a << 0, b = ((b += ((f = ((f += (b ^ a & ((e = ((e += (a ^ f & (b ^ a)) + t[1] - 165796510) << 5 | e >>> 27) + b << 0) ^ b)) + t[6] - 1069501632) << 9 | f >>> 23) + e << 0) ^ e & ((a = ((a += (e ^ b & (f ^ e)) + t[11] + 643717713) << 14 | a >>> 18) + f << 0) ^ f)) + t[0] - 373897302) << 20 | b >>> 12) + a << 0, b = ((b += ((f = ((f += (b ^ a & ((e = ((e += (a ^ f & (b ^ a)) + t[5] - 701558691) << 5 | e >>> 27) + b << 0) ^ b)) + t[10] + 38016083) << 9 | f >>> 23) + e << 0) ^ e & ((a = ((a += (e ^ b & (f ^ e)) + t[15] - 660478335) << 14 | a >>> 18) + f << 0) ^ f)) + t[4] - 405537848) << 20 | b >>> 12) + a << 0, b = ((b += ((f = ((f += (b ^ a & ((e = ((e += (a ^ f & (b ^ a)) + t[9] + 568446438) << 5 | e >>> 27) + b << 0) ^ b)) + t[14] - 1019803690) << 9 | f >>> 23) + e << 0) ^ e & ((a = ((a += (e ^ b & (f ^ e)) + t[3] - 187363961) << 14 | a >>> 18) + f << 0) ^ f)) + t[8] + 1163531501) << 20 | b >>> 12) + a << 0, b = ((b += ((f = ((f += (b ^ a & ((e = ((e += (a ^ f & (b ^ a)) + t[13] - 1444681467) << 5 | e >>> 27) + b << 0) ^ b)) + t[2] - 51403784) << 9 | f >>> 23) + e << 0) ^ e & ((a = ((a += (e ^ b & (f ^ e)) + t[7] + 1735328473) << 14 | a >>> 18) + f << 0) ^ f)) + t[12] - 1926607734) << 20 | b >>> 12) + a << 0, b = ((b += ((r = (f = ((f += ((c = b ^ a) ^ (e = ((e += (c ^ f) + t[5] - 378558) << 4 | e >>> 28) + b << 0)) + t[8] - 2022574463) << 11 | f >>> 21) + e << 0) ^ e) ^ (a = ((a += (r ^ b) + t[11] + 1839030562) << 16 | a >>> 16) + f << 0)) + t[14] - 35309556) << 23 | b >>> 9) + a << 0, b = ((b += ((r = (f = ((f += ((c = b ^ a) ^ (e = ((e += (c ^ f) + t[1] - 1530992060) << 4 | e >>> 28) + b << 0)) + t[4] + 1272893353) << 11 | f >>> 21) + e << 0) ^ e) ^ (a = ((a += (r ^ b) + t[7] - 155497632) << 16 | a >>> 16) + f << 0)) + t[10] - 1094730640) << 23 | b >>> 9) + a << 0, b = ((b += ((r = (f = ((f += ((c = b ^ a) ^ (e = ((e += (c ^ f) + t[13] + 681279174) << 4 | e >>> 28) + b << 0)) + t[0] - 358537222) << 11 | f >>> 21) + e << 0) ^ e) ^ (a = ((a += (r ^ b) + t[3] - 722521979) << 16 | a >>> 16) + f << 0)) + t[6] + 76029189) << 23 | b >>> 9) + a << 0, b = ((b += ((r = (f = ((f += ((c = b ^ a) ^ (e = ((e += (c ^ f) + t[9] - 640364487) << 4 | e >>> 28) + b << 0)) + t[12] - 421815835) << 11 | f >>> 21) + e << 0) ^ e) ^ (a = ((a += (r ^ b) + t[15] + 530742520) << 16 | a >>> 16) + f << 0)) + t[2] - 995338651) << 23 | b >>> 9) + a << 0, b = ((b += ((f = ((f += (b ^ ((e = ((e += (a ^ (b | ~f)) + t[0] - 198630844) << 6 | e >>> 26) + b << 0) | ~a)) + t[7] + 1126891415) << 10 | f >>> 22) + e << 0) ^ ((a = ((a += (e ^ (f | ~b)) + t[14] - 1416354905) << 15 | a >>> 17) + f << 0) | ~e)) + t[5] - 57434055) << 21 | b >>> 11) + a << 0, b = ((b += ((f = ((f += (b ^ ((e = ((e += (a ^ (b | ~f)) + t[12] + 1700485571) << 6 | e >>> 26) + b << 0) | ~a)) + t[3] - 1894986606) << 10 | f >>> 22) + e << 0) ^ ((a = ((a += (e ^ (f | ~b)) + t[10] - 1051523) << 15 | a >>> 17) + f << 0) | ~e)) + t[1] - 2054922799) << 21 | b >>> 11) + a << 0, b = ((b += ((f = ((f += (b ^ ((e = ((e += (a ^ (b | ~f)) + t[8] + 1873313359) << 6 | e >>> 26) + b << 0) | ~a)) + t[15] - 30611744) << 10 | f >>> 22) + e << 0) ^ ((a = ((a += (e ^ (f | ~b)) + t[6] - 1560198380) << 15 | a >>> 17) + f << 0) | ~e)) + t[13] + 1309151649) << 21 | b >>> 11) + a << 0, b = ((b += ((f = ((f += (b ^ ((e = ((e += (a ^ (b | ~f)) + t[4] - 145523070) << 6 | e >>> 26) + b << 0) | ~a)) + t[11] - 1120210379) << 10 | f >>> 22) + e << 0) ^ ((a = ((a += (e ^ (f | ~b)) + t[2] + 718787259) << 15 | a >>> 17) + f << 0) | ~e)) + t[9] - 343485551) << 21 | b >>> 11) + a << 0, this.first ? (this.h0 = e + 1732584193 << 0, this.h1 = b - 271733879 << 0, this.h2 = a - 1732584194 << 0, this.h3 = f + 271733878 << 0, this.first = !1) : (this.h0 = this.h0 + e << 0, this.h1 = this.h1 + b << 0, this.h2 = this.h2 + a << 0, this.h3 = this.h3 + f << 0) }, _0x5887c8.prototype.hex = function() { this.finalize(); var e = this.h0, b = this.h1, a = this.h2, f = this.h3; return _0x3a9a1b[e >> 4 & 15] + _0x3a9a1b[15 & e] + _0x3a9a1b[e >> 12 & 15] + _0x3a9a1b[e >> 8 & 15] + _0x3a9a1b[e >> 20 & 15] + _0x3a9a1b[e >> 16 & 15] + _0x3a9a1b[e >> 28 & 15] + _0x3a9a1b[e >> 24 & 15] + _0x3a9a1b[b >> 4 & 15] + _0x3a9a1b[15 & b] + _0x3a9a1b[b >> 12 & 15] + _0x3a9a1b[b >> 8 & 15] + _0x3a9a1b[b >> 20 & 15] + _0x3a9a1b[b >> 16 & 15] + _0x3a9a1b[b >> 28 & 15] + _0x3a9a1b[b >> 24 & 15] + _0x3a9a1b[a >> 4 & 15] + _0x3a9a1b[15 & a] + _0x3a9a1b[a >> 12 & 15] + _0x3a9a1b[a >> 8 & 15] + _0x3a9a1b[a >> 20 & 15] + _0x3a9a1b[a >> 16 & 15] + _0x3a9a1b[a >> 28 & 15] + _0x3a9a1b[a >> 24 & 15] + _0x3a9a1b[f >> 4 & 15] + _0x3a9a1b[15 & f] + _0x3a9a1b[f >> 12 & 15] + _0x3a9a1b[f >> 8 & 15] + _0x3a9a1b[f >> 20 & 15] + _0x3a9a1b[f >> 16 & 15] + _0x3a9a1b[f >> 28 & 15] + _0x3a9a1b[f >> 24 & 15] }, _0x5887c8.prototype.toString = _0x5887c8.prototype.hex, _0x5887c8.prototype.digest = function() { this.finalize(); var e = this.h0, b = this.h1, a = this.h2, f = this.h3; return [255 & e, e >> 8 & 255, e >> 16 & 255, e >> 24 & 255, 255 & b, b >> 8 & 255, b >> 16 & 255, b >> 24 & 255, 255 & a, a >> 8 & 255, a >> 16 & 255, a >> 24 & 255, 255 & f, f >> 8 & 255, f >> 16 & 255, f >> 24 & 255] }, _0x5887c8.prototype.array = _0x5887c8.prototype.digest, _0x5887c8.prototype.arrayBuffer = function() { this.finalize(); var e = new ArrayBuffer(16), b = new Uint32Array(e); return b[0] = this.h0, b[1] = this.h1, b[2] = this.h2, b[3] = this.h3, e }, _0x5887c8.prototype.buffer = _0x5887c8.prototype.arrayBuffer, _0x5887c8.prototype.base64 = function() { for (var e, b, a, f = "", c = this.array(), r = 0; r < 15;) e = c[r++], b = c[r++], a = c[r++], f += _0x2c185e[e >>> 2] + _0x2c185e[63 & (e << 4 | b >>> 4)] + _0x2c185e[63 & (b << 2 | a >>> 6)] + _0x2c185e[63 & a]; return f + (_0x2c185e[(e = c[r]) >>> 2] + _0x2c185e[e << 4 & 63] + "==") }; var _0x4dd781 = _0x38ba77(); _0x17dcbf ? _0x770f81.exports = _0x4dd781 : (_0x1702f9.md5 = _0x4dd781, _0x554fed && (void 0)(function() { return _0x4dd781 })) }() }); function _0x178cef(e) { return jsvmp("484e4f4a403f52430038001eab0015840e8ee21a00000000000000621b000200001d000146000306000e271f001b000200021d00010500121b001b000b021b000b04041d0001071b000b0500000003000126207575757575757575757575757575757575757575757575757575757575757575", [, , void 0 !== _0x124d1a ? _0x124d1a : void 0, _0x178cef, e]) } for (var _0xb55f3e = { boe: !1, aid: 0, dfp: !1, sdi: !1, enablePathList: [], _enablePathListRegex: [], urlRewriteRules: [], _urlRewriteRules: [], initialized: !1, enableTrack: !1, track: { unitTime: 0, unitAmount: 0, fre: 0 }, triggerUnload: !1, region: "", regionConf: {}, umode: 0, v: !1, perf: !1, xxbg: !0 }, _0x3eaf64 = { debug: function(e, b) { let a = !1; a = !1 } }, _0x233455 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], _0x2e9f6d = [], _0x511f86 = [], _0x3d35de = 0; _0x3d35de < 256; _0x3d35de++) _0x2e9f6d[_0x3d35de] = _0x233455[_0x3d35de >> 4 & 15] + _0x233455[15 & _0x3d35de], _0x3d35de < 16 && (_0x3d35de < 10 ? _0x511f86[48 + _0x3d35de] = _0x3d35de : _0x511f86[87 + _0x3d35de] = _0x3d35de); var _0x2ce54d = function(e) { for (var b = e.length, a = "", f = 0; f < b;) a += _0x2e9f6d[e[f++]]; return a }, _0x5960a2 = function(e) { for (var b = e.length >> 1, a = b << 1, f = new Uint8Array(b), c = 0, r = 0; r < a;) f[c++] = _0x511f86[e.charCodeAt(r++)] << 4 | _0x511f86[e.charCodeAt(r++)]; return f }, _0x4e46b6 = { encode: _0x2ce54d, decode: _0x5960a2 }; function sign(e, b) { return jsvmp("484e4f4a403f5243001f240fbf2031ccf317480300000000000007181b0002012e1d00921b000b171b000b02402217000a1c1b000b1726402217000c1c1b000b170200004017002646000306000e271f001b000200021d00920500121b001b000b031b000b17041d0092071b000b041e012f17000d1b000b05260a0000101c1b000b06260a0000101c1b001b000b071e01301d00931b001b000b081e00081d00941b0048021d00951b001b000b1b1d00961b0048401d009e1b001b000b031b000b16041d009f1b001b000b09221e0131241b000b031b000b09221e0131241b000b1e0a000110040a0001101d00d51b001b000b09221e0131241b000b031b000b09221e0131241b000b180a000110040a0001101d00d71b001b000b0a1e00101d00d91b001b000b0b261b000b1a1b000b190a0002101d00db1b001b000b0c261b000b221b000b210a0002101d00dc1b001b000b0d261b000b230200200a0002101d00dd1b001b000b09221e0131241b000b031b000b24040a0001101d00df1b001b000b0e1a00221e00de240a0000104903e82b1d00e31b001b000b0f260a0000101d00e41b001b000b1d1d00e71b001b000b1a4901002b1d00e81b001b000b1a4901002c1d00ea1b001b000b191d00f21b001b000b1f480e191d00f81b001b000b1f480f191d00f91b001b000b20480e191d00fb1b001b000b20480f191d00fe1b001b000b25480e191d01001b001b000b25480f191d01011b001b000b264818344900ff2f1d01031b001b000b264810344900ff2f1d01321b001b000b264808344900ff2f1d01331b001b000b264800344900ff2f1d01341b001b000b274818344900ff2f1d01351b001b000b274810344900ff2f1d01361b001b000b274808344900ff2f1d01371b001b000b274800344900ff2f1d01381b001b000b281b000b29311b000b2a311b000b2b311b000b2c311b000b2d311b000b2e311b000b2f311b000b30311b000b31311b000b32311b000b33311b000b34311b000b35311b000b36311b000b37311b000b38311b000b39311d01391b004900ff1d013a1b001b000b10261b000b281b000b2a1b000b2c1b000b2e1b000b301b000b321b000b341b000b361b000b381b000b3a1b000b291b000b2b1b000b2d1b000b2f1b000b311b000b331b000b351b000b371b000b390a0013101d013b1b001b000b0c261b000b111b000b3b041b000b3c0a0002101d013c1b001b000b12261b000b1c1b000b3b1b000b3d0a0003101d013d1b001b000b13261b000b3e0200240a0002101d013e1b000b3f0000013f000126207575757575757575757575757575757575757575757575757575757575757575012b0e7776757a7d7643617c637661676a027a77065c717976706708777671667474766107767d65707c77760374766707707c7d607c7f7607757a61767166740a7c66677661447a77677b0a7a7d7d7661447a77677b0b7c666776615b767a747b670b7a7d7d76615b767a747b6709666076615274767d670b677c5f7c64766150726076077a7d77766b5c7508767f767067617c7d09667d7776757a7d76770963617c677c676a637608677c4067617a7d740470727f7f0763617c7076606010487c71797670673363617c707660604e067c717976706705677a677f76047d7c7776012e0125012402602341525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a383c2e0260224157787763747b2749586042512b233c5e75656420254b5a22412126384446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e0260214157787763747b2749586042512b233c5e75656420254b5a224121263e4446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e02602041525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a3e4c2e012a022222067f767d74677b0a707b7261507c7776526702222306707b726152670f487c717976706733447a7d777c644e08577c70667e767d6712487c7179767067335d72657a7472677c614e057960777c7e10487c7179767067335b7a60677c616a4e07637f66747a7d60084c637b727d677c7e0b70727f7f437b727d677c7e0b4c4c7d7a747b677e726176055266777a7c1850727d65726041767d7776617a7d74507c7d67766b6721570964767177617a657661137476675c647d43617c637661676a5d727e7660097f727d74667274766006707b617c7e760761667d677a7e7607707c7d7d767067144c4c64767177617a6576614c7665727f66726776134c4c60767f767d7a667e4c7665727f667267761b4c4c64767177617a6576614c6070617a63674c75667d70677a7c7d174c4c64767177617a6576614c6070617a63674c75667d70154c4c64767177617a6576614c6070617a63674c757d134c4c756b77617a6576614c7665727f66726776124c4c77617a6576614c667d64617263637677154c4c64767177617a6576614c667d64617263637677114c4c77617a6576614c7665727f66726776144c4c60767f767d7a667e4c667d64617263637677144c4c756b77617a6576614c667d64617263637677094c60767f767d7a667e0c70727f7f40767f767d7a667e164c40767f767d7a667e4c5a57564c4176707c6177766108777c70667e767d670478766a60057e7267707b06417674566b630a4f3748723e694e77704c067072707b764c04607c7e7608707675407b72616308507675407b72616305767c72637a16767c44767151617c64607661577a60637267707b76610f717a7d775c717976706752606a7d700e7a60565c44767151617c646076610120047c63767d0467766067097a7d707c747d7a677c077c7d7661617c6104707c77761242465c47524c564b5056565756574c5641410e607660607a7c7d40677c61727476076076675a67767e10607c7e7658766a5b766176516a6776770a61767e7c65765a67767e097a7d77766b767757510c437c7a7d6776615665767d670e5e40437c7a7d6776615665767d670d706176726776567f767e767d670670727d65726009677c5772677246415f076176637f727076034f603901740a7d72677a6576707c777614487c717976706733437f66747a7d526161726a4e4a4d7b676763602c294f3c4f3c3b48233e2a4e68223f206e3b4f3d48233e2a4e68223f206e3a68206e6f48723e75233e2a4e68223f276e3b2948723e75233e2a4e68223f276e3a68246e3a0127087f7c7072677a7c7d047b61767504757a7f76107b676763293c3c7f7c70727f7b7c606708637f7267757c617e02222102222007647a7d777c646002222703647a7d02222607727d77617c7a77022225057f7a7d666b022224067a637b7c7d7602222b047a63727702222a047a637c77022123037e7270022122097e72707a7d677c607b0c7e72704c637c64766163703a0470617c60036b22220570617a7c6005756b7a7c6004637a787602212102212002212702212602212502212402212b08757a6176757c6b3c067c637661723c05337c63613c05337c63673c07707b617c7e763c0867617a77767d673c047e607a7602212a0220230665767d777c6106547c7c747f760e4c637261727e40647a67707b5c7d0a777a61767067407a747d0a707c7d607a6067767d670660647a67707b03777c7e07637b727d677c7e047b7c7c7840525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a3e3d03727a77017d01750161096067726167477a7e7601670972717a7f7a677a76600a677a7e766067727e6322137b72617764726176507c7d70666161767d706a0c7776657a70765e767e7c616a087f727d74667274760a6176607c7f66677a7c7d0f7265727a7f4176607c7f66677a7c7d0960706176767d477c630a60706176767d5f767567107776657a7076437a6b767f4172677a7c0a63617c77667067406671077172676776616a016309677c66707b5a7d757c08677a7e76697c7d760a677a7e766067727e6321077463665a7d757c0b7960557c7d67605f7a60670b637f66747a7d605f7a60670a677a7e766067727e63200a76657661507c7c787a760767674c60707a77017e0b606a7d67726b5661617c610c7d72677a65765f767d74677b056167705a43097563457661607a7c7d0b4c4c657661607a7c7d4c4c08707f7a767d675a770a677a7e766067727e63270b766b67767d77557a767f77046366607b03727f7f04677b767d097172607625274c707b0c75617c7e507b7261507c7776067125274c2023022022087172607625274c23022021087172607625274c22022020087172607625274c2102202702202602202507747667477a7e760220240b777c7e5d7c6745727f7a77096066716067617a7d740863617c677c707c7f02202b02202a01230e222323232323232322222323232302272302272207757c616176727f02272104717c776a096067617a7d747a756a02686e0b717c776a45727f216067610a717c776a4c7b72607b2e01350366617f02272005626676616a0a72607c7f774c607a747d096372677b7d727e762e0967674c6476717a772e063566667a772e0227270227260e4c716a6776774c6076704c777a770227250a27212a272a2524212a25097576457661607a7c7d0227240e4c232151274925647c232323232202272b02272a05607f7a7076022623074056505a5d555c037d7c6409677a7e766067727e6305757f7c7c610661727d777c7e0f7476674747447671507c7c787a7660056767647a770867674c6476717a770767674476715a770b67674c6476717a774c65210967674476717a7745210761667d7d7a7d7405757f66607b087e7c65765f7a60670660637f7a70760671765e7c657609707f7a70785f7a6067077176507f7a70780c78766a717c7261775f7a60670a717658766a717c7261770b7270677a657640677267760b647a7d777c6440677267760360477e05676172707808667d7a67477a7e76037270700a667d7a67527e7c667d670871767b72657a7c61077e6074476a637603645a5707727a775f7a60670b63617a6572706a5e7c777606706660677c7e067260607a747d0f4456514c5756455a50564c5a5d555c0479607c7d0a6176747a7c7d507c7d75096176637c616746617f04766b7a67094b3e5e403e404746510c4b3e5e403e43524a5f5c525720232323232323232323232323232323232323232323232323232323232323232320772722772b70772a2b75232371212327762a2b23232a2a2b7670752b272124760165066671707c7776067776707c777602262202262102262002262702262602262502262402262b02262a022523022522022521022520", [, , void 0, void 0 !== _0x178cef ? _0x178cef : void 0, { boe: !1, aid: 0, dfp: !1, sdi: !1, enablePathList: [], _enablePathListRegex: [/\/web\/report/], urlRewriteRules: [], _urlRewriteRules: [], initialized: !1, enableTrack: !1, track: { unitTime: 0, unitAmount: 0, fre: 0 }, triggerUnload: !1, region: "", regionConf: {}, umode: 0, v: !1, perf: !1, xxbg: !0 }, () => 0, () => "03v", { ubcode: 0 }, { bogusIndex: 0, msNewTokenList: [], moveList: [], clickList: [], keyboardList: [], activeState: [], aidList: [], envcode: 0, msToken: "", msStatus: 0, __ac_testid: "", ttwid: "", tt_webid: "", tt_webid_v2: "" }, void 0 !== _0x4e46b6 ? _0x4e46b6 : void 0, { userAgent: b }, (e, b) => { let a = new Uint8Array(3); return a[0] = e / 256, a[1] = e % 256, a[2] = b % 256, String.fromCharCode.apply(null, a) }, (e, b) => { let a, f = [], c = 0, r = ""; for (let e = 0; e < 256; e++) f[e] = e; for (let b = 0; b < 256; b++) c = (c + f[b] + e.charCodeAt(b % e.length)) % 256, a = f[b], f[b] = f[c], f[c] = a; let t = 0; c = 0; for (let e = 0; e < b.length; e++) c = (c + f[t = (t + 1) % 256]) % 256, a = f[t], f[t] = f[c], f[c] = a, r += String.fromCharCode(b.charCodeAt(e) ^ f[(f[t] + f[c]) % 256]); return r }, (e, b) => jsvmp("484e4f4a403f524300281018f7b851f02d296e5b00000000000004a21b0002001d1d001e1b00131e00061a001d001f1b000b070200200200210d1b000b070200220200230d1b000b070200240200250d1b000b070200260200270d1b001b000b071b000b05191d00031b000200001d00281b0048001d00291b000b041e002a1b000b0b4803283b1700f11b001b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f4810331b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f480833301b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f301d002c1b00220b091b000b08221e002d241b000b0a4a00fc00002f4812340a000110281d00281b00220b091b000b08221e002d241b000b0a4a0003f0002f480c340a000110281d00281b00220b091b000b08221e002d241b000b0a490fc02f4806340a000110281d00281b00220b091b000b08221e002d241b000b0a483f2f0a000110281d002816ff031b000b041e002a1b000b0b294800391700e01b001b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f4810331b000b041e002a1b000b0b3917001e1b000b04221e002b241b000b0b0a0001104900ff2f4808331600054800301d002c1b00220b091b000b08221e002d241b000b0a4a00fc00002f4812340a000110281d00281b00220b091b000b08221e002d241b000b0a4a0003f0002f480c340a000110281d00281b00220b091b000b041e002a1b000b0b3917001e1b000b08221e002d241b000b0a490fc02f4806340a0001101600071b000b06281d00281b00220b091b000b06281d00281b000b090000002e000126207575757575757575757575757575757575757575757575757575757575757575012b0e7776757a7d7643617c637661676a027a77065c717976706708777671667474766107767d65707c77760374766707707c7d607c7f7607757a61767166740a7c66677661447a77677b0a7a7d7d7661447a77677b0b7c666776615b767a747b670b7a7d7d76615b767a747b6709666076615274767d670b677c5f7c64766150726076077a7d77766b5c7508767f767067617c7d09667d7776757a7d76770963617c677c676a637608677c4067617a7d740470727f7f0763617c7076606010487c71797670673363617c707660604e067c717976706705677a677f76047d7c7776012e0125012402602341525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a383c2e0260224157787763747b2749586042512b233c5e75656420254b5a22412126384446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e0260214157787763747b2749586042512b233c5e75656420254b5a224121263e4446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e02602041525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a3e4c2e012a022222067f767d74677b0a707b7261507c7776526702222306707b72615267", [, , , , e, b]), "undefined" != typeof Date ? Date : void 0, () => 0, (e, b, a, f, c, r, t, d, i, n, s, o, l, _, x, u, h, p, y) => { let v = new Uint8Array(19); return v[0] = e, v[1] = s, v[2] = b, v[3] = o, v[4] = a, v[5] = l, v[6] = f, v[7] = _, v[8] = c, v[9] = x, v[10] = r, v[11] = u, v[12] = t, v[13] = h, v[14] = d, v[15] = p, v[16] = i, v[17] = y, v[18] = n, String.fromCharCode.apply(null, v) }, e => String.fromCharCode(e), (e, b, a) => String.fromCharCode(e) + String.fromCharCode(b) + a, (e, b) => jsvmp("484e4f4a403f524300281018f7b851f02d296e5b00000000000004a21b0002001d1d001e1b00131e00061a001d001f1b000b070200200200210d1b000b070200220200230d1b000b070200240200250d1b000b070200260200270d1b001b000b071b000b05191d00031b000200001d00281b0048001d00291b000b041e002a1b000b0b4803283b1700f11b001b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f4810331b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f480833301b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f301d002c1b00220b091b000b08221e002d241b000b0a4a00fc00002f4812340a000110281d00281b00220b091b000b08221e002d241b000b0a4a0003f0002f480c340a000110281d00281b00220b091b000b08221e002d241b000b0a490fc02f4806340a000110281d00281b00220b091b000b08221e002d241b000b0a483f2f0a000110281d002816ff031b000b041e002a1b000b0b294800391700e01b001b000b04221e002b241b001e0029222d1b00241d00290a0001104900ff2f4810331b000b041e002a1b000b0b3917001e1b000b04221e002b241b000b0b0a0001104900ff2f4808331600054800301d002c1b00220b091b000b08221e002d241b000b0a4a00fc00002f4812340a000110281d00281b00220b091b000b08221e002d241b000b0a4a0003f0002f480c340a000110281d00281b00220b091b000b041e002a1b000b0b3917001e1b000b08221e002d241b000b0a490fc02f4806340a0001101600071b000b06281d00281b00220b091b000b06281d00281b000b090000002e000126207575757575757575757575757575757575757575757575757575757575757575012b0e7776757a7d7643617c637661676a027a77065c717976706708777671667474766107767d65707c77760374766707707c7d607c7f7607757a61767166740a7c66677661447a77677b0a7a7d7d7661447a77677b0b7c666776615b767a747b670b7a7d7d76615b767a747b6709666076615274767d670b677c5f7c64766150726076077a7d77766b5c7508767f767067617c7d09667d7776757a7d76770963617c677c676a637608677c4067617a7d740470727f7f0763617c7076606010487c71797670673363617c707660604e067c717976706705677a677f76047d7c7776012e0125012402602341525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a383c2e0260224157787763747b2749586042512b233c5e75656420254b5a22412126384446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e0260214157787763747b2749586042512b233c5e75656420254b5a224121263e4446527f567a245d5f717c624a475c4366697e5579597d616a6b2a5b45547072406750762e02602041525150575655545b5a59585f5e5d5c43424140474645444b4a49727170777675747b7a79787f7e7d7c63626160676665646b6a6923222120272625242b2a3e4c2e012a022222067f767d74677b0a707b7261507c7776526702222306707b72615267", [, , , , e, b]), , sign, e, void 0]) } module.exports = { sign }; ================================================ FILE: src/logger.py ================================================ # -*- coding: utf-8 -*- import os import sys from loguru import logger logger.remove() custom_format = "{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} - {message}" logger.add( sink=sys.stderr, format=custom_format, level="DEBUG", colorize=True, enqueue=True ) script_path = os.path.split(os.path.realpath(sys.argv[0]))[0] logger.add( f"{script_path}/logs/streamget.log", level="DEBUG", format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {name}:{function}:{line} - {message}", filter=lambda i: i["level"].name != "INFO", serialize=False, enqueue=True, retention=1, rotation="300 KB", encoding='utf-8' ) logger.add( f"{script_path}/logs/PlayURL.log", level="INFO", format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {message}", filter=lambda i: i["level"].name == "INFO", serialize=False, enqueue=True, retention=1, rotation="300 KB", encoding='utf-8' ) ================================================ FILE: src/proxy.py ================================================ import os import sys from enum import Enum, auto from dataclasses import dataclass, field from .utils import logger class ProxyType(Enum): HTTP = auto() HTTPS = auto() SOCKS = auto() @dataclass(frozen=True) class ProxyInfo: ip: str = field(default="", repr=True) port: str = field(default="", repr=True) def __post_init__(self): if (self.ip and not self.port) or (not self.ip and self.port): raise ValueError("IP or port cannot be empty") if (self.ip and self.port) and (not self.port.isdigit() or not (1 <= int(self.port) <= 65535)): raise ValueError("Port must be a digit between 1 and 65535") class ProxyDetector: def __init__(self): if sys.platform.startswith('win'): import winreg self.winreg = winreg self.__path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings' with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as key_user: self.__INTERNET_SETTINGS = winreg.OpenKeyEx(key_user, self.__path, 0, winreg.KEY_ALL_ACCESS) else: self.__is_windows = False def get_proxy_info(self) -> ProxyInfo: if sys.platform.startswith('win'): ip, port = self._get_proxy_info_windows() else: ip, port = self._get_proxy_info_linux() return ProxyInfo(ip, port) def is_proxy_enabled(self) -> bool: if sys.platform.startswith('win'): return self._is_proxy_enabled_windows() else: return self._is_proxy_enabled_linux() def _get_proxy_info_windows(self) -> tuple[str, str]: ip, port = "", "" if self._is_proxy_enabled_windows(): try: ip_port = self.winreg.QueryValueEx(self.__INTERNET_SETTINGS, "ProxyServer")[0] if ip_port: ip, port = ip_port.split(":") except FileNotFoundError as err: logger.warning("No proxy information found: " + str(err)) except Exception as err: logger.error("An error occurred: " + str(err)) else: logger.debug("No proxy is enabled on the system") return ip, port def _is_proxy_enabled_windows(self) -> bool: try: if self.winreg.QueryValueEx(self.__INTERNET_SETTINGS, "ProxyEnable")[0] == 1: return True except FileNotFoundError as err: print("No proxy information found: " + str(err)) except Exception as err: print("An error occurred: " + str(err)) return False @staticmethod def _get_proxy_info_linux() -> tuple[str, str]: proxies = { 'http': os.getenv('http_proxy'), 'https': os.getenv('https_proxy'), 'ftp': os.getenv('ftp_proxy') } ip = port = "" for proto, proxy in proxies.items(): if proxy: ip, port = proxy.split(':') break return ip, port def _is_proxy_enabled_linux(self) -> bool: proxies = self._get_proxy_info_linux() return any(proxy != '' for proxy in proxies) ================================================ FILE: src/room.py ================================================ # -*- encoding: utf-8 -*- """ Author: Hmily GitHub:https://github.com/ihmily Date: 2023-07-17 23:52:05 Update: 2025-02-04 04:57:00 Copyright (c) 2023 by Hmily, All Rights Reserved. """ import re import urllib.parse import execjs import httpx import urllib.request from . import JS_SCRIPT_PATH, utils no_proxy_handler = urllib.request.ProxyHandler({}) opener = urllib.request.build_opener(no_proxy_handler) class UnsupportedUrlError(Exception): pass HEADERS = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) ' 'SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36', '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', 'Cookie': 's_v_web_id=verify_lk07kv74_QZYCUApD_xhiB_405x_Ax51_GYO9bUIyZQVf' } HEADERS_PC = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', 'Cookie': 'sessionid=7494ae59ae06784454373ce25761e864; __ac_nonce=0670497840077ee4c9eb2; ' '__ac_signature=_02B4Z6wo00f012DZczQAAIDCJJBb3EjnINdg-XeAAL8-db; ' 's_v_web_id=verify_m1ztgtjj_vuHnMLZD_iwZ9_4YO4_BdN1_7wLP3pyqXsf2; ' } # X-bogus算法 async def get_xbogus(url: str, headers: dict | None = None) -> str: if not headers or 'user-agent' not in (k.lower() for k in headers): headers = HEADERS query = urllib.parse.urlparse(url).query xbogus = execjs.compile(open(f'{JS_SCRIPT_PATH}/x-bogus.js').read()).call( 'sign', query, headers.get("User-Agent", "user-agent")) return xbogus # 获取房间ID和用户secID async def get_sec_user_id(url: str, proxy_addr: str | None = None, headers: dict | None = None) -> tuple | None: if not headers or all(k.lower() not in ['user-agent', 'cookie'] for k in headers): headers = HEADERS try: proxy_addr = utils.handle_proxy_addr(proxy_addr) async with httpx.AsyncClient(proxy=proxy_addr, timeout=15) as client: response = await client.get(url, headers=headers, follow_redirects=True) redirect_url = response.url if 'reflow/' in str(redirect_url): match = re.search(r'sec_user_id=([\w_\-]+)&', str(redirect_url)) if match: sec_user_id = match.group(1) room_id = str(redirect_url).split('?')[0].rsplit('/', maxsplit=1)[1] return room_id, sec_user_id else: raise RuntimeError("Could not find sec_user_id in the URL.") else: raise UnsupportedUrlError("The redirect URL does not contain 'reflow/'.") except UnsupportedUrlError as e: raise e except Exception as e: raise RuntimeError(f"An error occurred: {e}") # 获取抖音号 async def get_unique_id(url: str, proxy_addr: str | None = None, headers: dict | None = None) -> str | None: if not headers or all(k.lower() not in ['user-agent', 'cookie'] for k in headers): headers = HEADERS try: proxy_addr = utils.handle_proxy_addr(proxy_addr) async with httpx.AsyncClient(proxy=proxy_addr, timeout=15) as client: response = await client.get(url, headers=headers, follow_redirects=True) redirect_url = str(response.url) if 'reflow/' in str(redirect_url): raise UnsupportedUrlError("Unsupported URL") sec_user_id = redirect_url.split('?')[0].rsplit('/', maxsplit=1)[1] headers['Cookie'] = ('ttwid=1%7C4ejCkU2bKY76IySQENJwvGhg1IQZrgGEupSyTKKfuyk%7C1740470403%7Cbc9a' 'd2ee341f1a162f9e27f4641778030d1ae91e31f9df6553a8f2efa3bdb7b4; __ac_nonce=06' '83e59f3009cc48fbab0; __ac_signature=_02B4Z6wo00f01mG6waQAAIDB9JUCzFb6.TZhmsU' 'AAPBf34; __ac_referer=__ac_blank') user_page_response = await client.get(f'https://www.iesdouyin.com/share/user/{sec_user_id}', headers=headers, follow_redirects=True) matches = re.findall(r'unique_id":"(.*?)","verification_type', user_page_response.text) if matches: unique_id = matches[-1] return unique_id else: raise RuntimeError("Could not find unique_id in the response.") except UnsupportedUrlError as e: raise e except Exception as e: raise RuntimeError(f"An error occurred: {e}") # 获取直播间webID async def get_live_room_id(room_id: str, sec_user_id: str, proxy_addr: str | None = None, params: dict | None = None, headers: dict | None = None) -> str: if not headers or all(k.lower() not in ['user-agent', 'cookie'] for k in headers): headers = HEADERS if not params: params = { "verifyFp": "verify_lk07kv74_QZYCUApD_xhiB_405x_Ax51_GYO9bUIyZQVf", "type_id": "0", "live_id": "1", "room_id": room_id, "sec_user_id": sec_user_id, "app_id": "1128", "msToken": "wrqzbEaTlsxt52-vxyZo_mIoL0RjNi1ZdDe7gzEGMUTVh_HvmbLLkQrA_1HKVOa2C6gkxb6IiY6TY2z8enAkPEwGq--gM" "-me3Yudck2ailla5Q4osnYIHxd9dI4WtQ==", } api = f'https://webcast.amemv.com/webcast/room/reflow/info/?{urllib.parse.urlencode(params)}' xbogus = await get_xbogus(api) api = api + "&X-Bogus=" + xbogus try: proxy_addr = utils.handle_proxy_addr(proxy_addr) async with httpx.AsyncClient(proxy=proxy_addr, timeout=15) as client: response = await client.get(api, headers=headers) response.raise_for_status() json_data = response.json() return json_data['data']['room']['owner']['web_rid'] except httpx.HTTPStatusError as e: print(f"HTTP status error occurred: {e.response.status_code}") raise except Exception as e: print(f"An exception occurred during get_live_room_id: {e}") raise if __name__ == '__main__': room_url = "https://v.douyin.com/iQLgKSj/" _room_id, sec_uid = get_sec_user_id(room_url) web_rid = get_live_room_id(_room_id, sec_uid) print("return web_rid:", web_rid) ================================================ FILE: src/spider.py ================================================ # -*- encoding: utf-8 -*- """ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-15 23:15:00 Update: 2025-10-23 18:28:00 Copyright (c) 2023-2025 by Hmily, All Rights Reserved. Function: Get live stream data. """ import hashlib import random import subprocess import time import uuid from operator import itemgetter import urllib.parse import urllib.error from typing import List import httpx import ssl import re import json import execjs import urllib.request from . import JS_SCRIPT_PATH, utils from .utils import trace_error_decorator, generate_random_string from .logger import script_path from .room import get_sec_user_id, get_unique_id, UnsupportedUrlError from .http_clients.async_http import async_req from .ab_sign import ab_sign ssl_context = ssl.create_default_context() ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE OptionalStr = str | None OptionalDict = dict | None def get_params(url: str, params: str) -> OptionalStr: parsed_url = urllib.parse.urlparse(url) query_params = urllib.parse.parse_qs(parsed_url.query) if params in query_params: return query_params[params][0] async def get_play_url_list(m3u8: str, proxy: OptionalStr = None, header: OptionalDict = None, abroad: bool = False) -> List[str]: resp = await async_req(url=m3u8, proxy_addr=proxy, headers=header, abroad=abroad) play_url_list = [] for i in resp.split('\n'): if i.startswith('https://'): play_url_list.append(i.strip()) if not play_url_list: for i in resp.split('\n'): if i.strip().endswith('m3u8'): play_url_list.append(i.strip()) bandwidth_pattern = re.compile(r'BANDWIDTH=(\d+)') bandwidth_list = bandwidth_pattern.findall(resp) url_to_bandwidth = {url: int(bandwidth) for bandwidth, url in zip(bandwidth_list, play_url_list)} play_url_list = sorted(play_url_list, key=lambda url: url_to_bandwidth[url], reverse=True) return play_url_list async def get_douyin_web_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None): headers = { 'cookie': 'ttwid=1%7C2iDIYVmjzMcpZ20fcaFde0VghXAA3NaNXE_SLR68IyE%7C1761045455' '%7Cab35197d5cfb21df6cbb2fa7ef1c9262206b062c315b9d04da746d0b37dfbc7d', 'referer': 'https://live.douyin.com/335354047186', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/116.0.5845.97 Safari/537.36 Core/1.116.567.400 QQBrowser/19.7.6764.400', } if cookies: headers['cookie'] = cookies try: web_rid = url.split('?')[0].split('live.douyin.com/')[-1] params = { "aid": "6383", "app_name": "douyin_web", "live_id": "1", "device_platform": "web", "language": "zh-CN", "browser_language": "zh-CN", "browser_platform": "Win32", "browser_name": "Chrome", "browser_version": "116.0.0.0", "web_rid": web_rid, 'msToken': '', } api = f'https://live.douyin.com/webcast/room/web/enter/?{urllib.parse.urlencode(params)}' a_bogus = ab_sign(urllib.parse.urlparse(api).query, headers['user-agent']) api += "&a_bogus=" + a_bogus try: json_str = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) if not json_str: raise Exception("it triggered risk control") json_data = json.loads(json_str)['data'] if not json_data['data']: raise Exception(f"{url} VR live is not supported") room_data = json_data['data'][0] room_data['anchor_name'] = json_data['user']['nickname'] except Exception as e: raise Exception(f"Douyin web data fetch error, because {e}.") if room_data['status'] == 2: if 'stream_url' not in room_data: raise RuntimeError( "The live streaming type or gameplay is not supported on the computer side yet, please use the " "app to share the link for recording." ) live_core_sdk_data = room_data['stream_url']['live_core_sdk_data'] pull_datas = room_data['stream_url']['pull_datas'] if live_core_sdk_data: if pull_datas: key = list(pull_datas.keys())[0] json_str = pull_datas[key]['stream_data'] else: json_str = live_core_sdk_data['pull_data']['stream_data'] json_data = json.loads(json_str) if 'origin' in json_data['data']: stream_data = live_core_sdk_data['pull_data']['stream_data'] origin_data = json.loads(stream_data)['data']['origin']['main'] sdk_params = json.loads(origin_data['sdk_params']) origin_hls_codec = sdk_params.get('VCodec') or '' origin_url_list = json_data['data']['origin']['main'] origin_m3u8 = {'ORIGIN': origin_url_list["hls"] + '&codec=' + origin_hls_codec} origin_flv = {'ORIGIN': origin_url_list["flv"] + '&codec=' + origin_hls_codec} hls_pull_url_map = room_data['stream_url']['hls_pull_url_map'] flv_pull_url = room_data['stream_url']['flv_pull_url'] room_data['stream_url']['hls_pull_url_map'] = {**origin_m3u8, **hls_pull_url_map} room_data['stream_url']['flv_pull_url'] = {**origin_flv, **flv_pull_url} except Exception as e: print(f"Error message: {e} Error line: {e.__traceback__.tb_lineno}") room_data = {'anchor_name': ""} return room_data @trace_error_decorator async def get_douyin_app_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0', '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', 'Referer': 'https://live.douyin.com/', 'Cookie': 'ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986' } if cookies: headers['Cookie'] = cookies async def get_app_data(room_id: str, sec_uid: str) -> dict: app_params = { "verifyFp": "verify_hwj52020_7szNlAB7_pxNY_48Vh_ALKF_GA1Uf3yteoOY", "type_id": "0", "live_id": "1", "room_id": room_id, "sec_user_id": sec_uid, "version_code": "99.99.99", "app_id": "1128" } api2 = f'https://webcast.amemv.com/webcast/room/reflow/info/?{urllib.parse.urlencode(app_params)}' a_bogus = ab_sign(urllib.parse.urlparse(api2).query, headers['User-Agent']) api2 += "&a_bogus=" + a_bogus try: json_str2 = await async_req(url=api2, proxy_addr=proxy_addr, headers=headers) if not json_str2: raise Exception("it triggered risk control") json_data2 = json.loads(json_str2)['data'] if not json_data2.get('room'): raise Exception(f"{url} VR live is not supported") room_data2 = json_data2['room'] room_data2['anchor_name'] = room_data2['owner']['nickname'] return room_data2 except Exception as e: raise Exception(f"Douyin app data fetch error, because {e}.") try: web_rid = url.split('?')[0].split('live.douyin.com/') if len(web_rid) > 1: return await get_douyin_web_stream_data(url, proxy_addr, cookies) else: try: data = await get_sec_user_id(url, proxy_addr=proxy_addr) _room_id, _sec_uid = data room_data = await get_app_data(_room_id, _sec_uid) except UnsupportedUrlError: unique_id = await get_unique_id(url, proxy_addr=proxy_addr) return await get_douyin_stream_data(f'https://live.douyin.com/{unique_id}') if room_data['status'] == 2: if 'stream_url' not in room_data: raise RuntimeError( "The live streaming type or gameplay is not supported on the computer side yet, please use the " "app to share the link for recording." ) live_core_sdk_data = room_data['stream_url']['live_core_sdk_data'] pull_datas = room_data['stream_url']['pull_datas'] if live_core_sdk_data: if pull_datas: key = list(pull_datas.keys())[0] json_str = pull_datas[key]['stream_data'] else: json_str = live_core_sdk_data['pull_data']['stream_data'] json_data = json.loads(json_str) if 'origin' in json_data['data']: stream_data = live_core_sdk_data['pull_data']['stream_data'] origin_data = json.loads(stream_data)['data']['origin']['main'] sdk_params = json.loads(origin_data['sdk_params']) origin_hls_codec = sdk_params.get('VCodec') or '' origin_url_list = json_data['data']['origin']['main'] origin_m3u8 = {'ORIGIN': origin_url_list["hls"] + '&codec=' + origin_hls_codec} origin_flv = {'ORIGIN': origin_url_list["flv"] + '&codec=' + origin_hls_codec} hls_pull_url_map = room_data['stream_url']['hls_pull_url_map'] flv_pull_url = room_data['stream_url']['flv_pull_url'] room_data['stream_url']['hls_pull_url_map'] = {**origin_m3u8, **hls_pull_url_map} room_data['stream_url']['flv_pull_url'] = {**origin_flv, **flv_pull_url} except Exception as e: print(f"Error message: {e} Error line: {e.__traceback__.tb_lineno}") room_data = {'anchor_name': ""} return room_data @trace_error_decorator async def get_douyin_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', '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', 'Referer': 'https://live.douyin.com/', 'Cookie': 'ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986' } if cookies: headers['Cookie'] = cookies try: origin_url_list = None html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) match_json_str = re.search(r'(\{\\"state\\":.*?)]\\n"]\)', html_str) if not match_json_str: match_json_str = re.search(r'(\{\\"common\\":.*?)]\\n"]\)
', html_str, re.DOTALL)[0] except Exception: raise ConnectionError("Please check if your network can access the TikTok website normally") json_data = json.loads(json_str) return json_data @trace_error_decorator async def get_kuaishou_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', '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', } if cookies: headers['Cookie'] = cookies try: html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) except Exception as e: print(f"Failed to fetch data from {url}.{e}") return {"type": 1, "is_live": False} try: json_str = re.search('', html_str)[0] json_data = json.loads(json_str) rid = json_data['pageProps']['room']['roomInfo']['roomInfo']['rid'] headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0' url2 = f'https://www.douyu.com/betard/{rid}' json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) result = { "anchor_name": json_data['room']['nickname'], "is_live": False } if json_data['room']['videoLoop'] == 0 and json_data['room']['show_status'] == 1: result["title"] = json_data['room']['room_name'].replace(' ', '') result["is_live"] = True result["room_id"] = json_data['room']['room_id'] return result @trace_error_decorator async def get_douyu_stream_data(rid: str, rate: str = '-1', proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: did = '10000000000000000000000000003306' params_list = await get_token_js(rid, did, proxy_addr=proxy_addr) headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'Referer': 'https://m.douyu.com/3125893?rid=3125893&dyshid=0-96003918aa5365bc6dcb4933000316p1&dyshci=181', 'Cookie': 'dy_did=413b835d2ae00270f0c69f6400031601; acf_did=413b835d2ae00270f0c69f6400031601; Hm_lvt_e99aee90ec1b2106afe7ec3b199020a7=1692068308,1694003758; m_did=96003918aa5365bc6dcb4933000316p1; dy_teen_mode=%7B%22uid%22%3A%22472647365%22%2C%22status%22%3A0%2C%22birthday%22%3A%22%22%2C%22password%22%3A%22%22%7D; PHPSESSID=td59qi2fu2gepngb8mlehbeme3; acf_auth=94fc9s%2FeNj%2BKlpU%2Br8tZC3Jo9sZ0wz9ClcHQ1akL2Nhb6ZyCmfjVWSlR3LFFPuePWHRAMo0dt9vPSCoezkFPOeNy4mYcdVOM1a8CbW0ZAee4ipyNB%2Bflr58; dy_auth=bec5yzM8bUFYe%2FnVAjmUAljyrsX%2FcwRW%2FyMHaoArYb5qi8FS9tWR%2B96iCzSnmAryLOjB3Qbeu%2BBD42clnI7CR9vNAo9mva5HyyL41HGsbksx1tEYFOEwxSI; wan_auth37wan=5fd69ed5b27fGM%2FGoswWwDo%2BL%2FRMtnEa4Ix9a%2FsH26qF0sR4iddKMqfnPIhgfHZUqkAk%2FA1d8TX%2B6F7SNp7l6buIxAVf3t9YxmSso8bvHY0%2Fa6RUiv8; acf_uid=472647365; acf_username=472647365; acf_nickname=%E7%94%A8%E6%88%B776576662; acf_own_room=0; acf_groupid=1; acf_phonestatus=1; acf_avatar=https%3A%2F%2Fapic.douyucdn.cn%2Fupload%2Favatar%2Fdefault%2F24_; acf_ct=0; acf_ltkid=25305099; acf_biz=1; acf_stk=90754f8ed18f0c24; Hm_lpvt_e99aee90ec1b2106afe7ec3b199020a7=1694003778' } if cookies: headers['Cookie'] = cookies data = { 'v': params_list[0], 'did': params_list[1], 'tt': params_list[2], 'sign': params_list[3], # 10分钟有效期 'ver': '22011191', 'rid': rid, 'rate': rate, # 0蓝光、3超清、2高清、-1默认 } # app_api = 'https://m.douyu.com/hgapi/livenc/room/getStreamUrl' app_api = f'https://www.douyu.com/lapi/live/getH5Play/{rid}' json_str = await async_req(url=app_api, proxy_addr=proxy_addr, headers=headers, data=data) json_data = json.loads(json_str) return json_data @trace_error_decorator async def get_yy_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', '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', 'Referer': 'https://www.yy.com/', 'Cookie': 'hd_newui=0.2103068903976506; hdjs_session_id=0.4929014850884579; hdjs_session_time=1694004002636; hiido_ui=0.923076230899782' } if cookies: headers['Cookie'] = cookies html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) anchor_name = re.search('nick: "(.*?)",\n\\s+logo', html_str).group(1) cid = re.search('sid : "(.*?)",\n\\s+ssid', html_str, re.DOTALL).group(1) data = '{"head":{"seq":1701869217590,"appidstr":"0","bidstr":"121","cidstr":"' + cid + '","sidstr":"' + cid + '","uid64":0,"client_type":108,"client_ver":"5.17.0","stream_sys_ver":1,"app":"yylive_web","playersdk_ver":"5.17.0","thundersdk_ver":"0","streamsdk_ver":"5.17.0"},"client_attribute":{"client":"web","model":"web0","cpu":"","graphics_card":"","os":"chrome","osversion":"0","vsdk_version":"","app_identify":"","app_version":"","business":"","width":"1920","height":"1080","scale":"","client_type":8,"h265":0},"avp_parameter":{"version":1,"client_type":8,"service_type":0,"imsi":0,"send_time":1701869217,"line_seq":-1,"gear":4,"ssl":1,"stream_format":0}}' data_bytes = data.encode('utf-8') params = { "uid": "0", "cid": cid, "sid": cid, "appid": "0", "sequence": "1701869217590", "encode": "json" } url2 = f'https://stream-manager.yy.com/v3/channel/streams?{urllib.parse.urlencode(params)}' json_str = await async_req(url=url2, data=data_bytes, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) json_data['anchor_name'] = anchor_name params = { 'uid': '', 'sid': cid, 'ssid': cid, '_': int(time.time() * 1000), } detail_api = f'https://www.yy.com/live/detail?{urllib.parse.urlencode(params)}' json_str2 = await async_req(detail_api, proxy_addr=proxy_addr, headers=headers) json_data2 = json.loads(json_str2) json_data['title'] = json_data2['data']['roomName'] return json_data @trace_error_decorator async def get_bilibili_room_info_h5(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> str: headers = { 'user-agent': 'Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) ' 'SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36', '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', 'cookie': '', 'origin': 'https://live.bilibili.com', 'referer': 'https://live.bilibili.com/26066074', } if cookies: headers['cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] api = f'https://api.live.bilibili.com/xlive/web-room/v1/index/getH5InfoByRoom?room_id={room_id}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) room_info = json.loads(json_str) title = room_info['data']['room_info'].get('title') if room_info.get('data') else '' return title @trace_error_decorator async def get_bilibili_room_info(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', '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', } if cookies: headers['Cookie'] = cookies try: room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] json_str = await async_req(f'https://api.live.bilibili.com/room/v1/Room/room_init?id={room_id}', proxy_addr=proxy_addr, headers=headers) room_info = json.loads(json_str) uid = room_info['data']['uid'] live_status = True if room_info['data']['live_status'] == 1 else False api = f'https://api.live.bilibili.com/live_user/v1/Master/info?uid={uid}' json_str2 = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) anchor_info = json.loads(json_str2) anchor_name = anchor_info['data']['info']['uname'] title = await get_bilibili_room_info_h5(url, proxy_addr, cookies) return {"anchor_name": anchor_name, "live_status": live_status, "room_url": url, "title": title} except Exception as e: print(e) return {"anchor_name": '', "live_status": False, "room_url": url} @trace_error_decorator async def get_bilibili_stream_data(url: str, qn: str = '10000', platform: str = 'web', proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> OptionalStr: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0', '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', 'origin': 'https://live.bilibili.com', 'referer': 'https://live.bilibili.com/26066074', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] params = { 'cid': room_id, 'qn': qn, 'platform': platform, } play_api = f'https://api.live.bilibili.com/room/v1/Room/playUrl?{urllib.parse.urlencode(params)}' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) if json_data and json_data['code'] == 0: for i in json_data['data']['durl']: if 'd1--cn-gotcha' in i['url']: return i['url'] return json_data['data']['durl'][-1]['url'] else: params = { "room_id": room_id, "protocol": "0,1", "format": "0,1,2", "codec": "0,1,2", "qn": qn, "platform": "web", "ptype": "8", "dolby": "5", "panorama": "1", "hdr_type": "0,1" } # 此接口因网页上有限制, 需要配置登录后的cookie才能获取最高画质 api = f'https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?{urllib.parse.urlencode(params)}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) if json_data['data']['live_status'] == 0: print("The anchor did not start broadcasting.") return playurl_info = json_data['data']['playurl_info'] format_list = playurl_info['playurl']['stream'][0]['format'] stream_data_list = format_list[0]['codec'] sorted_stream_list = sorted(stream_data_list, key=itemgetter("current_qn"), reverse=True) # qn: 30000=杜比 20000=4K 10000=原画 400=蓝光 250=超清 150=高清 80=流畅 video_quality_options = {'10000': 0, '400': 1, '250': 2, '150': 3, '80': 4} qn_count = len(sorted_stream_list) select_stream_index = min(video_quality_options[qn], qn_count - 1) stream_data: dict = sorted_stream_list[select_stream_index] base_url = stream_data['base_url'] host = stream_data['url_info'][0]['host'] extra = stream_data['url_info'][0]['extra'] m3u8_url = host + base_url + extra return m3u8_url @trace_error_decorator async def get_xhs_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'xy-common-params': 'platform=iOS&sid=session.1722166379345546829388', 'referer': 'https://app.xhs.cn/', } if cookies: headers['Cookie'] = cookies if "xhslink.com" in url: url = await async_req(url, proxy_addr=proxy_addr, headers=headers, redirect_url=True) host_id = get_params(url, "host_id") user_id = re.search("/user/profile/(.*?)(?=/|\\?|$)", url) user_id = user_id.group(1) if user_id else host_id result = {"anchor_name": '', "is_live": False} html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers) match_data = re.search("", html_str) if match_data: json_str = match_data.group(1).replace("undefined", "null") json_data = json.loads(json_str) if json_data.get("liveStream"): stream_data = json_data["liveStream"] if stream_data.get("liveStatus") == "success": room_info = stream_data["roomData"]["roomInfo"] title = room_info.get("roomTitle") if title and "回放" not in title: live_link = room_info["deeplink"] anchor_name = get_params(live_link, "host_nickname") flv_url = get_params(live_link, "flvUrl") room_id = flv_url.split('live/')[1].split('.')[0] flv_url = f"http://live-source-play.xhscdn.com/live/{room_id}.flv" m3u8_url = flv_url.replace('.flv', '.m3u8') result |= { "anchor_name": anchor_name, "is_live": True, "title": title, "flv_url": flv_url, "m3u8_url": m3u8_url, 'record_url': flv_url } return result profile_url = f"https://www.xiaohongshu.com/user/profile/{user_id}" html_str = await async_req(profile_url, proxy_addr=proxy_addr, headers=headers) anchor_name = re.search("@(.*?) 的个人主页", html_str) if anchor_name: result["anchor_name"] = anchor_name.group(1) return result @trace_error_decorator async def get_bigo_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', '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', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Referer': 'https://www.bigo.tv/', } if cookies: headers['Cookie'] = cookies if 'bigo.tv' not in url: html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers) web_url = re.search( '', html_str).group(1) room_id = web_url.split('&h=')[-1] else: if '&h=' in url: room_id = url.split('&h=')[-1] else: room_id = url.split("?")[0].rsplit("/", maxsplit=1)[-1] data = {'siteId': room_id} # roomId url2 = 'https://ta.bigo.tv/official_website/studio/getInternalStudioInfo' json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers, data=data) json_data = json.loads(json_str) anchor_name = json_data['data']['nick_name'] live_status = json_data['data']['alive'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: live_title = json_data['data']['roomTopic'] m3u8_url = json_data['data']['hls_src'] result['m3u8_url'] = m3u8_url result['record_url'] = m3u8_url result |= {"title": live_title, "is_live": True, "m3u8_url": m3u8_url, 'record_url': m3u8_url} elif result['anchor_name'] == '': html_str = await async_req(url=f'https://www.bigo.tv/{url.split("/")[3]}/{room_id}', proxy_addr=proxy_addr, headers=headers) match_anchor_name = re.search('欢迎来到(.*?)的直播间', html_str, re.DOTALL) if match_anchor_name: anchor_name = match_anchor_name.group(1) else: match_anchor_name = re.search('', html_str, re.DOTALL) anchor_name = match_anchor_name.group(1) result['anchor_name'] = anchor_name return result @trace_error_decorator async def get_blued_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', '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', } if cookies: headers['Cookie'] = cookies html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) json_str = re.search('decodeURIComponent\\(\"(.*?)\"\\)\\),window\\.Promise', html_str, re.DOTALL).group(1) json_str = urllib.parse.unquote(json_str) json_data = json.loads(json_str) anchor_name = json_data['userInfo']['name'] live_status = json_data['userInfo']['onLive'] result = {"anchor_name": anchor_name, "is_live": False} if live_status: m3u8_url = json_data['liveInfo']['liveUrl'] result |= {"is_live": True, "m3u8_url": m3u8_url, 'record_url': m3u8_url} return result @trace_error_decorator async def login_sooplive(username: str, password: str, proxy_addr: OptionalStr = None) -> OptionalStr: if len(username) < 6 or len(password) < 10: raise RuntimeError("sooplive login failed! Please enter the correct account and password for the sooplive " "platform in the config.ini file.") headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Origin': 'https://play.sooplive.co.kr', 'Referer': 'https://play.sooplive.co.kr/superbsw123/277837074', } data = { 'szWork': 'login', 'szType': 'json', 'szUid': username, 'szPassword': password, 'isSaveId': 'true', 'isSavePw': 'true', 'isSaveJoin': 'true', 'isLoginRetain': 'Y', } url = 'https://login.sooplive.co.kr/app/LoginAction.php' try: cookie_dict = await async_req(url, proxy_addr=proxy_addr, headers=headers, data=data, return_cookies=True, timeout=20) cookie_str = '; '.join([f"{k}={v}" for k, v in cookie_dict.items()]) return cookie_str except Exception as e: print(f"An error occurred during login: {e}") raise Exception( "sooplive login failed, please check if the account password in the configuration file is correct." ) @trace_error_decorator async def get_sooplive_cdn_url(broad_no: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', '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', 'Origin': 'https://play.sooplive.co.kr', 'Referer': 'https://play.sooplive.co.kr/oul282/249469582', 'Content-Type': 'application/x-www-form-urlencoded', } if cookies: headers['Cookie'] = cookies params = { 'return_type': 'gcp_cdn', 'use_cors': 'false', 'cors_origin_url': 'play.sooplive.co.kr', 'broad_key': f'{broad_no}-common-master-hls', 'time': '8361.086329376785', } url2 = 'http://livestream-manager.sooplive.co.kr/broad_stream_assign.html?' + urllib.parse.urlencode(params) json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) return json_data @trace_error_decorator async def get_sooplive_tk(url: str, rtype: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> str | tuple: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0', 'Origin': 'https://play.sooplive.co.kr', 'Referer': 'https://play.sooplive.co.kr/secretx/250989857', 'Content-Type': 'application/x-www-form-urlencoded', } if cookies: headers['Cookie'] = cookies split_url = url.split('/') bj_id = split_url[3] if len(split_url) < 6 else split_url[5] room_password = get_params(url, "pwd") if not room_password: room_password = '' data = { 'bid': bj_id, 'bno': '', 'type': rtype, 'pwd': room_password, 'player_type': 'html5', 'stream_type': 'common', 'quality': 'master', 'mode': 'landing', 'from_api': '0', 'is_revive': 'false', } url2 = f'https://live.sooplive.co.kr/afreeca/player_live_api.php?bjid={bj_id}' json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True) json_data = json.loads(json_str) if rtype == 'aid': token = json_data["CHANNEL"]["AID"] return token else: bj_name = json_data['CHANNEL']['BJNICK'] bj_id = json_data['CHANNEL']['BJID'] return f"{bj_name}-{bj_id}", json_data['CHANNEL']['BNO'] def get_soop_headers(cookies): headers = { 'client-id': str(uuid.uuid4()), 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, ' 'like Gecko) Version/18.5 Mobile/15E148 Safari/604.1 Edg/141.0.0.0', } if cookies: headers['cookie'] = cookies return headers async def _get_soop_channel_info_global(bj_id, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> str: headers = get_soop_headers(cookies) api = 'https://api.sooplive.com/v2/channel/info/' + str(bj_id) json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) nickname = json_data['data']['streamerChannelInfo']['nickname'] channelId = json_data['data']['streamerChannelInfo']['channelId'] anchor_name = f"{nickname}-{channelId}" return anchor_name async def _get_soop_stream_info_global(bj_id, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> tuple: headers = get_soop_headers(cookies) api = 'https://api.sooplive.com/v2/stream/info/' + str(bj_id) json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) status = json_data['data']['isStream'] title = json_data['data']['title'] return status, title async def _fetch_web_stream_data_global(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: split_url = url.split('/') bj_id = split_url[3] if len(split_url) < 6 else split_url[5] anchor_name = await _get_soop_channel_info_global(bj_id) result = {"anchor_name": anchor_name or '', "is_live": False, "live_url": url} status, title = await _get_soop_stream_info_global(bj_id) if not status: return result else: async def _get_url_list(m3u8: str) -> list[str]: headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0', } if cookies: headers['cookie'] = cookies resp = await async_req(url=m3u8, proxy_addr=proxy_addr, headers=headers) play_url_list = [] url_prefix = '/'.join(m3u8.split('/')[0:3]) for i in resp.split('\n'): if not i.startswith('#') and i.strip(): play_url_list.append(url_prefix + i.strip()) bandwidth_pattern = re.compile(r'BANDWIDTH=(\d+)') bandwidth_list = bandwidth_pattern.findall(resp) url_to_bandwidth = {purl: int(bandwidth) for bandwidth, purl in zip(bandwidth_list, play_url_list)} play_url_list = sorted(play_url_list, key=lambda purl: url_to_bandwidth[purl], reverse=True) return play_url_list m3u8_url = 'https://global-media.sooplive.com/live/' + str(bj_id) + '/master.m3u8' result |= { 'is_live': True, 'title': title, 'm3u8_url': m3u8_url, 'play_url_list': await _get_url_list(m3u8_url) } return result @trace_error_decorator async def get_sooplive_stream_data( url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None, username: OptionalStr = None, password: OptionalStr = None ) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', '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', 'Referer': 'https://m.sooplive.co.kr/', 'Content-Type': 'application/x-www-form-urlencoded', } if cookies: headers['Cookie'] = cookies if "sooplive.com" in url: return await _fetch_web_stream_data_global(url, proxy_addr, cookies) split_url = url.split('/') bj_id = split_url[3] if len(split_url) < 6 else split_url[5] data = { 'bj_id': bj_id, 'broad_no': '', 'agent': 'web', 'confirm_adult': 'true', 'player_type': 'webm', 'mode': 'live', } url2 = 'http://api.m.sooplive.co.kr/broad/a/watch' json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True) json_data = json.loads(json_str) if 'user_nick' in json_data['data']: anchor_name = json_data['data']['user_nick'] if "bj_id" in json_data['data']: anchor_name = f"{anchor_name}-{json_data['data']['bj_id']}" else: anchor_name = '' result = {"anchor_name": anchor_name or '' ,"is_live": False} async def get_url_list(m3u8: str) -> List[str]: resp = await async_req(url=m3u8, proxy_addr=proxy_addr, headers=headers, abroad=True) play_url_list = [] url_prefix = m3u8.rsplit('/', maxsplit=1)[0] + '/' for i in resp.split('\n'): if i.startswith('auth_playlist'): play_url_list.append(url_prefix + i.strip()) bandwidth_pattern = re.compile(r'BANDWIDTH=(\d+)') bandwidth_list = bandwidth_pattern.findall(resp) url_to_bandwidth = {purl: int(bandwidth) for bandwidth, purl in zip(bandwidth_list, play_url_list)} play_url_list = sorted(play_url_list, key=lambda purl: url_to_bandwidth[purl], reverse=True) return play_url_list if not anchor_name: async def handle_login() -> OptionalStr: cookie = await login_sooplive(username, password, proxy_addr=proxy_addr) if 'AuthTicket=' in cookie: print("sooplive platform login successful! Starting to fetch live streaming data...") return cookie async def fetch_data(cookie, _result) -> dict: aid_token = await get_sooplive_tk(url, rtype='aid', proxy_addr=proxy_addr, cookies=cookie) _anchor_name, _broad_no = await get_sooplive_tk(url, rtype='info', proxy_addr=proxy_addr, cookies=cookie) _view_url_data = await get_sooplive_cdn_url(_broad_no, proxy_addr=proxy_addr) _view_url = _view_url_data['view_url'] _m3u8_url = _view_url + '?aid=' + aid_token _result |= { "anchor_name": _anchor_name, "is_live": True, "m3u8_url": _m3u8_url, 'play_url_list': await get_url_list(_m3u8_url), 'new_cookies': cookie } return _result if json_data['data']['code'] == -3001: print("sooplive live stream failed to retrieve, the live stream just ended.") return result elif json_data['data']['code'] == -3002: print("sooplive live stream retrieval failed, the live needs 19+, you are not logged in.") print("Attempting to log in to the sooplive live streaming platform with your account and password, " "please ensure it is configured.") new_cookie = await handle_login() if new_cookie and len(new_cookie) > 0: return await fetch_data(new_cookie, result) raise RuntimeError("sooplive login failed, please check if the account and password are correct") elif json_data['data']['code'] == -3004: if cookies and len(cookies) > 0: return await fetch_data(cookies, result) else: raise RuntimeError("sooplive login failed, please check if the account and password are correct") elif json_data['data']['code'] == -6001: print("error message:Please check if the input sooplive live room address " "is correct.") return result if json_data['result'] == 1 and anchor_name: broad_no = json_data['data']['broad_no'] hls_authentication_key = json_data['data']['hls_authentication_key'] view_url_data = await get_sooplive_cdn_url(broad_no, proxy_addr=proxy_addr) view_url = view_url_data['view_url'] m3u8_url = view_url + '?aid=' + hls_authentication_key result |= {'is_live': True, 'm3u8_url': m3u8_url, 'play_url_list': await get_url_list(m3u8_url)} result['new_cookies'] = None return result @trace_error_decorator async def get_netease_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://cc.163.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies url = url + '/' if url[-1] != '/' else url html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) json_str = re.search('', html_str, re.DOTALL).group(1) json_data = json.loads(json_str) room_data = json_data['props']['pageProps']['roomInfoInitData'] live_data = room_data['live'] result = {"is_live": False} live_status = live_data.get('status') == 1 result["anchor_name"] = live_data.get('nickname', room_data.get('nickname')) if live_status: result |= { 'is_live': True, 'title': live_data['title'], 'stream_list': live_data.get('quickplay'), 'm3u8_url': live_data.get('sharefile') } return result @trace_error_decorator async def get_qiandurebo_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,' 'application/signed-exchange;v=b3;q=0.7', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://qiandurebo.com/web/index.php', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies html_str = await async_req(url=url, proxy_addr=proxy_addr, headers=headers) data = re.search('var user = (.*?)\r\n\\s+user\\.play_url', html_str, re.DOTALL).group(1) anchor_name = re.findall('"zb_nickname": "(.*?)",\r\n', data) result = {"anchor_name": "", "is_live": False} if len(anchor_name) > 0: result['anchor_name'] = anchor_name[0] play_url = re.findall('"play_url": "(.*?)",\r\n', data) if len(play_url) > 0 and 'common-text-center" style="display:block' not in html_str: result |= { 'anchor_name': anchor_name[0], 'is_live': True, 'flv_url': play_url[0], 'record_url': play_url[0] } return result @trace_error_decorator async def get_pandatv_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://www.pandalive.co.kr', 'referer': 'https://www.pandalive.co.kr/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies user_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] url2 = 'https://api.pandalive.co.kr/v1/live/play' data = { 'userId': user_id, 'info': 'media fanGrade', } room_password = get_params(url, "pwd") if not room_password: room_password = '' data2 = { 'action': 'watch', 'userId': user_id, 'password': room_password, 'shareLinkType': '', } result = {"anchor_name": "", "is_live": False} json_str = await async_req('https://api.pandalive.co.kr/v1/member/bj', proxy_addr=proxy_addr, headers=headers, data=data, abroad=True) json_data = json.loads(json_str) if "bjInfo" not in json_data: raise RuntimeError(json_data.get("message", 'Unknown error')) anchor_id = json_data['bjInfo']['id'] anchor_name = f"{json_data['bjInfo']['nick']}-{anchor_id}" result['anchor_name'] = anchor_name live_status = 'media' in json_data if live_status: json_str = await async_req(url2, proxy_addr=proxy_addr, headers=headers, data=data2, abroad=True) json_data = json.loads(json_str) if 'errorData' in json_data: if json_data['errorData']['code'] == 'needAdult': raise RuntimeError(f"{url} The live room requires login and is only accessible to adults. Please " f"correctly fill in the login cookie in the configuration file.") else: raise RuntimeError(json_data['errorData']['code'], json_data['message']) play_url = json_data['PlayList']['hls'][0]['url'] play_url_list = await get_play_url_list(m3u8=play_url, proxy=proxy_addr, header=headers, abroad=True) result |= {'is_live': True, 'm3u8_url': play_url, 'play_url_list': play_url_list} return result @trace_error_decorator async def get_maoerfm_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://fm.missevan.com/live/868895007', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] url2 = f'https://fm.missevan.com/api/v2/live/{room_id}' json_str = await async_req(url=url2, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['info']['creator']['username'] live_status = False if 'room' in json_data['info']: live_status = json_data['info']['room']['status']['broadcasting'] result = {"anchor_name": anchor_name, "is_live": live_status} if live_status: stream_list = json_data['info']['room']['channel'] m3u8_url = stream_list['hls_pull_url'] flv_url = stream_list['flv_pull_url'] title = json_data['info']['room']['name'] result |= {'is_live': True, 'title': title, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_winktv_bj_info(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> tuple: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'content-type': 'application/x-www-form-urlencoded', 'referer': 'https://www.winktv.co.kr/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies user_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] data = { 'userId': user_id, 'info': 'media', } info_api = 'https://api.winktv.co.kr/v1/member/bj' json_str = await async_req(url=info_api, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True) json_data = json.loads(json_str) live_status = 'media' in json_data anchor_id = json_data['bjInfo']['id'] anchor_name = f"{json_data['bjInfo']['nick']}-{anchor_id}" return anchor_name, live_status @trace_error_decorator async def get_winktv_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'content-type': 'application/x-www-form-urlencoded', 'referer': 'https://www.winktv.co.kr', 'origin': 'https://www.winktv.co.kr', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies user_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] room_password = get_params(url, "pwd") if not room_password: room_password = '' data = { 'action': 'watch', 'userId': user_id, 'password': room_password, 'shareLinkType': '', } anchor_name, live_status = await get_winktv_bj_info(url=url, proxy_addr=proxy_addr, cookies=cookies) result = {"anchor_name": anchor_name, "is_live": live_status} if live_status: play_api = 'https://api.winktv.co.kr/v1/live/play' json_str = await async_req(url=play_api, proxy_addr=proxy_addr, headers=headers, data=data, abroad=True) if '403: Forbidden' in json_str: raise ConnectionError(f"Your network has been banned from accessing WinkTV ({json_str})") json_data = json.loads(json_str) if 'errorData' in json_data: if json_data['errorData']['code'] == 'needAdult': raise RuntimeError(f"{url} The live stream is only accessible to logged-in adults. Please ensure that " f"the cookie is correctly filled in the configuration file after logging in.") else: raise RuntimeError(json_data['errorData']['code'], json_data['message']) m3u8_url = json_data['PlayList']['hls'][0]['url'] play_url_list = await get_play_url_list(m3u8=m3u8_url, proxy=proxy_addr, header=headers, abroad=True) result['m3u8_url'] = m3u8_url result['play_url_list'] = play_url_list return result @trace_error_decorator async def login_flextv(username: str, password: str, proxy_addr: OptionalStr = None) -> OptionalStr: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'content-type': 'application/json;charset=UTF-8', 'referer': 'https://www.ttinglive.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } data = { 'loginId': username, 'password': password, 'loginKeep': True, 'saveId': True, 'device': 'PCWEB', } url = 'https://www.ttinglive.com/v2/api/auth/signin' try: print("Logging into FlexTV platform...") cookie_dict = await async_req(url, proxy_addr=proxy_addr, headers=headers, json_data=data, return_cookies=True, timeout=20) if cookie_dict and 'flx_oauth_access' in cookie_dict: cookie_str = '; '.join([f"{k}={v}" for k, v in cookie_dict.items()]) return cookie_str else: print("Please check if the FlexTV account and password in the configuration file are correct.") return None except Exception as e: print(f"FlexTV login request exception: {e}") raise Exception( "FlexTV login failed, please check if the account and password in the configuration file are correct." ) async def get_flextv_stream_url( url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None ) -> str: async def fetch_data(cookie) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://www.ttinglive.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } user_id = url.split('/live')[0].rsplit('/', maxsplit=1)[-1] if cookie: headers['Cookie'] = cookie play_api = f'https://www.ttinglive.com/api/channels/{user_id}/stream?option=all' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers, abroad=True) if 'HTTP Error 400: Bad Request' in json_str: raise ConnectionError( "Failed to retrieve FlexTV live streaming data, please switch to a different proxy and try again." ) return json.loads(json_str) json_data = await fetch_data(cookies) if 'sources' in json_data and len(json_data['sources']) > 0: play_url = json_data['sources'][0]['url'] return play_url @trace_error_decorator async def get_flextv_stream_data( url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None, username: OptionalStr = None, password: OptionalStr = None ) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://www.ttinglive.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies user_id = url.split('/live')[0].rsplit('/', maxsplit=1)[-1] result = {"anchor_name": '', "is_live": False} new_cookies = None try: url2 = f'https://www.ttinglive.com/channels/{user_id}/live' html_str = await async_req(url2, proxy_addr=proxy_addr, headers=headers, abroad=True) json_str = re.search('', html_str).group(1) json_data = json.loads(json_str) channel_data = json_data['props']['pageProps']['channel'] login_need = 'message' in channel_data and '로그인후 이용이 가능합니다.' in channel_data.get('message') if login_need: print("FlexTV live stream retrieval failed [not logged in]: 19+ live streams are only available for " "logged-in adults.") print("Attempting to log in to the FlexTV live streaming platform, please ensure your account and " "password are correctly filled in the configuration file.") if len(username) < 6 or len(password) < 8: raise RuntimeError("FlexTV登录失败!请在config.ini配置文件中填写正确的FlexTV平台的账号和密码") new_cookies = await login_flextv(username, password, proxy_addr=proxy_addr) if new_cookies: print("Logged into FlexTV platform successfully! Starting to fetch live streaming data...") else: raise RuntimeError("FlexTV login failed") cookies = new_cookies if new_cookies else cookies headers['Cookie'] = cookies html_str = await async_req(url2, proxy_addr=proxy_addr, headers=headers, abroad=True) json_str = re.search('', html_str).group(1) json_data = json.loads(json_str) channel_data = json_data['props']['pageProps']['channel'] live_status = 'message' not in channel_data if live_status: anchor_id = channel_data['owner']['loginId'] anchor_name = f"{channel_data['owner']['nickname']}-{anchor_id}" result["anchor_name"] = anchor_name play_url = await get_flextv_stream_url(url=url, proxy_addr=proxy_addr, cookies=cookies) if play_url: result['is_live'] = True if '.m3u8' in play_url: play_url_list = await get_play_url_list(m3u8=play_url, proxy=proxy_addr, header=headers, abroad=True) if play_url_list: result['m3u8_url'] = play_url result['play_url_list'] = play_url_list else: result['flv_url'] = play_url result['record_url'] = play_url else: url2 = f'https://www.ttinglive.com/channels/{user_id}' html_str = await async_req(url2, proxy_addr=proxy_addr, headers=headers, abroad=True) anchor_name = re.search(' tuple: # 本算法参考项目:https://github.com/785415581/MusicBox/blob/b8f716d43d/doc/analysis/analyze_captured_data.md modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee' \ '341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe487' \ '5d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7' nonce = b'0CoJUm6Qyw8W8jud' public_key = '010001' from Crypto.Cipher import AES from Crypto.Util.Padding import pad import base64 import binascii import secrets def create_secret_key(size: int) -> bytes: charset = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=[]{}|;:,.<>?' return ''.join(secrets.choice(charset) for _ in range(size)).encode('utf-8') def aes_encrypt(_text: str | bytes, _sec_key: str | bytes) -> bytes: if isinstance(_text, str): _text = _text.encode('utf-8') if isinstance(_sec_key, str): _sec_key = _sec_key.encode('utf-8') _sec_key = _sec_key[:16] # 16 (AES-128), 24 (AES-192), or 32 (AES-256) bytes iv = bytes('0102030405060708', 'utf-8') encryptor = AES.new(_sec_key, AES.MODE_CBC, iv) padded_text = pad(_text, AES.block_size) ciphertext = encryptor.encrypt(padded_text) encoded_ciphertext = base64.b64encode(ciphertext) return encoded_ciphertext def rsa_encrypt(_text: str | bytes, pub_key: str, mod: str) -> str: if isinstance(_text, str): _text = _text.encode('utf-8') text_reversed = _text[::-1] text_int = int(binascii.hexlify(text_reversed), 16) encrypted_int = pow(text_int, int(pub_key, 16), int(mod, 16)) return format(encrypted_int, 'x').zfill(256) sec_key = create_secret_key(16) enc_text = aes_encrypt(aes_encrypt(json.dumps(text), nonce), sec_key) enc_sec_key = rsa_encrypt(sec_key, public_key, modulus) return enc_text.decode(), enc_sec_key async def get_looklive_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: """ 通过PC网页端的接口获取完整直播源,只有params和encSecKey这两个加密请求参数。 params: 由两次AES加密完成 ncSecKey: 由一次自写的加密函数完成,值可固定 """ headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0', 'Accept': 'application/json, text/javascript', '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', 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': 'https://look.163.com/', } if cookies: headers['Cookie'] = cookies room_id = re.search('live\\?id=(.*?)&', url).group(1) params, secretkey = get_looklive_secret_data({"liveRoomNo": room_id}) request_data = {'params': params, 'encSecKey': secretkey} api = 'https://api.look.163.com/weapi/livestream/room/get/v3' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers, data=request_data) json_data = json.loads(json_str) anchor_name = json_data['data']['anchor']['nickName'] live_status = json_data['data']['liveStatus'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: result["is_live"] = True if json_data['data']['roomInfo']['liveType'] == 1: print("Look live currently only supports audio live streaming, not video live streaming!") else: play_url_list = json_data['data']['roomInfo']['liveUrl'] live_title = json_data['data']['roomInfo']['title'] result |= { "title": live_title, "flv_url": play_url_list['httpPullUrl'], "m3u8_url": play_url_list['hlsPullUrl'], "record_url": play_url_list['hlsPullUrl'], } return result @trace_error_decorator async def login_popkontv( username: str, password: str, proxy_addr: OptionalStr = None, code: OptionalStr = 'P-00001' ) -> tuple: headers = { 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Authorization': 'Basic FpAhe6mh8Qtz116OENBmRddbYVirNKasktdXQiuHfm88zRaFydTsFy63tzkdZY0u', 'Content-Type': 'application/json', 'Origin': 'https://www.popkontv.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } data = { 'partnerCode': code, 'signId': username, 'signPwd': password, } url = 'https://www.popkontv.com/api/proxy/member/v1/login' try: proxy_addr = utils.handle_proxy_addr(proxy_addr) async with httpx.AsyncClient(proxy=proxy_addr, timeout=20, verify=False) as client: response = await client.post(url, json=data, headers=headers) response.raise_for_status() json_data = response.json() login_status_code = json_data.get("statusCd") if login_status_code == 'E4010': raise Exception("popkontv login failed, please reconfigure the correct login account or password!") elif login_status_code == 'S2000': token = json_data['data'].get("token") partner_code = json_data['data'].get("partnerCode") return token, partner_code else: raise Exception(f"popkontv login failed, {json_data.get('statusMsg', 'unknown error')}") except httpx.HTTPStatusError as e: print(f"HTTP status error occurred during login: {e.response.status_code}") raise except Exception as e: print(f"An exception occurred during popkontv login: {e}") raise @trace_error_decorator async def get_popkontv_stream_data( url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None, username: OptionalStr = None, code: OptionalStr = 'P-00001' ) -> tuple: headers = { 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Content-Type': 'application/json', 'Origin': 'https://www.popkontv.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if cookies: headers['Cookie'] = cookies if 'mcid' in url: anchor_id = re.search('mcid=(.*?)&', url).group(1) else: anchor_id = re.search('castId=(.*?)(?=&|$)', url).group(1) data = { 'partnerCode': code, 'searchKeyword': anchor_id, 'signId': username, } api = 'https://www.popkontv.com/api/proxy/broadcast/v1/search/all' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers, json_data=data, abroad=True) json_data = json.loads(json_str) partner_code = '' anchor_name = 'Unknown' for item in json_data['data']['broadCastList']: if item['mcSignId'] == anchor_id: mc_name = item['nickName'] anchor_name = f"{mc_name}-{anchor_id}" partner_code = item['mcPartnerCode'] break if not partner_code: if 'mcPartnerCode' in url: regex_result = re.search('mcPartnerCode=(P-\\d+)', url) else: regex_result = re.search('partnerCode=(P-\\d+)', url) partner_code = regex_result.group(1) if regex_result else code notices_url = f'https://www.popkontv.com/channel/notices?mcid={anchor_id}&mcPartnerCode={partner_code}' notices_response = await async_req(notices_url, proxy_addr=proxy_addr, headers=headers, abroad=True) mc_name_match = re.search(r'"mcNickName":"([^"]+)"', notices_response) mc_name = mc_name_match.group(1) if mc_name_match else 'Unknown' anchor_name = f"{anchor_id}-{mc_name}" live_url = f"https://www.popkontv.com/live/view?castId={anchor_id}&partnerCode={partner_code}" html_str2 = await async_req(live_url, proxy_addr=proxy_addr, headers=headers, abroad=True) json_str2 = re.search('', html_str2).group(1) json_data2 = json.loads(json_str2) if 'mcData' in json_data2['props']['pageProps']: room_data = json_data2['props']['pageProps']['mcData']['data'] is_private = room_data['mc_isPrivate'] cast_start_date_code = room_data['mc_castStartDate'] mc_sign_id = room_data['mc_signId'] cast_type = room_data['castType'] return anchor_name, [cast_start_date_code, partner_code, mc_sign_id, cast_type, is_private] else: return anchor_name, None @trace_error_decorator async def get_popkontv_stream_url( url: str, proxy_addr: OptionalStr = None, access_token: OptionalStr = None, username: OptionalStr = None, password: OptionalStr = None, partner_code: OptionalStr = 'P-00001' ) -> dict: headers = { 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'ClientKey': 'Client FpAhe6mh8Qtz116OENBmRddbYVirNKasktdXQiuHfm88zRaFydTsFy63tzkdZY0u', 'Content-Type': 'application/json', 'Origin': 'https://www.popkontv.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } if access_token: headers['Authorization'] = f'Bearer {access_token}' anchor_name, room_info = await get_popkontv_stream_data( url, proxy_addr=proxy_addr, code=partner_code, username=username) result = {"anchor_name": anchor_name, "is_live": False} new_token = None if room_info: cast_start_date_code, cast_partner_code, mc_sign_id, cast_type, is_private = room_info result["is_live"] = True room_password = get_params(url, "pwd") if int(is_private) != 0 and not room_password: raise RuntimeError(f"Failed to retrieve live room data because {anchor_name}'s room is a private room. " f"Please configure the room password and try again.") async def fetch_data(header: dict = None, code: str = None) -> str: data = { 'androidStore': 0, 'castCode': f'{mc_sign_id}-{cast_start_date_code}', 'castPartnerCode': cast_partner_code, 'castSignId': mc_sign_id, 'castType': cast_type, 'commandType': 0, 'exePath': 5, 'isSecret': is_private, 'partnerCode': code, 'password': room_password, 'signId': username, 'version': '4.6.2', } play_api = 'https://www.popkontv.com/api/proxy/broadcast/v1/castwatchonoffguest' return await async_req(play_api, proxy_addr=proxy_addr, json_data=data, headers=header, abroad=True) json_str = await fetch_data(headers, partner_code) if 'HTTP Error 400' in json_str or 'statusCd":"E5000' in json_str: print("Failed to retrieve popkontv live stream [token does not exist or has expired]: Please log in to " "watch.") print("Attempting to log in to the popkontv live streaming platform, please ensure your account " "and password are correctly filled in the configuration file.") if len(username) < 4 or len(password) < 10: raise RuntimeError("popkontv login failed! Please enter the correct account and password for the " "popkontv platform in the config.ini file.") print("Logging into popkontv platform...") new_access_token, new_partner_code = await login_popkontv( username=username, password=password, proxy_addr=proxy_addr, code=partner_code ) if new_access_token and len(new_access_token) == 640: print("Logged into popkontv platform successfully! Starting to fetch live streaming data...") headers['Authorization'] = f'Bearer {new_access_token}' new_token = f'Bearer {new_access_token}' json_str = await fetch_data(headers, new_partner_code) else: raise RuntimeError("popkontv login failed, please check if the account and password are correct") json_data = json.loads(json_str) status_msg = json_data["statusMsg"] if json_data['statusCd'] == "L000A": print("Failed to retrieve live stream source,", status_msg) raise RuntimeError("You are an unverified member. After logging into the popkontv official website, " "please verify your mobile phone at the bottom of the 'My Page' > 'Edit My " "Information' to use the service.") elif json_data['statusCd'] == "L0001": cast_start_date_code = int(cast_start_date_code) - 1 json_str = await fetch_data(headers, partner_code) json_data = json.loads(json_str) m3u8_url = json_data['data']['castHlsUrl'] result |= {"m3u8_url": m3u8_url, "record_url": m3u8_url} elif json_data['statusCd'] == "L0000": m3u8_url = json_data['data']['castHlsUrl'] result |= {"m3u8_url": m3u8_url, "record_url": m3u8_url} else: raise RuntimeError("Failed to retrieve live stream source,", status_msg) result['new_token'] = new_token return result @trace_error_decorator async def login_twitcasting( account_type: str, username: str, password: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None ) -> OptionalStr: headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': 'https://twitcasting.tv/indexcaslogin.php?redir=%2Findexloginwindow.php%3Fnext%3D%252F&keep=1', 'Cookie': 'hl=zh; did=04fb08f1b15d248644f1dfa82816d323; _ga=GA1.1.1021187740.1709706998; keep=1; mfadid=yrQiEB26ruRg7mlMavABMBZWdOddzojW; _ga_X8R46Y30YM=GS1.1.1709706998.1.1.1709712274.0.0.0', 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies if account_type == "twitter": login_url = 'https://twitcasting.tv/indexpasswordlogin.php' login_api = 'https://twitcasting.tv/indexpasswordlogin.php?redir=/indexloginwindow.php?next=%2F&keep=1' else: login_url = 'https://twitcasting.tv/indexcaslogin.php?redir=%2F&keep=1' login_api = 'https://twitcasting.tv/indexcaslogin.php?redir=/indexloginwindow.php?next=%2F&keep=1' html_str = await async_req(login_url, proxy_addr=proxy_addr, headers=headers) cs_session_id = re.search('', html_str).group(1) data = { 'username': username, 'password': password, 'action': 'login', 'cs_session_id': cs_session_id, } try: cookie_dict = await async_req(login_api, proxy_addr=proxy_addr, headers=headers, data=data, return_cookies=True, timeout=20) if 'tc_ss' in cookie_dict: cookie = utils.dict_to_cookie_str(cookie_dict) return cookie except Exception as e: print("TwitCasting login error,", e) @trace_error_decorator async def get_twitcasting_stream_url( url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None, account_type: OptionalStr = None, username: OptionalStr = None, password: OptionalStr = None, ) -> dict: headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Referer': 'https://twitcasting.tv/?ch0', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', } anchor_id = url.split('/')[3] if cookies: headers['Cookie'] = cookies async def get_data(header) -> tuple: html_str = await async_req(url, proxy_addr=proxy_addr, headers=header) anchor = re.search("(.*?) \\(@(.*?)\\) 的直播 - Twit", html_str) title = re.search('<meta name="twitter:title" content="(.*?)">\n\\s+<meta', html_str) status = re.search('data-is-onlive="(.*?)"\n\\s+data-view-mode', html_str) movie_id = re.search('data-movie-id="(.*?)" data-audience-id', html_str) return f'{anchor.group(1).strip()}-{anchor.group(2)}-{movie_id.group(1)}', status.group(1), title.group(1) result = {"anchor_name": '', "is_live": False} new_cookie = None try: to_login = get_params(url, "login") if to_login == 'true': print("Attempting to log in to TwitCasting...") new_cookie = await login_twitcasting( account_type=account_type, username=username, password=password, proxy_addr=proxy_addr, cookies=cookies) if not new_cookie: raise RuntimeError("TwitCasting login failed, please check if the account password in the " "configuration file is correct") print("TwitCasting login successful! Starting to fetch data...") headers['Cookie'] = new_cookie anchor_name, live_status, live_title = await get_data(headers) except AttributeError: print("Failed to retrieve TwitCasting data, attempting to log in...") new_cookie = await login_twitcasting( account_type=account_type, username=username, password=password, proxy_addr=proxy_addr, cookies=cookies) if not new_cookie: raise RuntimeError("TwitCasting login failed, please check if the account and password in the " "configuration file are correct") print("TwitCasting login successful! Starting to fetch data...") headers['Cookie'] = new_cookie anchor_name, live_status, live_title = await get_data(headers) result["anchor_name"] = anchor_name if live_status == 'true': url_streamserver = f"https://twitcasting.tv/streamserver.php?target={anchor_id}&mode=client&player=pc_web" stream_data = await async_req(url_streamserver, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(stream_data) if not json_data.get('tc-hls') or not json_data['tc-hls'].get("streams"): raise RuntimeError("No m3u8_url,please check the url") stream_dict = json_data['tc-hls']["streams"] quality_order = {"high": 0, "medium": 1, "low": 2} sorted_streams = sorted(stream_dict.items(), key=lambda item: quality_order[item[0]]) play_url_list = [url for quality, url in sorted_streams] result |= {'title': live_title, 'is_live': True, "play_url_list": play_url_list} result['new_cookies'] = new_cookie return result @trace_error_decorator async def get_baidu_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Connection': 'keep-alive', 'Referer': 'https://live.baidu.com/', 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies uid = random.choice([ 'h5-683e85bdf741bf2492586f7ca39bf465', 'h5-c7c6dc14064a136be4215b452fab9eea', 'h5-4581281f80bb8968bd9a9dfba6050d3a' ]) room_id = re.search('room_id=(.*?)&', url).group(1) params = { 'cmd': '371', 'action': 'star', 'service': 'bdbox', 'osname': 'baiduboxapp', 'data': '{"data":{"room_id":"' + room_id + '","device_id":"h5-683e85bdf741bf2492586f7ca39bf465",' '"source_type":0,"osname":"baiduboxapp"},"replay_slice":0,' '"nid":"","schemeParams":{"src_pre":"pc","src_suf":"other",' '"bd_vid":"","share_uid":"","share_cuk":"","share_ecid":"",' '"zb_tag":"","shareTaskInfo":"{\\"room_id\\":\\"9175031377\\"}",' '"share_from":"","ext_params":"","nid":""}}', 'ua': '360_740_ANDROID_0', 'bd_vid': '', 'uid': uid, '_': str(int(time.time() * 1000)), } app_api = f'https://mbd.baidu.com/searchbox?{urllib.parse.urlencode(params)}' json_str = await async_req(url=app_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) key = list(json_data['data'].keys())[0] data = json_data['data'][key] anchor_name = data['host']['name'] result = {"anchor_name": anchor_name, "is_live": False} if data['status'] == "0": result["is_live"] = True live_title = data['video']['title'] play_url_list = data['video']['url_clarity_list'] url_list = [] prefix = 'https://hls.liveshow.bdstatic.com/live/' if play_url_list: for i in play_url_list: url_list.append( prefix + i['urls']['flv'].rsplit('.', maxsplit=1)[0].rsplit('/', maxsplit=1)[1] + '.m3u8') else: play_url_list = data['video']['url_list'] for i in play_url_list: url_list.append(prefix + i['urls'][0]['hls'].rsplit('?', maxsplit=1)[0].rsplit('/', maxsplit=1)[1]) if url_list: result |= {"is_live": True, "title": live_title, 'play_url_list': url_list} return result @trace_error_decorator async def get_weibo_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Cookie': 'XSRF-TOKEN=qAP-pIY5V4tO6blNOhA4IIOD; SUB=_2AkMRNMCwf8NxqwFRmfwWymPrbI9-zgzEieKnaDFrJRMxHRl-yT9kqmkhtRB6OrTuX5z9N_7qk9C3xxEmNR-8WLcyo2PM; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WWemwcqkukCduUO11o9sBqA; WBPSESS=Wk6CxkYDejV3DDBcnx2LOXN9V1LjdSTNQPMbBDWe4lO2HbPmXG_coMffJ30T-Avn_ccQWtEYFcq9fab1p5RR6PEI6w661JcW7-56BszujMlaiAhLX-9vT4Zjboy1yf2l', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', 'Referer': 'https://weibo.com/u/5885340893' } if cookies: headers['Cookie'] = cookies room_id = '' if 'show/' in url: room_id = url.split('?')[0].split('show/')[1] else: uid = url.split('?')[0].rsplit('/u/', maxsplit=1)[1] web_api = f'https://weibo.com/ajax/statuses/mymblog?uid={uid}&page=1&feature=0' json_str = await async_req(web_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) for i in json_data['data']['list']: if 'page_info' in i and i['page_info']['object_type'] == 'live': room_id = i['page_info']['object_id'] break result = {"anchor_name": '', "is_live": False} if room_id: app_api = f'https://weibo.com/l/pc/anchor/live?live_id={room_id}' # app_api = f'https://weibo.com/l/!/2/wblive/room/show_pc_live.json?live_id={room_id}' json_str = await async_req(url=app_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['data']['user_info']['name'] result["anchor_name"] = anchor_name live_status = json_data['data']['item']['status'] if live_status == 1: result["is_live"] = True live_title = json_data['data']['item']['desc'] play_url_list = json_data['data']['item']['stream_info']['pull'] m3u8_url = play_url_list['live_origin_hls_url'] flv_url = play_url_list['live_origin_flv_url'] result['title'] = live_title result['play_url_list'] = [ {"m3u8_url": m3u8_url, "flv_url": flv_url}, {"m3u8_url": m3u8_url.split('_')[0] + '.m3u8', "flv_url": flv_url.split('_')[0] + '.flv'} ] return result @trace_error_decorator async def get_kugou_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', 'Accept': 'application/json', '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', 'Referer': 'https://fanxing2.kugou.com/', } if cookies: headers['Cookie'] = cookies if 'roomId' in url: room_id = re.search('roomId=(\\d+)', url).group(1) else: room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] app_api = f'https://service2.fanxing.kugou.com/roomcen/room/web/cdn/getEnterRoomInfo?roomId={room_id}' json_str = await async_req(url=app_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['data']['normalRoomInfo']['nickName'] result = {"anchor_name": anchor_name, "is_live": False} if not anchor_name: raise RuntimeError( "Music channel live rooms are not supported for recording, please switch to a different live room." ) live_status = json_data['data']['liveType'] if live_status != -1: params = { 'std_rid': room_id, 'std_plat': '7', 'std_kid': '0', 'streamType': '1-2-4-5-8', 'ua': 'fx-flash', 'targetLiveTypes': '1-5-6', 'version': '1000', 'supportEncryptMode': '1', 'appid': '1010', '_': str(int(time.time() * 1000)), } api = f'https://fx1.service.kugou.com/video/pc/live/pull/mutiline/streamaddr?{urllib.parse.urlencode(params)}' json_str2 = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data2 = json.loads(json_str2) stream_data = json_data2['data']['lines'] if stream_data: flv_url = stream_data[-1]['streamProfiles'][0]['httpsFlv'][0] result |= {"is_live": True, "flv_url": flv_url, "record_url": flv_url} return result async def get_twitchtv_room_info(url: str, token: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> tuple: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0', 'Accept-Language': 'zh-CN', 'Referer': 'https://www.twitch.tv/', 'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko', 'Client-Integrity': token, 'Content-Type': 'text/plain;charset=UTF-8', } if cookies: headers['Cookie'] = cookies uid = url.split('?')[0].rsplit('/', maxsplit=1)[-1] data = [ { "operationName": "ChannelShell", "variables": { "login": uid }, "extensions": { "persistedQuery": { "version": 1, "sha256Hash": "580ab410bcd0c1ad194224957ae2241e5d252b2c5173d8e0cce9d32d5bb14efe" } } }, ] json_str = await async_req('https://gql.twitch.tv/gql', proxy_addr=proxy_addr, headers=headers, json_data=data, abroad=True) json_data = json.loads(json_str) user_data = json_data[0]['data']['userOrError'] login_name = user_data["login"] nickname = f"{user_data['displayName']}-{login_name}" status = True if user_data['stream'] else False return nickname, status @trace_error_decorator async def get_twitchtv_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', 'Accept-Language': 'en-US', 'Referer': 'https://www.twitch.tv/', 'Client-ID': 'kimne78kx3ncx6brgo4mv6wki5h1ko', 'device-id': generate_random_string(16).lower(), } if cookies: headers['Cookie'] = cookies uid = url.split('?')[0].rsplit('/', maxsplit=1)[-1] data = { "operationName": "PlaybackAccessToken_Template", "query": "query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, " "$isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, " "params: {platform: \"web\", playerBackend: \"mediaplayer\", playerType: $playerType}) @include(if: " "$isLive) { value signature authorization { isForbidden forbiddenReasonCode } __typename " "} videoPlaybackAccessToken(id: $vodID, params: {platform: \"web\", playerBackend: \"mediaplayer\", " "playerType: $playerType}) @include(if: $isVod) { value signature __typename }}", "variables": { "isLive": True, "login": uid, "isVod": False, "vodID": "", "playerType": "site" } } json_str = await async_req('https://gql.twitch.tv/gql', proxy_addr=proxy_addr, headers=headers, json_data=data, abroad=True) json_data = json.loads(json_str) token = json_data['data']['streamPlaybackAccessToken']['value'] sign = json_data['data']['streamPlaybackAccessToken']['signature'] anchor_name, live_status = await get_twitchtv_room_info(url=url, token=token, proxy_addr=proxy_addr, cookies=cookies) result = {"anchor_name": anchor_name, "is_live": live_status} if live_status: play_session_id = random.choice(["bdd22331a986c7f1073628f2fc5b19da", "064bc3ff1722b6f53b0b5b8c01e46ca5"]) params = { "acmb": "e30=", "allow_source": "true", "browser_family": "firefox", "browser_version": "124.0", "cdm": "wv", "fast_bread": "true", "os_name": "Windows", "os_version": "NT%2010.0", "p": "3553732", "platform": "web", "play_session_id": play_session_id, "player_backend": "mediaplayer", "player_version": "1.28.0-rc.1", "playlist_include_framerate": "true", "reassignments_supported": "true", "sig": sign, "token": token, "transcode_mode": "cbr_v1" } access_key = urllib.parse.urlencode(params) m3u8_url = f'https://usher.ttvnw.net/api/channel/hls/{uid}.m3u8?{access_key}' play_url_list = await get_play_url_list(m3u8=m3u8_url, proxy=proxy_addr, header=headers, abroad=True) result |= {'m3u8_url': m3u8_url, 'play_url_list': play_url_list} return result @trace_error_decorator async def get_liveme_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://www.liveme.com', 'referer': 'https://www.liveme.com', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies if 'index.html' not in url: html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers, abroad=True) match_url = re.search('<meta property="og:url" content="(.*?)">', html_str) if match_url: url = match_url.group(1) room_id = url.split("/index.html")[0].rsplit('/', maxsplit=1)[-1] sign_data = execjs.compile(open(f'{JS_SCRIPT_PATH}/liveme.js').read()).call('sign', room_id, f'{JS_SCRIPT_PATH}/crypto-js.min.js') lm_s_sign = sign_data.pop("lm_s_sign") tongdun_black_box = sign_data.pop("tongdun_black_box") platform = sign_data.pop("os") headers['lm-s-sign'] = lm_s_sign params = { 'alias': 'liveme', 'tongdun_black_box': tongdun_black_box, 'os': platform, } api = f'https://live.liveme.com/live/queryinfosimple?{urllib.parse.urlencode(params)}' json_str = await async_req(api, data=sign_data, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) stream_data = json_data['data']['video_info'] anchor_name = stream_data['uname'] live_status = stream_data['status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == "0": m3u8_url = stream_data['hlsvideosource'] flv_url = stream_data['videosource'] result |= { 'is_live': True, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': m3u8_url or flv_url } return result async def get_huajiao_sn(url: str, cookies: OptionalStr = None, proxy_addr: OptionalStr = None) -> tuple | None: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://www.huajiao.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies live_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] api = f'https://www.huajiao.com/l/{live_id}' try: html_str = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) json_str = re.search('var feed = (.*?});', html_str).group(1) json_data = json.loads(json_str) sn = json_data['feed']['sn'] uid = json_data['author']['uid'] nickname = json_data['author']['nickname'] live_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] return nickname, sn, uid, live_id except Exception: utils.replace_url(f'{script_path}/config/URL_config.ini', old=url, new='#' + url) raise RuntimeError("Failed to retrieve live room data, the Huajiao live room address is not fixed, please use " "the anchor's homepage address for recording.") async def get_huajiao_user_info(url: str, cookies: OptionalStr = None, proxy_addr: OptionalStr = None) -> OptionalDict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://www.huajiao.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies if 'user' in url: uid = url.split('?')[0].split('user/')[1] params = { 'uid': uid, 'fmt': 'json', '_': str(int(time.time() * 1000)), } api = f'https://webh.huajiao.com/User/getUserFeeds?{urllib.parse.urlencode(params)}' json_str = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) html_str = await async_req(url=f'https://www.huajiao.com/user/{uid}', proxy_addr=proxy_addr, headers=headers) anchor_name = re.search('<title>(.*?)的主页.*', html_str).group(1) if json_data['data'] and 'sn' in json_data['data']['feeds'][0]['feed']: feed = json_data['data']['feeds'][0]['feed'] return { "anchor_name": anchor_name, "title": feed['title'], "is_live": True, "sn": feed['sn'], "liveid": feed['relateid'], "uid": uid } else: return {"anchor_name": anchor_name, "is_live": False} async def get_huajiao_stream_url_app(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> OptionalDict: headers = { 'User-Agent': 'living/9.4.0 (com.huajiao.seeding; build:2410231746; iOS 17.0.0) Alamofire/9.4.0', 'accept-language': 'zh-Hans-US;q=1.0', 'sdk_version': '1', } if cookies: headers['Cookie'] = cookies room_id = url.rsplit('/', maxsplit=1)[1] api = f'https://live.huajiao.com/feed/getFeedInfo?relateid={room_id}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) if json_data['errmsg'] or not json_data['data'].get('creatime'): print("Failed to retrieve live room data, the Huajiao live room address is not fixed, please manually change " "the address for recording.") return data = json_data['data'] return { "anchor_name": data['author']['nickname'], "title": data['feed']['title'], "is_live": True, "sn": data['feed']['sn'], "liveid": data['feed']['relateid'], "uid": data['author']['uid'] } @trace_error_decorator async def get_huajiao_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://www.huajiao.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies result = {"anchor_name": "", "is_live": False} if 'user/' in url: if not cookies: return result room_data = await get_huajiao_user_info(url, cookies, proxy_addr) else: url = await async_req(url, proxy_addr=proxy_addr, headers=headers, redirect_url=True) if url.rstrip('/') == 'https://www.huajiao.com': print( "Failed to retrieve live room data, the Huajiao live room address is not fixed, please manually change " "the address for recording.") return result room_data = await get_huajiao_stream_url_app(url, proxy_addr) if room_data: result["anchor_name"] = room_data.pop("anchor_name") live_status = room_data.pop("is_live") if live_status: result["title"] = room_data.pop("title") params = { "time": int(time.time() * 1000), "version": "1.0.0", **room_data, "encode": "h265" } api = f'https://live.huajiao.com/live/substream?{urllib.parse.urlencode(params)}' json_str = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) result |= { 'is_live': True, 'flv_url': json_data['data']['h264_url'], 'record_url': json_data['data']['h264_url'], } return result @trace_error_decorator async def get_liuxing_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'Referer': 'https://wap.7u66.com/198189?promoters=0', 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] params = { "promoters": "0", "roomidx": room_id, "currentUrl": f"https://www.7u66.com/{room_id}?promoters=0" } api = f'https://wap.7u66.com/api/ui/room/v1.0.0/live.ashx?{urllib.parse.urlencode(params)}' json_str = await async_req(url=api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) room_info = json_data['data']['roomInfo'] anchor_name = room_info['nickname'] live_status = room_info["live_stat"] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: idx = room_info['idx'] live_id = room_info['liveId1'] flv_url = f'https://txpull1.5see.com/live/{idx}/{live_id}.flv' result |= {'is_live': True, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_showroom_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies if '/room/profile' in url: room_id = url.split('room_id=')[-1] else: html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers, abroad=True) room_id = re.search('href="/room/profile\\?room_id=(.*?)"', html_str).group(1) info_api = f'https://www.showroom-live.com/api/live/live_info?room_id={room_id}' json_str = await async_req(info_api, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) anchor_name = json_data['room_name'] result = {"anchor_name": anchor_name, "is_live": False} live_status = json_data['live_status'] if live_status == 2: result["is_live"] = True web_api = f'https://www.showroom-live.com/api/live/streaming_url?room_id={room_id}&abr_available=1' json_str = await async_req(web_api, proxy_addr=proxy_addr, headers=headers, abroad=True) if json_str: json_data = json.loads(json_str) streaming_url_list = json_data['streaming_url_list'] for i in streaming_url_list: if i['type'] == 'hls_all': m3u8_url = i['url'] result['m3u8_url'] = m3u8_url if m3u8_url: m3u8_url_list = await get_play_url_list(m3u8_url, proxy=proxy_addr, header=headers, abroad=True) if m3u8_url_list: result['play_url_list'] = [f"{m3u8_url.rsplit('/', maxsplit=1)[0]}/{i}" for i in m3u8_url_list] else: result['play_url_list'] = [m3u8_url] result['play_url_list'] = [i.replace('https://', 'http://') for i in result['play_url_list']] break return result @trace_error_decorator async def get_acfun_sign_params(proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> tuple: did = f'web_{utils.generate_random_string(16)}' headers = { 'referer': 'https://live.acfun.cn/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', 'cookie': f'_did={did};', } if cookies: headers['Cookie'] = cookies data = { 'sid': 'acfun.api.visitor', } api = 'https://id.app.acfun.cn/rest/app/visitor/login' json_str = await async_req(api, data=data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) user_id = json_data["userId"] visitor_st = json_data["acfun.api.visitor_st"] return user_id, did, visitor_st @trace_error_decorator async def get_acfun_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'referer': 'https://live.acfun.cn/live/17912421', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies author_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] user_info_api = f'https://live.acfun.cn/rest/pc-direct/user/userInfo?userId={author_id}' json_str = await async_req(user_info_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['profile']['name'] status = 'liveId' in json_data['profile'] result = {"anchor_name": anchor_name, "is_live": False} if status: result["is_live"] = True user_id, did, visitor_st = await get_acfun_sign_params(proxy_addr=proxy_addr, cookies=cookies) params = { 'subBiz': 'mainApp', 'kpn': 'ACFUN_APP', 'kpf': 'PC_WEB', 'userId': user_id, 'did': did, 'acfun.api.visitor_st': visitor_st, } data = { 'authorId': author_id, 'pullStreamType': 'FLV', } play_api = f'https://api.kuaishouzt.com/rest/zt/live/web/startPlay?{urllib.parse.urlencode(params)}' json_str = await async_req(play_api, data=data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_title = json_data['data']['caption'] videoPlayRes = json_data['data']['videoPlayRes'] play_url_list = json.loads(videoPlayRes)['liveAdaptiveManifest'][0]['adaptationSet']['representation'] play_url_list = sorted(play_url_list, key=itemgetter('bitrate'), reverse=True) result |= {'play_url_list': play_url_list, 'title': live_title} return result @trace_error_decorator async def get_changliao_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'Accept': 'application/json, text/plain, */*', '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', 'Referer': 'https://wap.tlclw.com/phone/15777?promoters=0', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] params = { 'roomidx': room_id, 'currentUrl': f'https://wap.tlclw.com/{room_id}', } play_api = f'https://wap.tlclw.com/api/ui/room/v1.0.0/live.ashx?{urllib.parse.urlencode(params)}' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['data']['roomInfo']['nickname'] live_status = json_data['data']['roomInfo']['live_stat'] async def get_live_domain(page_url): html_str = await async_req(page_url, proxy_addr=proxy_addr, headers=headers) config_json_str = re.findall("var config = (.*?)config.webskins", html_str, re.DOTALL)[0].rsplit(";", maxsplit=1)[0].strip() config_json_data = json.loads(config_json_str) stream_flv_domain = config_json_data['domainpullstream_flv'] stream_hls_domain = config_json_data['domainpullstream_hls'] return stream_flv_domain, stream_hls_domain result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: flv_domain, hls_domain = await get_live_domain(url) live_id = json_data['data']['roomInfo']['liveID'] flv_url = f'{flv_domain}/{live_id}.flv' m3u8_url = f'{hls_domain}/{live_id}.m3u8' result |= {'is_live': True, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_yingke_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Referer': 'https://www.inke.cn/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies parsed_url = urllib.parse.urlparse(url) query_params = urllib.parse.parse_qs(parsed_url.query) uid = query_params['uid'][0] live_id = query_params['id'][0] params = { 'uid': uid, 'id': live_id, '_t': str(int(time.time())), } api = f'https://webapi.busi.inke.cn/web/live_share_pc?{urllib.parse.urlencode(params)}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['data']['media_info']['nick'] live_status = json_data['data']['status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: m3u8_url = json_data['data']['live_addr'][0]['hls_stream_addr'] flv_url = json_data['data']['live_addr'][0]['stream_addr'] result |= {'is_live': True, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': m3u8_url} return result @trace_error_decorator async def get_yinbo_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'Accept': 'application/json, text/plain, */*', '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', 'Referer': 'https://live.ybw1666.com/800005143?promoters=0', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] params = { 'roomidx': room_id, 'currentUrl': f'https://wap.ybw1666.com/{room_id}', } play_api = f'https://wap.ybw1666.com/api/ui/room/v1.0.0/live.ashx?{urllib.parse.urlencode(params)}' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) room_data = json_data['data']['roomInfo'] anchor_name = room_data['nickname'] live_status = room_data['live_stat'] async def get_live_domain(page_url): html_str = await async_req(page_url, proxy_addr=proxy_addr, headers=headers) config_json_str = re.findall("var config = (.*?)config.webskins", html_str, re.DOTALL)[0].rsplit(";", maxsplit=1)[0].strip() config_json_data = json.loads(config_json_str) stream_flv_domain = config_json_data['domainpullstream_flv'] stream_hls_domain = config_json_data['domainpullstream_hls'] return stream_flv_domain, stream_hls_domain result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: flv_domain, hls_domain = await get_live_domain(url) live_id = room_data['liveID'] flv_url = f'{flv_domain}/{live_id}.flv' m3u8_url = f'{hls_domain}/{live_id}.m3u8' result |= {'is_live': True, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_zhihu_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies if 'people/' in url: user_id = url.split('people/')[1] api = f'https://api.zhihu.com/people/{user_id}/profile?profile_new_version=' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_page_url = json_data['drama']['living_theater']['theater_url'] else: live_page_url = url web_id = live_page_url.split('?')[0].rsplit('/', maxsplit=1)[-1] html_str = await async_req(live_page_url, proxy_addr=proxy_addr, headers=headers) json_str2 = re.findall('', html_str)[0] json_data2 = json.loads(json_str2) live_data = json_data2['initialState']['theater']['theaters'][web_id] anchor_name = live_data['actor']['name'] live_status = live_data['drama']['status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: live_title = live_data['theme'] play_url = live_data['drama']['playInfo'] result |= { 'is_live': True, 'title': live_title, 'm3u8_url': play_url['hlsUrl'], 'flv_url': play_url['playUrl'], 'record_url': play_url['hlsUrl'] } return result @trace_error_decorator async def get_chzzk_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'origin': 'https://chzzk.naver.com', 'referer': 'https://chzzk.naver.com/live/458f6ec20b034f49e0fc6d03921646d2', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] play_api = f'https://api.chzzk.naver.com/service/v3/channels/{room_id}/live-detail' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) live_data = json_data['content'] anchor_name = live_data['channel']['channelName'] live_status = live_data['status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 'OPEN': play_data = json.loads(live_data['livePlaybackJson']) m3u8_url = play_data['media'][0]['path'] m3u8_url_list = await get_play_url_list(m3u8_url, proxy=proxy_addr, header=headers, abroad=True) prefix = m3u8_url.split('?')[0].rsplit('/', maxsplit=1)[0] m3u8_url_list = [prefix + '/' + i for i in m3u8_url_list] result |= {"is_live": True, "m3u8_url": m3u8_url, "play_url_list": m3u8_url_list} return result @trace_error_decorator async def get_haixiu_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://www.haixiutv.com', 'referer': 'https://www.haixiutv.com/', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = url.split("?")[0].rsplit('/', maxsplit=1)[-1] if 'haixiutv' in url: access_token = "pLXSC%252FXJ0asc1I21tVL5FYZhNJn2Zg6d7m94umCnpgL%252BuVm31GQvyw%253D%253D" else: access_token = "s7FUbTJ%252BjILrR7kicJUg8qr025ZVjd07DAnUQd8c7g%252Fo4OH9pdSX6w%253D%253D" params = { "accessToken": access_token, "tku": "3000006", "c": "10138100100000", "_st1": int(time.time() * 1000) } ajax_data = execjs.compile(open(f'{JS_SCRIPT_PATH}/haixiu.js').read()).call('sign', params, f'{JS_SCRIPT_PATH}/crypto-js.min.js') params["accessToken"] = urllib.parse.unquote(urllib.parse.unquote(access_token)) params['_ajaxData1'] = ajax_data params['_'] = int(time.time() * 1000) if 'haixiutv' in url: api = f'https://service.haixiutv.com/v2/room/{room_id}/media/advanceInfoRoom?{urllib.parse.urlencode(params)}' else: headers['origin'] = 'https://www.lehaitv.com' headers['referer'] = 'https://www.lehaitv.com' api = f'https://service.lehaitv.com/v2/room/{room_id}/media/advanceInfoRoom?{urllib.parse.urlencode(params)}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) stream_data = json_data['data'] anchor_name = stream_data['nickname'] live_status = stream_data['live_status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: flv_url = stream_data['media_url_web'] result |= {'is_live': True, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_vvxqiu_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'Access-Control-Request-Method': 'GET', 'Origin': 'https://h5webcdn-pro.vvxqiu.com', 'Referer': 'https://h5webcdn-pro.vvxqiu.com/', } if cookies: headers['Cookie'] = cookies room_id = get_params(url, "roomId") api_1 = f'https://h5p.vvxqiu.com/activity-center/fanclub/activity/captain/banner?roomId={room_id}&product=vvstar' json_str = await async_req(api_1, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['data']['anchorName'] if not anchor_name: params = { 'sessionId': '', 'userId': '', 'product': 'vvstar', 'tickToken': '', 'roomId': room_id, } json_str = await async_req( f'https://h5p.vvxqiu.com/activity-center/halloween2023/banner?{urllib.parse.urlencode(params)}', proxy_addr=proxy_addr, headers=headers ) json_data = json.loads(json_str) anchor_name = json_data['data']['memberVO']['memberName'] result = {"anchor_name": anchor_name, "is_live": False} m3u8_url = f'https://liveplay-pro.wasaixiu.com/live/1400442770_{room_id}_{room_id[2:]}_single.m3u8' resp = await async_req(m3u8_url, proxy_addr=proxy_addr, headers=headers) if 'Not Found' not in resp: result |= {'is_live': True, 'm3u8_url': m3u8_url, 'record_url': m3u8_url} return result @trace_error_decorator async def get_17live_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://17.live', 'referer': 'https://17.live/', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] api_1 = f'https://wap-api.17app.co/api/v1/user/room/{room_id}' json_str = await async_req(api_1, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data["displayName"] result = {"anchor_name": anchor_name, "is_live": False} json_data = { 'liveStreamID': room_id, } api_1 = f'https://wap-api.17app.co/api/v1/lives/{room_id}/viewers/alive' json_str = await async_req(api_1, json_data=json_data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_status = json_data.get("status") if live_status and live_status == 2: flv_url = json_data['pullURLsInfo']['rtmpURLs'][0]['urlHighQuality'] result |= {'is_live': True, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_langlive_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://www.lang.live', 'referer': 'https://www.lang.live/', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] api_1 = f'https://api.lang.live/langweb/v1/room/liveinfo?room_id={room_id}' json_str = await async_req(api_1, proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) live_info = json_data['data']['live_info'] anchor_name = live_info['nickname'] live_status = live_info['live_status'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: flv_url = json_data['data']['live_info']['liveurl'] m3u8_url = json_data['data']['live_info']['liveurl_hls'] result |= {'is_live': True, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': m3u8_url} return result @trace_error_decorator async def get_pplive_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Content-Type': 'application/json', 'Origin': 'https://m.pp.weimipopo.com', 'Referer': 'https://m.pp.weimipopo.com/', 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = get_params(url, 'anchorUid') json_data = { 'inviteUuid': '', 'anchorUuid': room_id, } if 'catshow' in url: api = 'https://api.catshow168.com/live/preview' headers['Origin'] = 'https://h.catshow168.com' headers['Referer'] = 'https://h.catshow168.com' else: api = 'https://api.pp.weimipopo.com/live/preview' json_str = await async_req(api, json_data=json_data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_info = json_data['data'] anchor_name = live_info['name'] live_status = live_info['living'] result = {"anchor_name": anchor_name, "is_live": False} if live_status: m3u8_url = live_info['pullUrl'] result |= {'is_live': True, 'm3u8_url': m3u8_url, 'record_url': m3u8_url} return result @trace_error_decorator async def get_6room_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://ios.6.cn/?ver=8.0.3&build=4', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies room_id = url.split('?')[0].rsplit('/', maxsplit=1)[1] html_str = await async_req(f'https://v.6.cn/{room_id}', proxy_addr=proxy_addr, headers=headers) room_id = re.search('rid: \'(.*?)\',\n\\s+roomid', html_str).group(1) data = { 'av': '3.1', 'encpass': '', 'logiuid': '', 'project': 'v6iphone', 'rate': '1', 'rid': '', 'ruid': room_id, } api = 'https://v.6.cn/coop/mobile/index.php?padapi=coop-mobile-inroom.php' json_str = await async_req(api, data=data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) flv_title = json_data['content']['liveinfo']['flvtitle'] anchor_name = json_data['content']['roominfo']['alias'] result = {"anchor_name": anchor_name, "is_live": False} if flv_title: flv_url = f'https://wlive.6rooms.com/httpflv/{flv_title}.flv' result |= {'is_live': True, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_shopee_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept': 'application/json, text/plain, */*', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'referer': 'https://live.shopee.sg/share?from=live&session=802458&share_user_id=', 'user-agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', } if cookies: headers['Cookie'] = cookies result = {"anchor_name": "", "is_live": False} is_living = False if 'live.shopee' not in url and 'uid' not in url: url = await async_req(url, proxy_addr=proxy_addr, headers=headers, redirect_url=True, abroad=True) if 'live.shopee' in url: host_suffix = url.split('/')[2].rsplit('.', maxsplit=1)[1] is_living = get_params(url, 'uid') is None else: host_suffix = url.split('/')[2].split('.', maxsplit=1)[0] uid = get_params(url, 'uid') api_host = f'https://live.shopee.{host_suffix}' session_id = get_params(url, 'session') if uid: json_str = await async_req(f'{api_host}/api/v1/shop_page/live/ongoing?uid={uid}', proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) if json_data['data']['ongoing_live']: session_id = json_data['data']['ongoing_live']['session_id'] is_living = True else: json_str = await async_req(f'{api_host}/api/v1/shop_page/live/replay_list?offset=0&limit=1&uid={uid}', proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) if json_data['data']['replay']: result['anchor_name'] = json_data['data']['replay'][0]['nick_name'] return result json_str = await async_req(f'{api_host}/api/v1/session/{session_id}', proxy_addr=proxy_addr, headers=headers, abroad=True) json_data = json.loads(json_str) if not json_data.get('data'): print("Fetch shopee live data failed, please update the address of the live broadcast room and try again.") return result uid = json_data['data']['session']['uid'] anchor_name = json_data['data']['session']['nickname'] live_status = json_data['data']['session']['status'] result["anchor_name"] = anchor_name result['uid'] = f'uid={uid}&session={session_id}' if live_status == 1 and is_living: flv_url = json_data['data']['session']['play_url'] title = json_data['data']['session']['title'] result |= {'is_live': True, 'title': title, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_youtube_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers, abroad=True) json_str = re.search('var ytInitialPlayerResponse = (.*?);var meta = document\\.createElement', html_str).group(1) json_data = json.loads(json_str) result = {"anchor_name": "", "is_live": False} if 'videoDetails' not in json_data: print("Error: Please log in to YouTube on your device's webpage and configure cookies in the config.ini") return result result['anchor_name'] = json_data['videoDetails']['author'] live_status = json_data['videoDetails'].get('isLive') if live_status: live_title = json_data['videoDetails']['title'] m3u8_url = json_data['streamingData']["hlsManifestUrl"] play_url_list = await get_play_url_list(m3u8_url, proxy=proxy_addr, header=headers, abroad=True) result |= {"is_live": True, "title": live_title, "m3u8_url": m3u8_url, "play_url_list": play_url_list} return result @trace_error_decorator async def get_taobao_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Referer': 'https://huodong.m.taobao.com/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', 'Cookie': '', } if cookies: headers['Cookie'] = cookies if '_m_h5_tk' not in headers['Cookie']: print('Error: Cookies is empty! please input correct cookies') live_id = get_params(url, 'id') if not live_id: html_str = await async_req(url, proxy_addr=proxy_addr, headers=headers) redirect_url = re.findall("var url = '(.*?)';", html_str)[0] live_id = get_params(redirect_url, 'id') params = { 'jsv': '2.7.0', 'appKey': '12574478', 't': '1733104933120', 'sign': '', 'AntiFlood': 'true', 'AntiCreep': 'true', 'api': 'mtop.mediaplatform.live.livedetail', 'v': '4.0', 'preventFallback': 'true', 'type': 'jsonp', 'dataType': 'jsonp', 'callback': 'mtopjsonp1', 'data': '{"liveId":"' + live_id + '","creatorId":null}', } for i in range(2): app_key = '12574478' _m_h5_tk = re.findall('_m_h5_tk=(.*?);', headers['Cookie'])[0] t13 = int(time.time() * 1000) pre_sign_str = f'{_m_h5_tk.split("_")[0]}&{t13}&{app_key}&' + params['data'] sign = execjs.compile(open(f'{JS_SCRIPT_PATH}/taobao-sign.js').read()).call('sign', pre_sign_str) params |= {'sign': sign, 't': t13} api = f'https://h5api.m.taobao.com/h5/mtop.mediaplatform.live.livedetail/4.0/?{urllib.parse.urlencode(params)}' jsonp_str, new_cookie = await async_req(url=api, proxy_addr=proxy_addr, headers=headers, timeout=20, return_cookies=True, include_cookies=True) json_data = utils.jsonp_to_json(jsonp_str) ret_msg = json_data['ret'] if ret_msg == ['SUCCESS::调用成功']: anchor_name = json_data['data']['broadCaster']['accountName'] result = {"anchor_name": anchor_name, "is_live": False} live_status = json_data['data']['streamStatus'] if live_status == '1': live_title = json_data['data']['title'] play_url_list = json_data['data']['liveUrlList'] def get_sort_key(item): definition_priority = { "lld": 0, "ld": 1, "md": 2, "hd": 3, "ud": 4 } def_value = item.get('definition') or item.get('newDefinition') priority = definition_priority.get(def_value, -1) return priority play_url_list = sorted(play_url_list, key=get_sort_key, reverse=True) result |= {"is_live": True, "title": live_title, "play_url_list": play_url_list, 'live_id': live_id} return result else: print(f'Error: Taobao live data fetch failed, {ret_msg[0]}') if '_m_h5_tk' in new_cookie and '_m_h5_tk_enc' in new_cookie: headers['Cookie'] = re.sub('_m_h5_tk=(.*?);', new_cookie['_m_h5_tk'], headers['Cookie']) headers['Cookie'] = re.sub('_m_h5_tk_enc=(.*?);', new_cookie['_m_h5_tk_enc'], headers['Cookie']) else: print('Error: Try to update cookie failed, please update the cookies in the configuration file') @trace_error_decorator async def get_jd_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'User-Agent': 'ios/7.830 (ios 17.0; ; iPhone 15 (A2846/A3089/A3090/A3092))', 'origin': 'https://lives.jd.com', 'referer': 'https://lives.jd.com/', 'x-referer-page': 'https://lives.jd.com/', } if cookies: headers['Cookie'] = cookies redirect_url = await async_req(url, proxy_addr=proxy_addr, headers=headers, redirect_url=True) author_id = get_params(redirect_url, 'authorId') result = {"anchor_name": '', "is_live": False} if not author_id: live_id = re.search('#/(.*?)\\?origin', redirect_url) if not live_id: return result live_id = live_id.group(1) result['anchor_name'] = f'jd_{live_id}' else: data = { 'functionId': 'talent_head_findTalentMsg', 'appid': 'dr_detail', 'body': '{"authorId":"' + author_id + '","monitorSource":"1","userId":""}', } info_api = 'https://api.m.jd.com/talent_head_findTalentMsg' json_str = await async_req(info_api, data=data, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['result']['talentName'] result['anchor_name'] = anchor_name if 'livingRoomJump' not in json_data['result']: return result live_id = json_data['result']['livingRoomJump']['params']['id'] params = { "body": '{"liveId": "' + live_id + '"}', "functionId": "getImmediatePlayToM", "appid": "h5-live" } api = f'https://api.m.jd.com/client.action?{urllib.parse.urlencode(params)}' # backup_api: https://api.m.jd.com/api json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_status = json_data['data']['status'] if live_status == 1: if author_id: data = { 'functionId': 'jdTalentContentList', 'appid': 'dr_detail', 'body': '{"authorId":"' + author_id + '","type":1,"userId":"","page":1,"offset":"-1",' '"monitorSource":"1","pageSize":1}', } json_str2 = await async_req('https://api.m.jd.com/jdTalentContentList', data=data, proxy_addr=proxy_addr, headers=headers) json_data2 = json.loads(json_str2) result['title'] = json_data2['result']['content'][0]['title'] flv_url = json_data['data']['videoUrl'] m3u8_url = json_data['data']['h5VideoUrl'] result |= {"is_live": True, "m3u8_url": m3u8_url, "flv_url": flv_url, "record_url": m3u8_url} return result @trace_error_decorator async def get_faceit_stream_data(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'Referer': 'https://www.faceit.com/zh/players/qpjzz/stream', 'faceit-referer': 'web-next', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', } if cookies: headers['Cookie'] = cookies nickname = re.findall('/players/(.*?)/stream', url)[0] api = f'https://www.faceit.com/api/users/v1/nicknames/{nickname}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) user_id = json_data['payload']['id'] api2 = f'https://www.faceit.com/api/stream/v1/streamings?userId={user_id}' json_str2 = await async_req(api2, proxy_addr=proxy_addr, headers=headers) json_data2 = json.loads(json_str2) platform_info = json_data2['payload'][0] anchor_name = platform_info.get('userNickname') anchor_id = platform_info.get('platformId') platform = platform_info.get('platform') if platform == 'twitch': result = await get_twitchtv_stream_data(f'https://www.twitch.tv/{anchor_id}') result['anchor_name'] = anchor_name else: result = {'anchor_name': anchor_name, 'is_live': False} return result @trace_error_decorator async def get_migu_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'origin': 'https://www.miguvideo.com', 'referer': 'https://www.miguvideo.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', 'appCode': 'miguvideo_default_www', 'appId': 'miguvideo', 'channel': 'H5', } if cookies: headers['Cookie'] = cookies web_id = url.split('?')[0].rsplit('/')[-1] api = f'https://vms-sc.miguvideo.com/vms-match/v6/staticcache/basic/basic-data/{web_id}/miguvideo' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['body']['title'] live_title = json_data['body'].get('title') + '-' + json_data['body'].get('detailPageTitle', '') room_id = json_data['body'].get('pId') result = {"anchor_name": anchor_name, "is_live": False} if not room_id: return result params = { 'contId': room_id, 'rateType': '3', 'clientId': str(uuid.uuid4()), 'timestamp': int(time.time() * 1000), 'flvEnable': 'true', 'xh265': 'false', 'chip': 'mgwww', 'channelId': '', } api = f'https://webapi.miguvideo.com/gateway/playurl/v3/play/playurl?{urllib.parse.urlencode(params)}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) live_status = json_data['body']['content']['currentLive'] if live_status != '1': return result else: result['title'] = live_title source_url = json_data['body']['urlInfo']['url'] async def _get_dd_calcu(url): try: result = subprocess.run( ["node", f"{JS_SCRIPT_PATH}/migu.js", url], capture_output=True, text=True, check=True ) return result.stdout.strip() except execjs.ProgramError: raise execjs.ProgramError('Failed to execute JS code. Please check if the Node.js environment') ddCalcu = await _get_dd_calcu(source_url) real_source_url = f'{source_url}&ddCalcu={ddCalcu}&sv=10010' if '.m3u8' in real_source_url: m3u8_url = await async_req( real_source_url, proxy_addr=proxy_addr, headers=headers, redirect_url=True) result['m3u8_url'] = m3u8_url result['record_url'] = m3u8_url else: result['flv_url'] = real_source_url result['record_url'] = real_source_url result['is_live'] = True return result @trace_error_decorator async def get_lianjie_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', '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', } if cookies: headers['cookie'] = cookies room_id = url.split('?')[0].rsplit('lailianjie.com/', maxsplit=1)[-1] play_api = f'https://api.lailianjie.com/ApiServices/service/live/getRoomInfo?&_$t=&_sign=&roomNumber={room_id}' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) room_data = json_data['data'] anchor_name = room_data['nickname'] live_status = room_data['isonline'] result = {"anchor_name": anchor_name, "is_live": False} if live_status == 1: title = room_data['defaultRoomTitle'] webrtc_url = room_data['videoUrl'] https_url = "https://" + webrtc_url.split('webrtc://')[1] flv_url = https_url.replace('?', '.flv?') m3u8_url = https_url.replace('?', '.m3u8?') result |= {'is_live': True, 'title': title, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_laixiu_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: def generate_uuid(ua_type: str): if ua_type == "mobile": return str(uuid.uuid4()) return str(uuid.uuid4()).replace('-', '') def calculate_sign(ua_type: str = 'pc'): a = int(time.time() * 1000) s = generate_uuid(ua_type) u = 'kk792f28d6ff1f34ec702c08626d454b39pro' input_str = f"web{s}{a}{u}" md5_hash = hashlib.md5(input_str.encode('utf-8')).hexdigest() return { 'timestamp': a, 'imei': s, 'requestId': md5_hash, 'inputString': input_str } sign_data = calculate_sign(ua_type='pc') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0', 'mobileModel': 'web', 'timestamp': str(sign_data['timestamp']), 'loginType': '2', 'versionCode': '10003', 'imei': sign_data['imei'], 'requestId': sign_data['requestId'], 'channel': '9', 'version': '1.0.0', 'os': 'web', 'platform': 'WEB', 'Origin': 'https://www.imkktv.com', 'Referer': 'https://www.imkktv.com/', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', } if cookies: headers['cookie'] = cookies pattern = r"(?:roomId|anchorId)=(.*?)(?=&|$)" match = re.search(pattern, url) room_id = match.group(1) if match else '' play_api = f'https://api.imkktv.com/liveroom/getShareLiveVideo?roomId={room_id}' json_str = await async_req(play_api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) room_data = json_data['data'] anchor_name = room_data['nickname'] live_status = room_data['playStatus'] == 0 result = {"anchor_name": anchor_name, "is_live": False} if live_status: flv_url = room_data['playUrl'] result |= {'is_live': True, 'flv_url': flv_url, 'record_url': flv_url} return result @trace_error_decorator async def get_picarto_stream_url(url: str, proxy_addr: OptionalStr = None, cookies: OptionalStr = None) -> dict: headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0', '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', } if cookies: headers['cookie'] = cookies anchor_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] api = f'https://ptvintern.picarto.tv/api/channel/detail/{anchor_id}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) anchor_name = json_data['channel']['name'] live_status = json_data['channel']['online'] result = {"anchor_name": anchor_name, "is_live": live_status} if live_status: title = json_data['channel']['title'] m3u8_url = f"https://1-edge1-us-newyork.picarto.tv/stream/hls/golive+{anchor_name}/index.m3u8" result |= {'is_live': True, 'title': title, 'm3u8_url': m3u8_url, 'record_url': m3u8_url} return result ================================================ FILE: src/stream.py ================================================ # -*- encoding: utf-8 -*- """ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-15 23:15:00 Update: 2025-02-06 02:28:00 Copyright (c) 2023-2025 by Hmily, All Rights Reserved. Function: Get live stream data. """ import base64 import hashlib import json import time import random import re from operator import itemgetter import urllib.parse import urllib.request from .utils import trace_error_decorator from .spider import ( get_douyu_stream_data, get_bilibili_stream_data ) from .http_clients.async_http import get_response_status QUALITY_MAPPING = {"OD": 0, "BD": 0, "UHD": 1, "HD": 2, "SD": 3, "LD": 4} def get_quality_index(quality) -> tuple: if not quality: return list(QUALITY_MAPPING.items())[0] quality_str = str(quality).upper() if quality_str.isdigit(): quality_int = int(quality_str[0]) quality_str = list(QUALITY_MAPPING.keys())[quality_int] return quality_str, QUALITY_MAPPING.get(quality_str, 0) @trace_error_decorator async def get_douyin_stream_url(json_data: dict, video_quality: str, proxy_addr: str) -> dict: anchor_name = json_data.get('anchor_name') result = { "anchor_name": anchor_name, "is_live": False, } status = json_data.get("status", 4) if status == 2: stream_url = json_data['stream_url'] flv_url_dict = stream_url['flv_pull_url'] flv_url_list: list = list(flv_url_dict.values()) m3u8_url_dict = stream_url['hls_pull_url_map'] m3u8_url_list: list = list(m3u8_url_dict.values()) while len(flv_url_list) < 5: flv_url_list.append(flv_url_list[-1]) m3u8_url_list.append(m3u8_url_list[-1]) video_quality, quality_index = get_quality_index(video_quality) m3u8_url = m3u8_url_list[quality_index] flv_url = flv_url_list[quality_index] ok = await get_response_status(url=m3u8_url, proxy_addr=proxy_addr) if not ok: index = quality_index + 1 if quality_index < 4 else quality_index - 1 m3u8_url = m3u8_url_list[index] flv_url = flv_url_list[index] result |= { 'is_live': True, 'title': json_data['title'], 'quality': video_quality, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': m3u8_url or flv_url, } return result @trace_error_decorator async def get_tiktok_stream_url(json_data: dict, video_quality: str, proxy_addr: str) -> dict: if not json_data: return {"anchor_name": None, "is_live": False} def get_video_quality_url(stream, q_key) -> list: play_list = [] for key in stream: url_info = stream[key]['main'] sdk_params = url_info['sdk_params'] sdk_params = json.loads(sdk_params) vbitrate = int(sdk_params['vbitrate']) v_codec = sdk_params.get('VCodec', '') play_url = '' if url_info.get(q_key): if url_info[q_key].endswith(".flv") or url_info[q_key].endswith(".m3u8"): play_url = url_info[q_key] + '?codec=' + v_codec else: play_url = url_info[q_key] + '&codec=' + v_codec resolution = sdk_params['resolution'] if vbitrate != 0 and resolution: width, height = map(int, resolution.split('x')) play_list.append({'url': play_url, 'vbitrate': vbitrate, 'resolution': (width, height)}) play_list.sort(key=itemgetter('vbitrate'), reverse=True) play_list.sort(key=lambda x: (-x['vbitrate'], -x['resolution'][0], -x['resolution'][1])) return play_list live_room = json_data['LiveRoom']['liveRoomUserInfo'] user = live_room['user'] anchor_name = f"{user['nickname']}-{user['uniqueId']}" status = user.get("status", 4) result = { "anchor_name": anchor_name, "is_live": False, } if status == 2: stream_data = live_room['liveRoom']['streamData']['pull_data']['stream_data'] stream_data = json.loads(stream_data).get('data', {}) flv_url_list = get_video_quality_url(stream_data, 'flv') m3u8_url_list = get_video_quality_url(stream_data, 'hls') while len(flv_url_list) < 5: flv_url_list.append(flv_url_list[-1]) while len(m3u8_url_list) < 5: m3u8_url_list.append(m3u8_url_list[-1]) video_quality, quality_index = get_quality_index(video_quality) flv_dict: dict = flv_url_list[quality_index] m3u8_dict: dict = m3u8_url_list[quality_index] check_url = m3u8_dict.get('url') or flv_dict.get('url') ok = await get_response_status(url=check_url, proxy_addr=proxy_addr, http2=False) if not ok: index = quality_index + 1 if quality_index < 4 else quality_index - 1 flv_dict: dict = flv_url_list[index] m3u8_dict: dict = m3u8_url_list[index] flv_url = flv_dict['url'] m3u8_url = m3u8_dict['url'] result |= { 'is_live': True, 'title': live_room['liveRoom']['title'], 'quality': video_quality, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': m3u8_url or flv_url, } return result @trace_error_decorator async def get_kuaishou_stream_url(json_data: dict, video_quality: str) -> dict: if json_data['type'] == 1 and not json_data["is_live"]: return json_data live_status = json_data['is_live'] result = { "type": 2, "anchor_name": json_data['anchor_name'], "is_live": live_status, } if live_status: quality_mapping_bit = {'OD': 99999, 'BD': 4000, 'UHD': 2000, 'HD': 1000, 'SD': 800, 'LD': 600} if video_quality in QUALITY_MAPPING: quality, quality_index = get_quality_index(video_quality) if 'm3u8_url_list' in json_data: m3u8_url_list = json_data['m3u8_url_list'][::-1] while len(m3u8_url_list) < 5: m3u8_url_list.append(m3u8_url_list[-1]) m3u8_url = m3u8_url_list[quality_index]['url'] result['m3u8_url'] = m3u8_url if 'flv_url_list' in json_data: if 'bitrate' in json_data['flv_url_list'][0]: flv_url_list = json_data['flv_url_list'] flv_url_list = sorted(flv_url_list, key=lambda x: x['bitrate'], reverse=True) quality_str = str(video_quality).upper() if quality_str.isdigit(): video_quality, quality_index_bitrate_value = list(quality_mapping_bit.items())[int(quality_str)] else: quality_index_bitrate_value = quality_mapping_bit.get(quality_str, 99999) video_quality = quality_str quality_index = next( (i for i, x in enumerate(flv_url_list) if x['bitrate'] <= quality_index_bitrate_value), None) if quality_index is None: quality_index = len(flv_url_list) - 1 flv_url = flv_url_list[quality_index]['url'] result['flv_url'] = flv_url result['record_url'] = flv_url else: flv_url_list = json_data['flv_url_list'][::-1] while len(flv_url_list) < 5: flv_url_list.append(flv_url_list[-1]) flv_url = flv_url_list[quality_index]['url'] result |= {'flv_url': flv_url, 'record_url': flv_url} result['is_live'] = True result['quality'] = video_quality return result @trace_error_decorator async def get_huya_stream_url(json_data: dict, video_quality: str) -> dict: game_live_info = json_data['data'][0]['gameLiveInfo'] live_title = game_live_info['introduction'] stream_info_list = json_data['data'][0]['gameStreamInfoList'] anchor_name = game_live_info.get('nick', '') result = { "anchor_name": anchor_name, "is_live": False, } if stream_info_list: select_cdn = stream_info_list[0] flv_url = select_cdn.get('sFlvUrl') stream_name = select_cdn.get('sStreamName') flv_url_suffix = select_cdn.get('sFlvUrlSuffix') hls_url = select_cdn.get('sHlsUrl') hls_url_suffix = select_cdn.get('sHlsUrlSuffix') flv_anti_code = select_cdn.get('sFlvAntiCode') def get_anti_code(old_anti_code: str) -> str: # js地址:https://hd.huya.com/cdn_libs/mobile/hysdk-m-202402211431.js params_t = 100 sdk_version = 2403051612 # sdk_id是13位数毫秒级时间戳 t13 = int(time.time()) * 1000 sdk_sid = t13 # 计算uuid和uid参数值 init_uuid = (int(t13 % 10 ** 10 * 1000) + int(1000 * random.random())) % 4294967295 # 直接初始化 uid = random.randint(1400000000000, 1400009999999) # 经过测试uid也可以使用init_uuid代替 seq_id = uid + sdk_sid # 移动端请求的直播流地址中包含seqId参数 # 计算ws_time参数值(16进制) 可以是当前毫秒时间戳,当然也可以直接使用url_query['wsTime'][0] # 原始最大误差不得慢240000毫秒 target_unix_time = (t13 + 110624) // 1000 ws_time = f"{target_unix_time:x}".lower() # fm参数值是经过url编码然后base64编码得到的,解码结果类似 DWq8BcJ3h6DJt6TY_$0_$1_$2_$3 # 具体细节在上面js中查看,大概在32657行代码开始,有base64混淆代码请自行替换 url_query = urllib.parse.parse_qs(old_anti_code) ws_secret_pf = base64.b64decode(urllib.parse.unquote(url_query['fm'][0]).encode()).decode().split("_")[0] ws_secret_hash = hashlib.md5(f'{seq_id}|{url_query["ctype"][0]}|{params_t}'.encode()).hexdigest() ws_secret = f'{ws_secret_pf}_{uid}_{stream_name}_{ws_secret_hash}_{ws_time}' ws_secret_md5 = hashlib.md5(ws_secret.encode()).hexdigest() anti_code = ( f'wsSecret={ws_secret_md5}&wsTime={ws_time}&seqid={seq_id}&ctype={url_query["ctype"][0]}&ver=1' f'&fs={url_query["fs"][0]}&uuid={init_uuid}&u={uid}&t={params_t}&sv={sdk_version}' f'&sdk_sid={sdk_sid}&codec=264' ) return anti_code new_anti_code = get_anti_code(flv_anti_code) flv_url = f'{flv_url}/{stream_name}.{flv_url_suffix}?{new_anti_code}&ratio=' m3u8_url = f'{hls_url}/{stream_name}.{hls_url_suffix}?{new_anti_code}&ratio=' quality_list = flv_anti_code.split('&exsphd=') if len(quality_list) > 1 and video_quality not in ["OD", "BD"]: pattern = r"(?<=264_)\d+" quality_list = list(re.findall(pattern, quality_list[1]))[::-1] while len(quality_list) < 5: quality_list.append(quality_list[-1]) video_quality_options = { "UHD": quality_list[0], "HD": quality_list[1], "SD": quality_list[2], "LD": quality_list[3] } if video_quality not in video_quality_options: raise ValueError( f"Invalid video quality. Available options are: {', '.join(video_quality_options.keys())}") flv_url = flv_url + str(video_quality_options[video_quality]) m3u8_url = m3u8_url + str(video_quality_options[video_quality]) result |= { 'is_live': True, 'title': live_title, 'quality': video_quality, 'm3u8_url': m3u8_url, 'flv_url': flv_url, 'record_url': flv_url or m3u8_url } return result @trace_error_decorator async def get_douyu_stream_url(json_data: dict, video_quality: str, cookies: str, proxy_addr: str) -> dict: if not json_data["is_live"]: return json_data video_quality_options = { "OD": '0', "BD": '0', "UHD": '3', "HD": '2', "SD": '1', "LD": '1' } rid = str(json_data["room_id"]) json_data.pop("room_id") rate = video_quality_options.get(video_quality, '0') flv_data = await get_douyu_stream_data(rid, rate, cookies=cookies, proxy_addr=proxy_addr) rtmp_url = flv_data['data'].get('rtmp_url') rtmp_live = flv_data['data'].get('rtmp_live') if rtmp_live: flv_url = f'{rtmp_url}/{rtmp_live}' json_data |= {'quality': video_quality, 'flv_url': flv_url, 'record_url': flv_url} return json_data @trace_error_decorator async def get_yy_stream_url(json_data: dict) -> dict: anchor_name = json_data.get('anchor_name', '') result = { "anchor_name": anchor_name, "is_live": False, } if 'avp_info_res' in json_data: stream_line_addr = json_data['avp_info_res']['stream_line_addr'] cdn_info = list(stream_line_addr.values())[0] flv_url = cdn_info['cdn_info']['url'] result |= { 'is_live': True, 'title': json_data['title'], 'quality': 'OD', 'flv_url': flv_url, 'record_url': flv_url } return result @trace_error_decorator async def get_bilibili_stream_url(json_data: dict, video_quality: str, proxy_addr: str, cookies: str) -> dict: anchor_name = json_data["anchor_name"] if not json_data["live_status"]: return { "anchor_name": anchor_name, "is_live": False } room_url = json_data['room_url'] video_quality_options = { "OD": '10000', "BD": '400', "UHD": '250', "HD": '150', "SD": '80', "LD": '80' } select_quality = video_quality_options[video_quality] play_url = await get_bilibili_stream_data( room_url, qn=select_quality, platform='web', proxy_addr=proxy_addr, cookies=cookies) return { 'anchor_name': json_data['anchor_name'], 'is_live': True, 'title': json_data['title'], 'quality': video_quality, 'record_url': play_url } @trace_error_decorator async def get_netease_stream_url(json_data: dict, video_quality: str) -> dict: if not json_data['is_live']: return json_data m3u8_url = json_data['m3u8_url'] flv_url = None if json_data.get('stream_list'): stream_list = json_data['stream_list']['resolution'] order = ['blueray', 'ultra', 'high', 'standard'] sorted_keys = [key for key in order if key in stream_list] while len(sorted_keys) < 5: sorted_keys.append(sorted_keys[-1]) video_quality, quality_index = get_quality_index(video_quality) selected_quality = sorted_keys[quality_index] flv_url_list = stream_list[selected_quality]['cdn'] selected_cdn = list(flv_url_list.keys())[0] flv_url = flv_url_list[selected_cdn] return { "is_live": True, "anchor_name": json_data['anchor_name'], "title": json_data['title'], 'quality': video_quality, "m3u8_url": m3u8_url, "flv_url": flv_url, "record_url": flv_url or m3u8_url } async def get_stream_url(json_data: dict, video_quality: str, url_type: str = 'm3u8', spec: bool = False, hls_extra_key: str | int = None, flv_extra_key: str | int = None) -> dict: if not json_data['is_live']: return json_data play_url_list = json_data['play_url_list'] while len(play_url_list) < 5: play_url_list.append(play_url_list[-1]) video_quality, selected_quality = get_quality_index(video_quality) data = { "anchor_name": json_data['anchor_name'], "is_live": True } def get_url(key): play_url = play_url_list[selected_quality] return play_url[key] if key else play_url if url_type == 'all': m3u8_url = get_url(hls_extra_key) flv_url = get_url(flv_extra_key) data |= { "m3u8_url": json_data['m3u8_url'] if spec else m3u8_url, "flv_url": json_data['flv_url'] if spec else flv_url, "record_url": m3u8_url } elif url_type == 'm3u8': m3u8_url = get_url(hls_extra_key) data |= {"m3u8_url": json_data['m3u8_url'] if spec else m3u8_url, "record_url": m3u8_url} else: flv_url = get_url(flv_extra_key) data |= {"flv_url": flv_url, "record_url": flv_url} data['title'] = json_data.get('title') data['quality'] = video_quality return data ================================================ FILE: src/utils.py ================================================ # -*- coding: utf-8 -*- import json import os import random import shutil import string from pathlib import Path import functools import hashlib import re import traceback from typing import Any from urllib.parse import parse_qs, urlparse from collections import OrderedDict import execjs from .logger import logger import configparser OptionalStr = str | None OptionalDict = dict | None class Color: RED = "\033[31m" GREEN = "\033[32m" YELLOW = "\033[33m" BLUE = "\033[34m" MAGENTA = "\033[35m" CYAN = "\033[36m" WHITE = "\033[37m" RESET = "\033[0m" @staticmethod def print_colored(text, color): print(f"{color}{text}{Color.RESET}") def trace_error_decorator(func: callable) -> callable: @functools.wraps(func) def wrapper(*args: list, **kwargs: dict) -> Any: try: return func(*args, **kwargs) except execjs.ProgramError: logger.warning('Failed to execute JS code. Please check if the Node.js environment') except Exception as e: error_line = traceback.extract_tb(e.__traceback__)[-1].lineno error_info = f"message: type: {type(e).__name__}, {str(e)} in function {func.__name__} at line: {error_line}" logger.error(error_info) return [] return wrapper def check_md5(file_path: str | Path) -> str: with open(file_path, 'rb') as fp: file_md5 = hashlib.md5(fp.read()).hexdigest() return file_md5 def dict_to_cookie_str(cookies_dict: dict) -> str: cookie_str = '; '.join([f"{key}={value}" for key, value in cookies_dict.items()]) return cookie_str def read_config_value(file_path: str | Path, section: str, key: str) -> str | None: config = configparser.ConfigParser() try: config.read(file_path, encoding='utf-8-sig') except Exception as e: print(f"Error occurred while reading the configuration file: {e}") return None if section in config: if key in config[section]: return config[section][key] else: print(f"Key [{key}] does not exist in section [{section}].") else: print(f"Section [{section}] does not exist in the file.") return None def update_config(file_path: str | Path, section: str, key: str, new_value: str) -> None: config = configparser.ConfigParser() try: config.read(file_path, encoding='utf-8-sig') except Exception as e: print(f"An error occurred while reading the configuration file: {e}") return if section not in config: print(f"Section [{section}] does not exist in the file.") return # 转义%字符 escaped_value = new_value.replace('%', '%%') config[section][key] = escaped_value try: with open(file_path, 'w', encoding='utf-8-sig') as configfile: config.write(configfile) print(f"The value of {key} under [{section}] in the configuration file has been updated.") except Exception as e: print(f"Error occurred while writing to the configuration file: {e}") def get_file_paths(directory: str) -> list: file_paths = [] for root, dirs, files in os.walk(directory): for file in files: file_paths.append(os.path.join(root, file)) return file_paths def remove_emojis(text: str, replace_text: str = '') -> str: emoji_pattern = re.compile( "[" "\U0001F1E0-\U0001F1FF" # flags (iOS) "\U0001F300-\U0001F5FF" # symbols & pictographs "\U0001F600-\U0001F64F" # emoticons "\U0001F680-\U0001F6FF" # transport & map symbols "\U0001F700-\U0001F77F" # alchemical symbols "\U0001F780-\U0001F7FF" # Geometric Shapes Extended "\U0001F800-\U0001F8FF" # Supplemental Arrows-C "\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs "\U0001FA00-\U0001FA6F" # Chess Symbols "\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A "\U00002702-\U000027B0" # Dingbats "]+", flags=re.UNICODE ) return emoji_pattern.sub(replace_text, text) def remove_duplicate_lines(file_path: str | Path) -> None: unique_lines = OrderedDict() text_encoding = 'utf-8-sig' with open(file_path, 'r', encoding=text_encoding) as input_file: for line in input_file: unique_lines[line.strip()] = None with open(file_path, 'w', encoding=text_encoding) as output_file: for line in unique_lines: output_file.write(line + '\n') def check_disk_capacity(file_path: str | Path, show: bool = False) -> float: absolute_path = os.path.abspath(file_path) directory = os.path.dirname(absolute_path) disk_usage = shutil.disk_usage(directory) disk_root = Path(directory).anchor free_space_gb = disk_usage.free / (1024 ** 3) if show: print(f"{disk_root} Total: {disk_usage.total / (1024 ** 3):.2f} GB " f"Used: {disk_usage.used / (1024 ** 3):.2f} GB " f"Free: {free_space_gb:.2f} GB\n") return free_space_gb def handle_proxy_addr(proxy_addr): if proxy_addr: if not proxy_addr.startswith('http'): proxy_addr = 'http://' + proxy_addr else: proxy_addr = None return proxy_addr def generate_random_string(length: int) -> str: characters = string.ascii_uppercase + string.digits random_string = ''.join(random.choices(characters, k=length)) return random_string def jsonp_to_json(jsonp_str: str) -> OptionalDict: pattern = r'(\w+)\((.*)\);?$' match = re.search(pattern, jsonp_str) if match: _, json_str = match.groups() json_obj = json.loads(json_str) return json_obj else: raise Exception("No JSON data found in JSONP response.") def replace_url(file_path: str | Path, old: str, new: str) -> None: with open(file_path, 'r', encoding='utf-8-sig') as f: content = f.read() if old in content: with open(file_path, 'w', encoding='utf-8-sig') as f: f.write(content.replace(old, new)) def get_query_params(url: str, param_name: OptionalStr) -> dict | list[str]: parsed_url = urlparse(url) query_params = parse_qs(parsed_url.query) if param_name is None: return query_params else: values = query_params.get(param_name, []) return values