History

better discnumber/totaldiscs handling

Sigrid Solveig Haflínudóttir committed 7 years ago

Commit d8ea5981 parent bb928452 files · +20 −10Browse files

Unified · Split

2 files
  1. input.go +18 −8
  2. track.go +2 −2
input.go+18−8
@@ -6,6 +6,7 @@ import ( · 5 unmodified lines
66 "io"
77 "os"
88 "path/filepath"
9+ "strconv"
910 "strings"
1011
1112 "github.com/ftrvxmtrx/chub/cue"
@@ -73,7 +74,6 @@ func NewInput(path string) (in *Input, err error) { · 61 unmodified lines
7374 err = fmt.Errorf("%s: %s", f.Name, err)
7475 return
7576 }
76− in.TotalDisks++
7777 in.Audio = append(in.Audio, audio)
7878 filesFromCue = append(filesFromCue, f)
7979 }
@@ -85,16 +85,26 @@ func NewInput(path string) (in *Input, err error) { · 5 unmodified lines
8585 in.SongWriter = sheet.Songwriter
8686 in.Title = sheet.Title
8787
88+ var diskNumber int
8889 for _, c := range sheet.Comments {
89− if strings.HasPrefix(c, "DATE") {
90− words := strings.Fields(c)
91− in.Date = words[len(words)-1]
90+ if words := strings.SplitAfterN(c, " ", 2); len(words) < 2 {
91+ continue
92+ } else if strings.HasPrefix(c, "DATE") {
93+ in.Date = words[1]
9294 } else if strings.HasPrefix(c, "GENRE") {
93− words := strings.SplitAfterN(c, " ", 2)
9495 in.Genre = words[1]
9596 } else if strings.HasPrefix(c, "COMPOSER") {
96− words := strings.SplitAfterN(c, " ", 2)
9797 in.Composer = words[1]
98+ } else if len(in.Audio) == 1 {
99+ // FIXME no idea what to do with several discnumber comments in a cue sheet
100+ if strings.HasPrefix(c, "DISCNUMBER") {
101+ diskNumber, err = strconv.Atoi(words[1])
102+ } else if strings.HasPrefix(c, "TOTALDISCS") {
103+ in.TotalDisks, err = strconv.Atoi(words[1])
104+ }
105+ }
106+ if err != nil {
107+ return
98108 }
99109 }
100110
@@ -121,8 +131,8 @@ func NewInput(path string) (in *Input, err error) { · 20 unmodified lines
121131 Genre: in.Genre,
122132 Date: in.Date,
123133 TotalTracks: &in.TotalTracks,
124− TotalDisks: &in.TotalDisks,
125− DiskNumber: i + 1,
134+ TotalDisks: in.TotalDisks,
135+ DiskNumber: diskNumber,
126136 }
127137 for _, c := range ft.Comments {
128138 if strings.HasPrefix(c, "COMPOSER") {
track.go+2−2
@@ -8,9 +8,9 @@ import ( · 7 unmodified lines
88
99 type Track struct {
1010 Number int `json:"number,omitempty"`
11− DiskNumber int `json:"diskNumber"`
11+ DiskNumber int `json:"diskNumber,omitempty"`
1212 TotalTracks *int `json:"totalTracks"`
13− TotalDisks *int `json:"totalDisks"`
13+ TotalDisks int `json:"totalDisks,omitempty"`
1414 Composer string `json:"composer,omitempty"`
1515 Performer string `json:"performer,omitempty"`
1616 SongWriter string `json:"songWriter,omitempty"`

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t