rls

package module
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 22 Imported by: 2

README

about

a package to parse release names. see go doc.

use

package main

import (
	"fmt"

	"github.com/moistari/rls"
)

func main() {
	const title = "The_Velvet_Underground-The_Complete_Matrix_Tapes-Reissue_Limited_Edition_Boxset-8LP-2019-NOiR"
	r := rls.ParseString(title)
	fmt.Printf("%q:\n", r)
	fmt.Printf("  type: %s\n", r.Type)
	fmt.Printf("  artist: %s\n", r.Artist)
	fmt.Printf("  title: %s\n", r.Title)
	fmt.Printf("  year: %d\n", r.Year)
	fmt.Printf("  disc: %s\n", r.Disc)
	fmt.Printf("  source: %s\n", r.Source)
	fmt.Printf("  edition: %q\n", r.Edition)
	fmt.Printf("  other: %q\n", r.Other)
	fmt.Printf("  group: %s\n", r.Group)
	// Output:
	// "The_Velvet_Underground-The_Complete_Matrix_Tapes-Reissue_Limited_Edition_Boxset-8LP-2019-NOiR":
	//   type: music
	//   artist: The Velvet Underground
	//   title: The Complete Matrix Tapes
	//   year: 2019
	//   disc: 8x
	//   source: LP
	//   edition: ["Limited.Edition"]
	//   other: ["REISSUE" "BOXSET"]
	//   group: NOiR
}

Documentation

Overview

Package rls parses release information.

Index

Examples

Constants

This section is empty.

Variables

View Source
var CompareMap = map[Type]int{
	Unknown:   0,
	Movie:     1,
	Series:    2,
	Episode:   2,
	Music:     3,
	App:       4,
	Game:      5,
	Book:      6,
	Audiobook: 7,
	Comic:     9,
	Education: 8,
	Magazine:  10,
}

CompareMap is the release compare map. Modifying this will alter the order by which different release types are grouped together when using Compare with a sort operation.

Functions

func Compare

func Compare(a, b Release) int

Compare compares a to b, normalizing titles with Normalize, comparing the resulting lower cased strings. Release types are grouped together based on the precedence defined in CompareMap.

func MustClean added in v0.1.17

func MustClean(s string) string

MustClean applies the Clean transform to s.

func MustNormalize added in v0.1.19

func MustNormalize(s string) string

MustNormalize applies the Normalize transform to s, returning a lower cased, clean form of s useful for matching titles.

func NamedCaptureLexer

func NamedCaptureLexer(strs ...string) func([]byte, []byte, int, int) ([]byte, [][]byte, int, int, bool)

NamedCaptureLexer returns a func that matches named capture groups, returning as name/value string pairs.

func NewCleaner added in v0.3.0

func NewCleaner() transform.Transformer

NewCleaner creates a text transformer chain that transforms text to its textual decomposed clean form (NFD), removing all non-spacing marks, converting all spaces to ' ', removing ', collapsing adjacent spaces into a single ' ', and finally returning the canonical normalized form (NFC).

See: https://go.dev/blog/normalization

func NewNormalizer added in v0.3.0

func NewNormalizer() transform.Transformer

NewNormalizer creates a new a text transformer chain (similiar to NewCleaner) that normalizes text to lower case clean form useful for matching titles.

See: https://go.dev/blog/normalization

Types

type Builder

type Builder interface {
	Build([]Tag, int) Release
}

Builder is the interface for release builders.

var DefaultBuilder Builder

DefaultBuilder is the default release tag builder.

type Collapser added in v0.1.19

type Collapser struct {
	// Spc is the space rune.
	Spc rune
	// Lower toggles lower casing.
	Lower bool
	// Trim toggles trimming leading/trailing spaces.
	Trim bool
	// Remove are the runes to remove.
	Remove map[rune]bool
	// Space are the runes to convert to Spc.
	Space map[rune]bool
	// Transformer is a rune transformer.
	Transformer func(rune, rune, rune) rune
}

Collapser is a transform.Transformer that converts spaces to ' ', removes specified runes, and collapses adjacent spaces to a single ' '.

See: https://go.dev/blog/normalization

func NewCollapser added in v0.1.19

func NewCollapser(lower, trim bool, remove, space string, transformer func(rune, rune, rune) rune) Collapser

NewCollapser creates a text transformer that collapses spaces, removes specific runes, optionally lower cases runes, and removes non-spacing marks.

Ideally used between a transform chain of norm.NFD and norm.NFC.

Clean, Normalize, and MustClean, MustNormalize are provided for utility purposes.

See: https://go.dev/blog/normalization

func (Collapser) Reset added in v0.1.19

func (Collapser) Reset()

Reset satisfies the transform.Transformer interface.

func (Collapser) Transform added in v0.1.19

func (c Collapser) Transform(dst, src []byte, atEOF bool) (int, int, error)

Transform satisfies the transform.Transformer interface.

type LexFunc

type LexFunc func([]byte, []byte, []Tag, []Tag, int, int) ([]Tag, []Tag, int, int, bool)

LexFunc is the signature for lexer funcs.

type Lexer

type Lexer interface {
	Initialize(map[string][]*taginfo.Taginfo, *regexp.Regexp, map[string]bool) (LexFunc, bool, bool)
}

Lexer is the interface for lexers.

func DefaultLexers

func DefaultLexers() []Lexer

DefaultLexers returns the default tag tag lexers.

func NewAudioLexer

func NewAudioLexer() Lexer

NewAudioLexer creates a tag lexer for audios.

func NewDateLexer

func NewDateLexer(strs ...string) Lexer

NewDateLexer creates a tag lexer for a date.

func NewDiscLexer

func NewDiscLexer(strs ...string) Lexer

NewDiscLexer creates a tag lexer for a disc.

n - number
t - type
x - xXtype

func NewDiscSourceYearLexer

func NewDiscSourceYearLexer(strs ...string) Lexer

NewDiscSourceYearLexer creates a tag lexer for the combined disc, source, year style tag.

func NewEpisodeLexer

func NewEpisodeLexer() Lexer

NewEpisodeLexer creates a tag lexer for a single episode (`- 2 -`, `- 867 (`, `- 100 [`).

func NewExtLexer

func NewExtLexer() Lexer

NewExtLexer creates a tag lexer for a file's extension.

func NewGenreLexer

func NewGenreLexer() Lexer

NewGenreLexer creates a tag lexer for a genre.

func NewGroupLexer

func NewGroupLexer() Lexer

NewGroupLexer creates a tag lexer for a group.

func NewIDLexer

func NewIDLexer() Lexer

NewIDLexer creates a tag lexer for a music id.

func NewMetaLexer

func NewMetaLexer(strs ...string) Lexer

NewMetaLexer creates a tag lexer for a file's meta data.

func NewSeriesLexer

func NewSeriesLexer(strs ...string) Lexer

NewSeriesLexer creates a tag lexer for a series.

func NewTrimWhitespaceLexer

func NewTrimWhitespaceLexer() Lexer

NewTrimWhitespaceLexer creates a tag lexer that matches leading and ending whitespace.

func NewVersionLexer

func NewVersionLexer(strs ...string) Lexer

NewVersionLexer creates a tag lexer for a version.

type Parser

type Parser interface {
	Parse([]byte) ([]Tag, int)
	ParseRelease([]byte) Release
}

Parser is the interface for parsers.

var DefaultParser Parser

DefaultParser is the default tag parser.

func NewDefaultParser

func NewDefaultParser() Parser

NewDefaultParser creates a new default tag parser.

func NewTagParser

func NewTagParser(infos map[string][]*taginfo.Taginfo, lexers ...Lexer) Parser

NewTagParser creates a new release tag parser.

type Release

type Release struct {
	Type Type

	Artist   string
	Title    string
	Subtitle string
	Alt      string

	Platform string
	Arch     string

	Source     string
	Resolution string
	Collection string

	Year  int
	Month int
	Day   int

	Series  int
	Episode int
	Version string
	Disc    string

	Codec    []string
	HDR      []string
	Audio    []string
	Channels string
	Other    []string
	Cut      []string
	Edition  []string
	Language []string

	Size      string
	Region    string
	Container string
	Genre     string
	ID        string
	Group     string
	Meta      []string
	Site      string
	Sum       string
	Pass      string
	Req       bool
	Ext       string
	// contains filtered or unexported fields
}

Release is release information.

func Parse

func Parse(src []byte) Release

Parse creates a release from src.

Example
package main

import (
	"fmt"

	"github.com/moistari/rls"
)

func main() {
	const title = "The_Velvet_Underground-The_Complete_Matrix_Tapes-Reissue_Limited_Edition_Boxset-8LP-2019-NOiR"
	r := rls.ParseString(title)
	fmt.Printf("%q:\n", r)
	fmt.Printf("  type: %s\n", r.Type)
	fmt.Printf("  artist: %s\n", r.Artist)
	fmt.Printf("  title: %s\n", r.Title)
	fmt.Printf("  year: %d\n", r.Year)
	fmt.Printf("  disc: %s\n", r.Disc)
	fmt.Printf("  source: %s\n", r.Source)
	fmt.Printf("  edition: %q\n", r.Edition)
	fmt.Printf("  other: %q\n", r.Other)
	fmt.Printf("  group: %s\n", r.Group)
}
Output:

"The_Velvet_Underground-The_Complete_Matrix_Tapes-Reissue_Limited_Edition_Boxset-8LP-2019-NOiR":
  type: music
  artist: The Velvet Underground
  title: The Complete Matrix Tapes
  year: 2019
  disc: 8x
  source: LP
  edition: ["Limited.Edition"]
  other: ["REISSUE" "BOXSET"]
  group: NOiR

func ParseString

func ParseString(src string) Release

ParseString creates a release from src

func (Release) Dates

func (r Release) Dates() []Tag

Dates returns date tags not used.

func (Release) Format

func (r Release) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

Format Options:

o - original release
v - tag type followed by colon and quoted capture value (Date:["2009", "", ""])
s - normalized capture value (2009)
e - tag type and normal value (as in s) surrounded by angle brackets (<Date:2009>)
q - original captured value, quoted

func (Release) String

func (r Release) String() string

String satisfies the fmt.Stringer interface.

func (Release) Tags

func (r Release) Tags() []Tag

Tags returns all tags.

func (Release) Unused

func (r Release) Unused() []Tag

Unused returns text tags not used in titles.

type ReleaseScanner

type ReleaseScanner struct {
	// contains filtered or unexported fields
}

ReleaseScanner is a release scanner.

func NewReleaseScanner

func NewReleaseScanner(p Parser, opts ...ReleaseScannerOption) *ReleaseScanner

NewReleaseScanner creates a new release scanner.

func NewScanner

func NewScanner(opts ...ReleaseScannerOption) *ReleaseScanner

NewScanner creates a new release scanner using the default parser.

func (*ReleaseScanner) Err

func (s *ReleaseScanner) Err() error

Err returns the last encountered error.

func (*ReleaseScanner) Scan

func (s *ReleaseScanner) Scan(ctx context.Context, scanner Scanner) <-chan *Scan

Scan scans until the context is closed, or the scanner is exhausted.

func (*ReleaseScanner) ScanReader

func (s *ReleaseScanner) ScanReader(ctx context.Context, r io.Reader) <-chan *Scan

ScanReader scans a reader until the context is closed, or the reader is exhausted.

type ReleaseScannerOption

type ReleaseScannerOption func(*ReleaseScanner)

ReleaseScannerOption is a release scanner option.

func WithWorkers

func WithWorkers(workers int) ReleaseScannerOption

WithWorkers is a release scanner option to set the number of workers.

type Scan

type Scan struct {
	Release Release
	Line    string
	ID      int64
}

Scan represents scanned work.

type ScanRecoverError

type ScanRecoverError struct {
	Worker int
	ID     int64
	S      string
	Stack  []byte
	Err    interface{}
}

ScanRecoverError is a scan recover error.

func (*ScanRecoverError) Error

func (err *ScanRecoverError) Error() string

Error satisfies the error interface.

type Scanner

type Scanner interface {
	Scan() bool
	Text() string
	Err() error
}

Scanner is the scanner interface. Compatible with bufio.Scanner.

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag is a release tag.

func Find

func Find(tags []Tag, s string, count int, verb rune, types ...TagType) ([]Tag, int)

Find finds a tag.

func NewTag

func NewTag(typ TagType, f taginfo.FindFunc, b ...[]byte) Tag

NewTag creates a new tag.

func ParseTags

func ParseTags(src []byte) ([]Tag, int)

ParseTags parses tags from src.

func ParseTagsString

func ParseTagsString(src string) ([]Tag, int)

ParseTagsString parses tags from src.

func (Tag) Arch

func (tag Tag) Arch() string

Arch normalizes the arch value.

func (Tag) As

func (tag Tag) As(typ TagType, f taginfo.FindFunc) Tag

As returns a copy of tag as a tag of the specified type.

func (Tag) Audio

func (tag Tag) Audio() string

Audio normalizes an audio value.

func (Tag) Channels

func (tag Tag) Channels() string

Channels normalizes an channels value.

func (Tag) Codec

func (tag Tag) Codec() string

Codec normalizes a codec value.

func (Tag) Collection

func (tag Tag) Collection() string

Collection normalizes the collection value.

func (Tag) Container

func (tag Tag) Container() string

Container normalizes the container value.

func (Tag) Cut

func (tag Tag) Cut() string

Cut normalizes the cut value.

func (Tag) Date

func (tag Tag) Date() (int, int, int)

Date normalizes the date value.

func (Tag) Delim

func (tag Tag) Delim() string

Delim normalizes the delimiter value.

func (Tag) Disc

func (tag Tag) Disc() string

Disc normmalizes the disc value.

func (Tag) Edition

func (tag Tag) Edition() string

Edition normalizes the edition value.

func (Tag) Ext

func (tag Tag) Ext() string

Ext normalizes a file ext value.

func (Tag) Format

func (tag Tag) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

Format Options:

q - all values including captured values, quoted (["2009", "2009", "", ""])
o - original capture (2009)
v - tag type followed by colon and quoted capture value (Date:["2009", "", ""])
s - normalized capture value (2009)
r - same as s
e - tag type and normal value (as in s) surrounded by angle brackets (<Date:2009>)

func (Tag) Genre

func (tag Tag) Genre() string

Genre normalizes the genre value.

func (Tag) Group

func (tag Tag) Group() string

Group normalizes the group value.

func (Tag) HDR added in v0.2.0

func (tag Tag) HDR() string

HDR normalizes a hdr value.

func (Tag) ID

func (tag Tag) ID() string

ID normalizes the id value.

func (Tag) Info

func (tag Tag) Info() *taginfo.Taginfo

Info retrieves the tag's tag info.

func (Tag) InfoExcl

func (tag Tag) InfoExcl() bool

InfoExcl returns the associated tag info excl.

func (Tag) InfoTitle

func (tag Tag) InfoTitle() string

InfoTitle retrieves the tag's title.

func (Tag) InfoType

func (tag Tag) InfoType() Type

InfoType returns the associated tag info type.

func (Tag) Is

func (tag Tag) Is(types ...TagType) bool

Is returns true when tag is of a type.

func (Tag) Language

func (tag Tag) Language() string

Language normalizes the language value.

func (Tag) Match

func (tag Tag) Match(s string, verb rune, types ...TagType) bool

Match determines if s matches the tag.

func (Tag) Meta

func (tag Tag) Meta() (string, string)

Meta normalizes a file meta value.

func (Tag) Normalize

func (tag Tag) Normalize() string

Normalize returns the normalized string for the tag.

func (Tag) Other

func (tag Tag) Other() string

Other normalizes the other value.

func (Tag) Platform

func (tag Tag) Platform() string

Platform normalizes the platform value.

func (Tag) Prev added in v0.2.4

func (tag Tag) Prev() TagType

Prev returns the tag's previous tag type.

func (Tag) Region

func (tag Tag) Region() string

Region normalizes the region value.

func (Tag) Resolution

func (tag Tag) Resolution() string

Resolution normalizes the resolution value.

func (Tag) Revert added in v0.5.1

func (tag Tag) Revert() Tag

Revert returns a copy of tag as the tag's previous type.

func (Tag) Series

func (tag Tag) Series() (int, int)

Series normalizes the series value.

func (Tag) SingleEp added in v0.5.9

func (tag Tag) SingleEp() bool

SingleEp returns true when the

func (Tag) Size

func (tag Tag) Size() string

Size normalizes the size value.

func (Tag) Source

func (tag Tag) Source() string

Source normalizes the source value.

func (Tag) TagType

func (tag Tag) TagType() TagType

TagType returns the tag's tag type.

func (Tag) Text

func (tag Tag) Text() string

Text normalizes the text value.

func (Tag) TextReplace added in v0.2.4

func (tag Tag) TextReplace(old, newstr string, n int) string

TextReplace normalizes the text value and replaces the supplied string.

func (Tag) Version

func (tag Tag) Version() string

Version normalizes the version value.

func (Tag) Was added in v0.5.1

func (tag Tag) Was(types ...TagType) bool

Was returns true when tag's prev is of a type.

func (Tag) Whitespace

func (tag Tag) Whitespace() string

Whitespace normalizes the whitespace value.

type TagBuilder

type TagBuilder struct {
	// contains filtered or unexported fields
}

TagBuilder is a release builder.

func NewTagBuilder

func NewTagBuilder() *TagBuilder

NewTagBuilder creates a new release builder.

func (*TagBuilder) Build

func (b *TagBuilder) Build(tags []Tag, end int) Release

Build builds a release from tags.

func (*TagBuilder) Init

func (b *TagBuilder) Init(infos map[string][]*taginfo.Taginfo) Builder

Init creates a new builder using the provided infos.

type TagLexer

type TagLexer struct {
	Init     func(map[string][]*taginfo.Taginfo, *regexp.Regexp, map[string]bool)
	Lex      LexFunc
	NotFirst bool
	Once     bool
}

TagLexer is a tag lexer.

func NewRegexpLexer

func NewRegexpLexer(typ TagType, ignoreCase bool) TagLexer

NewRegexpLexer creates a tag lexer for a regexp.

func NewRegexpSourceLexer

func NewRegexpSourceLexer(typ TagType, ignoreCase bool) TagLexer

NewRegexpSourceLexer creates a tag lexer for a regexp.

func (TagLexer) Initialize

func (lexer TagLexer) Initialize(infos map[string][]*taginfo.Taginfo, delim *regexp.Regexp, short map[string]bool) (LexFunc, bool, bool)

Init satisfies the Lexer interface.

type TagParser

type TagParser struct {
	// contains filtered or unexported fields
}

TagParser is a release tag parser.

func (*TagParser) Parse

func (p *TagParser) Parse(src []byte) ([]Tag, int)

Parse parses tags in buf.

func (*TagParser) ParseRelease

func (p *TagParser) ParseRelease(src []byte) Release

ParseRelease parses a release from src.

func (*TagParser) SetBuilder

func (p *TagParser) SetBuilder(builder Builder)

SetBuilder sets the builder for the tag parser.

type TagType

type TagType int

TagType is a tag type.

const (
	TagTypeWhitespace TagType = iota
	TagTypeDelim
	TagTypeText
	TagTypePlatform
	TagTypeArch
	TagTypeSource
	TagTypeResolution
	TagTypeCollection
	TagTypeDate
	TagTypeSeries
	TagTypeVersion
	TagTypeDisc
	TagTypeCodec
	TagTypeHDR
	TagTypeAudio
	TagTypeChannels
	TagTypeOther
	TagTypeCut
	TagTypeEdition
	TagTypeLanguage
	TagTypeSize
	TagTypeRegion
	TagTypeContainer
	TagTypeGenre
	TagTypeID
	TagTypeGroup
	TagTypeMeta
	TagTypeExt
)

TagType values.

func (TagType) Is

func (typ TagType) Is(types ...TagType) bool

Is returns true when tag type is in types.

func (TagType) String

func (i TagType) String() string

type Type

type Type int

Type is a release type.

const (
	Unknown Type = iota
	App
	Audiobook
	Book
	Comic
	Education
	Episode
	Game
	Magazine
	Movie
	Music
	Series
)

Release types.

func ParseType

func ParseType(s string) Type

ParseType parses a type from s.

func (Type) Is

func (typ Type) Is(types ...Type) bool

Is returns true when the type is in types.

func (Type) String

func (typ Type) String() string

String satisfies the fmt.Stringer interface.

Directories

Path Synopsis
Package reutil has regexp util funcs.
Package reutil has regexp util funcs.
Package taginfo contains tag info.
Package taginfo contains tag info.

Jump to

Keyboard shortcuts

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