Skip to main content

Unit Tests

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_sqrtminusone.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.7.tar.gz (16.2 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.7-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitch_auto_clipper-0.1.7.tar.gz
  • Upload date:
  • Size: 16.2 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.7.tar.gz
Algorithm Hash digest
SHA256 d64adf5e4cc64f75f83b93ab0ab974637be211ee624c2246419d60133c1290b5
MD5 70830b1c852dc8241109d22c397bc9f5
BLAKE2b-256 0b1e92d1b0816076087c68939785827ebc7b50ad032f1d1200419d30d9fa5bf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for twitch_auto_clipper-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 28f8288156543a4cf1f9bee6f07de5046d5f93a7bb9a6c126ecc92cd148ab298
MD5 8df06b7e59fcd9e7ca099bc01af366bd
BLAKE2b-256 977522a84da644e319e1cc0995e604d60b8bc5d3942daedfeae393b24793c5c8

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.1.9

2 files

0.1.8

2 files

This release

0.1.7 This release

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