Skip to main content

Social Media Downloader for Python

Project description


btch-downloader

A Python library for downloading content from various social media platforms asynchronously.

Installation

Python Installation

Install the library using pip:

pip install btch-downloader

Node.js Installation

If using a Node.js project, you can install the btch-downloader package from npm:

npm install btch-downloader

For Node.js usage details, refer to the official npm package documentation.

Prerequisites

  • Python 3.8 or higher (for Python usage)
  • Required dependencies: httpx, asyncio (for Python)
  • Some platforms (e.g., Instagram, Twitter) may require authentication or API keys for full functionality. Refer to the official Python documentation for setup details.

Usage

Python Usage

The library provides asynchronous functions to download content from supported platforms. Below is an example demonstrating how to use each downloader function:

import asyncio
from btch_downloader import ttdl, igdl, twitter, youtube, fbdown, aio, mediafire, capcut, gdrive, pinterest

async def main():
    # TikTok Downloader
    tiktok_result = await ttdl("https://vm.tiktok.com/ZGJAmhSrp/")
    print("TikTok:", tiktok_result)

    # Instagram Downloader
    instagram_result = await igdl("https://www.instagram.com/p/ByxKbUSnubS/?utm_source=ig_web_copy_link")
    print("Instagram:", instagram_result)
    
    # YouTube Downloader
    youtube_result = await youtube("https://www.youtube.com/watch?v=Z28dtg_QmFw")
    print("YouTube:", youtube_result)
    
    # Facebook Downloader
    facebook_result = await fbdown("https://www.facebook.com/watch/?v=1393572814172251")
    print("Facebook:", facebook_result)
    
    # AIO (All-in-One) Downloader
    aio_result = await aio("https://www.facebook.com/watch/?v=1393572814172251")
    print("AIO:", aio_result)
    
    # MediaFire Downloader
    mediafire_result = await mediafire("https://www.mediafire.com/file/941xczxhn27qbby/GBWA_V12.25FF-By.SamMods-.apk/file")
    print("MediaFire:", mediafire_result)
    
    # Capcut Downloader
    capcut_result = await capcut("https://www.capcut.com/template-detail/7299286607478181121?template_id=7299286607478181121&share_token=80302b19-8026-4101-81df-2fd9a9cecb9c&enter_from=template_detail®ion=ID&language=in&platform=copy_link&is_copy_link=1")
    print("Capcut:", capcut_result)
    
    # Google Drive Downloader
    gdrive_result = await gdrive("https://drive.google.com/file/d/1thDYWcS5p5FFhzTpTev7RUv0VFnNQyZ4/view?usp=drivesdk")
    print("Google Drive:", gdrive_result)
    
    # Pinterest Downloader
    pinterest_result = await pinterest("https://pin.it/4CVodSq")
    print("Pinterest:", pinterest_result)
    
    # Pinterest Search
    pinterest_search_result = await pinterest("Zhao Lusi")
    print("Pinterest Search:", pinterest_search_result)
    
    # Twitter Downloader
    twitter_result = await twitter("https://twitter.com/gofoodindonesia/status/1229369819511709697")
    print("Twitter:", twitter_result)

asyncio.run(main())

Error Handling Example

To handle potential errors (e.g., invalid URLs or network issues), save the following code to a file named test.py and run it with a URL or keyword as an argument. Below is an example for all supported functions:

import asyncio
import json
import sys
from btch_downloader import ttdl, igdl, twitter, youtube, fbdown, aio, mediafire, capcut, gdrive, pinterest

async def main(url, function_name):
    try:
        if function_name == "ttdl":
            result = await ttdl(url)
        elif function_name == "igdl":
            result = await igdl(url)
        elif function_name == "twitter":
            result = await twitter(url)
        elif function_name == "youtube":
            result = await youtube(url)
        elif function_name == "fbdown":
            result = await fbdown(url)
        elif function_name == "aio":
            result = await aio(url)
        elif function_name == "mediafire":
            result = await mediafire(url)
        elif function_name == "capcut":
            result = await capcut(url)
        elif function_name == "gdrive":
            result = await gdrive(url)
        elif function_name == "pinterest":
            result = await pinterest(url)
        elif function_name == "pinterest_search":
            result = await pinterest(url)  # For search, URL is a keyword
        else:
            raise ValueError("Invalid function name")
        print(json.dumps(result, indent=2))
    except Exception as e:
        print(json.dumps({"error": str(e)}), file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print(json.dumps({"error": "Please provide a function name and URL/keyword"}), file=sys.stderr)
        sys.exit(1)
    function_name = sys.argv[1]
    url = sys.argv[2]
    asyncio.run(main(url, function_name))

Run the script with a specific function and URL/keyword, for example:

python3 test.py ttdl "https://vm.tiktok.com/ZGJAmhSrp/"
python3 test.py igdl "https://www.instagram.com/p/ByxKbUSnubS/?utm_source=ig_web_copy_link"
python3 test.py youtube "https://www.youtube.com/watch?v=Z28dtg_QmFw"
python3 test.py fbdown "https://www.facebook.com/watch/?v=1393572814172251"
python3 test.py aio "https://www.facebook.com/watch/?v=1393572814172251"
python3 test.py mediafire "https://www.mediafire.com/file/941xczxhn27qbby/GBWA_V12.25FF-By.SamMods-.apk/file"
python3 test.py capcut "https://www.capcut.com/template-detail/7299286607478181121?template_id=7299286607478181121&share_token=80302b19-8026-4101-81df-2fd9a9cecb9c&enter_from=template_detail®ion=ID&language=in&platform=copy_link&is_copy_link=1"
python3 test.py gdrive "https://drive.google.com/file/d/1thDYWcS5p5FFhzTpTev7RUv0VFnNQyZ4/view?usp=drivesdk"
python3 test.py pinterest "https://pin.it/4CVodSq"
python3 test.py pinterest_search "Zhao Lusi"
python3 test.py twitter "https://twitter.com/gofoodindonesia/status/1229369819511709697"

Features

  • Download content from TikTok, Instagram, Twitter, YouTube, Facebook, MediaFire, Capcut, Google Drive, and Pinterest.
  • Asynchronous API calls using httpx for efficient performance (Python).
  • Simple and consistent interface across all platforms.
  • Support for Pinterest search by keyword.

API Reference

Each downloader function accepts a URL (or keyword for Pinterest search) and returns a dictionary containing the downloaded content details.

Common Parameters

  • url (str): The URL of the content to download (e.g., video, image, or file link). For Pinterest search, provide a keyword instead.
  • Optional: Some functions may accept additional parameters (e.g., authentication tokens). Check the official Python documentation or Node.js documentation for details.

Return Value

Each function returns a dictionary with the following possible keys:

  • url (str): Direct URL to the downloaded content (e.g., video or image file).
  • metadata (dict): Additional information about the content (e.g., title, author, or resolution).
  • error (str): Error message if the download fails (only in case of failure).

Supported Platforms and Functions

Function Platform Description
ttdl TikTok Downloads videos or images from TikTok.
igdl Instagram Downloads posts, reels, or stories from Instagram.
twitter Twitter Downloads media from Twitter posts.
youtube YouTube Downloads videos or audio from YouTube.
fbdown Facebook Downloads videos from Facebook.
aio All-in-One Attempts to download from any supported platform.
mediafire MediaFire Downloads files from MediaFire links.
capcut Capcut Downloads templates or videos from Capcut.
gdrive Google Drive Downloads files from Google Drive.
pinterest Pinterest Downloads pins or searches for content by keyword.

Notes

  • Some platforms may require authentication or have rate limits. Ensure you comply with each platform's terms of service.
  • The aio function automatically detects the platform from the URL but may be slower than platform-specific functions.
  • For large files or slow networks, ensure proper error handling and timeouts.

Documentation

License

MIT 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

btch_downloader-4.0.16.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

btch_downloader-4.0.16-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file btch_downloader-4.0.16.tar.gz.

File metadata

  • Download URL: btch_downloader-4.0.16.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for btch_downloader-4.0.16.tar.gz
Algorithm Hash digest
SHA256 adcf66916f479b2d2fbf81bc1d6ef8509503161b0a5f37d728f7aeee1b55316f
MD5 7ecaa83f6d95130c4389a2efb860924b
BLAKE2b-256 8d2c6012faf35343bcec9bac934e7de6b6034a80047cbd51249095364d02d7d1

See more details on using hashes here.

File details

Details for the file btch_downloader-4.0.16-py3-none-any.whl.

File metadata

File hashes

Hashes for btch_downloader-4.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 f237663352b14f216610e40128e355f8f263fefe058cd2e2454dd51519b23c96
MD5 16cc82f09192159fe5b618c2d76b99fa
BLAKE2b-256 e93fde4506a01f1b3601479c085677ba52ebe8824e63e992beefcd89d93200b0

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