4 "github.com/Kovensky/go-anidb/titles"
10 var titlesDB = &titles.TitlesDatabase{}
12 // Loads the database from anime-titles.dat.gz in the cache dir.
13 func RefreshTitles() error {
14 if flock := lockFile(cachePath("anime-titles.dat.gz")); flock != nil {
19 fh, err := cache.Open("anime-titles.dat.gz")
29 // Returns true if the titles database is up-to-date (newer than 24 hours).
30 func TitlesUpToDate() (ok bool) {
31 return time.Now().Sub(titlesDB.UpdateTime) < 24*time.Hour
34 // Downloads a new anime-titles database if the database is outdated.
36 // Saves the database as anime-titles.dat.gz in the cache dir.
37 func UpdateTitles() error {
38 // too new, no need to update
43 if flock := lockFile(cachePath("anime-titles.dat.gz")); flock != nil {
48 c := &http.Client{Transport: &http.Transport{DisableCompression: true}}
50 resp, err := c.Get(titles.DataDumpURL)
54 defer resp.Body.Close()
56 fh, err := cache.Create("anime-titles.dat.gz")
61 _, err = io.Copy(fh, resp.Body)
66 return RefreshTitles()