m3u

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 10 Imported by: 0

README

M3U

Build Pull Request license

A basic golang M3U playlist parser library.

Installation

go get github.com/jamesnetherton/m3u

Usage

Example using a local playlist:

package main

import (
	"fmt"
	"github.com/jamesnetherton/m3u"
)

func main() {
	playlist, err := m3u.Parse("testdata/playlist.m3u")

	if err == nil {
		for _, track := range playlist.Tracks {
			fmt.Println("Track name:", track.Name)
			fmt.Println("Track length:", track.Length)
			fmt.Println("Track URI:", track.URI)
			fmt.Println("Track Tags:")
			for i := range track.Tags {
				fmt.Println(" -",track.Tags[i].Name,"=>",track.Tags[i].Value)

			}
			fmt.Println("----------")
		}	
	} else {
		fmt.Println(err)
	}
}

Example using a remote playlist:

package main

import (
	"fmt"
	"github.com/jamesnetherton/m3u"
)

func main() {
	playlist, err := m3u.Parse("https://raw.githubusercontent.com/jamesnetherton/m3u/master/testdata/playlist.m3u")

	if err == nil {
		for _, track := range playlist.Tracks {
			fmt.Println("Track name:", track.Name)
			fmt.Println("Track length:", track.Length)
			fmt.Println("Track URI:", track.URI)
			fmt.Println("Track Tags:")
			for i := range track.Tags {
				fmt.Println(" -",track.Tags[i].Name,"=>",track.Tags[i].Value)

			}
			fmt.Println("----------")
		}	
	} else {
		fmt.Println(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshall

func Marshall(p Playlist) (io.Reader, error)

Marshall Playlist to an m3u file.

func MarshallInto

func MarshallInto(p Playlist, into *bufio.Writer) error

MarshallInto a *bufio.Writer a Playlist.

Types

type Playlist

type Playlist struct {
	Tracks []Track
}

Playlist is a type that represents an m3u playlist containing 0 or more tracks

func Parse

func Parse(fileName string) (Playlist, error)

Parse parses an m3u playlist with the given file name and returns a Playlist

type Tag

type Tag struct {
	Name  string
	Value string
}

A Tag is a simple key/value pair

type Track

type Track struct {
	Name   string
	Length int
	URI    string
	Tags   []Tag
}

Track represents an m3u track with a Name, Lengh, URI and a set of tags

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL