Skip to content

Commit

Permalink
fix(ep_parse_err): fix episode parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamjz committed Dec 5, 2023
1 parent 61855a6 commit 394171b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion internal/search/resp.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package search

import "encoding/json"

type TraceMoeResponse struct {
FrameCount int `json:"frameCount"`
Error string `json:"error"`
Expand All @@ -9,14 +11,23 @@ type TraceMoeResponse struct {
type Result struct {
Anilist *Anilist `json:"anilist"`
Filename string `json:"filename"`
Episode int `json:"episode"`
Episode Episode `json:"episode"`
From float64 `json:"from"`
To float64 `json:"to"`
Similarity float64 `json:"similarity"`
Video string `json:"video"`
Image string `json:"image"`
}

type Episode string

var _ json.Unmarshaler = (*Episode)(nil)

func (ep *Episode) UnmarshalJSON(data []byte) error {
*ep = Episode(data)
return nil
}

type Anilist struct {
ID int `json:"id"`
IDMal int `json:"idMal"`
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func New(dataSrc string, typ searchType) Model {

type resultItem struct {
index int
episode int
episode search.Episode
name string
from float64
to float64
Expand All @@ -83,7 +83,7 @@ func (i resultItem) Title() string { return i.name }
func (i resultItem) Description() string {
var sb strings.Builder

sb.WriteString(fmt.Sprintf("Episode: %d\n", i.episode))
sb.WriteString(fmt.Sprintf("Episode: %s\n", i.episode))
sb.WriteString(fmt.Sprintf("From %s to %s\n", formatTime(i.from), formatTime(i.to)))
sb.WriteString(fmt.Sprintf("Similarity: %.3f%s", i.similarity*100, "%"))

Expand Down

0 comments on commit 394171b

Please sign in to comment.