Add CDDB1 calculation
This commit is contained in:
parent
9948b9cab0
commit
64c5f33c27
18
server.go
18
server.go
|
@ -89,11 +89,11 @@ type discEntry struct {
|
|||
Tracks []trackEntry `json:"tracks"`
|
||||
}
|
||||
type trackEntry struct {
|
||||
Duration int `json:"duration,omitempty"`
|
||||
MainTitle string `json:"title,omitempty"`
|
||||
OriginalTitle string `json:"originaltitle,omitempty"`
|
||||
Titles []string `json:"titles,omitempty"`
|
||||
Artists []artistEntry `json:"artists,omitempty"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
MainTitle string `json:"title,omitempty"`
|
||||
Original string `json:"original,omitempty"`
|
||||
Titles []string `json:"titles,omitempty"`
|
||||
Artists []artistEntry `json:"artists,omitempty"`
|
||||
}
|
||||
type artistEntry struct {
|
||||
Position string `json:"position"`
|
||||
|
@ -477,7 +477,7 @@ func processIndexDirectory(filePath, indexPath, kind string, wg *sync.WaitGroup)
|
|||
}
|
||||
switch keyEntry {
|
||||
case "original title":
|
||||
track.OriginalTitle = strings.TrimSpace(strings.Join(getStringValue(entry.MainTitle, values), " "))
|
||||
track.Original = strings.TrimSpace(strings.Join(getStringValue(entry.MainTitle, values), " "))
|
||||
case "lyrics", "vocals", "arranger", "composer", "producer":
|
||||
track.Artists = append(track.Artists, getArtistEntries(keyEntry, values)...)
|
||||
case "arrangement":
|
||||
|
@ -644,6 +644,10 @@ func main() {
|
|||
return
|
||||
}
|
||||
switch splits[1] {
|
||||
case "hello":
|
||||
writer.Write([]byte("200 hello and welcome\n.\n"))
|
||||
return
|
||||
|
||||
case "query":
|
||||
formatEntry := func(cddb1 utilities.CDDB1, result findByDurationResult) (out string) {
|
||||
var group string
|
||||
|
@ -666,6 +670,8 @@ func main() {
|
|||
}
|
||||
|
||||
cddb1 := utilities.NewCDDB1FromString(splits[2])
|
||||
|
||||
//cddb1_calc := utilities.GetCDDB1FromTOC(splits[3:])
|
||||
if cddb1 == 0 {
|
||||
writer.Write([]byte("500 Command syntax error\n.\n"))
|
||||
return
|
||||
|
|
|
@ -3,6 +3,7 @@ package utilities
|
|||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -33,3 +34,28 @@ func (c CDDB1) String() string {
|
|||
binary.BigEndian.PutUint32(b, uint32(c))
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
func GetCDDB1FromTOC(toc []string) CDDB1 {
|
||||
if len(toc) < 3 {
|
||||
return 0
|
||||
}
|
||||
var t []int
|
||||
for _, i := range toc[1 : len(toc)-1] {
|
||||
item, err := strconv.Atoi(i)
|
||||
if err == nil {
|
||||
t = append(t, item)
|
||||
}
|
||||
}
|
||||
|
||||
length := uint32(((time.Second * time.Duration(t[0]-t[1])) / 75).Seconds())
|
||||
checksum := uint32(0)
|
||||
for i := 1; i < len(t); i++ {
|
||||
n := uint32(t[i] / 75)
|
||||
for n > 0 {
|
||||
checksum += n % 10
|
||||
n /= 10
|
||||
}
|
||||
}
|
||||
|
||||
return CDDB1(uint32((len(t)-1)&0xFF) | ((length & 0xFFFF) << 8) | ((checksum % 255) << 24))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue