mirror of
https://github.com/kemko/icecast-ripper.git
synced 2026-01-01 15:55:42 +03:00
* feat: integrate MP3 duration extraction and silence handling - Added a new dependency on github.com/tcolgate/mp3 for MP3 frame decoding. - Implemented actual MP3 duration retrieval in the scanRecordings function, falling back to an estimation if retrieval fails. - Introduced a silent frame asset for generating silence in audio streams. - Created a silence reader to provide a continuous stream of silent frames. - Added necessary documentation and licensing for the new MP3 package. - Updated .gitignore to exclude MP3 files except for the internal data directory. * feat: update README and improve application configuration and logging * refactor: remove unused GenerateFileHash function and improve resource cleanup in MP3 and recorder modules
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// Config stores application configuration loaded from environment variables
|
|
type Config struct {
|
|
StreamURL string `mapstructure:"STREAM_URL"` // URL of the Icecast stream to record
|
|
CheckInterval time.Duration `mapstructure:"CHECK_INTERVAL"` // How often to check if the stream is live
|
|
RecordingsPath string `mapstructure:"RECORDINGS_PATH"` // Where to store recordings
|
|
TempPath string `mapstructure:"TEMP_PATH"` // Where to store temporary files during recording
|
|
BindAddress string `mapstructure:"BIND_ADDRESS"` // HTTP server address:port
|
|
PublicURL string `mapstructure:"PUBLIC_URL"` // Public-facing URL for RSS feed links
|
|
LogLevel string `mapstructure:"LOG_LEVEL"` // Logging level (debug, info, warn, error)
|
|
}
|
|
|
|
// LoadConfig reads configuration from environment variables
|
|
func LoadConfig() (*Config, error) {
|
|
v := viper.New()
|
|
v.AutomaticEnv()
|
|
|
|
// Set default values
|
|
defaults := map[string]interface{}{
|
|
"STREAM_URL": "",
|
|
"CHECK_INTERVAL": "1m",
|
|
"RECORDINGS_PATH": "./recordings",
|
|
"TEMP_PATH": "/tmp",
|
|
"BIND_ADDRESS": ":8080",
|
|
"PUBLIC_URL": "http://localhost:8080",
|
|
"LOG_LEVEL": "info",
|
|
}
|
|
|
|
for key, value := range defaults {
|
|
v.SetDefault(key, value)
|
|
}
|
|
|
|
var config Config
|
|
if err := v.Unmarshal(&config); err != nil {
|
|
return nil, fmt.Errorf("failed to parse configuration: %w", err)
|
|
}
|
|
|
|
// Validate required fields
|
|
if config.StreamURL == "" {
|
|
return nil, fmt.Errorf("STREAM_URL is required")
|
|
}
|
|
|
|
return &config, nil
|
|
}
|