summaryrefslogtreecommitdiff
path: root/recording/config.go
blob: ff3ae2a7c9121aef67870df9f925f06835cc92ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package recording

import (
	"fmt"
	"github.com/keuin/slbr/bilibili"
	"github.com/keuin/slbr/common"
)

type TaskConfig struct {
	RoomId    common.RoomId   `mapstructure:"room_id"`
	Transport TransportConfig `mapstructure:"transport"`
	Download  DownloadConfig  `mapstructure:"download"`
	Watch     WatchConfig     `mapstructure:"watch"`
}

type TransportConfig struct {
	SocketTimeoutSeconds int                  `mapstructure:"socket_timeout_seconds"`
	RetryIntervalSeconds int                  `mapstructure:"retry_interval_seconds"`
	MaxRetryTimes        int                  `mapstructure:"max_retry_times"`
	AllowedNetworkTypes  []bilibili.IpNetType `mapstructure:"allowed_network_types"`
}

type DownloadConfig struct {
	SaveDirectory                    string `mapstructure:"save_directory"`
	DiskWriteBufferBytes             int    `mapstructure:"disk_write_buffer_bytes"`
	UseSpecialExtNameBeforeFinishing bool   `mapstructure:"use_special_ext_name_when_downloading"`
}

type WatchConfig struct {
	LiveInterruptedRestartSleepSeconds int `mapstructure:"live_interrupted_restart_sleep_seconds"`
}

func DefaultTransportConfig() TransportConfig {
	return TransportConfig{
		SocketTimeoutSeconds: 10,
		RetryIntervalSeconds: 2,
		MaxRetryTimes:        5,
	}
}

func (t TaskConfig) String() string {
	return fmt.Sprintf("Room ID: %v, %v, %v", t.RoomId, t.Transport.String(), t.Download.String())
}

func (t TransportConfig) String() string {
	return fmt.Sprintf("Socket timeout: %vs, Retry interval: %vs, Max retry times: %v",
		t.SocketTimeoutSeconds, t.RetryIntervalSeconds, t.MaxRetryTimes)
}

func (d DownloadConfig) String() string {
	return fmt.Sprintf("Save directory: \"%v\"", d.SaveDirectory)
}