Skip to main content

高性能异步Twitter/X Space下载器,支持并发下载和自动合并

Project description

Twitter/X Space Downloader

高性能异步Twitter Space下载器,支持并发下载和自动合并。

功能特点

  • 🚀 异步高速下载,支持100+并发连接
  • 💾 内存流式处理,无临时文件
  • 📦 使用Python库而非命令行工具,更稳定可靠
  • 🔄 自动重试机制,提高下载成功率
  • 📊 实时进度显示和统计信息
  • 🧹 智能缓存清理,支持用户中断
  • 🎵 自动合并音频片段为完整文件

系统要求

  • Python 3.7+
  • ffmpeg 二进制文件(用于音频合并)
  • 网络连接

安装

使用pip安装(推荐)

pip install twitter-space-downloader

安装后,您可以在任何地方使用命令:

# 完整命令名
twitter-space-downloader "https://twitter.com/i/spaces/1234567890"

# 或使用简短别名
tsd "https://twitter.com/i/spaces/1234567890"

从源码安装

克隆仓库并安装:

git clone https://github.com/yourusername/twitter-space-downloader.git
cd twitter-space-downloader
pip install .

系统要求

  • Python 3.7+
  • ffmpeg 二进制文件(用于音频合并)

安装ffmpeg

macOS (使用Homebrew)

brew install ffmpeg

Ubuntu/Debian

sudo apt update
sudo apt install ffmpeg

Windows

  • 下载并安装 FFmpeg
  • 确保ffmpeg在系统PATH中

使用方法

基本用法

twitter-space-downloader "https://twitter.com/i/spaces/1234567890"

# 或使用简短别名
tsd "https://twitter.com/i/spaces/1234567890"

高级选项

# 调整并发数(默认100)
twitter-space-downloader --max-workers 150 "https://twitter.com/i/spaces/1234567890"

# 保留临时文件(主要是m3u8播放列表)
twitter-space-downloader --keep-temp "https://twitter.com/i/spaces/1234567890"

# 调整重试次数(默认3次)
twitter-space-downloader --max-retries 5 "https://twitter.com/i/spaces/1234567890"

# 查看帮助
twitter-space-downloader --help

参数说明

  • --max-workers: 并发下载连接数(推荐50-200,默认100)
  • --keep-temp: 保留临时文件(仅m3u8播放列表文件)
  • --max-retries: 每个片段的最大重试次数(默认3次)

工作原理

  1. 🔍 程序使用yt-dlp库提取Space的音频流信息
  2. 📥 并发下载所有音频片段到内存(无临时文件)
  3. 🔄 使用ffmpeg从内存数据直接合并为完整音频文件
  4. 🧹 自动清理临时的m3u8播放列表文件

性能特点

  • 内存流式处理: 所有音频片段直接在内存中处理,避免磁盘I/O
  • 零临时文件: 不生成临时音频文件,只有m3u8播放列表
  • 高并发: 支持100+并发连接同时下载
  • 智能重试: 失败片段自动重试,不影响其他下载

中断处理

  • Ctrl+C 可随时停止下载
  • 程序会自动清理临时的m3u8文件
  • 内存中的数据会自动释放

性能优化

  • 网络较好: 可增加 --max-workers 到150-200
  • 网络不稳定: 可减少到50-80
  • 重试调整: 根据网络情况调整 --max-retries

故障排除

  1. 安装依赖失败: 确保Python版本3.7+,尝试使用虚拟环境
  2. ffmpeg未找到: 确保ffmpeg已安装且在系统PATH中
  3. 下载失败: 检查Space URL是否正确,网络连接是否稳定
  4. 内存不足: 对于超长Space,可能需要足够的内存

许可证

MIT License - 详见 LICENSE 文件

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twitter_space_downloader-1.0.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twitter_space_downloader-1.0.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file twitter_space_downloader-1.0.0.tar.gz.

File metadata

  • Download URL: twitter_space_downloader-1.0.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for twitter_space_downloader-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7e7dfdfd7fa4af4375281ac0c3ddd31781b7359380828c89efe944a3cbdedc45
MD5 2752314799f1bfa77335f039556b1fe2
BLAKE2b-256 a4067ed88808c8baf0ee3f3cb1ede19fba162322e63513fc8131636a797b6c47

See more details on using hashes here.

File details

Details for the file twitter_space_downloader-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for twitter_space_downloader-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e47a33b7e9cb161ae40411760d3e44b8d5c945a0389b0304d7dd6bf5b89617a
MD5 7ac9b16a9da566eb6087faa880f2f3d4
BLAKE2b-256 c71ad1fe20e33572c32caf9058f2344403452fd0bfba0a0b7e8afb7ebbe4b50d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page