Skip to main content

A Python package for YouTube channel analytics

Project description

YTubeInsight

PyPI version Python Versions License: MIT Documentation Status

YTubeInsight is a Python package for effortless YouTube channel analytics. Track video counts, extract details, and gain insights from YouTube channels with ease.

Features

  • Analyze YouTube channels using either full channel URLs or channel IDs
  • Count videos published within the last year
  • Retrieve detailed information about each video (title, publish date, URL)
  • Easy-to-use API with comprehensive error handling
  • Compatibility with Python 3.6+

Installation

You can install YTubeInsight using pip. We recommend using a virtual environment to manage your dependencies. You can choose between venv (built into Python) or conda based on your preference.

Option 1: Using venv

  1. Create a virtual environment:

    python -m venv ytubeinsight-env
    
  2. Activate the virtual environment:

    • On Windows:
      ytubeinsight-env\Scripts\activate
      
    • On macOS and Linux:
      source ytubeinsight-env/bin/activate
      
  3. Install YTubeInsight:

    pip install ytubeinsight
    

Option 2: Using conda

  1. Create a conda environment:

    conda create --name ytubeinsight-env python=3.8
    
  2. Activate the conda environment:

    conda activate ytubeinsight-env
    
  3. Install YTubeInsight:

    pip install ytubeinsight
    

Quick Start

Here's a simple example of how to use YTubeInsight:

from ytubeinsight import analyze_channel

# Replace with your YouTube Data API key
API_KEY = 'YOUR_API_KEY_HERE'

# Analyze a channel by URL
channel_url = 'https://www.youtube.com/channel/UC_x5XG1OV2P6uZZ5FSM9Ttw'
result = analyze_channel(channel_url, API_KEY)

print(f"Videos published in the last year: {result['video_count']}")

# Print details of the first video
if result['video_data']:
    video = result['video_data'][0]
    print(f"Latest video:")
    print(f"Title: {video['title']}")
    print(f"Published on: {video['published_at']}")
    print(f"URL: {video['url']}")

Detailed Usage

Analyzing a channel by URL

from ytubeinsight import analyze_channel

result = analyze_channel('https://www.youtube.com/channel/UC_x5XG1OV2P6uZZ5FSM9Ttw', 'YOUR_API_KEY')

Analyzing a channel by ID

from ytubeinsight import analyze_channel

result = analyze_channel('UCJFp8uSYCjXOMnkUyb3CQ3Q', 'YOUR_API_KEY', is_channel_id=True)

Handling errors

from ytubeinsight import analyze_channel, YTubeInsightError

try:
    result = analyze_channel('invalid_channel_url', 'YOUR_API_KEY')
except YTubeInsightError as e:
    print(f"An error occurred: {str(e)}")

API Reference

analyze_channel(channel_input, api_key, is_channel_id=False)

Analyzes a YouTube channel and returns video data for the past year.

  • channel_input: Either a full channel URL or channel ID
  • api_key: YouTube Data API key
  • is_channel_id: Boolean indicating if channel_input is a channel ID

Returns a dictionary containing:

  • video_count: Number of videos published in the last year
  • video_data: List of dictionaries, each containing video details (title, publish date, URL)

For more detailed API documentation, please visit our Read the Docs page.

Obtaining a YouTube Data API Key

To use YTubeInsight, you need a YouTube Data API key. Here's how to get one:

  1. Go to the Google Developers Console.
  2. Create a new project or select an existing one.
  3. Enable the YouTube Data API v3 for your project.
  4. Create credentials (API key) for your project.
  5. Use this API key in your YTubeInsight calls.

Remember to keep your API key secret and never share it publicly.

Requirements

  • Python 3.6+
  • google-api-python-client
  • requests
  • beautifulsoup4

Development

To set up the development environment:

  1. Clone the repository:

    git clone https://github.com/FahimFBA/YTubeInsight.git
    cd YTubeInsight
    
  2. Create and activate a virtual environment (choose one):

    • Using venv:
      python -m venv venv
      source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
      
    • Using conda:
      conda create --name ytubeinsight-dev python=3.8
      conda activate ytubeinsight-dev
      
  3. Install the development dependencies:

    pip install -e .[dev]
    
  4. Run the tests:

    pytest
    

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the Code of Conduct.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

For a detailed changelog, please see the CHANGELOG.md file.

Acknowledgments

  • Google for providing the YouTube Data API
  • All contributors who help improve this package

Support

If you encounter any problems or have any questions, please open an issue on GitHub.

Disclaimer

This project is not affiliated with, authorized, maintained, sponsored or endorsed by YouTube or any of its affiliates or subsidiaries. This is an independent and unofficial API. Use at your own risk.

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

ytubeinsight-0.1.1.tar.gz (96.0 kB view details)

Uploaded Source

Built Distribution

ytubeinsight-0.1.1-py3-none-any.whl (110.3 kB view details)

Uploaded Python 3

File details

Details for the file ytubeinsight-0.1.1.tar.gz.

File metadata

  • Download URL: ytubeinsight-0.1.1.tar.gz
  • Upload date:
  • Size: 96.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for ytubeinsight-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f3dd9fe7b0dfa47c19acf8a343581418c01a8499903947b91138d89a656b292
MD5 95af46d1e04fca938fad0322bd71b7a9
BLAKE2b-256 336103584001cba90c03c083148f821e92df9d2dcb7939a1ce8197aaa05562fb

See more details on using hashes here.

File details

Details for the file ytubeinsight-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ytubeinsight-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 110.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for ytubeinsight-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e70944da93e38297e9d03ffa4777e6d80b0097ced5098f93c413d85ecd7f5f9
MD5 046638f546407189f79de581a4c1ab13
BLAKE2b-256 5fbb3dd7ad4e0af32a8d931039618292760822302ee87698a7e7c1e47567d6c1

See more details on using hashes here.

Supported by

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