xmltv

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT, MIT Imports: 2 Imported by: 0

README

XMLTV

A Go library for parsing and generating XMLTV formatted data.

Overview

This package provides Go structures for parsing and generating XMLTV formatted data by implementing all elements of the XMLTV DTD.

XMLTV is an XML-based format widely used in electronic program guides (EPG) for describing TV listings.

Installation

go get github.com/sherif-fanous/xmltv

Usage Examples

Parsing XMLTV Data
package main

import (
    "encoding/xml"
    "log"
    "os"

    "github.com/sherif-fanous/xmltv"
)

func main() {
    // Read XMLTV file
    data, err := os.ReadFile("epg.xml")
    if err != nil {
        log.Fatalf("Error reading file: %v", err)
    }

    // Parse XMLTV data
    var epg xmltv.EPG
    if err := xml.Unmarshal(data, &epg); err != nil {
        log.Fatalf("Error parsing XMLTV: %v", err)
    }

    // Access the data
    log.Printf("Found %d channels and %d programmes\n", len(epg.Channels), len(epg.Programmes))

    for _, channel := range epg.Channels {
        for _, displayName := range channel.DisplayNames {
            log.Printf("Channel name: %s\n", displayName.Text)
        }
    }
}
Creating XMLTV Data
package main

import (
    "encoding/xml"
    "io/fs"
    "log"
    "os"
    "time"

    "github.com/sherif-fanous/xmltv"
)

func makePointer[T any](t T) *T {
    return &t
}

func main() {
    now := time.Now()

    // Create a new XMLTV document
    epg := xmltv.EPG{
        GeneratorInfoName: makePointer("My Example Generator"),
        Channels: []xmltv.Channel{
            {
                ID: "channel1.example.com",
                DisplayNames: []xmltv.DisplayName{
                    {Text: "Example TV"},
                    {Text: "ETV", Lang: makePointer("en")},
                },
                Icons: []xmltv.Icon{
                    {Source: "https://example.com/logo.png"},
                },
            },
        },
        Programmes: []xmltv.Programme{
            {
                Start:   xmltv.Time{Time: now},
                Stop:    &xmltv.Time{Time: now.Add(30 * time.Minute)},
                Channel: "channel1.example.com",
                Titles: []xmltv.Title{
                    {Text: "Sample Program"},
                },
                Descriptions: []xmltv.Description{
                    {Text: "This is a sample program description."},
                },
                Categories: []xmltv.Category{
                    {Text: "Entertainment"},
                },
            },
        },
    }

    // Marshal to XML
    output, err := xml.MarshalIndent(epg, "", "  ")
    if err != nil {
        log.Fatalf("Error marshaling XMLTV: %v\n", err)
    }

    // Add XML header
    result := []byte(xml.Header + string(output))

    // Write to file
    if err := os.WriteFile("output.xml", result, fs.FileMode(0644)); err != nil {
        log.Fatalf("Error writing file: %v\n", err)
    }

    log.Println("XMLTV file created successfully!")
}

Documentation

Overview

Package xmltv provides Go structures for parsing and generating XMLTV formatted data by implementing all elements of the XMLTV DTD. XMLTV is an XML-based format widely used in electronic program guides (EPG) for describing TV listings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	XMLName xml.Name         `xml:"actor"`
	Role    *string          `xml:"role,attr,omitempty"`
	IsGuest *types.XMLTVBool `xml:"guest,attr,omitempty"`
	Images  []Image          `xml:"image,omitempty"`
	URLs    []URL            `xml:"url,omitempty"`
	Text    string           `xml:",chardata"`
}

type Adapter

type Adapter struct {
	XMLName xml.Name `xml:"adapter"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type Aspect

type Aspect struct {
	XMLName xml.Name `xml:"aspect"`
	Text    string   `xml:",chardata"`
}

type Audio

type Audio struct {
	XMLName xml.Name         `xml:"audio"`
	Present *types.XMLTVBool `xml:"present,omitempty"`
	Stereo  *Stereo          `xml:"stereo,omitempty"`
}

type Bool

type Bool = types.XMLTVBool

Bool is a public alias of the internal boolean type

type Category

type Category struct {
	XMLName xml.Name `xml:"category"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Channel

type Channel struct {
	XMLName      xml.Name      `xml:"channel"`
	ID           string        `xml:"id,attr"`
	DisplayNames []DisplayName `xml:"display-name"`
	Icons        []Icon        `xml:"icon,omitempty"`
	URLs         []URL         `xml:"url,omitempty"`
}

Channel represents a channel.

type Commentator

type Commentator struct {
	XMLName xml.Name `xml:"commentator"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type Composer

type Composer struct {
	XMLName xml.Name `xml:"composer"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type Country

type Country struct {
	XMLName xml.Name `xml:"country"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Credits

type Credits struct {
	XMLName      xml.Name      `xml:"credits"`
	Directors    []Director    `xml:"director,omitempty"`
	Actors       []Actor       `xml:"actor,omitempty"`
	Writers      []Writer      `xml:"writer,omitempty"`
	Adapters     []Adapter     `xml:"adapter,omitempty"`
	Producers    []Producer    `xml:"producer,omitempty"`
	Composers    []Composer    `xml:"composer,omitempty"`
	Editors      []Editor      `xml:"editor,omitempty"`
	Presenters   []Presenter   `xml:"presenter,omitempty"`
	Commentators []Commentator `xml:"commentator,omitempty"`
	Guests       []Guest       `xml:"guest,omitempty"`
}

type Description

type Description struct {
	XMLName xml.Name `xml:"desc"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Director

type Director struct {
	XMLName xml.Name `xml:"director"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type DisplayName

type DisplayName struct {
	XMLName xml.Name `xml:"display-name"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type EPG

type EPG = TV

EPG is an alias for TV.

type Editor

type Editor struct {
	XMLName xml.Name `xml:"editor"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type EpisodeNumber

type EpisodeNumber struct {
	XMLName xml.Name `xml:"episode-num"`
	System  string   `xml:"system,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Guest

type Guest struct {
	XMLName xml.Name `xml:"guest"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type Icon

type Icon struct {
	XMLName xml.Name `xml:"icon"`
	Source  string   `xml:"src,attr"`
	Width   *int     `xml:"width,attr,omitempty"`
	Height  *int     `xml:"height,attr,omitempty"`
}

type Image

type Image struct {
	XMLName     xml.Name          `xml:"image"`
	Type        *ImageType        `xml:"type,attr,omitempty"`
	Size        *ImageSize        `xml:"size,attr,omitempty"`
	Orientation *ImageOrientation `xml:"orient,attr,omitempty"`
	System      *string           `xml:"system,attr,omitempty"`
	Text        string            `xml:",chardata"`
}

type ImageOrientation

type ImageOrientation string
const (
	ImageOrientationPortrait  ImageOrientation = "P"
	ImageOrientationLandscape ImageOrientation = "L"
)

type ImageSize

type ImageSize int
const (
	ImageSizeSmall  ImageSize = 1
	ImageSizeMedium ImageSize = 2
	ImageSizeLarge  ImageSize = 3
)

type ImageType

type ImageType string
const (
	ImageTypePoster    ImageType = "poster"
	ImageTypeBackdrop  ImageType = "backdrop"
	ImageTypeStill     ImageType = "still"
	ImageTypePerson    ImageType = "person"
	ImageTypeCharacter ImageType = "character"
)

type Keyword

type Keyword struct {
	XMLName xml.Name `xml:"keyword"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Language

type Language struct {
	XMLName xml.Name `xml:"language"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type LastChance

type LastChance struct {
	XMLName xml.Name `xml:"last-chance"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Length

type Length struct {
	XMLName xml.Name    `xml:"length"`
	Units   LengthUnits `xml:"units,attr"`
	Text    *int        `xml:",chardata"`
}

type LengthUnits

type LengthUnits string
const (
	LengthUnitsSeconds LengthUnits = "seconds"
	LengthUnitsMinutes LengthUnits = "minutes"
	LengthUnitsHours   LengthUnits = "hours"
)

type OriginalLanguage

type OriginalLanguage struct {
	XMLName xml.Name `xml:"orig-language"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Premiere

type Premiere struct {
	XMLName xml.Name `xml:"premiere"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Presenter

type Presenter struct {
	XMLName xml.Name `xml:"presenter"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type PreviouslyShown

type PreviouslyShown struct {
	XMLName xml.Name         `xml:"previously-shown"`
	Start   *types.XMLTVTime `xml:"start,attr,omitempty"`
	Channel *string          `xml:"channel,attr,omitempty"`
}

type Producer

type Producer struct {
	XMLName xml.Name `xml:"producer"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

type Programme

type Programme struct {
	XMLName          xml.Name          `xml:"programme"`
	Start            types.XMLTVTime   `xml:"start,attr"`
	Stop             *types.XMLTVTime  `xml:"stop,attr,omitempty"`
	PDCStart         *types.XMLTVTime  `xml:"pdc-start,attr,omitempty"`
	VPSStart         *types.XMLTVTime  `xml:"vps-start,attr,omitempty"`
	ShowView         *string           `xml:"showview,attr,omitempty"`
	VideoPlus        *string           `xml:"videoplus,attr,omitempty"`
	Channel          string            `xml:"channel,attr"`
	ClumpIndex       *string           `xml:"clumpidx,attr,omitempty"`
	Titles           []Title           `xml:"title"`
	SubTitles        []SubTitle        `xml:"sub-title,omitempty"`
	Descriptions     []Description     `xml:"desc,omitempty"`
	Credits          *Credits          `xml:"credits,omitempty"`
	Date             *types.XMLTVTime  `xml:"date,omitempty"`
	Categories       []Category        `xml:"category,omitempty"`
	Keywords         []Keyword         `xml:"keyword,omitempty"`
	Language         *Language         `xml:"language,omitempty"`
	OriginalLanguage *OriginalLanguage `xml:"orig-language,omitempty"`
	Length           *Length           `xml:"length,omitempty"`
	Icons            []Icon            `xml:"icon,omitempty"`
	URLs             []URL             `xml:"url,omitempty"`
	Countries        []Country         `xml:"country,omitempty"`
	EpisodeNumbers   []EpisodeNumber   `xml:"episode-num,omitempty"`
	Video            *Video            `xml:"video,omitempty"`
	Audio            *Audio            `xml:"audio,omitempty"`
	PreviouslyShown  *PreviouslyShown  `xml:"previously-shown,omitempty"`
	Premiere         *Premiere         `xml:"premiere,omitempty"`
	Lastchance       *LastChance       `xml:"last-chance,omitempty"`
	IsNew            types.XMLTVBool   `xml:"new,omitempty"`
	Subtitles        []Subtitles       `xml:"subtitles,omitempty"`
	Ratings          []Rating          `xml:"rating,omitempty"`
	StarRatings      []StarRating      `xml:"star-rating,omitempty"`
	Reviews          []Review          `xml:"review,omitempty"`
	Images           []Image           `xml:"image,omitempty"`
}

Programme represents a programme.

type Quality

type Quality struct {
	XMLName xml.Name `xml:"quality"`
	Text    string   `xml:",chardata"`
}

type Rating

type Rating struct {
	XMLName xml.Name `xml:"rating"`
	System  *string  `xml:"system,attr,omitempty"`
	Value   *Value   `xml:"value,omitempty"`
	Icons   []Icon   `xml:"icon,omitempty"`
}

type Review

type Review struct {
	XMLName  xml.Name    `xml:"review"`
	Type     *ReviewType `xml:"type,attr,omitempty"`
	Source   *string     `xml:"source,attr,omitempty"`
	Reviewer *string     `xml:"reviewer,attr,omitempty"`
	Lang     *string     `xml:"lang,attr,omitempty"`
	Text     string      `xml:",chardata"`
}

type ReviewType

type ReviewType string
const (
	ReviewTypeText ReviewType = "text"
	ReviewTypeURL  ReviewType = "url"
)

type StarRating

type StarRating struct {
	XMLName xml.Name `xml:"star-rating"`
	System  *string  `xml:"system,attr,omitempty"`
	Value   *Value   `xml:"value,omitempty"`
	Icons   []Icon   `xml:"icon,omitempty"`
}

type Stereo

type Stereo struct {
	XMLName xml.Name `xml:"stereo"`
	Text    string   `xml:",chardata"`
}

type SubTitle

type SubTitle struct {
	XMLName xml.Name `xml:"sub-title"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Subtitles

type Subtitles struct {
	XMLName  xml.Name       `xml:"subtitles"`
	Type     *SubtitlesType `xml:"type,attr,omitempty"`
	Language *Language      `xml:"language,omitempty"`
}

type SubtitlesType

type SubtitlesType string
const (
	SubtitlesTypeTeletext   SubtitlesType = "teletext"
	SubtitlesTypeOnScreen   SubtitlesType = "onscreen"
	SubtitlesTypeDeafSigned SubtitlesType = "deaf-signed"
)

type TV

type TV struct {
	XMLName           xml.Name         `xml:"tv"`
	Date              *types.XMLTVTime `xml:"date,attr,omitempty"`
	SourceInfoURL     *string          `xml:"source-info-url,attr,omitempty"`
	SourceInfoName    *string          `xml:"source-info-name,attr,omitempty"`
	SourceDataURL     *string          `xml:"source-data-url,attr,omitempty"`
	GeneratorInfoName *string          `xml:"generator-info-name,attr,omitempty"`
	GeneratorInfoURL  *string          `xml:"generator-info-url,attr,omitempty"`
	Channels          []Channel        `xml:"channel,omitempty"`
	Programmes        []Programme      `xml:"programme,omitempty"`
}

TV represents the root element of an XMLTV document.

type Time

type Time = types.XMLTVTime

Time is a public alias of the internal time type

type Title

type Title struct {
	XMLName xml.Name `xml:"title"`
	Lang    *string  `xml:"lang,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type URL

type URL struct {
	XMLName xml.Name `xml:"url"`
	System  *string  `xml:"system,attr,omitempty"`
	Text    string   `xml:",chardata"`
}

type Value

type Value struct {
	XMLName xml.Name `xml:"value"`
	Text    string   `xml:",chardata"`
}

type Video

type Video struct {
	XMLName xml.Name         `xml:"video"`
	Present *types.XMLTVBool `xml:"present,omitempty"`
	Colour  *types.XMLTVBool `xml:"colour,omitempty"`
	Aspect  *Aspect          `xml:"aspect,omitempty"`
	Quality *Quality         `xml:"quality,omitempty"`
}

type Writer

type Writer struct {
	XMLName xml.Name `xml:"writer"`
	Images  []Image  `xml:"image,omitempty"`
	URLs    []URL    `xml:"url,omitempty"`
	Text    string   `xml:",chardata"`
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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