package main import ( "path" "regexp" "strconv" "strings" "time" ) // An AlbumState describe the state of an Album type AlbumState int // An AlbumID uniquely identifies an Album both here and www.bedetheque.com type AlbumID uint64 const ( // NEW is "État neuf" state NEW AlbumState = iota // 0 // MINT is "Très bon état" state MINT // 1 // GOOD is "Bon état" state GOOD // 2 // AVERAGE is "État moyen" state AVERAGE // 3 // BAD is "Mauvais état" state BAD // 4 ) // A Link represent a link to a ressource type Link struct { // Title of the link Title string `bl_name:"nom" bl_analyzer:"simple"` // Target of the link Target string `bl_name:"target" bl_index:"false" bl_include_all:"false"` } // An Album is the core object in our system // // This is basically the data we store on bdgest.com, and that we want // in our system to be retrieve from type Album struct { ID AlbumID ISBN string Series string `json:"série"` Title string `json:"titre"` Num int NumA string State AlbumState Editor string `json:"éditeur"` Collection string `json:"collection"` SatID string `json:"ref"` LegalDeposit time.Time PrintDate time.Time PurchaseDate time.Time CoverURL string Description string `json:"description"` Note float64 Scenarists []string `json:"scenario"` Designers []string `json:"dessins"` Colorists []string `json:"couleurs"` Links map[string]string FetchDate time.Time } func AlbumIDString(ID AlbumID) string { return strconv.FormatUint(uint64(ID), 10) } var rxAuthorSkip = regexp.MustCompile(`\A<.*>\z`) func (a *Album) Authors() []string { authorsUnsafe := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers)) authors := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers)) set := map[string]bool{} authorsUnsafe = append(authorsUnsafe, a.Designers...) authorsUnsafe = append(authorsUnsafe, a.Scenarists...) authorsUnsafe = append(authorsUnsafe, a.Colorists...) for _, author := range authorsUnsafe { if rxAuthorSkip.MatchString(author) == true || set[author] == true { continue } authors = append(authors, author) set[author] = true } return authors } func (a *Album) String() string { res := strconv.FormatUint(uint64(a.ID), 10) + ": " if len(a.Collection) > 0 { res += a.Collection + ": " } return res + a.Title } var rxExt = regexp.MustCompile(`\.([0-9]+)([a-zA-Z]+)\z`) func AlbumCoverExt(URL string) string { ext := path.Ext(URL) m := rxExt.FindStringSubmatch(ext) if m != nil { ext = "." + m[2] } return strings.ToLower(ext) }