]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Add EpisodeString field to File
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Thu, 25 Jul 2013 21:14:33 +0000 (18:14 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Thu, 25 Jul 2013 21:14:33 +0000 (18:14 -0300)
Pre-formats and pre-processes the EpisodeNumber.

file.go
filecache.go

diff --git a/file.go b/file.go
index d80a19224e550b2f9e323ca52348ce39608ed964..6606f23a73ea347cc4f86f6060bc1fe488a8db71 100644 (file)
--- a/file.go
+++ b/file.go
@@ -41,6 +41,7 @@ type File struct {
        GID GID
        LID LIDMap
 
+       EpisodeString string
        EpisodeNumber misc.EpisodeList
 
        Incomplete bool
index 6dd244b386f42e789a3509aeab02a4ed621ba935..5718e1d061e1ab57860e8d835d296b5a5381b4f0 100644 (file)
@@ -212,6 +212,8 @@ func sanitizeCodec(codec string) string {
        return codec
 }
 
+var opedRE = regexp.MustCompile(`\A(Opening|Ending)(?: (\d+))?\z`)
+
 func (adb *AniDB) parseFileResponse(f **File, reply udpapi.APIReply, calledFromFIDsByGID bool) bool {
        if reply.Error() != nil {
                return false
@@ -340,6 +342,34 @@ func (adb *AniDB) parseFileResponse(f **File, reply udpapi.APIReply, calledFromF
                }
        }
 
+       epstr := epno.String()
+       if len(epno) == 1 && epno[0].Type == misc.EpisodeTypeCredits && epno[0].Len() == 1 {
+               typ := ""
+               n := 0
+
+               if ep := <-adb.EpisodeByID(eid); ep == nil {
+               } else if m := opedRE.FindStringSubmatch(ep.Titles["en"]); len(m) > 2 {
+                       num, err := strconv.ParseInt(m[2], 10, 32)
+                       if err == nil {
+                               n = int(num)
+                       }
+
+                       typ = m[1]
+               }
+
+               gobi := fmt.Sprintf("%d", n)
+               if n == 0 {
+                       gobi = ""
+               }
+
+               switch typ {
+               case "Opening":
+                       epstr = "OP" + gobi
+               case "Ending":
+                       epstr = "ED" + gobi
+               }
+       }
+
        version := FileVersion(1)
        switch i := ints[7]; {
        case i&stateV5 != 0:
@@ -403,6 +433,7 @@ func (adb *AniDB) parseFileResponse(f **File, reply udpapi.APIReply, calledFromF
                GID: gid,
                LID: lidMap,
 
+               EpisodeString: epstr,
                EpisodeNumber: epno,
 
                RelatedEpisodes: related,