]> git.lizzy.rs Git - go-anidb.git/blobdiff - filecache.go
anidb: Allow setting the Logger to use for logging traffic
[go-anidb.git] / filecache.go
index 5718e1d061e1ab57860e8d835d296b5a5381b4f0..cb8d528281a9f47f20f07de47d2ba9a1fb396b87 100644 (file)
@@ -6,7 +6,6 @@ import (
        "github.com/Kovensky/go-anidb/udp"
        "github.com/Kovensky/go-fscache"
        "image"
-       "log"
        "regexp"
        "sort"
        "strconv"
@@ -116,7 +115,7 @@ func (adb *AniDB) FileByID(fid FID) <-chan *File {
        return ch
 }
 
-var validEd2kHash = regexp.MustCompile(`\A[:xdigit:]{32}\z`)
+var validEd2kHash = regexp.MustCompile(`\A[[:xdigit:]]{32}\z`)
 
 // Retrieves a File by its Ed2kHash + Filesize combination. Uses the UDP API.
 func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File {
@@ -152,7 +151,7 @@ func (adb *AniDB) FileByEd2kSize(ed2k string, size int64) <-chan *File {
        fid := FID(0)
 
        switch ts, err := Cache.Get(&fid, key...); {
-       case err != nil && time.Now().Sub(ts) < FileCacheDuration:
+       case err == nil && time.Now().Sub(ts) < FileCacheDuration:
                intentMap.NotifyClose(fid, key...)
                return ch
        }
@@ -300,7 +299,7 @@ func (adb *AniDB) parseFileResponse(f **File, reply udpapi.APIReply, calledFromF
                        if partial {
                                if calledFromFIDsByGID {
                                        epno = test
-                                       log.Printf("UDP!!! FID %d is only part of episode %s with no complementary files", fid, epno)
+                                       adb.Logger.Printf("UDP!!! FID %d is only part of episode %s with no complementary files", fid, epno)
                                } else if len(test) == 1 && test[0].Start.Number == test[0].End.Number {
                                        fids := []int{}