Add Creator Info + Fetching to JNC Module. Implement .cbz chapter generation
This commit is contained in:
parent
1661c7de42
commit
b36bc9b0b2
2 changed files with 345 additions and 49 deletions
jnc
51
jnc/jnc.go
51
jnc/jnc.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -90,7 +91,7 @@ type Volume struct {
|
|||
Number int `json:"number"`
|
||||
OriginalPublisher string `json:"originalPublisher"`
|
||||
Label string `json:"label"`
|
||||
Creators []string `json:"creators"` // TODO: check, might not be correct
|
||||
Creators Creators `json:"creators"` // TODO: check, might not be correct
|
||||
hidden bool
|
||||
ForumTopicId int `json:"forumTopicId"`
|
||||
Created string `json:"created"`
|
||||
|
@ -105,6 +106,28 @@ type Volume struct {
|
|||
OnSale bool `json:"onSale"`
|
||||
}
|
||||
|
||||
type Creators []Creator
|
||||
|
||||
type Creator struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Role string `json:"role"`
|
||||
OriginalName string `json:"originalName "`
|
||||
}
|
||||
|
||||
func (creators *Creators) Contains(name string) bool {
|
||||
return slices.ContainsFunc(*creators, func(c Creator) bool {
|
||||
return c.Name == name
|
||||
})
|
||||
}
|
||||
|
||||
func (creators *Creators) Get(name string) *Creator {
|
||||
idx := slices.IndexFunc(*creators, func(c Creator) bool {
|
||||
return c.Name == name
|
||||
})
|
||||
return &(*creators)[idx]
|
||||
}
|
||||
|
||||
type VolumeAugmented struct {
|
||||
Info Volume
|
||||
Downloads []Download
|
||||
|
@ -116,7 +139,7 @@ func (volume *VolumeAugmented) UpdateAvailable() bool {
|
|||
if volume.downloaded == "" && len(volume.Downloads) != 0 {
|
||||
return true // The file has never been downloaded but at least one is available
|
||||
}
|
||||
|
||||
|
||||
downloadedTime, err := time.Parse(time.RFC3339, volume.downloaded)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -367,6 +390,30 @@ func (jncApi *Api) FetchLibrarySeries() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// FetchVolumeInfo retrieves additional Volume Info that was not returned when retrieving the entire Library
|
||||
func (jncApi *Api) FetchVolumeInfo(volume Volume) (Volume, error) {
|
||||
fmt.Println("Fetching Volume details...")
|
||||
res, err := http.Get(ApiV2Url + "volumes/" + volume.Id + "?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
|
||||
if err != nil {
|
||||
return volume, err
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return volume, errors.New(res.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return volume, err
|
||||
}
|
||||
err = json.Unmarshal(body, &volume)
|
||||
if err != nil {
|
||||
return volume, err
|
||||
}
|
||||
|
||||
return volume, nil
|
||||
}
|
||||
|
||||
// GetLibrarySeries returns a list of unique series found in the User's library. Tags are only included if FetchLibrarySeries was previously called.
|
||||
func (jncApi *Api) GetLibrarySeries() (seriesList []SerieAugmented, err error) {
|
||||
arr := make([]SerieAugmented, 0, len(jncApi._series))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue