mirror of
https://github.com/bitmagnet-io/bitmagnet.git
synced 2026-05-06 04:16:44 -04:00
c16f76130c
The classifier has been re-implemented and now uses a DSL allowing for full customisation. Several bugs have also been fixed. - Closes https://github.com/bitmagnet-io/bitmagnet/issues/182 - Closes https://github.com/bitmagnet-io/bitmagnet/issues/70 - Closes https://github.com/bitmagnet-io/bitmagnet/issues/68 - Hopefully fixes https://github.com/bitmagnet-io/bitmagnet/issues/126
41 lines
1012 B
Go
41 lines
1012 B
Go
package classifier
|
|
|
|
import (
|
|
"github.com/bitmagnet-io/bitmagnet/internal/classifier/classification"
|
|
"github.com/bitmagnet-io/bitmagnet/internal/classifier/parsers"
|
|
)
|
|
|
|
const parseDateName = "parse_date"
|
|
|
|
type parseDateAction struct{}
|
|
|
|
func (parseDateAction) name() string {
|
|
return parseDateName
|
|
}
|
|
|
|
var parseDatePayloadSpec = payloadLiteral[string]{
|
|
literal: parseDateName,
|
|
description: "Try to parse a date from the name of the current torrent",
|
|
}
|
|
|
|
func (parseDateAction) compileAction(ctx compilerContext) (action, error) {
|
|
if _, err := parseDatePayloadSpec.Unmarshal(ctx); err != nil {
|
|
return action{}, ctx.error(err)
|
|
}
|
|
return action{
|
|
run: func(ctx executionContext) (classification.Result, error) {
|
|
parsed := parsers.ParseDate(ctx.torrent.Name)
|
|
if parsed.IsNil() {
|
|
return ctx.result, classification.ErrUnmatched
|
|
}
|
|
cl := ctx.result
|
|
cl.Date = parsed
|
|
return cl, nil
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (parseDateAction) JsonSchema() JsonSchema {
|
|
return parseDatePayloadSpec.JsonSchema()
|
|
}
|