Skip to content
Snippets Groups Projects
Select Git revision
  • 6b724c8fce31d5e70eae4eacc1a7d32b3e73b6a7
  • noblogs default
  • noblogs-5.7.1
  • upstream
  • noblogs-5.7
  • noblogs-5.6new
  • upstream5.5.1
  • noblogs28dic
  • upstream28dic
  • noblogs-5.5.1
  • noblogs-5.4.2
  • noblogs-5.4_seconda
  • noblogs-5.4
  • noblogs-7c
  • wp5.2.3p3
  • mergedbconf
  • noblogs-5.7.1
  • noblogs.5.7.0p1
  • noblogs-5.7.0
  • noblogs-5.6p3
  • noblogs5.6p2
  • noblogs-5.6p1
  • noblogs-5.6
  • noblogs-5.4.2p1
  • noblogs-5.4.2
  • noblogs-5.4.1
  • noblogs-5.4
  • noblogs-p5.4
  • noblogs-5.3.2p2
  • noblogs-5.3.2p1
  • noblogs-5.3.2
  • noblogs-5.3
  • noblogs-5.2.3p4
  • noblogs-5.2.3p3
  • noblogs-5.2.3p2
  • noblogs-5.2.3p1
36 results

revisions.js

Blame
  • refine.go 3.22 KiB
    package liber
    
    import (
    	"bufio"
    	"bytes"
    	"errors"
    	"fmt"
    	"io"
    	"log"
    	"os"
    )
    
    func (db *Database) RefineFunc(dir string, chooser MetadataChooserFunc) func(*Book) error {
    	storage := NewFileStorage(dir)
    	refiners := defaultMetadataRefiners
    
    	return func(book *Book) error {
    		if err := refineMetadata(book, "", storage, refiners, chooser); err == nil {
    			log.Printf("%s: updated metadata", book.Id)
    			return db.PutBook(book)
    		}
    		return nil
    	}
    }
    
    // ListBooks writes IDs of books that match any of a series of
    // functions to an io.Writer.
    func (db *Database) ListBooks(w io.Writer, matchFuncs ...func(book *Book) bool) error {
    	return db.onAllBooks(func(book *Book) error {
    		ok := false
    		for _, f := range matchFuncs {
    			if f(book) {
    				ok = true
    				break
    			}
    		}
    		if ok {
    			fmt.Fprintf(w, "%s\n", book.Id)
    		}
    		return nil
    	})
    }
    
    // WithBookIDs calls a function on books whose IDs are read from the
    // specified io.Reader.
    func (db *Database) WithBookIDs(r io.Reader, f func(book *Book) error) error {
    	scanner := bufio.NewScanner(r)
    	for scanner.Scan() {
    		id := ParseID(string(bytes.TrimSpace(scanner.Bytes())))
    		book, err := db.GetBook(id)
    		if err != nil {
    			log.Printf("error: no such book %s", id)
    			continue
    		}
    		if err := f(book); err != nil {
    			log.Printf("error: %s: %v", id, err)
    			// Stop?
    		}
    	}
    	return scanner.Err()
    }
    
    // Local path is a hint for generating the cover image.
    func findCoverImage(book *Book, path string, refiners []MetadataRefiner, storage *FileStorage) error {
    	if book.CoverPath != "" {
    		return nil
    	}
    
    	localCoverPath := path + ".cover.png"
    	for _, refiner := range refiners {