mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
Fixed #50
This commit is contained in:
parent
616542aa04
commit
9400591c6f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -93,8 +93,9 @@ func (w *Channel) Run() {
|
|||||||
|
|
||||||
// close file when offline so user can move/delete it
|
// close file when offline so user can move/delete it
|
||||||
if w.file != nil {
|
if w.file != nil {
|
||||||
w.file.Close()
|
if err := w.releaseFile(); err != nil {
|
||||||
w.file = nil
|
w.log(logTypeError, "release file: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.log(logTypeInfo, "channel is offline, check again 1 min later")
|
w.log(logTypeInfo, "channel is offline, check again 1 min later")
|
||||||
|
|||||||
@ -47,9 +47,6 @@ func (w *Channel) newFile() error {
|
|||||||
if err := os.MkdirAll(filepath.Dir(filename), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Dir(filename), 0777); err != nil {
|
||||||
return fmt.Errorf("create folder: %w", err)
|
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)
|
file, err := os.OpenFile(filename+".ts", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot open file: %s: %w", filename, err)
|
return fmt.Errorf("cannot open file: %s: %w", filename, err)
|
||||||
@ -59,28 +56,33 @@ func (w *Channel) newFile() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// tidyZeroes
|
// releaseFile
|
||||||
func (w *Channel) tidyZeroes(dir string) error {
|
func (w *Channel) releaseFile() error {
|
||||||
files, err := os.ReadDir(dir)
|
if w.file == nil {
|
||||||
if err != nil {
|
return nil
|
||||||
return fmt.Errorf("read directory: %w", err)
|
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
// close the file to remove it
|
||||||
fileInfo, err := file.Info()
|
if err := w.file.Close(); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("close file: %s: %w", w.file.Name(), err)
|
||||||
return fmt.Errorf("get file info: %w", err)
|
}
|
||||||
}
|
// remove it if it was empty
|
||||||
if filepath.Ext(file.Name()) == ".ts" && fileInfo.Size() == 0 {
|
if w.SegmentFilesize == 0 {
|
||||||
if err := os.Remove(filepath.Join(dir, file.Name())); err != nil {
|
w.log(logTypeInfo, "%s was removed because it was empty", w.file.Name())
|
||||||
return fmt.Errorf("remove zero file: %s: %w", file.Name(), err)
|
|
||||||
}
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextFile
|
// nextFile
|
||||||
func (w *Channel) nextFile() error {
|
func (w *Channel) nextFile() error {
|
||||||
|
if err := w.releaseFile(); err != nil {
|
||||||
|
w.log(logTypeError, "release file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
w.splitIndex++
|
w.splitIndex++
|
||||||
w.SegmentFilesize = 0
|
w.SegmentFilesize = 0
|
||||||
w.SegmentDuration = 0
|
w.SegmentDuration = 0
|
||||||
|
|||||||
2
main.go
2
main.go
@ -31,7 +31,7 @@ const logo = `
|
|||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "chaturbate-dvr",
|
Name: "chaturbate-dvr",
|
||||||
Version: "1.0.2",
|
Version: "1.0.3",
|
||||||
Usage: "Records your favorite Chaturbate stream 😎🫵",
|
Usage: "Records your favorite Chaturbate stream 😎🫵",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user