The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

WWW::Twitch - automate parts of Twitch without the need for an API key

SYNOPSIS

use 5.012; # say
my $channel = 'corion_de';
my $twitch = WWW::Twitch->new();
my $info = $twitch->live_stream($channel);
if( $info ) {
my $id = $info->{id};
opendir my $dh, '.'
or die "$!";
# If we have stale recordings, maybe our network went down
# in between
my @recordings = grep { /\b$id\.mp4(\.part)?$/ && -M $_ < 30/24/60/60 }
readdir $dh;
if( ! @recordings ) {
say "$channel is live (Stream $id)";
say "Launching youtube-dl";
exec "youtube_dl", '-q', "https://www.twitch.tv/$channel";
} else {
say "$channel is recording (@recordings)";
};
} else {
say "$channel is offline";
}

METHODS

->new

my $twitch = WWW::Twitch->new();

Creates a new Twitch client

device_id

Optional device id. If missing, a hardcoded device id will be used.

client_id

Optional client id. If missing, a hardcoded client id will be used.

client_version

Optional client version. If missing, a hardcoded client version will be used.

ua

Optional HTTP user agent. If missing, a HTTP::Tiny object will be constructed.

->schedule( $channel )

my $schedule = $twitch->schedule( 'somechannel', %options );

Fetch the schedule of a channel

->is_live( $channel )

if( $twitch->is_live( 'somechannel' ) ) {
...
}

Check whether a stream is currently live on a channel

->stream_playback_access_token( $channel )

my $tok = $twitch->stream_playback_access_token( 'somechannel' );
say $tok->{channel_id};

Internal method to fetch the stream playback access token

->live_stream( $channel )

my $tok = $twitch->live_stream( 'somechannel' );

Internal method to fetch information about a stream on a channel

->stream_status( $channel )

my $status = $twitch->stream_status_f( 'somechannel', 'another_channel' );
for my $channel ($status->get) {
say $status->{channel}, $status->{status};
}

Fetches the status of multiple channels