Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streaming download option to Video.bytes() #1186

Merged
merged 1 commit into from
Aug 24, 2024

Conversation

cmooredev
Copy link
Contributor

Add streaming

  • Implements optional streaming functionality for video downloads
  • Maintains existing non-streaming behavior as default
  • Uses httpx for async streaming, keeps requests for synchronous downloads
  • Adds minimal changes to existing codebase

Lets you handle larger videos by allowing concurrent processing or uploading of video chunks, while still keeping the current functionality for users who don’t need streaming.​

Example Usage

async def test_stream_bytes():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        video = api.video(url="https://www.tiktok.com/@davidteathercodes/video/7074717081563942186")
        
        await video.info()

        total_streamed_bytes = 0
        with open("streamed_BYTES.mp4", "wb") as f:
            async for chunk in await video.bytes(stream=True):
                f.write(chunk)
                total_streamed_bytes += len(chunk)
                print(f"Streamed chunk: {len(chunk)} bytes")
        print(f"Total streamed bytes: {total_streamed_bytes}")

@davidteather davidteather merged commit b9bed95 into davidteather:main Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants