Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additions to previous hotfixes and go mod tidy #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Example

downloadURL, err := wcd.CreateDownloadURL(torrentSearch.Results[0].Torrents[0].TorrentID)
if err != nil {
log.Fatal(downloadURL)
log.Fatal(err)
}
log.Println(downloadURL)
```
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/charles-haynes/whatapi
go 1.12

require (
github.com/jmoiron/sqlx v1.2.0
golang.org/x/net v0.0.0-20191109021931-daa7c04131f5
golang.org/x/net v0.0.0-20210825183410-e898025ed96a
k8s.io/apimachinery v0.23.0
k8s.io/client-go v0.23.0
)
598 changes: 590 additions & 8 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions r_artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ArtistGroupStruct struct {
GroupRecordLabelF string `json:"groupRecordLabel"`
GroupCatalogueNumberF string `json:"groupCatalogueNumber"`
GroupCategoryID string `json:"groupCategoryID"`
TagsF map[int]string `json:"tags"`
TagsF []string `json:"tags"`
ReleaseTypeF int `json:"releaseType"`
GroupVanityHouse bool `json:"groupVanityHouse"`
HasBookmarked bool `json:"hasBookmarked"`
Expand Down Expand Up @@ -134,7 +134,7 @@ func (g ArtistGroupStruct) ReleaseType() int {
return g.ReleaseTypeF
}

func (g ArtistGroupStruct) Tags() map[int]string {
func (g ArtistGroupStruct) Tags() []string {
return g.TagsF
}

Expand Down
2 changes: 1 addition & 1 deletion r_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Notifications struct {
HasLog bool `json:"hasLog"`
HasCue bool `json:"hasCue"`
LogScore int `json:"logScore"`
FreeTorrent string `json:"freeTorrent"`
FreeTorrent string `json:"freeTorrent"` // actually bool
LogInDB bool `json:"logInDb"`
Unread bool `json:"unread"`
} `json:"results"`
Expand Down
4 changes: 2 additions & 2 deletions r_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type TorrentSearchResultStruct struct {
GroupID int `json:"groupId"`
GroupName string `json:"groupName"`
ArtistF string `json:"artist"`
TagsF map[int]string `json:"tags"`
TagsF []string `json:"tags"`
Bookmarked bool `json:"bookmarked"`
VanityHouse bool `json:"vanityHouse"`
GroupYear int `json:"groupYear"`
Expand Down Expand Up @@ -157,7 +157,7 @@ func (ts TorrentSearchResultStruct) ReleaseType() int {
return ts.ReleaseTypeF
}

func (ts TorrentSearchResultStruct) Tags() map[int]string {
func (ts TorrentSearchResultStruct) Tags() []string {
return ts.TagsF
}

Expand Down
41 changes: 29 additions & 12 deletions r_torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ type MusicInfo struct {
}

type GroupStruct struct {
WikiBodyF string `json:"wikiBody"`
WikiImageF string `json:"wikiImage"`
IDF int `json:"id"`
NameF string `json:"name"`
YearF int `json:"year"`
RecordLabelF string `json:"recordLabel"`
CatalogueNumberF string `json:"catalogueNumber"`
ReleaseTypeF int `json:"releaseType"`
CategoryID int `json:"categoryId"`
CategoryName string `json:"categoryName"`
Time string `json:"time"`
VanityHouse bool `json:"vanityHouse"`
IsBookmarked bool `json:"isBookmarked"`
MusicInfo MusicInfo `json:"musicInfo"`
TagsF []string `json:"tags"`
artists []string
importance []int
}

type GroupStructTagsID struct {
WikiBodyF string `json:"wikiBody"`
WikiImageF string `json:"wikiImage"`
IDF int `json:"id"`
Expand Down Expand Up @@ -170,7 +190,7 @@ func (g GroupStruct) ReleaseType() int {
return g.ReleaseTypeF
}

func (g GroupStruct) Tags() map[int]string {
func (g GroupStruct) Tags() []string {
return g.TagsF
}

Expand Down Expand Up @@ -343,7 +363,7 @@ type ArtistTorrentStruct struct {
HasCue bool `json:"hasCue"`
LogScore int `json:"logScore"`
FileCountF int `json:"fileCount"`
FreeTorrent string `json:"freeTorrent"`
FreeTorrent string `json:"freeTorrent"` // actually bool
Size int64 `json:"size"`
Leechers int `json:"leechers"`
Seeders int `json:"seeders"`
Expand Down Expand Up @@ -423,7 +443,7 @@ type TorrentStruct struct {
Seeders int `json:"seeders"`
Leechers int `json:"leechers"`
Snatched int `json:"snatched"`
FreeTorrent string `json:"freeTorrent"`
FreeTorrent string `json:"freeTorrent"` // actually bool
Reported bool `json:"reported"`
Time string `json:"time"`
DescriptionF string `json:"description"`
Expand Down Expand Up @@ -490,15 +510,12 @@ func (t TorrentStruct) FileCount() int {
func (t TorrentStruct) FileSize() int64 {
return t.Size
}
func (t *TorrentStruct) Files() ([]FileStruct, error) {
if t.files != nil {
return t.files, nil
}
f, err := t.ParseFileList()
if err != nil {
return f, err
func (t *TorrentStruct) Files() (files []FileStruct, err error) {
files, parse_err := t.parseFileList()
if parse_err != nil {
return files, parse_err
}
t.files = f
t.files = files
return t.files, nil
}

Expand All @@ -513,7 +530,7 @@ func (fs FileStruct) Name() string {
}

// ParseFileList returns a slice of FileStruts for a torrent
func (t TorrentStruct) ParseFileList() ([]FileStruct, error) {
func (t TorrentStruct) parseFileList() ([]FileStruct, error) {
if t.FileList == "" {
return []FileStruct{}, nil
}
Expand Down
40 changes: 30 additions & 10 deletions whatapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"time"

"golang.org/x/net/publicsuffix"
retrywait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
)

type PSList struct{}
Expand Down Expand Up @@ -86,7 +88,7 @@ type Group interface {
Artist() string
Year() int
ReleaseType() int
Tags() map[int]string
Tags() []string
String() string
}

Expand Down Expand Up @@ -343,9 +345,35 @@ func (w *ClientStruct) GetJSON(requestURL string, responseObj interface{}) (err
if err != nil {
return err
}
if body, err = w.doRequest(req); err != nil {

err = retry.OnError(retrywait.Backoff{
Duration: 15 * time.Second,
Steps: 4,
Factor: 3,
Jitter: 0.1,
}, func(err error) bool {
es := err.Error()
return es == "Request failed: Status Code 503 Service Unavailable" || // err from html
es == "Request failed: Rate limit exceeded" // err from json
}, func() (err error) {
if body, err = w.doRequest(req); err != nil {
return err // err from http
}

var st GenericResponse
if err := json.Unmarshal(body, &st); err != nil {
return err
}
if err := checkResponseStatus(st.Status, st.Error); err != nil {
return err // err from json
}

return err
})
if err != nil {
return err
}

if err = w.updateCache(requestURL, body); err != nil {
return err
}
Expand All @@ -355,14 +383,6 @@ func (w *ClientStruct) GetJSON(requestURL string, responseObj interface{}) (err
break
}

var st GenericResponse
if err := json.Unmarshal(body, &st); err != nil {
return err
}

if err := checkResponseStatus(st.Status, st.Error); err != nil {
return err
}
switch ro := responseObj.(type) {
case *ArtistResponse: // hack around orpheus bug in get artist
err := json.Unmarshal(body, ro)
Expand Down