Merges Album and AlbumDescription

This commit is contained in:
2016-01-19 18:18:24 +01:00
parent 53b2d9c07b
commit 719a3cf82e
9 changed files with 402 additions and 555 deletions

141
album.go
View File

@@ -1,14 +1,6 @@
package main
import (
"fmt"
"regexp"
"strings"
"time"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
import "time"
// An AlbumState describe the state of an Album
type AlbumState int
@@ -29,109 +21,44 @@ const (
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
Title string
Num int
NumA string
State AlbumState
ID AlbumID `bl_name:"id" bl_index:"false" bl_include_all:"false"`
ISBN string `bl_name:"isbn" bl_analyzer:"keyword" bl_include_all:"false"`
Series string `bl_name:"série" bl_analyzer:"fr"`
Title string `bl_name:"titre" bl_analyzer:"fr"`
Num int `bl_name:"num" bl_index:"false" bl_include_all:"false"`
NumA string `bl_name:"num_a" bl_index:"false" bl_include_all:"false"`
State AlbumState `bl_name:"state" bl_index:"false" bl_include_all:"false"`
Author string
Editor string
Collection string
SatID string
Author string `bl_name:"auteur" bl_analyzer:"simple"`
Editor string `bl_name:"editor" bl_analyzer:"simple"`
Collection string `bl_name:"collection" bl_analyzer:"fr"`
LegalDeposit time.Time
PrintDate time.Time
PurchaseDate time.Time
}
var endDelim = regexp.MustCompile(` \(.*\)\z`)
var wordBoundaries = regexp.MustCompile(`[^[:alnum:]]+`)
var punctuation = regexp.MustCompile(`[!?\.:;,]`)
func sanitizeTitleString(title string) string {
// first sanitize accuented characters.
isOk := func(r rune) bool {
return r < 32 || r >= 127
}
// The isOk filter is such that there is no need to chain to norm.NFC
t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
// This Transformer could also trivially be applied as an io.Reader
// or io.Writer filter to automatically do such filtering when reading
// or writing data anywhere.
title, _, _ = transform.String(t, title)
//Now we remove all punctuat
return strings.Trim(wordBoundaries.ReplaceAllString(punctuation.ReplaceAllString(title, ""), "-"), "-")
}
// GetBedethequeComURI tries to guess the URI used by bedetheque.com to reference an album, using reverse-engineered euristics
func (a *Album) GetBedethequeComURI() string {
// we check for determinant
matches := endDelim.FindString(a.Series)
series := a.Series
titleMatch := false
if len(matches) != 0 {
series = strings.TrimSuffix(series, matches)
det := strings.Trim(matches, " ()")
if det[len(det)-1] != '\'' {
det = det + " "
}
titleCompare := det + strings.ToLower(series[:1]) + series[1:]
titleMatch = (titleCompare == a.Title)
} else {
titleMatch = (a.Series == a.Title)
}
series = sanitizeTitleString(series)
title := sanitizeTitleString(a.Title)
//first we test if we have a tome identifier
tomeIdent := ""
if a.Num < 0 {
tomeIdent = a.NumA
} else {
tomeIdent = fmt.Sprintf("Tome-%d%s", a.Num, a.NumA)
}
if titleMatch {
if len(tomeIdent) == 0 {
return fmt.Sprintf("BD-%s-%d.html", series, a.ID)
}
return fmt.Sprintf("BD-%s-%s-%d.html", series, tomeIdent, a.ID)
}
if len(tomeIdent) == 0 {
return fmt.Sprintf("BD-%s-%s-%d.html", series, title, a.ID)
}
return fmt.Sprintf("BD-%s-%s-%s-%d.html",
series,
tomeIdent,
title,
a.ID)
}
// A Link represent a link to a ressource
type Link struct {
// Title of the link
Title string
// Target of the link
Target string
}
// An AlbumDescription is a more complete BD description
//
// It holds data that can be fetched from bedetheque.com
type AlbumDescription struct {
CoverExt string
Description string
Note float64
Scenarist []Link
Designer []Link
Colorist []Link
SatID string `bl_name:"cote" bl_analyzer:"keyword"`
LegalDeposit time.Time `bl_name:"dl" bl_index:"false" bl_include_all:"false"`
PrintDate time.Time `bl_name:"ai" bl_index:"false" bl_include_all:"false"`
PurchaseDate time.Time `bl_name:"achat" bl_index:"false" bl_include_all:"false"`
CoverURL string `bl_name:"cover" bl_index:"false" bl_include_all:"false"`
Description string `bl_name:"description" bl_analyzer:"fr"`
Note float64 `bl_name:"note" bl_index:"false" bl_include_all:"false"`
Scenarist []Link `bl_name:"scenario" bl_analyzer:"simple"`
Designer []Link `bl_name:"dessins" bl_analyzer:"simple"`
Colorist []Link `bl_name:"couleurs" bl_analyzer:"simple"`
FetchDate time.Time `bl_name:"old" bl_index:"false" bl_include_all:"false"`
}