Documentation
¶
Overview ¶
Package epg contains a client for the C More EPG Web API
Installation ¶
Just go get the package:
go get -u github.com/TV4/epg
Usage ¶
A small usage example
package main import ( "context" "fmt" "time" epg "github.com/TV4/epg" ) func main() { var ( ec = epg.NewClient() ctx = context.Background() date = epg.DateAtTime(time.Now()) ) if r, err := ec.Get(ctx, epg.Sweden, epg.Swedish, date); err == nil { c := r.Day().Channel(epg.TV4) for _, s := range c.Schedules { fmt.Println(s.CalendarDate, s.Program.Title) } } }
Documentation ¶
Index ¶
- Constants
- Variables
- func BaseURL(rawurl string) func(*Client)
- func ChannelID(name string) string
- func Date(year int, month time.Month, day int) string
- func DateAtTime(t time.Time) string
- func HTTPClient(hc *http.Client) func(*Client)
- func Names(s string) []string
- func UserAgent(ua string) func(*Client)
- type Channel
- type Client
- func (c *Client) Get(ctx context.Context, country Country, language Language, date string, ...) (*Response, error)
- func (c *Client) GetChannel(ctx context.Context, country Country, language Language, ...) (*Response, error)
- func (c *Client) GetChannelGroup(ctx context.Context, country Country, language Language, ...) (*Response, error)
- func (c *Client) GetPeriod(ctx context.Context, country Country, language Language, ...) (*Response, error)
- type Country
- type Day
- type Image
- type Language
- type Meta
- type Program
- type Response
- type Schedule
- type Time
Examples ¶
Constants ¶
const ( CanalExtra1 = "3" CanalExtra2 = "4" CanalExtra3 = "5" CanalExtraHD = "7" CanalFilm1 = "8" CanalFilm2 = "9" CanalFilm3 = "11" CanalHD = "12" CanalPanNordic = "15" CanalPlusHD = "17" CanalPlusHitsHD = "18" CanalSport2 = "21" CanalSport3 = "22" CanalSportFotboll = "25" CanalSportHockey = "26" CanalSportNorway = "27" CanalSportSweden = "28" CF4 = "29" SFK = "32" SFKBoxer = "33" SHD = "34" SeriesHD = "52" TV2SportPremium4HD = "53" CMoreFotbollHockeyKids = "54" CMoreLive2HD = "65" CMoreLive3HD = "66" CMoreLive4HD = "67" CMoreHockeyHD = "68" CMoreGolfHD = "70" CMoreGolfDenmarkHD = "71" CMoreGolf = "72" CMoreGolfDenmark = "73" SVT1 = "74" SVT2 = "75" TV4 = "76" TV4Sport = "78" Sjuan = "79" TV12 = "80" TV4FaktaXL = "81" TV4Fakta = "82" TV4Film = "83" TV4Guld = "84" TV4Komedi = "85" SVT24 = "86" SVTKunskapskanalen = "87" Barnkanalen = "88" CMoreStars = "89" CMoreStarsHD = "90" CMoreLive5 = "94" CMoreLive5HD = "95" Sportkanalen = "97" SportkanalenHD = "98" )
Channel constants
Data retrieved like this:
curl -H "Accept: application/xml" "https://api.cmore.se/epg/se/sv/2017-01-26/2017-02-13" | xmllint --format - | grep ChannelId | awk -F '"' '{print $2 " " $4 " = \"" $2 "\""}' | sort -n | uniq | awk '{print $2 " " $3 " " $4}' | pbcopy
Variables ¶
var ( // ErrNotFound means that the resource could not be found ErrNotFound = errors.New("not found") // ErrUnknown means that an unexpected error occurred ErrUnknown = errors.New("unknown error") )
var ImageBaseURL = &url.URL{Scheme: "https", Host: "img-cdn-cmore.b17g.services"}
ImageBaseURL is the base URL for images
var Stockholm *time.Location
Stockholm is the Time Zone in Sweden
Functions ¶
func DateAtTime ¶
DateAtTime returns the date string for the provided time.Time
func HTTPClient ¶
HTTPClient changes the *client HTTP client to the provided *http.Client
Types ¶
type Channel ¶
type Channel struct { ID string `xml:"ChannelId,attr" json:"channel_id"` Name string `xml:"Name,attr" json:"name"` Title string `xml:"Title,attr" json:"title"` LogoID string `xml:"LogoId,attr" json:"logo_id"` LogoDarkID string `xml:"LogoDarkId,attr" json:"logo_dark_id"` LogoLightID string `xml:"LogoLightId,attr" json:"logo_light_id"` IsHD bool `xml:"IsHd,attr" json:"hd"` Schedules []Schedule `xml:"Schedule" json:"schedules,omitempty"` }
Channel is a TV channel in the EPG
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for the EPG Web API
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, country Country, language Language, date string, attributes ...url.Values) (*Response, error)
Get retrieves a response for the given country, language and date
func (*Client) GetChannel ¶
func (c *Client) GetChannel(ctx context.Context, country Country, language Language, fromDate, toDate, channelID string, attributes ...url.Values) (*Response, error)
GetChannel retrieves a channel in the period fromDate until toDate
type Country ¶
type Country string
Country is the type used for lowercase ISO 3166-1 alpha-2 country codes as per https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
type Day ¶
type Day struct { BroadcastDate Time `xml:"BroadcastDate,attr" json:"broadcast_date"` Channels []Channel `xml:"Channel" json:"channels,omitempty"` }
Day is an EPG day
type Image ¶
type Image struct { ID string `xml:"Id,attr" json:"id"` Category string `xml:"Category,attr" json:"category"` }
Image is a typed identifier for an image that can be retrieved at https://img-cdn-cmore.b17g.services/:id/:format.img
(format 164 can be used to retrieve the full size image)
type Language ¶
type Language string
Language is the type used for ISO 639-1 language codes as per https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
type Program ¶
type Program struct { ID string `xml:"ProgramId,attr" json:"program_id"` Title string `xml:"Title,attr" json:"title"` OriginalTitle string `xml:"OriginalTitle,attr" json:"original_title"` Genre string `xml:"Genre,attr" json:"genre"` GenreKey string `xml:"GenreKey,attr" json:"genre_key"` FirstCalendarDate Time `xml:"FirstCalendarDate,attr" json:"first_calendar_date"` LastCalendarDate Time `xml:"LastCalendarDate,attr" json:"last_calendar_date"` VodStart Time `xml:"VodStart,attr" json:"vod_start"` VodEnd Time `xml:"VodEnd,attr" json:"vod_end"` Duration int `xml:"Duration,attr" json:"duration"` ContentSourceID string `xml:"ContentSourceId,attr" json:"content_source_id"` ProductionYear string `xml:"ProductionYear,attr" json:"production_year"` Rating string `xml:"Rating,attr" json:"rating"` Actors string `xml:"Actors,attr" json:"actors"` Directors string `xml:"Directors,attr" json:"directors"` Class string `xml:"Class,attr" json:"class"` Type string `xml:"Type,attr" json:"type"` Category string `xml:"Category,attr" json:"category"` IsDubbedVersionAvailable bool `xml:"IsDubbedVersionAvailable,attr" json:"dubbed_version_available"` VOD bool `xml:"Vod,attr" json:"vod"` OTTBlackout bool `xml:"OTTBlackout,attr" json:"ott_blackout"` IsDubbed bool `xml:"IsDubbed,attr" json:"dubbed"` Images []Image `xml:"Resources>Image" json:"images"` SeriesID string `xml:"SeriesId,attr" json:"series_id"` SeasonNumber int `xml:"SeasonNumber,attr" json:"season_number"` EpisodeNumber int `xml:"EpisodeNumber,attr" json:"episode_number"` NumberOfEpisodes int `xml:"NumberOfEpisodes,attr" json:"number_of_episodes"` SynopsisExtraShort string `xml:"Synopsis>ExtraShort" json:"extra_short"` SynopsisShort string `xml:"Synopsis>Short" json:"short"` SynopsisMedium string `xml:"Synopsis>Medium" json:"medium"` SynopsisLong string `xml:"Synopsis>Long" json:"long"` SynopsisFacts string `xml:"Synopsis>Facts" json:"facts"` }
Program is the program that is scheduled in the EPG
type Response ¶
type Response struct { Days []Day `xml:"Day,omitempty" json:"days,omitempty"` FromDate Time `xml:"FromDate,attr" json:"from_date,omitempty"` UntilDate Time `xml:"UntilDate,attr" json:"until_date,omitempty"` Meta *Meta `xml:"-" json:"meta,omitempty"` }
Response data from the EPG API
type Schedule ¶
type Schedule struct { ID string `xml:"ScheduleId,attr" json:"schedule_id"` NextStart Time `xml:"NextStart,attr" json:"next_start"` CalendarDate Time `xml:"CalendarDate,attr" json:"calendar_date"` IsPremiere bool `xml:"IsPremiere,attr" json:"premiere"` IsDubbed bool `xml:"IsDubbed,attr" json:"dubbed"` Type string `xml:"Type,attr" json:"type"` AlsoAvailableInHD bool `xml:"AlsoAvailableInHD,attr" json:"also_available_in_hd"` AlsoAvailableIn3D bool `xml:"AlsoAvailableIn3D,attr" json:"also_available_in_3d"` Is3D bool `xml:"Is3D,attr" json:"is_3d"` IsPPV bool `xml:"IsPPV,attr" json:"is_ppv"` PlayAssetID string `xml:"PlayAssetId1,attr" json:"play_asset_id"` Program Program `xml:"Program" json:"program"` }
Schedule is the TV program schedule of a channel in the EPG