// UpdateSeries updates the series metadata for all epub books on the device. All
// errors from individual books are returned through the log callback.
UpdateSeries updates the series metadata for all epub books on the device. All
errors from individual books are returned through the log callback.
// UpdateSeries updates the series metadata for all epub books on the device . All // errors from individual books are returned through the log callback .
func (k *Kobo) UpdateSeries(log func(filename string, i, total int, series string, index float64, err error)) error {
	var epubs []string
	err := filepath.Walk(k.Path, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return fmt.Errorf("error scanning %q: %w", path, err)
		}
		if !info.IsDir() && strings.EqualFold(filepath.Ext(path), ".epub") {
			epubs = append(epubs, path)
		}
		return nil
	})
	if err != nil {
		return err
	}
	relEpubs := make([]string, len(epubs))
	for i, epub := range epubs {
		relEpubs[i], err = filepath.Rel(k.Path, epub)
		if err != nil {
			return fmt.Errorf("could not resolve relative path to %#v: %w", epub, err)
		}
	}
	tx, err := k.DB.Begin()
	if err != nil {
		return fmt.Errorf("could not begin db transaction: %w", err)
	}
	for i, epub := range epubs {
		relEpub := relEpubs[i]
		series, index, err := readEPUBSeriesInfo(epub)
		if err != nil {
			log(relEpub, i, len(epubs), series, index, err)
			continue
		}
		if _, err := tx.Exec(
			"INSERT OR REPLACE INTO _seriesmeta (ImageId, Series, SeriesNumber) VALUES (?, ?, ?)",
			kobo.ContentIDToImageID(kobo.PathToContentID(relEpub)),
			sql.NullString{String: series, Valid: len(series) > 0},
			sql.NullString{String: strconv.FormatFloat(index, 'f', -1, 64), Valid: index > 0},
		); err != nil {
			log(relEpub, i, len(epubs), series, index, err)
			continue
		}
		log(relEpub, i, len(epubs), series, index, nil)
	}
	if err := tx.Commit(); err != nil {
		return fmt.Errorf("could not commit db transaction: %w", err)
	}
	return nil
}
func ( k * Kobo ) UpdateSeries ( log func ( filename string , i , total int , series string , index float64 , err error ) ) error { var epubs [ ] string err := filepath . Walk ( k . Path , func ( path string , info os . FileInfo , err error ) error { if err != nil { return fmt . Errorf ( " " , path , err ) } if ! info . IsDir ( ) && strings . EqualFold ( filepath . Ext ( path ) , " " ) { epubs = append ( epubs , path ) } return nil } ) if err != nil { return err } relEpubs := make ( [ ] string , len ( epubs ) ) for i , epub := range epubs { relEpubs [ i ] , err = filepath . Rel ( k . Path , epub ) if err != nil { return fmt . Errorf ( " " , epub , err ) } } tx , err := k . DB . Begin ( ) if err != nil { return fmt . Errorf ( " " , err ) } for i , epub := range epubs { relEpub := relEpubs [ i ] series , index , err := readEPUBSeriesInfo ( epub ) if err != nil { log ( relEpub , i , len ( epubs ) , series , index , err ) continue } if _ , err := tx . Exec ( " " , kobo . ContentIDToImageID ( kobo . PathToContentID ( relEpub ) ) , sql . NullString { String : series , Valid : len ( series ) > 0 } , sql . NullString { String : strconv . FormatFloat ( index , 'f' , - 1 , 64 ) , Valid : index > 0 } , ) ; err != nil { log ( relEpub , i , len ( epubs ) , series , index , err ) continue } log ( relEpub , i , len ( epubs ) , series , index , nil ) } if err := tx . Commit ( ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
UpdateSeries updates the series metadata for all epub books on the device.
UpdateSeries updates the series metadata for all epub books on the device .