mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(indexers): load custom definitions (#186)
This commit is contained in:
parent
159133ef35
commit
fdf69e6403
6 changed files with 147 additions and 14 deletions
|
@ -80,7 +80,7 @@ func main() {
|
||||||
downloadClientService = download_client.NewService(downloadClientRepo)
|
downloadClientService = download_client.NewService(downloadClientRepo)
|
||||||
actionService = action.NewService(actionRepo, downloadClientService, bus)
|
actionService = action.NewService(actionRepo, downloadClientService, bus)
|
||||||
apiService = indexer.NewAPIService()
|
apiService = indexer.NewAPIService()
|
||||||
indexerService = indexer.NewService(indexerRepo, apiService)
|
indexerService = indexer.NewService(cfg, indexerRepo, apiService)
|
||||||
filterService = filter.NewService(filterRepo, actionRepo, apiService, indexerService)
|
filterService = filter.NewService(filterRepo, actionRepo, apiService, indexerService)
|
||||||
releaseService = release.NewService(releaseRepo, actionService)
|
releaseService = release.NewService(releaseRepo, actionService)
|
||||||
ircService = irc.NewService(ircRepo, filterService, indexerService, releaseService)
|
ircService = irc.NewService(ircRepo, filterService, indexerService, releaseService)
|
||||||
|
|
|
@ -38,3 +38,7 @@ logLevel = "TRACE"
|
||||||
# Session secret
|
# Session secret
|
||||||
#
|
#
|
||||||
sessionSecret = "secret-session-key"
|
sessionSecret = "secret-session-key"
|
||||||
|
|
||||||
|
# Custom definitions
|
||||||
|
#
|
||||||
|
#customDefinitions = "test/definitions"
|
||||||
|
|
|
@ -16,12 +16,13 @@ var Config domain.Config
|
||||||
|
|
||||||
func Defaults() domain.Config {
|
func Defaults() domain.Config {
|
||||||
return domain.Config{
|
return domain.Config{
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: 8989,
|
Port: 8989,
|
||||||
LogLevel: "DEBUG",
|
LogLevel: "TRACE",
|
||||||
LogPath: "",
|
LogPath: "",
|
||||||
BaseURL: "/",
|
BaseURL: "/",
|
||||||
SessionSecret: "secret-session-key",
|
SessionSecret: "secret-session-key",
|
||||||
|
CustomDefinitions: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Host string `toml:"host"`
|
Host string `toml:"host"`
|
||||||
Port int `toml:"port"`
|
Port int `toml:"port"`
|
||||||
LogLevel string `toml:"logLevel"`
|
LogLevel string `toml:"logLevel"`
|
||||||
LogPath string `toml:"logPath"`
|
LogPath string `toml:"logPath"`
|
||||||
BaseURL string `toml:"baseUrl"`
|
BaseURL string `toml:"baseUrl"`
|
||||||
SessionSecret string `toml:"sessionSecret"`
|
SessionSecret string `toml:"sessionSecret"`
|
||||||
|
CustomDefinitions string `toml:"customDefinitions"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -26,6 +28,7 @@ type Service interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
|
config domain.Config
|
||||||
repo domain.IndexerRepo
|
repo domain.IndexerRepo
|
||||||
apiService APIService
|
apiService APIService
|
||||||
|
|
||||||
|
@ -38,8 +41,9 @@ type service struct {
|
||||||
lookupIRCServerDefinition map[string]map[string]domain.IndexerDefinition
|
lookupIRCServerDefinition map[string]map[string]domain.IndexerDefinition
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(repo domain.IndexerRepo, apiService APIService) Service {
|
func NewService(config domain.Config, repo domain.IndexerRepo, apiService APIService) Service {
|
||||||
return &service{
|
return &service{
|
||||||
|
config: config,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
apiService: apiService,
|
apiService: apiService,
|
||||||
indexerDefinitions: make(map[string]domain.IndexerDefinition),
|
indexerDefinitions: make(map[string]domain.IndexerDefinition),
|
||||||
|
@ -193,6 +197,14 @@ func (s *service) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.config.CustomDefinitions != "" {
|
||||||
|
// load custom indexer definitions
|
||||||
|
err = s.LoadCustomIndexerDefinitions()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not load custom indexer definitions: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// load the indexers' setup by the user
|
// load the indexers' setup by the user
|
||||||
indexerDefinitions, err := s.GetAll()
|
indexerDefinitions, err := s.GetAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -334,6 +346,59 @@ func (s *service) LoadIndexerDefinitions() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadCustomIndexerDefinitions load definitions from custom path
|
||||||
|
func (s *service) LoadCustomIndexerDefinitions() error {
|
||||||
|
if s.config.CustomDefinitions == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
outputDirRead, _ := os.Open(s.config.CustomDefinitions)
|
||||||
|
|
||||||
|
//entries, err := fs.ReadDir(Definitions, "definitions")
|
||||||
|
entries, err := outputDirRead.ReadDir(0)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Stack().Msgf("failed reading directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(entries) == 0 {
|
||||||
|
log.Fatal().Stack().Msgf("failed reading directory: %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
customCount := 0
|
||||||
|
|
||||||
|
for _, f := range entries {
|
||||||
|
file := filepath.Join(s.config.CustomDefinitions, f.Name())
|
||||||
|
|
||||||
|
if strings.Contains(f.Name(), ".yaml") {
|
||||||
|
log.Trace().Msgf("parsing custom: %v", file)
|
||||||
|
|
||||||
|
var d domain.IndexerDefinition
|
||||||
|
|
||||||
|
//data, err := fs.ReadFile(Definitions, filePath)
|
||||||
|
data, err := os.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Stack().Err(err).Msgf("failed reading file: %v", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(data, &d)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Stack().Err(err).Msgf("failed unmarshal file: %v", file)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.indexerDefinitions[d.Identifier] = d
|
||||||
|
|
||||||
|
customCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug().Msgf("Loaded %d custom indexer definitions", customCount)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) GetIndexersByIRCNetwork(server string) []domain.IndexerDefinition {
|
func (s *service) GetIndexersByIRCNetwork(server string) []domain.IndexerDefinition {
|
||||||
server = strings.ToLower(server)
|
server = strings.ToLower(server)
|
||||||
|
|
||||||
|
|
62
test/definitions/mock.yaml
Normal file
62
test/definitions/mock.yaml
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
---
|
||||||
|
#id: mock
|
||||||
|
name: MockIndexer
|
||||||
|
identifier: mock
|
||||||
|
description: MockIndexer is a mock indexer.
|
||||||
|
language: en-us
|
||||||
|
urls:
|
||||||
|
- http://localhost.test
|
||||||
|
privacy: private
|
||||||
|
protocol: torrent
|
||||||
|
supports:
|
||||||
|
- irc
|
||||||
|
source: custom
|
||||||
|
settings:
|
||||||
|
- name: rsskey
|
||||||
|
type: secret
|
||||||
|
label: RSS key
|
||||||
|
help: "Go to your profile and copy your RSS key"
|
||||||
|
regex: /([\da-fA-F]{20})
|
||||||
|
|
||||||
|
irc:
|
||||||
|
network: LocalHost
|
||||||
|
server: localhost
|
||||||
|
port: 6697
|
||||||
|
tls: true
|
||||||
|
channels:
|
||||||
|
- "#announces"
|
||||||
|
announcers:
|
||||||
|
- _AnnounceBot_
|
||||||
|
settings:
|
||||||
|
- name: nickserv.account
|
||||||
|
type: text
|
||||||
|
required: false
|
||||||
|
label: NickServ Account
|
||||||
|
help: NickServ account. Make sure to group your user and bot. Eg. user_bot
|
||||||
|
- name: nickserv.password
|
||||||
|
type: secret
|
||||||
|
required: false
|
||||||
|
label: NickServ Password
|
||||||
|
help: NickServ password
|
||||||
|
|
||||||
|
parse:
|
||||||
|
type: single
|
||||||
|
lines:
|
||||||
|
- test:
|
||||||
|
- "New Torrent Announcement: <PC :: Iso> Name:'debian live 10 6 0 amd64 standard iso' uploaded by 'Anonymous' - http://www.localhost.test/torrent/000000"
|
||||||
|
- "New Torrent Announcement: <PC :: Iso> Name:'debian live 10 6 0 amd64 standard iso' uploaded by 'Anonymous' freeleech - http://www.localhost.test/torrent/000000"
|
||||||
|
pattern: New Torrent Announcement:\s*<([^>]*)>\s*Name:'(.*)' uploaded by '([^']*)'\s*(freeleech)*\s*-\s*(https?\:\/\/[^\/]+\/)torrent\/(\d+)
|
||||||
|
vars:
|
||||||
|
- category
|
||||||
|
- torrentName
|
||||||
|
- uploader
|
||||||
|
- freeleech
|
||||||
|
- baseUrl
|
||||||
|
- torrentId
|
||||||
|
|
||||||
|
match:
|
||||||
|
torrenturl: "{{ .baseUrl }}rss/download/{{ .torrentId }}/{{ .rsskey }}/{{ .torrentName }}.torrent"
|
||||||
|
encode:
|
||||||
|
- torrentName
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue