Skip to content

Commit

Permalink
Fixed #50
Browse files Browse the repository at this point in the history
  • Loading branch information
YamiOdymel committed Feb 23, 2024
1 parent 616542a commit 9400591
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 20 deletions.
Binary file modified bin/arm64/darwin/chatubrate-dvr
Binary file not shown.
Binary file modified bin/arm64/linux/chatubrate-dvr
Binary file not shown.
Binary file modified bin/arm64/windows/chatubrate-dvr.exe
Binary file not shown.
Binary file modified bin/darwin/chatubrate-dvr
Binary file not shown.
Binary file modified bin/linux/chatubrate-dvr
Binary file not shown.
Binary file modified bin/windows/chatubrate-dvr.exe
Binary file not shown.
5 changes: 3 additions & 2 deletions chaturbate/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ func (w *Channel) Run() {

// close file when offline so user can move/delete it
if w.file != nil {
w.file.Close()
w.file = nil
if err := w.releaseFile(); err != nil {
w.log(logTypeError, "release file: %w", err)
}
}

w.log(logTypeInfo, "channel is offline, check again 1 min later")
Expand Down
36 changes: 19 additions & 17 deletions chaturbate/channel_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ func (w *Channel) newFile() error {
if err := os.MkdirAll(filepath.Dir(filename), 0777); err != nil {
return fmt.Errorf("create folder: %w", err)
}
if err := w.tidyZeroes(filepath.Dir(filename)); err != nil {
return fmt.Errorf("tidy zeroes: %w", err)
}
file, err := os.OpenFile(filename+".ts", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777)
if err != nil {
return fmt.Errorf("cannot open file: %s: %w", filename, err)
Expand All @@ -59,28 +56,33 @@ func (w *Channel) newFile() error {
return nil
}

// tidyZeroes
func (w *Channel) tidyZeroes(dir string) error {
files, err := os.ReadDir(dir)
if err != nil {
return fmt.Errorf("read directory: %w", err)
// releaseFile
func (w *Channel) releaseFile() error {
if w.file == nil {
return nil
}
for _, file := range files {
fileInfo, err := file.Info()
if err != nil {
return fmt.Errorf("get file info: %w", err)
}
if filepath.Ext(file.Name()) == ".ts" && fileInfo.Size() == 0 {
if err := os.Remove(filepath.Join(dir, file.Name())); err != nil {
return fmt.Errorf("remove zero file: %s: %w", file.Name(), err)
}
// close the file to remove it
if err := w.file.Close(); err != nil {
return fmt.Errorf("close file: %s: %w", w.file.Name(), err)
}
// remove it if it was empty
if w.SegmentFilesize == 0 {
w.log(logTypeInfo, "%s was removed because it was empty", w.file.Name())

if err := os.Remove(w.file.Name()); err != nil {
return fmt.Errorf("remove zero file: %s: %w", w.file.Name(), err)
}
}
w.file = nil
return nil
}

// nextFile
func (w *Channel) nextFile() error {
if err := w.releaseFile(); err != nil {
w.log(logTypeError, "release file: %w", err)
}

w.splitIndex++
w.SegmentFilesize = 0
w.SegmentDuration = 0
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const logo = `
func main() {
app := &cli.App{
Name: "chaturbate-dvr",
Version: "1.0.2",
Version: "1.0.3",
Usage: "Records your favorite Chaturbate stream 😎🫵",
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down

0 comments on commit 9400591

Please sign in to comment.