summaryrefslogtreecommitdiff
path: root/rddb
diff options
context:
space:
mode:
Diffstat (limited to 'rddb')
-rw-r--r--rddb/rddb.go238
1 files changed, 218 insertions, 20 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index 4fbb303..b963972 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -39,6 +39,8 @@ import (
var (
showMacroRe = regexp.MustCompile(`^LL 1 ([^ ]+) 0\!$`)
mysqlTableNameRe = regexp.MustCompile(`^[_0-9a-zA-Z-]+$`)
+ rhythmRegexp = regexp.MustCompile(`^[01]{4}$`)
+ starttimeRegexp = regexp.MustCompile(`^[0-2][0-9][0-5][0-9]$`)
)
const (
@@ -47,6 +49,133 @@ const (
defaultCartTitle = "[new cart]"
)
+type ShowType string
+
+const (
+ ShowTypeRegular ShowType = "n"
+ ShowTypeRerun ShowType = "r"
+ ShowTypeSpecial ShowType = "s"
+)
+
+func (s ShowType) String() string {
+ switch s {
+ case ShowTypeRegular:
+ return "regular"
+ case ShowTypeRerun:
+ return "re-run"
+ case ShowTypeSpecial:
+ return "special"
+ }
+ return "unknown"
+}
+
+type Weekday int
+
+func (w Weekday) String() string {
+ switch w {
+ case 1:
+ return "Montag"
+ case 2:
+ return "Dienstag"
+ case 3:
+ return "Mittwoch"
+ case 4:
+ return "Donnerstag"
+ case 5:
+ return "Freitag"
+ case 6:
+ return "Samstag"
+ case 7:
+ return "Sonntag"
+ }
+ return "-"
+}
+
+func showtypeFromString(in string) ShowType {
+ switch ShowType(in) {
+ case ShowTypeRerun:
+ return ShowTypeRerun
+ case ShowTypeSpecial:
+ return ShowTypeSpecial
+ }
+ return ShowTypeRegular
+}
+
+func rhythmFromString(in string) string {
+ if !rhythmRegexp.Match([]byte(in)) || in == "0000" {
+ return "????"
+ }
+ return in
+}
+
+func dowFromString(in string) Weekday {
+ tmp, err := strconv.ParseInt(in, 10, 32)
+ if err != nil {
+ return -1
+ }
+ if tmp < 1 || tmp > 7 {
+ return -1
+ }
+ return Weekday(tmp)
+}
+
+func starttimeFromString(in string) string {
+ if in == "----" {
+ return "--:--"
+ }
+ if !starttimeRegexp.Match([]byte(in)) {
+ return "??:??"
+ }
+ tmp, err := strconv.ParseUint(in, 10, 32)
+ if err != nil || tmp > 2359 {
+ return "??:??"
+ }
+ return in[:2] + ":" + in[2:]
+}
+
+func showlengthFromString(in string) uint {
+ tmp, err := strconv.ParseUint(in, 10, 32)
+ if err != nil {
+ return 0
+ }
+ return uint(tmp)
+}
+
+func parseShowParams(params string) (rhythm, starttime string, dow Weekday, length uint, stype ShowType) {
+ p := strings.Split(params, ";")
+ rhythm = "????"
+ dow = -1
+ starttime = "??:??"
+ length = 0
+ stype = ShowTypeRegular
+
+ if len(p) < 2 {
+ return
+ }
+ rhythm = rhythmFromString(p[1])
+
+ if len(p) < 3 {
+ return
+ }
+ dow = dowFromString(p[2])
+
+ if len(p) < 4 {
+ return
+ }
+ starttime = starttimeFromString(p[3])
+
+ if len(p) < 5 {
+ return
+ }
+ length = showlengthFromString(p[4])
+
+ if len(p) < 6 {
+ return
+ }
+ stype = showtypeFromString(p[5])
+ return
+}
+
type getPasswordResult struct {
password string
err error
@@ -104,14 +233,46 @@ type getMusicInfoRequest struct {
}
type ShowListEntry struct {
- ID uint
- Title string
- log string
- lowCart int
- highCart int
+ ID uint
+ Title string
+ TitleFull string
+ log string
+ Rhythm string
+ StartTime string
+ Dow Weekday
+ Length uint
+ Type ShowType
+ lowCart int
+ highCart int
+}
+
+type ShowList []ShowListEntry
+
+func (s ShowList) Len() int {
+ return len(s)
+}
+
+func (s ShowList) Less(i, j int) bool {
+ ititle := strings.ToLower(s[i].TitleFull)
+ jtitle := strings.ToLower(s[j].TitleFull)
+ if ititle == jtitle {
+ if s[i].Rhythm == s[j].Rhythm {
+ if s[i].Dow == s[j].Dow {
+ if s[i].StartTime == s[j].StartTime {
+ return s[i].ID < s[j].ID
+ }
+ return s[i].StartTime < s[j].StartTime
+ }
+ return s[i].Dow < s[j].Dow
+ }
+ return s[i].Rhythm > s[j].Rhythm
+ }
+ return ititle < jtitle
}
-type ShowList map[uint]ShowListEntry
+func (s ShowList) Swap(i, j int) {
+ s[i], s[j] = s[j], s[i]
+}
type getShowListResult struct {
shows ShowList
@@ -154,12 +315,26 @@ type getShowCartListRequest struct {
type JingleListEntry struct {
Group string
- Description string
+ Title string
ActiveCart int
InactiveCart int
}
-type JingleList map[string]JingleListEntry
+type JingleList []JingleListEntry
+
+func (jl JingleList) Len() int {
+ return len(jl)
+}
+
+func (jl JingleList) Less(i, j int) bool {
+ ititle := strings.ToLower(jl[i].Title)
+ jtitle := strings.ToLower(jl[j].Title)
+ return ititle < jtitle
+}
+
+func (jl JingleList) Swap(i, j int) {
+ jl[i], jl[j] = jl[j], jl[i]
+}
type getJingleListResult struct {
jingles JingleList
@@ -183,11 +358,26 @@ type getJingleCutListRequest struct {
}
type PoolListEntry struct {
- Group string
- Description string
+ Group string
+ ShortName string
+ Title string
+}
+
+type PoolList []PoolListEntry
+
+func (p PoolList) Len() int {
+ return len(p)
}
-type PoolList map[string]PoolListEntry
+func (p PoolList) Less(i, j int) bool {
+ ititle := strings.ToLower(p[i].Title)
+ jtitle := strings.ToLower(p[j].Title)
+ return ititle < jtitle
+}
+
+func (p PoolList) Swap(i, j int) {
+ p[i], p[j] = p[j], p[i]
+}
type getPoolListResult struct {
pools PoolList
@@ -301,7 +491,7 @@ func (d *db) init() (err error) {
if d.getJingleListStmt, err = d.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
return
}
- if d.getPoolListStmt, err = d.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
+ if d.getPoolListStmt, err = d.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,DROPBOXES.PATH,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
return
}
if d.getPoolCartsStmt, err = d.dbh.Prepare("select CART.NUMBER,CART.ARTIST,CART.TITLE,CART.ALBUM,CUTS.CUT_NAME,CUTS.EVERGREEN,CUTS.DESCRIPTION,CUTS.LENGTH,CUTS.ORIGIN_DATETIME,CUTS.PLAY_COUNTER,CUTS.LAST_PLAY_DATETIME from CUTS,CART where CUTS.CART_NUMBER = CART.NUMBER and CART.GROUP_NAME = ?;"); err != nil {
@@ -445,7 +635,6 @@ func (d *db) getShowList(username string) (result getShowListResult) {
}
defer rows.Close()
- result.shows = make(map[uint]ShowListEntry)
for rows.Next() {
var show ShowListEntry
var macros, params string
@@ -457,7 +646,16 @@ func (d *db) getShowList(username string) (result getShowListResult) {
continue
}
show.log = showMacroRe.FindStringSubmatch(macros)[1]
- result.shows[show.ID] = show
+ show.Rhythm, show.StartTime, show.Dow, show.Length, show.Type = parseShowParams(params)
+
+ show.TitleFull = show.Title
+ switch show.Type {
+ case ShowTypeRerun:
+ show.TitleFull += " (Wiederholung)"
+ case ShowTypeSpecial:
+ show.TitleFull += " (Sondersendung)"
+ }
+ result.shows = append(result.shows, show)
}
result.err = rows.Err()
return
@@ -544,18 +742,17 @@ func (d *db) getJingleList(username string) (result getJingleListResult) {
}
defer rows.Close()
- result.jingles = make(map[string]JingleListEntry)
for rows.Next() {
var jingle JingleListEntry
var params string
- if result.err = rows.Scan(&jingle.Group, &params, &jingle.ActiveCart, &jingle.InactiveCart, &jingle.Description); result.err != nil {
+ if result.err = rows.Scan(&jingle.Group, &params, &jingle.ActiveCart, &jingle.InactiveCart, &jingle.Title); result.err != nil {
return
}
if params[0] != 'J' {
continue
}
- result.jingles[jingle.Group] = jingle
+ result.jingles = append(result.jingles, jingle)
}
result.err = rows.Err()
return
@@ -578,18 +775,19 @@ func (d *db) getPoolList(username string) (result getPoolListResult) {
}
defer rows.Close()
- result.pools = make(map[string]PoolListEntry)
for rows.Next() {
var pool PoolListEntry
var params string
+ var shortName sql.NullString
- if result.err = rows.Scan(&pool.Group, &params, &pool.Description); result.err != nil {
+ if result.err = rows.Scan(&pool.Group, &params, &shortName, &pool.Title); result.err != nil {
return
}
if params[0] != 'M' {
continue
}
- result.pools[pool.Group] = pool
+ pool.ShortName = shortName.String
+ result.pools = append(result.pools, pool)
}
result.err = rows.Err()
return