29 lines
721 B
Go
29 lines
721 B
Go
package torrent
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"homelab.lan/music-agregator/internal/config"
|
|
)
|
|
|
|
func NewTorrentClient(cfg config.Config) (TorrentClient, error) {
|
|
var client TorrentClient
|
|
|
|
switch cfg.Torrent.ClientType {
|
|
case config.TorrentClientQbittorrent:
|
|
client = NewQbittorrentClient(cfg.Torrent.Url)
|
|
default:
|
|
return nil, fmt.Errorf("unknown torrent client type: %s", cfg.Torrent.ClientType)
|
|
}
|
|
|
|
if _, err := client.Login(cfg.Torrent.Username, cfg.Torrent.Password); err != nil {
|
|
return nil, fmt.Errorf("torrent client login failed: %w", err)
|
|
}
|
|
|
|
log.Info().Str("client", string(cfg.Torrent.ClientType)).Str("url", cfg.Torrent.Url).Msg("torrent client connected")
|
|
|
|
return client, nil
|
|
}
|