feat(subsonic): add internet radio support

* Initial commit of internet radio support.

* Added first test for internet radio.

* Refactor to prepare for more test cases.

* Added a few more tests. Realized that I was not calling as admin so added ability to mock admin.

* Added more internet radio tests. Added proper JSON unmarshaling for ID.

* More test cases. Fixed some accidental tabs in files.

* Fixed some more tabs.

* lint fixes

* Changed placeholder for homepage URL to fit into box.

* Finished out internet radio test cases. Found a few bad error codes in internet radio AND podcasts (mea culpa).

* Realized that delete via website was not checking properly if id existed. Fixed.

gofmt
This commit is contained in:
brian-doherty
2022-06-21 16:32:25 -05:00
committed by sentriz
parent 2afc63f64a
commit 7ab378accb
14 changed files with 743 additions and 12 deletions

View File

@@ -15,17 +15,19 @@ var (
ErrBadSeparator = errors.New("bad separator")
ErrNotAnInt = errors.New("not an int")
ErrBadPrefix = errors.New("bad prefix")
ErrBadJSON = errors.New("bad JSON")
)
type IDT string
const (
Artist IDT = "ar"
Album IDT = "al"
Track IDT = "tr"
Podcast IDT = "pd"
PodcastEpisode IDT = "pe"
separator = "-"
Artist IDT = "ar"
Album IDT = "al"
Track IDT = "tr"
Podcast IDT = "pd"
PodcastEpisode IDT = "pe"
InternetRadioStation IDT = "ir"
separator = "-"
)
type ID struct {
@@ -55,6 +57,8 @@ func New(in string) (ID, error) {
return ID{Type: Podcast, Value: val}, nil
case PodcastEpisode:
return ID{Type: PodcastEpisode, Value: val}, nil
case InternetRadioStation:
return ID{Type: InternetRadioStation, Value: val}, nil
default:
return ID{}, fmt.Errorf("%q: %w", partType, ErrBadPrefix)
}
@@ -71,6 +75,17 @@ func (i ID) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
func (i *ID) UnmarshalJSON(data []byte) (error) {
if (len(data) <= 2) {
return fmt.Errorf("too short: %w", ErrBadJSON)
}
id, err := New(string(data[1:len(data)-1])) // Strip quotes
if (err == nil) {
*i = id;
}
return err;
}
func (i ID) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}