-
Notifications
You must be signed in to change notification settings - Fork 1
/
episodes.go
42 lines (37 loc) · 1.21 KB
/
episodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package tapas
import (
"encoding/json"
"fmt"
"net/url"
"time"
"github.com/pkg/errors"
)
// EpisodeMeta holds metadata of a chapter.
type EpisodeMeta struct {
CreatedDate time.Time `json:"created_date"`
EarlyAccess bool `json:"early_access"`
Free bool `json:"free"`
ID int `json:"id"`
NSFW bool `json:"nsfw"`
Nu bool `json:"nu"`
Read bool `json:"read"`
Scene int `json:"scene"`
ScheduledDate time.Time `json:"scheduled_date"`
SupportSupportingAd bool `json:"support_supporting_ad"`
Thumbnail Image `json:"thumb"`
Title string `json:"title"`
Unlocked bool `json:"unlocked"`
}
func (e EpisodeMeta) String() string { return e.Title }
// Episodes fetches episodes of a series.
func (c *Client) Episodes(series int) ([]EpisodeMeta, error) {
raw, err := c.get(fmt.Sprintf("/series/%d/episodes", series), url.Values{})
if err != nil {
return nil, err
}
var res []EpisodeMeta
if err := json.Unmarshal(raw, &res); err != nil {
return nil, errors.Wrap(err, "could not unmarshal episodes")
}
return res, nil
}