From 2d85fe4239f7d1d4282250fed232f6cfdc381b70 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 12 Dec 2015 03:37:52 +0100 Subject: added xml parse for response of rdxport diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index e29e4df..749c895 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/importer.go @@ -27,10 +27,8 @@ package rhimport import ( "bufio" "bytes" - "encoding/xml" "fmt" "github.com/golang-basic/go-curl" - "io" "mime/multipart" "net/http" "os" @@ -134,22 +132,6 @@ func NewImportResult(rdres *RDWebResult) *ImportResult { return res } -type RDWebResult struct { - ResponseCode int `xml:"ResponseCode"` - ErrorString string `xml:"ErrorString"` - AudioConvertError int `xml:"AudioConvertError"` -} - -func NewRDWebResultFromXML(data io.Reader) (res *RDWebResult, err error) { - decoder := xml.NewDecoder(data) - res = &RDWebResult{} - if xmlerr := decoder.Decode(res); xmlerr != nil { - err = fmt.Errorf("Error parsing XML response: %s", xmlerr) - return - } - return -} - func add_cart(ctx *ImportContext) (result *RDWebResult, err error) { var b bytes.Buffer w := multipart.NewWriter(&b) diff --git a/src/helsinki.at/rhimport/rdxport_responses.go b/src/helsinki.at/rhimport/rdxport_responses.go new file mode 100644 index 0000000..db309d9 --- /dev/null +++ b/src/helsinki.at/rhimport/rdxport_responses.go @@ -0,0 +1,150 @@ +// +// rhimportd +// +// The Radio Helsinki Rivendell Import Daemon +// +// +// Copyright (C) 2015 Christian Pointner +// +// This file is part of rhimportd. +// +// rhimportd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// rhimportd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with rhimportd. If not, see . +// + +package rhimport + +import ( + "encoding/xml" + "fmt" + "io" +) + +type RDWebResult struct { + ResponseCode int `xml:"ResponseCode"` + ErrorString string `xml:"ErrorString"` + AudioConvertError int `xml:"AudioConvertError"` +} + +func NewRDWebResultFromXML(data io.Reader) (res *RDWebResult, err error) { + decoder := xml.NewDecoder(data) + res = &RDWebResult{} + if xmlerr := decoder.Decode(res); xmlerr != nil { + err = fmt.Errorf("Error parsing XML response: %s", xmlerr) + return + } + return +} + +type RDCartAdd struct { + Carts []RDCart `xml:"cart"` +} + +type RDCart struct { + Number int `xml:"number"` + Type string `xml:"type"` + GroupName string `xml:"groupName"` + Title string `xml:"title"` + Artist string `xml:"artist"` + Album string `xml:"album"` + Year string `xml:"year"` + Label string `xml:"label"` + Client string `xml:"client"` + Agency string `xml:"agency"` + Publisher string `xml:"publisher"` + Composer string `xml:"composer"` + UserDefined string `xml:"userDefined"` + UsageCode int `xml:"usageCode"` + ForcedLength string `xml:"forcedLength"` + AverageLength string `xml:"averageLength"` + LengthDeviation string `xml:"lengthDeviation"` + AverageSegueLength string `xml:"averageSegueLenth"` + AverageHookLength string `xml:"averageHookLength"` + CutQuantity int `xml:"cutQuantity"` + LastCutPlayer int `xml:"lastCutPlayed"` + Validity int `xml:"validity"` + EnforceLength bool `xml:"enforceLength"` + Asynchronous bool `xml:"asyncronous"` + Owner string `xml:"owner"` + MetadataDatetime string `xml:"metadataDatetime"` +} + +func NewRDCartAddFromXML(data io.Reader) (cart *RDCartAdd, err error) { + decoder := xml.NewDecoder(data) + cart = &RDCartAdd{} + if xmlerr := decoder.Decode(cart); xmlerr != nil { + err = fmt.Errorf("Error parsing XML response: %s", xmlerr) + return + } + return +} + +type RDCutAdd struct { + Cuts []RDCut `xml:"cut"` +} + +type RDCut struct { + Name string `xml:"cutName"` + CartNumber int `xml:"cartNumber"` + Number int `xml:"cutNumber"` + EverGreen bool `xml:"evergreen"` + Description string `xml:"description"` + OutCue string `xml:"outcue"` + ISRC string `xml:"isrc"` + ISCI string `xml:"isci"` + Length int `xml:"length"` + OriginDateTime string `xml:"originDatetime"` + StartDateTime string `xml:"startDatetime"` + EndDateTime string `xml:"endDatetime"` + Sunday bool `xml:"sun"` + Monday bool `xml:"mon"` + Tuesday bool `xml:"tue"` + Wednesday bool `xml:"wed"` + Thursday bool `xml:"thu"` + Friday bool `xml:"fri"` + Saturday bool `xml:"sat"` + StartDaypart string `xml:"startDaypart"` + EndDayPart string `xml:"endDaypart"` + OriginName string `xml:"originName"` + Weight int `xml:"weight"` + LastPlayDateTime string `xml:"lastPlayDatetime"` + PlayCounter int `xml:"playCounter"` + LocalCounter int `xml:"localCounter"` + Validiy int `xml:"validity"` + CondingFormat int `xml:"codingFormat"` + SampleRate int `xml:"sampleRate"` + BitRate int `xml:"bitRate"` + Channels int `xml:"channels"` + PlayGain int `xml:"playGain"` + StartPoint int `xml:"startPoint"` + EndPoint int `xml:"endPoint"` + FadeUpPoint int `xml:"fadeupPoint"` + FadeDownPoint int `xml:"fadedownPoint"` + SegueStartPoint int `xml:"segueStartPoint"` + SegueEndPoint int `xml:"segueEndPoint"` + SegueGain int `xml:"segueGain"` + HookStartPoint int `xml:"hookStartPoint"` + HookEndPoint int `xml:"hookEndPoint"` + TalkStartPoint int `xml:"talkStartPoint"` + TalkEndPoint int `xml:"talkEndPoint"` +} + +func NewRDCutAddFromXML(data io.Reader) (cut *RDCutAdd, err error) { + decoder := xml.NewDecoder(data) + cut = &RDCutAdd{} + if xmlerr := decoder.Decode(cut); xmlerr != nil { + err = fmt.Errorf("Error parsing XML response: %s", xmlerr) + return + } + return +} -- cgit v0.10.2