Skip to main content

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.

[demo]

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

Manually watching an entire stream to find moments worth clipping is time-consuming.

twitch_auto_clipper uses the audience's reaction as a signal: when chat suddenly becomes active around a particular message or emote, the bot can automatically capture the moment.

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-0.1.9.tar.gz (17.4 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-0.1.9-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitch_auto_clipper-0.1.9.tar.gz
  • Upload date:
  • Size: 17.4 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-0.1.9.tar.gz
Algorithm Hash digest
SHA256 abd86836848da46afa0c4eb6b4c331642fda2b3efccb35bbc99bb70395b84280
MD5 79dce0ea7c14c47c14c93b4ac1b2e041
BLAKE2b-256 c62b7a88a8cf579c66834b0a922e0b4f8567b7b900d7ed3c877c20473a923b83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for twitch_auto_clipper-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c96db11774cb7828ad67724a94ab2bd1dd4c3345d20a7f431816b740ae555478
MD5 36907411cc3c079371ff4aa8ec03e205
BLAKE2b-256 191cbaa1ef0914dc9e4c85cb584f8f3c65c4d5cf0356a3c99d8b127972dc55c1

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.1.9 This release

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