Code Monkey home page Code Monkey logo

twitchpl's Introduction

twitchpl - Get direct Twitch m3u8 HLS playlist โ–ถ๏ธ๐ŸŽต

Small lib used to extract twitch.tv livestreams HLS playlist for future needs

๐Ÿ”จ Installation

go install github.com/wmw64/twitchpl/cmd/twitchpl@latest

Features

  • ๐Ÿš€ Choose stream quality: best, worst or audio_only

๐Ÿง‘โ€๐Ÿ’ป Usage

CLI

wmw@zsh:~$ twitchpl honeymad
{
        "channel": "honeymad",
        "quality": "best",
        "resolution": "1920x1080",
        "frame_rate": 60,
        "url": "https://video-weaver.fra05.hls.ttvnw.net/v1/playlist/CzmA.m3u8"
}
wmw@zsh:~$

In your project

package main

import (
	"fmt"
	"os"

	"github.com/wmw64/twitchpl"
)

func main() {
	args := os.Args[1:]

	if len(args) == 0 {
		println("Pass twitch channel as an argument. Example: twitchpl asmongold")
		os.Exit(3)
	}

	pl, err := twitchpl.Get(context.Background(), args[0])
	if err != nil {
		panic(err)
	}

	// println(pl.AsJSON()) // Best quality by default
	// {
	// 	"channel": "asmongold",
	// 	"quality": "best",
	// 	"resolution": "1920x1080",
	// 	"frame_rate": 60,
	// 	"url": "https://video-weaver.arn04.hls.ttvnw.net/v1/playlist/C..JIG.m3u8"
	// }

	println(pl.AsURL())
	// https://video-weaver.arn04.hls.ttvnw.net/v1/playlist/C..JIG.m3u8

	//	println(pl.Worst().AsJSON())
	//	println(pl.Best().AsURL())
}

๐Ÿง  What I Learned

  • m3u8 parsing
  • GraphQL requests
  • Golangs basics (HTTP requests, nested structs, error handling)

๐Ÿ“ ToDo

  • Detect if channel doesn't exists
  • Ignore restreams

๐Ÿ‘ค Author & License

ยฉ๏ธ 2021 Ivan Smyshlyaev. MIT License ๐Ÿ‘‰ My instagram page

twitchpl's People

Contributors

evan-sm avatar

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.