Documentation ¶
Overview ¶
Package rls parses release information.
Index ¶
- Variables
- func Compare(a, b Release) int
- func MustClean(s string) string
- func MustNormalize(s string) string
- func NamedCaptureLexer(strs ...string) func([]byte, []byte, int, int) ([]byte, [][]byte, int, int, bool)
- func NewCleaner() transform.Transformer
- func NewNormalizer() transform.Transformer
- type Builder
- type Collapser
- type LexFunc
- type Lexer
- func DefaultLexers() []Lexer
- func NewAudioLexer() Lexer
- func NewDateLexer(strs ...string) Lexer
- func NewDiscLexer(strs ...string) Lexer
- func NewDiscSourceYearLexer(strs ...string) Lexer
- func NewEpisodeLexer() Lexer
- func NewExtLexer() Lexer
- func NewGenreLexer() Lexer
- func NewGroupLexer() Lexer
- func NewIDLexer() Lexer
- func NewMetaLexer(strs ...string) Lexer
- func NewSeriesLexer(strs ...string) Lexer
- func NewTrimWhitespaceLexer() Lexer
- func NewVersionLexer(strs ...string) Lexer
- type Parser
- type Release
- type ReleaseScanner
- type ReleaseScannerOption
- type Scan
- type ScanRecoverError
- type Scanner
- type Tag
- func (tag Tag) Arch() string
- func (tag Tag) As(typ TagType, f taginfo.FindFunc) Tag
- func (tag Tag) Audio() string
- func (tag Tag) Channels() string
- func (tag Tag) Codec() string
- func (tag Tag) Collection() string
- func (tag Tag) Container() string
- func (tag Tag) Cut() string
- func (tag Tag) Date() (int, int, int)
- func (tag Tag) Delim() string
- func (tag Tag) Disc() string
- func (tag Tag) Edition() string
- func (tag Tag) Ext() string
- func (tag Tag) Format(f fmt.State, verb rune)
- func (tag Tag) Genre() string
- func (tag Tag) Group() string
- func (tag Tag) HDR() string
- func (tag Tag) ID() string
- func (tag Tag) Info() *taginfo.Taginfo
- func (tag Tag) InfoExcl() bool
- func (tag Tag) InfoTitle() string
- func (tag Tag) InfoType() Type
- func (tag Tag) Is(types ...TagType) bool
- func (tag Tag) Language() string
- func (tag Tag) Match(s string, verb rune, types ...TagType) bool
- func (tag Tag) Meta() (string, string)
- func (tag Tag) Normalize() string
- func (tag Tag) Other() string
- func (tag Tag) Platform() string
- func (tag Tag) Prev() TagType
- func (tag Tag) Region() string
- func (tag Tag) Resolution() string
- func (tag Tag) Revert() Tag
- func (tag Tag) Series() (int, int)
- func (tag Tag) SingleEp() bool
- func (tag Tag) Size() string
- func (tag Tag) Source() string
- func (tag Tag) TagType() TagType
- func (tag Tag) Text() string
- func (tag Tag) TextReplace(old, newstr string, n int) string
- func (tag Tag) Version() string
- func (tag Tag) Was(types ...TagType) bool
- func (tag Tag) Whitespace() string
- type TagBuilder
- type TagLexer
- type TagParser
- type TagType
- type Type
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 MustNormalize ¶ added in v0.1.19
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).
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.
Types ¶
type Builder ¶
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.
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 NewDateLexer ¶
NewDateLexer creates a tag lexer for a date.
func NewDiscSourceYearLexer ¶
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 NewMetaLexer ¶
NewMetaLexer creates a tag lexer for a file's meta data.
func NewSeriesLexer ¶
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 ¶
NewVersionLexer creates a tag lexer for a version.
type Parser ¶
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.
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 ¶
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 (Release) Format ¶
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
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 ¶
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 ScanRecoverError ¶
ScanRecoverError is a scan recover error.
func (*ScanRecoverError) Error ¶
func (err *ScanRecoverError) Error() string
Error satisfies the error interface.
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag is a release tag.
func ParseTagsString ¶
ParseTagsString parses tags from src.
func (Tag) Collection ¶
Collection normalizes the collection value.
func (Tag) Format ¶
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) Resolution ¶
Resolution normalizes the resolution value.
func (Tag) TextReplace ¶ added in v0.2.4
TextReplace normalizes the text value and replaces the supplied string.
func (Tag) Whitespace ¶
Whitespace normalizes the whitespace value.
type TagBuilder ¶
type TagBuilder struct {
// contains filtered or unexported fields
}
TagBuilder is a release builder.
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 ¶
NewRegexpLexer creates a tag lexer for a regexp.
func NewRegexpSourceLexer ¶
NewRegexpSourceLexer creates a tag lexer for a regexp.
type TagParser ¶
type TagParser struct {
// contains filtered or unexported fields
}
TagParser is a release tag parser.
func (*TagParser) ParseRelease ¶
ParseRelease parses a release from src.
func (*TagParser) SetBuilder ¶
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.