autobrr/internal/domain/indexer.go
Ludvig Lundgren 2ea2293745
Feature: Get size by api for ptp btn and ggn (#66)
* chore: add package

* feat: get size by api for ptp and btn

* feat: download and parse torrent if not api

* feat: bypass tls check and load meta from file

* fix: no invite command needed for btn

* feat: add ggn api

* feat: imrpove logging

* feat: build request url

* feat: improve err logging
2022-01-05 23:52:29 +01:00

109 lines
3 KiB
Go

package domain
import (
"context"
"github.com/dustin/go-humanize"
)
type IndexerRepo interface {
Store(indexer Indexer) (*Indexer, error)
Update(indexer Indexer) (*Indexer, error)
List() ([]Indexer, error)
Delete(ctx context.Context, id int) error
FindByFilterID(id int) ([]Indexer, error)
}
type Indexer struct {
ID int64 `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Enabled bool `json:"enabled"`
Type string `json:"type,omitempty"`
Settings map[string]string `json:"settings,omitempty"`
}
type IndexerDefinition struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Enabled bool `json:"enabled,omitempty"`
Description string `json:"description"`
Language string `json:"language"`
Privacy string `json:"privacy"`
Protocol string `json:"protocol"`
URLS []string `json:"urls"`
Supports []string `json:"supports"`
Settings []IndexerSetting `json:"settings"`
SettingsMap map[string]string `json:"-"`
IRC *IndexerIRC `json:"irc"`
Parse IndexerParse `json:"parse"`
}
func (i IndexerDefinition) HasApi() bool {
for _, a := range i.Supports {
if a == "api" {
return true
}
}
return false
}
type IndexerSetting struct {
Name string `json:"name"`
Required bool `json:"required,omitempty"`
Type string `json:"type"`
Value string `json:"value,omitempty"`
Label string `json:"label"`
Default string `json:"default,omitempty"`
Description string `json:"description,omitempty"`
Help string `json:"help,omitempty"`
Regex string `json:"regex,omitempty"`
}
type IndexerIRC struct {
Network string `json:"network"`
Server string `json:"server"`
Port int `json:"port"`
TLS bool `json:"tls"`
Channels []string `json:"channels"`
Announcers []string `json:"announcers"`
SettingsMap map[string]string `json:"-"`
Settings []IndexerSetting `json:"settings"`
}
type IndexerParse struct {
Type string `json:"type"`
Lines []IndexerParseExtract `json:"lines"`
Match IndexerParseMatch `json:"match"`
}
type IndexerParseExtract struct {
Test []string `json:"test"`
Pattern string `json:"pattern"`
Vars []string `json:"vars"`
}
type IndexerParseMatch struct {
TorrentURL string `json:"torrenturl"`
Encode []string `json:"encode"`
}
type TorrentBasic struct {
Id string `json:"Id"`
TorrentId string `json:"TorrentId,omitempty"`
InfoHash string `json:"InfoHash"`
Size string `json:"Size"`
}
func (t TorrentBasic) ReleaseSizeBytes() uint64 {
if t.Size == "" {
return 0
}
releaseSizeBytes, err := humanize.ParseBytes(t.Size)
if err != nil {
// log could not parse into bytes
}
return releaseSizeBytes
}