Coder Social home page Coder Social logo

twitchlite's Introduction

Twitchlite

A lightweight livestream indexer for twitch.

It's made with basic PHP, HTML and CSS.

This project is using the Twitch helix api.

Default limit is 25 livestreams sorted after the most popular. Limit can go up to 100 and the offset can be used to look through less popular channels.

You can also choose livestreams playing a specific game. There is an option to pull the most popular games for autocompletion. This is enabled by default, but can be disabled in the config.php. The default amount of games is pulled is 100, but can customized in config.php.

With the new helix api you need to provide an oauth token before you can get any streams. If you also provide your user ID you can also get a list of live channels that you're following. After you provide the user ID a "Only followed" checkbox will appear in the top, where you then can submit a query to only see the channels you follow. There is an option you can add to config.php to have this view as the default view.

Installation

You can either clone the repo and set it up just as you would any other PHP site or you can have a look at the php-fpm based docker container https://hub.docker.com/r/mwalbeck/twitchlite

Setup

The following setup is only needed if you would like to use the only followed functionality. For it to work you need to an OAuth token and your numerical user id.

OAuth token

To get an oauth token please navigate to the following link.

https://id.twitch.tv/oauth2/authorize?client_id=tfdaga4350ved4acxim5958z1qcr8y&redirect_uri=http://localhost:8081&response_type=token&scope=user:read:follows

When you click on it, you will be asked to login to your twitch account if you aren't already logged in. Then you will be redirected to http://localhost:8081. The redirect URL should look something like the example below:

http://localhost:8081/#access_token=ukwr5ypmc3hzkrh7acwsh5x48bfuzy&scope=user%3Aread%3Afollows&token_type=bearer

You can then take the access_token from that URL. In this example it would be ukwr5ypmc3hzkrh7acwsh5x48bfuzy. Place that token in the config file as the oauth_token.

User ID

After you have got your OAuth token, you can retrieve your user id. To do so simply run the following cURL request, putting in the OAuth token you just got.

curl -X GET 'https://api.twitch.tv/helix/users' \
-H 'Authorization: Bearer PUT_OAUTH_TOKEN_HERE' \
-H 'Client-Id: tfdaga4350ved4acxim5958z1qcr8y'

Then in begining of the JSON response you should be able to find your id, just grab that and place it into your config.php as the user_id.

Config

For easy configuration place a config.php file in the root directory. Below you can see the available options. The assigned value is the default and in parentheses you can see the available options.

<?php
$oauth_token = "";
$user_id = "";
$only_followed_default = false; (true|false)
$default_limit = "25"; (1-100)
$get_top_games = true; (true|false)
$top_games_limit = "100"; (1-100)

if you wish to change one of the variables in logic.php you can simply override it by placing a variable with the same name in config.php with your desired value.

Demo

If you would like to try out Twitchlite you can visit the demo site at https://twitchlite.mwalbeck.org

twitchlite's People

Contributors

mwalbeck avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

twitchlite's Issues

When using "only followed" combined with a specified game, pagination problems occur

Environment
OS: CentOS 7
PHP: 7.3.13
Apache: 2.4.6

Issue
When you specify to use the only_followed_default option and search for a specific game, the results seem to sporadically be displayed across multiple pages. For example, the first page may have one or two streams, but then if you click Next, page two will have maybe three or four streams, etc.

Expected Behavior
When using only_followed_default, all streamers should show up as consolidated across the multiple pages as possible.

Reproduce

  • Clone the repository
  • Create a config.php file and add your valid oauth token and set only_followed_default to true.
  • Browse to the main index.php page
  • Search for a game (i.e. just use Dead by Daylight for an example)
  • Continue clicking "Next"

Additional Information

twitch helix api?

hello! any plans to convert this over to the new helix api, as they are decommissioning api v5 early next year. i tried a few things myself like changing the kraken to helix, and the oauth token header to "Authorization: Bearer xxxx" in the logic file, and using a "new" client id since newly created client ids don't have access to kraken. but i keep getting an error about line 44 on the index.php file. this would be greatly appreciated!

Adding Pagination

I think this should be possible, but essentially it would be great to have something such as a "next page, previous page" or "page 1, page 2" type of navigation. At least for the /streams/ endpoint.

An example query: /kraken/streams?limit=25&offset=25&stream_type=live

Produces pagination information in _links:

_links: {
self: "https://api.twitch.tv/kraken/streams?limit=25&offset=25&stream_type=live",
next: "https://api.twitch.tv/kraken/streams?limit=25&offset=50&stream_type=live",
prev: "https://api.twitch.tv/kraken/streams?limit=25&offset=0&stream_type=live",
featured: "https://api.twitch.tv/kraken/streams/featured",
summary: "https://api.twitch.tv/kraken/streams/summary",
followed: "https://api.twitch.tv/kraken/streams/followed"
}

Next button in pagination is "neverending"

Environment
OS: CentOS 7
PHP: 7.3.13
Apache: 2.4.6

Issue
At the top of the page where the Prev/Next buttons are, the Next button is able to be clicked even when there are no longer streams to be displayed. It continues to bring up blank pages.

Expected Behavior
Once you reach the limit of streams to be displayed, the Next button should become inaccessible.

Reproduce

  • Clone the repository
  • Browse to the main index.php page
  • Search for a game (i.e. just use Cuphead for an example)
  • Continue clicking "Next"

Additional Information

Following List?

Hello!

This is a very simple, basic PHP application that I've been looking for. However I was wondering if it was possible to do/add one thing with it. Instead of just pulling the top streamers, or streamers of a particular game, I was wondering if it would be possible to pull and display a list of streamers that an account follows?

For example, my use case is that I want a PHP/web page to display only the streamers that I follow that are streaming live.

Thanks!

Search Game Not Working When "followed" Checked

Hello again!

I'm not sure if you're still working on this project, but I still use it to this day. I only recently attempted searching for a game when I had the "Followed" checkmark enabled, and realized that it doesn't actually search for a game. It basically just lists out all the streamers that the corresponding oauth token is following.

Are you able to fix this so where I can have the Followed box checked, and still be able to search games and have them correctly populate?

Thanks again for this!

Limit Not Working

Hello again! I noticed there's an issue with the limit field not being applied. No matter what you specify, it always pulls Twitch's API default which I believe is 25. Not sure if it matters, but my PHP version is 5.6.30. Would you be able to look into this? Again, really love the whole "lite" aspect of this.

Also, this is kind a feature suggestion which I hate to bug you again with one (and I can create a new issue for you if you'd like to be able to reference something in your commits) but having pagination added would be great. Basically having a "Page 2 / Page 3" or "Next Page / Previous Page" kinda thing.

Add Sorting

I feel like I'm the only one who opens cases on this hah, so my apologies.

I'd like to request if there would be any chance to add a sorting option as well? For example, instead of automatically showing by who has the most viewers, maybe allow a reverse of that like who has the lowest viewers? Or maybe sort by followers? Or maybe that there's the new "tags" feature (e.g. Shooter, MOBA, IRL, FPS, etc) that you could sort by.

If not no worries, just thought I'd ask!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.