
[![Windows](https://github.com/Corion/WWW-Twitch/workflows/windows/badge.svg)](https://github.com/Corion/WWW-Twitch/actions?query=workflow%3Awindows)
[![MacOS](https://github.com/Corion/WWW-Twitch/workflows/macos/badge.svg)](https://github.com/Corion/WWW-Twitch/actions?query=workflow%3Amacos)
[![Linux](https://github.com/Corion/WWW-Twitch/workflows/linux/badge.svg)](https://github.com/Corion/WWW-Twitch/actions?query=workflow%3Alinux)

# NAME

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

# SYNOPSIS

    use 5.012; # say
    use WWW::Twitch;

    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](https://metacpan.org/pod/HTTP%3A%3ATiny)
    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
