Skip to main content

PyPI version Unit Tests Coverage Status

twitch_auto_clipper

Automatically create Twitch clips when chat activity spikes.

Twitch Auto Clipper monitors Twitch chat and detects moments where a large number of viewers send the same emote/message within a short period of time. When activity exceeds a configurable threshold, it automatically creates a Twitch clip.

https://github.com/user-attachments/assets/de26cc92-f84c-4ed1-9942-328684f99298

Installation

pip install twitch_auto_clipper

Requirements

Minimum Python version supported by twitch_auto_clipper is 3.10.

Quick start

from twitch_auto_clipper.TwitchAutoClipper import TwitchAutoClipper

clipper = TwitchAutoClipper(
    ["Marlon", "Lacy"],
    "YOUR_CLIENT_ID",
    "YOUR_CLIENT_SECRET",
    on_clip=lambda clip: print(clip),
    common_value=1,
    emote_value=2,
    clipable_message_ratio=0.5,
)

clipper.start()
clipper.join()

[!IMPORTANT] client_id and client_secret are saved in TwitchAuthTokens and only sent to the Twitch API.

[!IMPORTANT] Upon initialization of TwitchAutoClipper, your web browser should open to gain clipping permission for your Twitch account (as shown in the demo).

Features

  • Automatically handles Twitch OAuth token refresh
  • Automatically monitors multiple Twitch streams
  • Supports custom emotes/messages as clipping triggers
  • Optional 7TV emote support
  • Runs each streamer in separate thread

How it works

Twitch chat
     │
     ▼
Collect messages
     │
     ▼
Count messages / emotes
     │
     ▼
Detect activity spike
     │
     ▼
Threshold exceeded?
     │
    YES
     ▼
Create Twitch clip
     │
     ▼
Call on_clip callback

Usage

There are two classes that you will typically need:

  • TwitchAutoClipper — monitors Twitch chat and automatically creates clips when a message reaches the configured threshold.
  • Clip — contains information about a clip that was created.

TwitchAutoClipper

TwitchAutoClipper(
    streamers_names,
    client_id,
    client_secret,
    on_clip,
    counter_interval_seconds=...,
    clipable_message_ratio=...,
    clipable_wait=...,
    common_value=...,
    emote_value=...,
    excluded_words=...,
    logging_handlers=...,
    logging_level=...
)
Argument Description
streamers_names List of Twitch usernames to monitor. Usernames are case-insensitive and are converted to lowercase.
client_id Your Twitch application client ID. Available from the Twitch Developer Console.
client_secret Your Twitch application client secret. Available from the Twitch Developer Console.
on_clip Callback function invoked with a Clip instance when a clip is created.
counter_interval_seconds Time interval over which chat message frequencies are counted. Once the interval ends, the counters are reset.
clipable_message_ratio The weighted frequency of the most frequent message divided by the total number of messages received during the current interval. Because messages can have different values (common_value and emote_value), the ratio can exceed 1.
clipable_wait Time to wait before creating a clip after a message reaches the clipping threshold. The waiting and clipping are performed in a separate thread, so this does not block the streamer thread.
common_value Value assigned to a regular chat message. A regular message is any message that is not a 7TV emote when the streamer has a 7TV profile.
emote_value Value assigned to a 7TV emote.
excluded_words Words that should be excluded from message frequency counting.
logging_handlers Logging handlers used by the package. See examples/logger.py for an example using multiple handlers.
logging_level Logging level used by the package. See the Python logging documentation.

[!NOTE] If multiple streamers are configured, on_clip may be called concurrently from multiple threads. Make sure your callback is thread-safe and use the appropriate Python threading APIs when necessary.

Clip

A Clip instance contains information about the clip that was created.

Attribute Description
message The chat message that triggered the clip.
message_count Number of occurrences of the triggering message.
ratio Ratio of the triggering message to the total number of messages received during the counting interval.
broadcaster_id Twitch broadcaster ID of the streamer for whom the clip was created. See the Twitch API documentation.
url URL of the created clip.
timestamp Expected timestamp of the event highlighted by the clip.
duration Clip duration in seconds.

Motivation

There are a lot of AI clippers that are mostly paid services, largely as a result of their high inference costs. But why use AI when, on popular streams, you constantly have thousands of people evaluating the current state of the stream through chat?

By using the audience's reactions, you can extract clips from Twitch with almost no processing power.

Roadmap

  • Analyze Twitch chat through IRC
  • Twitch OAuth authentication
  • Automatically create clips
  • Monitor multiple live streamers
  • Save clips to a log
  • Add automated tests
  • Pip package
  • Web page for constants editing

Download files

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

Source Distribution

twitch_auto_clipper-1.0.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

twitch_auto_clipper-1.0.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitch_auto_clipper-1.0.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for twitch_auto_clipper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5510cc135a2e3bc9ab26e8d88e284b540649d76f1092a2925e9ee799a0e78279
MD5 94e9dfa6b155a82f11c4732fc746ba17
BLAKE2b-256 fdaeb0ffcfc5979fd0246eb8f3f08ee4855fd178bf7bbeedb200ef986e56bb24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for twitch_auto_clipper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e2a47f5f9dbee9dbee06971006febeb840cbd898a92e03cab53b40e6585c82c
MD5 a2086a13c6fb8991a4e6f5dad3c37570
BLAKE2b-256 6023096191de93d2523150fbec0ff43d2a1b08b0eea8d65ca7d4f9f724a3fdf7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page