bulk

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2017 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentPrefix

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 Save

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.

Types

type Image

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 Combine

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

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

func FindByID

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.

func LoadCSV

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL