Skip to content

Commit d0faa83

Browse files
committed
Initial Implementation
1 parent fe8737b commit d0faa83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3610
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[*.go]
9+
indent_style = tab
10+
11+
[Makefile]
12+
indent_style = tab

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ venv/
99
*.dylib
1010
*.test
1111
*.out
12+
twitch-stream-monitor

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.DEFAULT_GOAL := build
2+
3+
build:
4+
go build
5+
6+
fmt:
7+
go fmt ./...
8+
9+
imports:
10+
find internal -name '*.go' -exec goimports -w {} \;
11+
goimports -w *.go
12+
13+
tests:
14+
go test ./... -coverprofile=coverage.out
15+
16+
coverage:
17+
go tool cover -html=coverage.out

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Twitch Stream Monitor
2+
3+
* [Installation and Usage](#installation-and-usage)
4+
* [Installation and Usage (Windows)](#installation-and-usage-windows)
5+
* [Getting Credentials](docs/credentials.md)
6+
* [Webhook Configuration](docs/webhook.md)
7+
* [Environment Variables](docs/environment-variables.md)
8+
* [Development](docs/development.md)
9+
* [Ngrok Support](docs/ngrok.md)
10+
11+
## Installation and Usage
12+
13+
1. Download latest version form the releases page.
14+
2. Extract tar.gz file.
15+
3. Create a `.env` file as descibed in [Environment Variables](docs/environment-variables.md#.env).
16+
4. `cd` to the directory extracted on the step 2.
17+
5. Run `twitch-stream-monitor`.
18+
19+
## Installation and Usage (Windows)
20+
21+
1. Download latest version form the releases page.
22+
2. Extract zip file.
23+
3. Create a `twitch-stream-monitor.bat` file as descibed in [Environment Variables](docs/environment-variables.md#windows).
24+
4. Run `twitch-stream-monitor.bat`.

docs/credentials.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Getting Credentials
2+
3+
For tool to operate, we need a Twitch app. If you do not have one, follow [official documentation](https://dev.twitch.tv/docs/authentication#registration).
4+
5+
When asked, fill:
6+
7+
* **Name**: any name you want
8+
* **OAuth Redirect URLs**: `http://localhost`
9+
* **Category**: any would suffice, `Application Integration` more or less reflects the tool intention
10+
11+
After registration, you'll be presented with **Client IDs** and **Client Secret**. We need both, store them securely. **Client Secret** will be presented only once, so do not miss the opportunity.
12+
13+
After you received both **Client IDs** and **Client Secret**, use them to set `TWITCH_CLIENT_ID` and `TWITCH_CLIENT_SECRET` [environment variables](environment-variables.md) respectively.
14+
15+
## App Access Token
16+
17+
In order to communicate with a Twitch API, we need an App Access Token. By default app will request new token on each startup. You can override this behavior by providing one of the 2 environment variables:
18+
19+
* `TWITCH_APP_ACCESS_TOKEN` - If set, new token won't be requested and its value will be used instead.
20+
* `TWITCH_APP_ACCESS_TOKEN_LOCATION` - File location to store app access token. Next time app starts, it will use token from this file.
21+
22+
It is advised to set `TWITCH_APP_ACCESS_TOKEN_LOCATION`, since it will prevent unnecessary token generation on each restart and will enable auto-reneval of the token upon expiration.

docs/development.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Development
2+
3+
Before you can start working on the code, you need the following tooling:
4+
5+
* Git.
6+
* Go 1.17 or newer.
7+
* Python 3. Used for running tests, should be installed in all modern distros.
8+
* GNU Make. `build-essential` package in Ubuntu, for other distros refer to respective distro documentation.
9+
10+
## Clone the Code
11+
12+
```sh
13+
git clone git@github.com:ZipFile/twitch-stream-monitor.git
14+
cd twitch-stream-monitor
15+
```
16+
17+
## Preparing the Environment
18+
19+
If your intention is to build the code, skip this step.
20+
21+
Otherwise, in order to run tests and experiment with actual stream recording you need a working Python 3 installation and a Streamlink.
22+
23+
If you have both installed - great. If not, you can setup a [Python's virtualenv](https://docs.python.org/3/library/venv.html):
24+
25+
```sh
26+
python -m venv env
27+
. env/bin/activate
28+
```
29+
30+
And then install the Streamlink:
31+
32+
```sh
33+
pip install streamlink
34+
```
35+
36+
Next time whenever you're back to development, use:
37+
38+
```sh
39+
. env/bin/activate
40+
```
41+
42+
In case your streamlink located somewhere else or you do not want to use venv, set a `TWITCH_MONITOR_STREAMLINK_PATH` environment variable to the path pointing to the streamlink executable.
43+
44+
## Build
45+
46+
```sh
47+
make
48+
```
49+
50+
### Windows
51+
52+
```sh
53+
GOOS=windows make
54+
```
55+
56+
## Run Tests
57+
58+
```sh
59+
make tests
60+
```
61+
62+
## Format Code
63+
64+
```sh
65+
make imports
66+
make fmt
67+
```
68+
69+
## .env Support
70+
71+
See [environment variables](environment-variables.md#env).
72+
73+
## Debug Logging
74+
75+
Default logging configuration is to output messages of the level INFO and above in a [CBOR](https://cbor.io/) format so it can be processed by structured-log-aggregating software like [fluentd](https://docs.fluentd.org/parser/json).
76+
77+
For debugging purposes you likely want more verbosity and human-readability. This can be achieved by exporting following environment variables:
78+
79+
```sh
80+
TWITCH_MONITOR_LOG_LEVEL=trace
81+
TWITCH_MONITOR_LOG_PRETTY=true
82+
```
83+
84+
Either export them directly, or put into the `.env` file.
85+
86+
## Testing Webhooks
87+
88+
See [Ngrok Support](ngrok.md).

0 commit comments

Comments
 (0)