diff --git a/task/upload.go b/task/upload.go index b7b2e9c..87d10bb 100644 --- a/task/upload.go +++ b/task/upload.go @@ -219,10 +219,11 @@ func TaskTranscodeFile(tctx *TaskContext) (*TaskHandlerOutput, error) { getOutputLocations: func() ([]clients.OutputLocation, error) { _, outputLocation, err := outputLocations( params.Storage.URL, - out(isEnabled(params.Outputs.HLS.Path), params.Outputs.HLS.Path), - out(isEnabled(params.Outputs.MP4.Path), params.Outputs.MP4.Path), - out(isEnabled(params.Outputs.FMP4.Path), params.Outputs.FMP4.Path), - output{}, + outputs{ + hls: out(isEnabled(params.Outputs.HLS.Path), params.Outputs.HLS.Path), + mp4: out(isEnabled(params.Outputs.MP4.Path), params.Outputs.MP4.Path), + fmp4: out(isEnabled(params.Outputs.FMP4.Path), params.Outputs.FMP4.Path), + }, false, ) return outputLocation, err @@ -679,7 +680,15 @@ func uploadTaskOutputLocations(tctx *TaskContext) ([]OutputName, []clients.Outpu if tctx.Task.Params.Upload.Thumbnails { thumbsEnabled = OUTPUT_ENABLED } - outputNames, outputLocations, err := outputLocations(outURL, out(OUTPUT_ENABLED, playbackId), out(mp4, playbackId), output{}, out(thumbsEnabled, playbackId), !isEncryptionEnabled(*tctx.Task.Params.Upload)) + outputNames, outputLocations, err := outputLocations( + outURL, + outputs{ + hls: out(OUTPUT_ENABLED, playbackId), + mp4: out(mp4, playbackId), + thumbnails: out(thumbsEnabled, playbackId), + }, + !isEncryptionEnabled(*tctx.Task.Params.Upload), + ) if err != nil { return nil, nil, err } @@ -720,7 +729,14 @@ func clipTaskOutputLocations(tctx *TaskContext) ([]OutputName, []clients.OutputL return nil, nil, fmt.Errorf("error parsing object store URL %w", err) } - outputNames, outputLocations, err := outputLocations(outURL, out(OUTPUT_ENABLED, playbackId), out(OUTPUT_ENABLED, playbackId), output{}, output{}, false) + outputNames, outputLocations, err := outputLocations( + outURL, + outputs{ + hls: out(OUTPUT_ENABLED, playbackId), + mp4: out(OUTPUT_ENABLED, playbackId), + }, + false, + ) if err != nil { return nil, nil, err @@ -754,12 +770,16 @@ type output struct { path string } +type outputs struct { + hls output + mp4 output + fmp4 output + thumbnails output +} + func outputLocations( outURL string, - hls, - mp4, - fmp4, - thumbnails output, + outs outputs, sourceCopy bool, ) ([]OutputName, []clients.OutputLocation, error) { url, err := url.Parse(outURL) @@ -769,23 +789,23 @@ func outputLocations( names, locations := []OutputName{OutputNameOSPlaylistHLS, OutputNameEmpty}, []clients.OutputLocation{ - outputLocation(url, hls.path, &clients.OutputsRequest{HLS: hls.enabled}), - outputLocation(url, mp4.path, &clients.OutputsRequest{MP4: mp4.enabled}), + outputLocation(url, outs.hls.path, &clients.OutputsRequest{HLS: outs.hls.enabled}), + outputLocation(url, outs.mp4.path, &clients.OutputsRequest{MP4: outs.mp4.enabled}), } - if fmp4.enabled == OUTPUT_ENABLED { + if outs.fmp4.enabled == OUTPUT_ENABLED { names, locations = append(names, OutputNameEmpty), - append(locations, outputLocation(url, fmp4.path, &clients.OutputsRequest{FMP4: fmp4.enabled})) + append(locations, outputLocation(url, outs.fmp4.path, &clients.OutputsRequest{FMP4: outs.fmp4.enabled})) } if sourceCopy { names, locations = append(names, OutputNameOSSourceMP4), - append(locations, outputLocation(url, videoFileName(hls.path), &clients.OutputsRequest{SourceMp4: true})) + append(locations, outputLocation(url, videoFileName(outs.hls.path), &clients.OutputsRequest{SourceMp4: true})) } - if thumbnails.enabled == OUTPUT_ENABLED { + if outs.thumbnails.enabled == OUTPUT_ENABLED { names, locations = append(names, OutputNameEmpty), - append(locations, outputLocation(url, thumbnails.path, &clients.OutputsRequest{Thumbnails: thumbnails.enabled})) + append(locations, outputLocation(url, outs.thumbnails.path, &clients.OutputsRequest{Thumbnails: outs.thumbnails.enabled})) } return names, locations, nil } diff --git a/task/upload_test.go b/task/upload_test.go index beceaf4..bae5566 100644 --- a/task/upload_test.go +++ b/task/upload_test.go @@ -280,7 +280,15 @@ func TestOutputLocations(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, gotOutputLocations, err := outputLocations(tt.outURL, out(tt.hls, tt.hlsRelPath), out(tt.mp4, tt.mp4RelPath), output{}, out(tt.thumbs, tt.thumbsRelPath), tt.sourceCopy) + _, gotOutputLocations, err := outputLocations( + tt.outURL, + outputs{ + hls: out(tt.hls, tt.hlsRelPath), + mp4: out(tt.mp4, tt.mp4RelPath), + thumbnails: out(tt.thumbs, tt.thumbsRelPath), + }, + tt.sourceCopy, + ) if tt.hasError { require.Error(t, err)