importer

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package importer brings watch history, collections and custom posters over from another media server's data folder, so switching to Matinee doesn't mean starting again. The media files stay where they are: what the other server knew about a file is matched to Matinee's item for the same file, by path, after the admin's path changes (the two servers may see the same share under different folders).

The format read here is the library database (SQLite) and metadata bundles that server keeps in its data folder.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDatabase = errors.New("no media server data found there")

ErrNoDatabase means a folder has no library database in it, nor in the folders a few levels down.

View Source
var ErrUnreadable = fmt.Errorf("that isn't a media server database Matinee can read")

ErrUnreadable means the file isn't a library database Matinee can read.

Functions

func Find

func Find() []string

Find lists data folders found where that server keeps them by default on this computer, for an admin to pick from.

func MapPath

func MapPath(p string, changes []PathChange) string

MapPath applies the change with the longest matching start, and writes the rest of the path with the separators Matinee's side uses.

Types

type Account

type Account struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

Account is someone who watched on the other server.

type AccountSummary

type AccountSummary struct {
	Account
	Watched    int `json:"watched"`
	InProgress int `json:"inProgress"`
	Rated      int `json:"rated"`
	Found      int `json:"found"` // of those watched, on Matinee
}

AccountSummary is how much one account watched there, and how much of it Matinee has.

type Collection

type Collection struct {
	Name  string
	Items []int64
}

Collection is a named group of items.

type Item

type Item struct {
	ID       int64
	ParentID int64
	Type     int
	GUID     string
	Hash     string // names its metadata bundle
	Poster   string // the poster it uses; "upload://posters/…" for one someone uploaded
	Title    string
}

Item is a movie, show, season, episode, artist, album or track there.

type Location

type Location struct {
	DB string // the library database
	// DataDir is the data folder holding Metadata/ (custom posters); empty
	// when only the database is at hand, such as one uploaded on its own.
	DataDir string
}

Location is where an import reads from.

func Locate

func Locate(path string) (Location, error)

Locate finds the library database for a path an admin gave: the data folder itself, a folder above it, the Databases folder, or the database file.

type Options

type Options struct {
	// Accounts maps the other server's accounts to Matinee's accounts or
	// profiles; accounts left out are skipped.
	Accounts    map[int64]int64
	Watched     bool
	Collections bool
	Posters     bool
	Ratings     bool
	// Step is told what's done so far, out of the total, as the import goes.
	Step func(done, total int)
}

Options say what an import brings over, and for whom.

type PathChange

type PathChange struct {
	From string `json:"from"`
	To   string `json:"to"`
	// Files is how many files the change finds, when it's a suggestion.
	Files int `json:"files,omitempty"`
}

PathChange turns the start of the other server's paths into Matinee's: the same share may be /data/movies to one and /mnt/media/movies to the other.

func SuggestChanges

func SuggestChanges(files []string, known func(string) bool, byName map[string][]string, have []PathChange) []PathChange

SuggestChanges looks at the files that don't match and finds the path changes that would match them: a Matinee file with the same name and the same folders above it, up to where the two paths differ. It returns the changes that each find at least two files (or one, when that's all there is), most files first.

type Plan

type Plan struct {
	Changes []PathChange

	// Files counts the other server's files, and Matched the ones Matinee has.
	Files, Matched int
	// Unmatched lists a few files Matinee doesn't have, as examples.
	Unmatched []string
	// Suggested are path changes that would match more files.
	Suggested []PathChange
	// contains filtered or unexported fields
}

Plan is a snapshot matched to Matinee's files with a set of path changes.

func NewPlan

func NewPlan(snap *Snapshot, files []store.FileRef, changes []PathChange) *Plan

NewPlan matches a snapshot's files to Matinee's.

func (*Plan) Accounts

func (p *Plan) Accounts() []AccountSummary

Accounts sums up each account's history.

func (*Plan) Apply

func (p *Plan) Apply(ctx context.Context, s *store.Store, o Options) (Result, error)

Apply brings the history, collections and posters over. Places and watched marks only replace Matinee's own when the other server's are newer, so running an import again, or after watching here, loses nothing.

func (*Plan) Collections

func (p *Plan) Collections() int

Collections counts the collections with something Matinee has.

func (*Plan) Location

func (p *Plan) Location() Location

Location is where the plan's snapshot was read from.

func (*Plan) Posters

func (p *Plan) Posters() int

Posters counts the uploaded posters there are to bring over.

type Result

type Result struct {
	Watched         int `json:"watched"`         // marked watched
	InProgress      int `json:"inProgress"`      // given a place to resume from
	Kept            int `json:"kept"`            // left alone: watched more recently on Matinee
	Collections     int `json:"collections"`     // made or added to
	CollectionItems int `json:"collectionItems"` // titles put in them
	Posters         int `json:"posters"`
	Ratings         int `json:"ratings"` // given or changed
}

Result says what an import did.

type Snapshot

type Snapshot struct {
	Location    Location
	Accounts    []Account
	Items       map[int64]*Item
	Files       map[int64][]string // item id → its files, in part order
	Views       []View
	Collections []Collection
}

Snapshot is everything an import uses, read in one go.

func Read

func Read(ctx context.Context, loc Location) (*Snapshot, error)

Read copies the database (and its write-ahead log, so recent changes count) aside and reads what an import needs. The copy means the other server can keep running, and its files are never changed.

type View

type View struct {
	AccountID  int64
	GUID       string
	OffsetMs   int64
	Count      int64
	LastViewed int64 // Unix seconds; 0 when unknown
	// Rating is the account's rating out of 10 (0 for none), and RatedAt
	// when it was given.
	Rating  float64
	RatedAt int64
}

View is where one account is in one item, keyed by the item's GUID.

func (View) Watched

func (v View) Watched() bool

Watched says whether the record is about watching, not only a rating.

Directories

Path Synopsis
Package importertest builds a small data folder in the other media server's format, for tests.
Package importertest builds a small data folder in the other media server's format, for tests.

Jump to

Keyboard shortcuts

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