m3u

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 8 Imported by: 0

README

M3U

CircleCI 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

This section is empty.

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 Playlist, err 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