Skip to content

Commit

Permalink
Merge pull request #3 from vpoluyaktov/ffmpeg_progress_refactor
Browse files Browse the repository at this point in the history
FFMPEG progress reader refactored
  • Loading branch information
vpoluyaktov authored Nov 15, 2023
2 parents 50a4540 + b9915b6 commit 8789197
Show file tree
Hide file tree
Showing 28 changed files with 524 additions and 256 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ Since the copyrights for the majority of old-time radio shows have expired and m


## TODO:
- Implement Search/Replace for Description on Chapters page
- Finish Default Settings screen
- Create an audiobook Settings screen


1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
)

require (
github.com/hashicorp/go-version v1.6.0
github.com/rivo/tview v0.0.0-20230406072732-e22ce9588bb4
github.com/stretchr/testify v1.8.3
golang.org/x/net v0.17.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCyS
github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
20 changes: 20 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var (
var (
configFile = "config.yaml"
appVersion, buildDate string
repoOwner string = "vpoluyaktov"
repoName string = "abb_ia"
)

// Fields of this stuct should to be private but I have to make them public because yaml.Marshal/Unmarshal can't work with private fields
Expand All @@ -33,6 +35,7 @@ type Config struct {
ConcurrentDownloaders int `yaml:"ConcurrentDownloaders"`
ConcurrentEncoders int `yaml:"ConcurrentEncoders"`
ReEncodeFiles bool `yaml:"ReEncodeFiles"`
BasePortNumber int `yaml:"BasePortNumber"`
BitRateKbs int `yaml:"BitRateKbs"`
SampleRateHz int `yaml:"SampleRateHz"`
MaxFileSizeMb int `yaml:"MaxFileSizeMb"`
Expand Down Expand Up @@ -67,6 +70,7 @@ func Load() {
config.ConcurrentDownloaders = 5
config.ConcurrentEncoders = 5
config.ReEncodeFiles = true
config.BasePortNumber = 31000
config.BitRateKbs = 96
config.SampleRateHz = 44100
config.MaxFileSizeMb = 250
Expand Down Expand Up @@ -203,6 +207,14 @@ func (c *Config) IsReEncodeFiles() bool {
return c.ReEncodeFiles
}

func (c *Config) SetBasePortNumber(port int) {
c.BasePortNumber = port
}

func (c *Config) GetBasePortNumber() int {
return c.BasePortNumber
}

func (c *Config) SetBitRate(b int) {
c.BitRateKbs = b
}
Expand Down Expand Up @@ -314,6 +326,14 @@ func (c *Config) AppVersion() string {
return appVersion
}

func (c *Config) GetRepoOwner() string {
return repoOwner
}

func (c *Config) GetRepoName() string {
return repoName
}

func (c *Config) GetBuildDate() string {
// 2023-07-20T14:45:12Z
fmt := "01/02/2006"
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/audiobookShelfController.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controller

import (
"github.com/vpoluyaktov/abb_ia/internal/audiobookshelf"
"github.com/vpoluyaktov/abb_ia/internal/config"
"github.com/vpoluyaktov/abb_ia/internal/dto"
"github.com/vpoluyaktov/abb_ia/internal/logger"
"github.com/vpoluyaktov/abb_ia/internal/mq"
Expand All @@ -13,10 +12,10 @@ type AudiobookshelfController struct {
}

func NewAudiobookshelfController(dispatcher *mq.Dispatcher) *AudiobookshelfController {
dc := &AudiobookshelfController{}
dc.mq = dispatcher
dc.mq.RegisterListener(mq.AudiobookshelfController, dc.dispatchMessage)
return dc
c := &AudiobookshelfController{}
c.mq = dispatcher
c.mq.RegisterListener(mq.AudiobookshelfController, c.dispatchMessage)
return c
}

func (c *AudiobookshelfController) checkMQ() {
Expand All @@ -37,10 +36,11 @@ func (c *AudiobookshelfController) dispatchMessage(m *mq.Message) {

func (c *AudiobookshelfController) audiobookshelfScan(cmd *dto.AudiobookshelfScanCommand) {
logger.Info(mq.AudiobookshelfController + " received " + cmd.String())
url := config.Instance().GetAudiobookshelfUrl()
username := config.Instance().GetAudiobookshelfUser()
password := config.Instance().GetAudiobookshelfPassword()
libraryName := config.Instance().GetAudiobookshelfLibrary()
ab := cmd.Audiobook
url := ab.Config.GetAudiobookshelfUrl()
username := ab.Config.GetAudiobookshelfUser()
password := ab.Config.GetAudiobookshelfPassword()
libraryName := ab.Config.GetAudiobookshelfLibrary()

if url != "" && username != "" && password != "" && libraryName != "" {
loginResp, err := audiobookshelf.Login(url+"/login", username, password)
Expand Down
75 changes: 75 additions & 0 deletions internal/controller/bootController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package controller

import (
"time"

"github.com/vpoluyaktov/abb_ia/internal/config"
"github.com/vpoluyaktov/abb_ia/internal/dto"
"github.com/vpoluyaktov/abb_ia/internal/logger"
"github.com/vpoluyaktov/abb_ia/internal/mq"
"github.com/vpoluyaktov/abb_ia/internal/utils"
)

type BootController struct {
mq *mq.Dispatcher
}

func NewBootController(dispatcher *mq.Dispatcher) *BootController {
c := &BootController{}
c.mq = dispatcher
c.mq.RegisterListener(mq.BootController, c.dispatchMessage)
go c.bootStrap(&dto.BootstrapCommand{})
return c
}

func (c *BootController) checkMQ() {
m := c.mq.GetMessage(mq.BootController)
if m != nil {
c.dispatchMessage(m)
}
}

func (c *BootController) dispatchMessage(m *mq.Message) {
switch dto := m.Dto.(type) {
case *dto.BootstrapCommand:
go c.bootStrap(dto)
default:
m.UnsupportedTypeError(mq.BootController)
}
}

func (c *BootController) bootStrap(cmd *dto.BootstrapCommand) {
// wait for all components to initialize
time.Sleep(3 * time.Second)
if c.checkFFmpeg() {
c.checkNewVersion()
}
}

func (c *BootController) checkFFmpeg() bool {
if !(utils.CommandExists("ffmpeg") && utils.CommandExists("ffprobe")) {
logger.Fatal("Bootstrap: ffmpeg or ffprobe command not found")
c.mq.SendMessage(mq.BootController, mq.SearchPage, &dto.FFMPEGNotFoundError{}, true)
return false
}
return true
}

func (c *BootController) checkNewVersion() {

latestVersion, err := utils.GetLatestVersion(config.Instance().GetRepoOwner(), config.Instance().GetRepoName())
if err != nil {
logger.Error("Can't check new version: " + err.Error())
return
}

result, err := utils.CompareVersions(latestVersion, config.Instance().AppVersion())
if err != nil {
logger.Error("Can not compare versions: " + err.Error())
return
}

if result > 0 {
c.mq.SendMessage(mq.BootController, mq.SearchPage, &dto.NewAppVersionFound{CurrentVersion: config.Instance().AppVersion(), NewVersion: latestVersion}, true)
}
}
Loading

0 comments on commit 8789197

Please sign in to comment.