]> git.lizzy.rs Git - go-anidb.git/blobdiff - anime.go
Modernize
[go-anidb.git] / anime.go
index fa43987dc5948c102242f2e607995692164b7ecd..6c257f8ec675402340dfe878dc238cea7e09d49c 100644 (file)
--- a/anime.go
+++ b/anime.go
@@ -1,7 +1,8 @@
 package anidb
 
 import (
-       "github.com/Kovensky/go-anidb/misc"
+       "fmt"
+       "github.com/EliasFleckenstein03/go-anidb/misc"
        "strconv"
        "time"
 )
@@ -49,9 +50,9 @@ type Anime struct {
        AID AID  // The Anime ID.
        R18 bool // Whether this anime is considered porn.
 
-       Type          AnimeType    // Production/distribution type.
-       TotalEpisodes int          // Total number of regular episodes.
-       EpisodeCount  EpisodeCount // Known numbers of the various types of episodes.
+       Type          AnimeType         // Production/distribution type.
+       TotalEpisodes int               // Total number of regular episodes.
+       EpisodeCount  misc.EpisodeCount // Known numbers of the various types of episodes.
 
        StartDate time.Time // Date of first episode release, if available.
        EndDate   time.Time // Date of last episode release, if available.
@@ -70,7 +71,7 @@ type Anime struct {
        TemporaryVotes Rating // Votes from people who are still watching this.
        Reviews        Rating // Votes from reviewers.
 
-       Episodes Episodes // List of episodes.
+       Episodes []*Episode // List of episodes.
 
        Awards    []string
        Resources Resources
@@ -80,15 +81,6 @@ type Anime struct {
        Cached     time.Time // When the data was retrieved from the server.
 }
 
-type EpisodeCount struct {
-       RegularCount int
-       SpecialCount int
-       CreditsCount int
-       OtherCount   int
-       TrailerCount int
-       ParodyCount  int
-}
-
 // Convenience method that runs AnimeByID on the result of
 // SearchAnime.
 func (adb *AniDB) AnimeByName(name string) <-chan *Anime {
@@ -127,7 +119,7 @@ func (a *Anime) Episode(ep *misc.Episode) *Episode {
        case 1:
                return list[0]
        default:
-               panic("Single episode search returned more than one result")
+               panic(fmt.Sprintf("Single episode search returned more than one result (wanted %v, got %v)", ep, list))
        }
 }
 
@@ -144,3 +136,15 @@ func (a *Anime) EpisodeByString(name string) *Episode {
 func (a *Anime) EpisodeByNumber(number int) *Episode {
        return a.EpisodeByString(strconv.Itoa(number))
 }
+
+func (a *Anime) EpisodeByEID(eid EID) *Episode {
+       if a == nil {
+               return nil
+       }
+       for _, ep := range a.Episodes {
+               if ep.EID == eid {
+                       return ep
+               }
+       }
+       return nil
+}