4 "github.com/Kovensky/go-anidb/titles"
10 var titlesDB = &titles.TitlesDatabase{}
12 // Reloads titles from the cache.
13 func RefreshTitles() error {
14 flock := lockFile(cachePath("anime-titles.dat.gz"))
18 fh, err := cache.Open("anime-titles.dat.gz")
28 // Returns true if the titles database is up-to-date (newer than 24 hours).
29 func TitlesUpToDate() (ok bool) {
30 return time.Now().Sub(titlesDB.UpdateTime) < 24*time.Hour
33 // Downloads a new anime-titles database if the database is outdated.
35 // Caches the contents on memory, which gets saved by DumpCaches.
36 func UpdateTitles() error {
37 // too new, no need to update
42 flock := lockFile(cachePath("anime-titles.dat.gz"))
46 c := &http.Client{Transport: &http.Transport{DisableCompression: true}}
48 resp, err := c.Get(titles.DataDumpURL)
52 defer resp.Body.Close()
54 fh, err := cache.Create("anime-titles.dat.gz")
59 _, err = io.Copy(fh, resp.Body)
64 return RefreshTitles()