Skip to content

Commit

Permalink
Audiobookshelf upload UI implemented. Code refactoring
Browse files Browse the repository at this point in the history
vpoluyaktov committed Nov 23, 2023
1 parent a255c4d commit 66f813b
Showing 33 changed files with 244 additions and 289 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (

"abb_ia/internal/config"
"abb_ia/internal/dto"
"abb_ia/internal/github"
"abb_ia/internal/logger"
"abb_ia/internal/mq"
"abb_ia/internal/utils"
@@ -57,13 +58,13 @@ func (c *BootController) checkFFmpeg() bool {

func (c *BootController) checkNewVersion() {

latestVersion, err := utils.GetLatestVersion(config.Instance().GetRepoOwner(), config.Instance().GetRepoName())
latestVersion, err := github.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())
result, err := github.CompareVersions(latestVersion, config.Instance().AppVersion())
if err != nil {
logger.Error("Can not compare versions: " + err.Error())
return
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -17,13 +17,6 @@ type ChaptersController struct {
stopFlag bool
}

/**
* Creates a new ChaptersController instance.
* @param dispatcher - The message queue dispatcher.
* @returns The new ChaptersController instance.
*
* This code is useful for creating a new ChaptersController instance and registering it with the message queue dispatcher. This allows the ChaptersController to receive messages from the message queue and dispatch them to the appropriate handler.
**/
func NewChaptersController(dispatcher *mq.Dispatcher) *ChaptersController {
c := &ChaptersController{}
c.mq = dispatcher
@@ -60,15 +53,6 @@ func (c *ChaptersController) stopChapters(cmd *dto.StopCommand) {
logger.Debug(mq.ChaptersController + ": Received StopChapters command")
}

/**
* @description Splits an audiobook into parts and chapters.
* @param {dto.ChaptersCreate} cmd - The command to create chapters.
* @returns {void}
*
* This function is useful for splitting an audiobook into parts and chapters.
* It takes in a command object containing the audiobook and then splits the audiobook into parts and chapters.
* It then sends messages to the ChaptersPage and Footer to update the status and busy indicator.
*/
func (c *ChaptersController) createChapters(cmd *dto.ChaptersCreate) {

logger.Debug(mq.ChaptersController + " received " + cmd.String())
@@ -92,6 +76,7 @@ func (c *ChaptersController) createChapters(cmd *dto.ChaptersCreate) {
var fileNo int = 1
var chapterNo int = 1
var offset float64 = 0
var abSize int64 = 0
var partSize int64 = 0
var partDuration float64 = 0
var partChapters []dto.Chapter = []dto.Chapter{}
@@ -102,6 +87,7 @@ func (c *ChaptersController) createChapters(cmd *dto.ChaptersCreate) {
mp3, _ := ffmpeg.NewFFProbe(filePath)
chapterFiles = append(chapterFiles, dto.Mp3File{Number: fileNo, FileName: file.FileName, Size: mp3.Size(), Duration: mp3.Duration()})
fileNo++
abSize += mp3.Size()
partSize += mp3.Size()
partDuration += mp3.Duration()
chapter := dto.Chapter{Number: chapterNo, Name: mp3.Title(), Size: mp3.Size(), Duration: mp3.Duration(), Start: offset, End: offset + mp3.Duration(), Files: chapterFiles}
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/controller/conductor.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ func NewConductor(dispatcher *mq.Dispatcher) *Conductor {
c.controllers = append(c.controllers, NewChaptersController(c.dispatcher))
c.controllers = append(c.controllers, NewBuildController(c.dispatcher))
c.controllers = append(c.controllers, NewCopyController(c.dispatcher))
c.controllers = append(c.controllers, NewAudiobookshelfController(c.dispatcher))
c.controllers = append(c.controllers, NewUploadController(c.dispatcher))
c.controllers = append(c.controllers, NewCleanupController(c.dispatcher))
c.controllers = append(c.controllers, NewBootController(c.dispatcher))
return c
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ func (c *CopyController) dispatchMessage(m *mq.Message) {
func (c *CopyController) startCopy(cmd *dto.CopyCommand) {
c.startTime = time.Now()
logger.Info(mq.CopyController + " received " + cmd.String())

c.ab = cmd.Audiobook

// update part size and whole audiobook size after re-encoding
@@ -193,7 +192,7 @@ func (c *CopyController) updateFileCopyProgress(fileId int, fileName string, siz
}

// sent a message only if progress changed
c.mq.SendMessage(mq.CopyController, mq.BuildPage, &dto.UploadFileProgress{FileId: fileId, FileName: fileName, Percent: percent}, false)
c.mq.SendMessage(mq.CopyController, mq.BuildPage, &dto.CopyFileProgress{FileId: fileId, FileName: fileName, Percent: percent}, false)
}
c.filesCopy[fileId].fileId = fileId
c.filesCopy[fileId].fileSize = size
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"time"

"abb_ia/internal/dto"
"abb_ia/internal/ia_client"
"abb_ia/internal/ia"
"abb_ia/internal/logger"
"abb_ia/internal/mq"
"abb_ia/internal/utils"
File renamed without changes.
155 changes: 0 additions & 155 deletions internal/controller/searchController.go

This file was deleted.

5 changes: 3 additions & 2 deletions internal/controller/search_controller.go
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ func (c *SearchController) performSearch(cmd *dto.SearchCommand) {
for name, metadata := range d.Files {
format := metadata.Format
// collect mp3 files
// TODO: Implement filtering for mp3 files with multiple bitrates (see https://archive.org/details/voyage_moon_1512_librivox or https://archive.org/details/OTRR_Blair_of_the_Mounties_Singles for ex.)

if utils.Contains(dto.Mp3Formats, format) {
size, sErr := strconv.ParseInt(metadata.Size, 10, 64)
length, lErr := utils.TimeToSeconds(metadata.Length)
@@ -99,12 +99,13 @@ func (c *SearchController) performSearch(cmd *dto.SearchCommand) {
if metadata.Title != "" {
file.Title = metadata.Title
} else {
file.Title = file.Name
file.Title = utils.SanitizeMp3FileName(file.Name)
}
file.Size = size
file.Length = length
file.Format = metadata.Format
// check if there is a file with the same title but different bitrate. Keep highest bitrate only
// see https://archive.org/details/voyage_moon_1512_librivox or https://archive.org/details/OTRR_Blair_of_the_Mounties_Singles for ex.
addNewFile := true
for i, oldFile := range item.AudioFiles {
if file.Title == oldFile.Title {
Loading

0 comments on commit 66f813b

Please sign in to comment.