refactor: remove dead logger package and unused fields
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
ARLCookie string
|
ARLCookie string
|
||||||
OutputDir string
|
OutputDir string
|
||||||
HomeDir string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Config, error) {
|
func New() (*Config, error) {
|
||||||
@@ -49,6 +48,5 @@ func New() (*Config, error) {
|
|||||||
return &Config{
|
return &Config{
|
||||||
ARLCookie: arl,
|
ARLCookie: arl,
|
||||||
OutputDir: outputDir,
|
OutputDir: outputDir,
|
||||||
HomeDir: homeDir,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
AppConfig *config.Config
|
Session *Session
|
||||||
Session *Session
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ctx context.Context, appConfig *config.Config) (*Client, error) {
|
func NewClient(ctx context.Context, appConfig *config.Config) (*Client, error) {
|
||||||
@@ -25,8 +24,7 @@ func NewClient(ctx context.Context, appConfig *config.Config) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
AppConfig: appConfig,
|
Session: session,
|
||||||
Session: session,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/mathismqn/godeez/internal/crypto"
|
"github.com/mathismqn/godeez/internal/crypto"
|
||||||
"github.com/mathismqn/godeez/internal/deezer"
|
"github.com/mathismqn/godeez/internal/deezer"
|
||||||
"github.com/mathismqn/godeez/internal/fileutil"
|
"github.com/mathismqn/godeez/internal/fileutil"
|
||||||
"github.com/mathismqn/godeez/internal/logger"
|
|
||||||
"github.com/mathismqn/godeez/internal/store"
|
"github.com/mathismqn/godeez/internal/store"
|
||||||
"github.com/mathismqn/godeez/internal/tags"
|
"github.com/mathismqn/godeez/internal/tags"
|
||||||
)
|
)
|
||||||
@@ -26,7 +25,6 @@ type Client struct {
|
|||||||
appConfig *config.Config
|
appConfig *config.Config
|
||||||
resourceType string
|
resourceType string
|
||||||
deezerClient *deezer.Client
|
deezerClient *deezer.Client
|
||||||
Logger *logger.Logger
|
|
||||||
|
|
||||||
hashIndexOnce sync.Once
|
hashIndexOnce sync.Once
|
||||||
hashIndex *fileutil.HashIndex
|
hashIndex *fileutil.HashIndex
|
||||||
@@ -37,7 +35,6 @@ func New(appConfig *config.Config, resourceType string) *Client {
|
|||||||
return &Client{
|
return &Client{
|
||||||
appConfig: appConfig,
|
appConfig: appConfig,
|
||||||
resourceType: resourceType,
|
resourceType: resourceType,
|
||||||
Logger: logger.New(nil),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +48,7 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.downloadAllTracks(ctx, resource, id, opts, outputDir)
|
return c.downloadAllTracks(ctx, resource, opts, outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) initDeezerClient(ctx context.Context, opts Options) error {
|
func (c *Client) initDeezerClient(ctx context.Context, opts Options) error {
|
||||||
@@ -113,7 +110,7 @@ func (c *Client) createResource() (deezer.Resource, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) downloadAllTracks(ctx context.Context, resource deezer.Resource, resourceID string, opts Options, outputDir string) error {
|
func (c *Client) downloadAllTracks(ctx context.Context, resource deezer.Resource, opts Options, outputDir string) error {
|
||||||
tracks := resource.GetTracks()
|
tracks := resource.GetTracks()
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
@@ -121,7 +118,7 @@ func (c *Client) downloadAllTracks(ctx context.Context, resource deezer.Resource
|
|||||||
fmt.Printf("%s\n\nStarting download...\n\n", resource)
|
fmt.Printf("%s\n\nStarting download...\n\n", resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress := newProgressTracker(c.Logger, len(tracks), c.resourceType)
|
progress := newProgressTracker(len(tracks), c.resourceType)
|
||||||
|
|
||||||
for i, track := range tracks {
|
for i, track := range tracks {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
@@ -139,7 +136,7 @@ func (c *Client) downloadAllTracks(ctx context.Context, resource deezer.Resource
|
|||||||
progress.handleResult(i, track, result)
|
progress.handleResult(i, track, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress.printSummary(resource.GetTitle(), resourceID, outputDir, time.Since(startTime))
|
progress.printSummary(outputDir, time.Since(startTime))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/briandowns/spinner"
|
"github.com/briandowns/spinner"
|
||||||
"github.com/mathismqn/godeez/internal/deezer"
|
"github.com/mathismqn/godeez/internal/deezer"
|
||||||
"github.com/mathismqn/godeez/internal/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type downloadResult struct {
|
type downloadResult struct {
|
||||||
@@ -26,15 +25,13 @@ type downloadStats struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type progressTracker struct {
|
type progressTracker struct {
|
||||||
logger *logger.Logger
|
|
||||||
stats downloadStats
|
stats downloadStats
|
||||||
totalTracks int
|
totalTracks int
|
||||||
resourceType string
|
resourceType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProgressTracker(logger *logger.Logger, totalTracks int, resourceType string) *progressTracker {
|
func newProgressTracker(totalTracks int, resourceType string) *progressTracker {
|
||||||
return &progressTracker{
|
return &progressTracker{
|
||||||
logger: logger,
|
|
||||||
totalTracks: totalTracks,
|
totalTracks: totalTracks,
|
||||||
resourceType: resourceType,
|
resourceType: resourceType,
|
||||||
}
|
}
|
||||||
@@ -65,7 +62,6 @@ func (pt *progressTracker) handleResult(index int, track *deezer.Track, result d
|
|||||||
|
|
||||||
if result.err != nil {
|
if result.err != nil {
|
||||||
pt.stats.failed++
|
pt.stats.failed++
|
||||||
pt.logger.Errorf("Failed to download %s - %s: %v\n", track.Artist, trackTitle, result.err)
|
|
||||||
fmt.Printf("%s ✖ Failed: %s - %s:\n Error: %v\n",
|
fmt.Printf("%s ✖ Failed: %s - %s:\n Error: %v\n",
|
||||||
trackProgress, track.Artist, trackTitle, result.err)
|
trackProgress, track.Artist, trackTitle, result.err)
|
||||||
return
|
return
|
||||||
@@ -75,7 +71,6 @@ func (pt *progressTracker) handleResult(index int, track *deezer.Track, result d
|
|||||||
if len(result.warnings) > 0 {
|
if len(result.warnings) > 0 {
|
||||||
pt.stats.warnings++
|
pt.stats.warnings++
|
||||||
}
|
}
|
||||||
pt.logger.Infof("Downloaded %s - %s\n", track.Artist, trackTitle)
|
|
||||||
|
|
||||||
symbol := "✔"
|
symbol := "✔"
|
||||||
if len(result.warnings) > 0 {
|
if len(result.warnings) > 0 {
|
||||||
@@ -84,17 +79,11 @@ func (pt *progressTracker) handleResult(index int, track *deezer.Track, result d
|
|||||||
fmt.Printf("%s %s Downloaded: %s - %s\n", trackProgress, symbol, track.Artist, trackTitle)
|
fmt.Printf("%s %s Downloaded: %s - %s\n", trackProgress, symbol, track.Artist, trackTitle)
|
||||||
|
|
||||||
for _, w := range result.warnings {
|
for _, w := range result.warnings {
|
||||||
pt.logger.Warnf("Warning: %s\n", w)
|
|
||||||
fmt.Printf(" Warning: %s\n", w)
|
fmt.Printf(" Warning: %s\n", w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *progressTracker) printSummary(resourceTitle, resourceID, outputDir string, elapsed time.Duration) {
|
func (pt *progressTracker) printSummary(outputDir string, elapsed time.Duration) {
|
||||||
if pt.stats.downloaded > 0 || pt.stats.failed > 0 {
|
|
||||||
pt.logger.Infof("Resource %s (%s): %d downloaded, %d skipped, %d failed\n",
|
|
||||||
resourceTitle, resourceID, pt.stats.downloaded, pt.stats.skipped, pt.stats.failed)
|
|
||||||
}
|
|
||||||
|
|
||||||
if pt.resourceType != "track" {
|
if pt.resourceType != "track" {
|
||||||
warningsLine := ""
|
warningsLine := ""
|
||||||
if pt.stats.warnings > 0 {
|
if pt.stats.warnings > 0 {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package logger
|
|
||||||
|
|
||||||
import "log"
|
|
||||||
|
|
||||||
type Logger struct {
|
|
||||||
l *log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(l *log.Logger) *Logger {
|
|
||||||
return &Logger{l: l}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) logf(level, format string, args ...any) {
|
|
||||||
if l.l != nil {
|
|
||||||
l.l.Printf("["+level+"] "+format, args...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) Infof(format string, args ...any) { l.logf("INFO", format, args...) }
|
|
||||||
func (l *Logger) Warnf(format string, args ...any) { l.logf("WARN", format, args...) }
|
|
||||||
func (l *Logger) Errorf(format string, args ...any) { l.logf("ERROR", format, args...) }
|
|
||||||
Reference in New Issue
Block a user