Skip to content

Commit

Permalink
fix hls archiving
Browse files Browse the repository at this point in the history
- create the temp hls directory during convert
- clean up temp hls directory and converted mp4 on video move
  • Loading branch information
Zibbp committed Jul 31, 2024
1 parent 2fc0ee7 commit 65413df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
18 changes: 18 additions & 0 deletions internal/tasks/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func (w PostProcessVideoWorker) Work(ctx context.Context, job *river.Job[PostPro

// convert to HLS if needed
if config.Get().Archive.SaveAsHls {
// create temp hls directory
if err := utils.CreateDirectory(dbItems.Video.TmpVideoHlsPath); err != nil {
return err
}

// convert to hls
err = exec.ConvertVideoToHLS(ctx, dbItems.Video)
if err != nil {
return err
Expand Down Expand Up @@ -284,6 +290,18 @@ func (w MoveVideoWorker) Work(ctx context.Context, job *river.Job[MoveVideoArgs]
if err != nil {
return err
}

// clean up temp hls directory
if err := utils.DeleteDirectory(dbItems.Video.TmpVideoHlsPath); err != nil {
return err
}
// delete temp converted video
if utils.FileExists(dbItems.Video.TmpVideoConvertPath) {
err = utils.DeleteFile(dbItems.Video.TmpVideoConvertPath)
if err != nil {
return err
}
}
}

// set queue status to completed
Expand Down
1 change: 0 additions & 1 deletion internal/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ func MoveFolder(src string, dst string) error {
}

func DeleteFile(path string) error {
log.Debug().Msgf("deleting file: %s", path)
err := os.Remove(path)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/vod/vod.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (s *Service) DeleteVod(c echo.Context, vodID uuid.UUID, deleteFiles bool) e
return err
}
}
if err := utils.DeleteFile(v.TmpVideoHlsPath); err != nil {
if err := utils.DeleteDirectory(v.TmpVideoHlsPath); err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Debug().Msgf("temp file %s does not exist", v.TmpVideoHlsPath)
} else {
Expand Down
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ http {
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;

location ^~ /videos {
location ^~ /data/videos {
autoindex on;
alias /mnt/videos;

Expand Down

0 comments on commit 65413df

Please sign in to comment.