tagaa: github.com/kusubooru/tagaa/bulk Index | Files

package bulk

import "github.com/kusubooru/tagaa/bulk"

Package bulk has functions to load and save image metadata to a CSV file as needed by the 'Bulk Add CSV' Shimmie2 extension. The CSV file is assumed to have the following format:

"/path/to/image.jpg","spaced tags","source","rating s/q/e","/path/thumbnail.jpg"

The last record (thumbnail) is left empty as thumbnails can easily be generated by the server.

The package assumes that all images and the CSV file are under a certain directory path that is used as input in many package functions.

Index

Package Files

bulk.go

func Combine Uses

func Combine(images, imagesWithInfo []Image) []Image

Combine takes the metadata of imagesWithInfo and copies them to images returning the combined result.

func CurrentPrefix Uses

func CurrentPrefix(workingDir string, file io.Reader) (string, error)

CurrentPrefix reads from an open CSV file, reads the first line and uses the base directory of the provided workingDir path to find the path prefix used in the CSV file.

As an example if the provided workingDir path is '/localpath/pics' and the first line has '/serverpath/pics/pic1' then the returned current prefix will be '/serverpath'.

func LoadCSV Uses

func LoadCSV(file io.Reader) ([]Image, error)

LoadCSV loads the image metadata from a CSV file that is open for reading. The metadata are returned as slice of images and should be combined with the slice of images discovered by LoadImages by calling Combine.

func LoadImages Uses

func LoadImages(files []os.FileInfo) []Image

LoadImages expects a slice of directory entries (os.FileInfo) which is the result of a read directory like ioutil.ReadDir. It loops through the slice, ignoring any directory and keeps only the files with one of the following extensions: "gif", "jpeg", "jpg", "png", "swf"

It returns a slice of images without metadata, using the filename as Name and the order the files were found as an increasing ID starting from 0.

In case of a CSV file, the image metadata should be read using LoadCSV and then combined with the images (discovered by LoadImages) using Combine.

func Save Uses

func Save(file io.Writer, images []Image, dir, prefix string, useLinuxSep bool) error

Save will write the image metadata to an open for writing file. It will keep the base of the dir path and replace the prefix with the provided one.

type Image Uses

type Image struct {
    ID     int
    Name   string
    Tags   []string
    Source string
    Rating string
}

Image holds the metadata of each image from the CSV file.

func FindByID Uses

func FindByID(image []Image, id int) *Image

FindByID takes a slice of images, sorts them by ID and then finds then one with ID id.

Package bulk imports 7 packages (graph) and is imported by 1 packages. Updated 2018-01-21. Refresh now. Tools for package owners.