@@ -138,7 +138,7 @@ func (p *mcProvider) outputGroupsFrom(job *db.Job) ([]mediaconvert.OutputGroup,
138138 }
139139 mcOutputGroup .Outputs = mcOutputs
140140
141- destination := destinationPathFrom ( p . cfg . Destination , job . ID )
141+ destination := p . destinationPathFrom ( job )
142142
143143 switch container {
144144 case mediaconvert .ContainerTypeCmfc :
@@ -171,7 +171,7 @@ func (p *mcProvider) outputGroupsFrom(job *db.Job) ([]mediaconvert.OutputGroup,
171171 mcOutputGroup .OutputGroupSettings = & mediaconvert.OutputGroupSettings {
172172 Type : mediaconvert .OutputGroupTypeFileGroupSettings ,
173173 FileGroupSettings : & mediaconvert.FileGroupSettings {
174- Destination : aws .String (destination ),
174+ Destination : aws .String (destination + "m" ),
175175 },
176176 }
177177 default :
@@ -184,8 +184,14 @@ func (p *mcProvider) outputGroupsFrom(job *db.Job) ([]mediaconvert.OutputGroup,
184184 return mcOutputGroups , nil
185185}
186186
187- func destinationPathFrom (destBase string , jobID string ) string {
188- return fmt .Sprintf ("%s/%s/" , strings .TrimRight (destBase , "/" ), jobID )
187+ func (p * mcProvider ) destinationPathFrom (job * db.Job ) string {
188+ var basePath string
189+ if cfgBasePath := job .DestinationBasePath ; cfgBasePath != "" {
190+ basePath = cfgBasePath
191+ } else {
192+ basePath = p .cfg .Destination
193+ }
194+ return fmt .Sprintf ("%s/%s/" , strings .TrimRight (basePath , "/" ), job .ID )
189195}
190196
191197func (p * mcProvider ) CreatePreset (preset db.Preset ) (string , error ) {
@@ -221,49 +227,117 @@ func (p *mcProvider) JobStatus(job *db.Job) (*provider.JobStatus, error) {
221227 return & provider.JobStatus {}, errors .Wrap (err , "fetching job info with the mediaconvert API" )
222228 }
223229
224- return p .jobStatusFrom (job .ProviderJobID , job . ID , jobResp .Job ), nil
230+ return p .jobStatusFrom (job .ProviderJobID , job , jobResp .Job ), nil
225231}
226232
227- func (p * mcProvider ) jobStatusFrom (providerJobID string , jobID string , job * mediaconvert.Job ) * provider.JobStatus {
233+ func (p * mcProvider ) jobStatusFrom (providerJobID string , job * db. Job , mcJob * mediaconvert.Job ) * provider.JobStatus {
228234 status := & provider.JobStatus {
229235 ProviderJobID : providerJobID ,
230236 ProviderName : Name ,
231- Status : providerStatusFrom (job .Status ),
232- StatusMessage : statusMsgFrom (job ),
237+ Status : providerStatusFrom (mcJob .Status ),
238+ StatusMessage : statusMsgFrom (mcJob ),
233239 Output : provider.JobOutput {
234- Destination : destinationPathFrom ( p . cfg . Destination , jobID ),
240+ Destination : p . destinationPathFrom ( job ),
235241 },
236242 }
237243
238244 if status .Status == provider .StatusFinished {
239245 status .Progress = 100
240- } else if p := job .JobPercentComplete ; p != nil {
246+ } else if p := mcJob .JobPercentComplete ; p != nil {
241247 status .Progress = float64 (* p )
242248 }
243249
244250 var files []provider.OutputFile
245- for _ , groupDetails := range job .OutputGroupDetails {
246- for _ , outputDetails := range groupDetails .OutputDetails {
247- if outputDetails .VideoDetails == nil {
251+ if settings := mcJob .Settings ; settings != nil {
252+ for _ , group := range settings .OutputGroups {
253+ groupDestination , err := outputGroupDestinationFrom (group )
254+ if err != nil {
248255 continue
249256 }
257+ for _ , output := range group .Outputs {
258+ file := provider.OutputFile {}
259+
260+ if modifier := output .NameModifier ; modifier != nil {
261+ if extension , err := fileExtensionFromContainer (output .ContainerSettings ); err == nil {
262+ file .Path = groupDestination + * modifier + extension
263+ } else {
264+ continue
265+ }
266+ } else {
267+ continue
268+ }
269+
270+ if video := output .VideoDescription ; video != nil {
271+ if height := video .Height ; height != nil {
272+ file .Height = * height
273+ }
274+
275+ if width := video .Width ; width != nil {
276+ file .Width = * width
277+ }
278+ }
279+
280+ if container , err := containerIdentifierFrom (output .ContainerSettings ); err == nil {
281+ file .Container = container
282+ }
283+
284+ files = append (files , file )
285+ }
286+ }
287+ }
250288
251- file := provider. OutputFile {}
289+ status . Output . Files = files
252290
253- if height := outputDetails .VideoDetails .HeightInPx ; height != nil {
254- file .Height = * height
255- }
291+ return status
292+ }
256293
257- if width := outputDetails .VideoDetails .WidthInPx ; width != nil {
258- file .Width = * width
259- }
294+ func outputGroupDestinationFrom (group mediaconvert.OutputGroup ) (string , error ) {
295+ if group .OutputGroupSettings == nil {
296+ return "" , errors .New ("output group contained no settings" )
297+ }
298+
299+ switch group .OutputGroupSettings .Type {
300+ case mediaconvert .OutputGroupTypeFileGroupSettings :
301+ fsSettings := group .OutputGroupSettings .FileGroupSettings
302+ if fsSettings == nil {
303+ return "" , errors .New ("file group settings were nil" )
304+ }
260305
261- files = append (files , file )
306+ if fsSettings .Destination == nil {
307+ return "" , errors .New ("file group destination was nil" )
262308 }
309+
310+ return * fsSettings .Destination , nil
311+ default :
312+ return "" , fmt .Errorf ("output enumeration not supported for output group %q" ,
313+ group .OutputGroupSettings .Type )
263314 }
264- status . Output . Files = files
315+ }
265316
266- return status
317+ func fileExtensionFromContainer (settings * mediaconvert.ContainerSettings ) (string , error ) {
318+ if settings == nil {
319+ return "" , errors .New ("container settings were nil" )
320+ }
321+
322+ switch settings .Container {
323+ case mediaconvert .ContainerTypeMp4 :
324+ return ".mp4" , nil
325+ default :
326+ return "" , fmt .Errorf ("could not determine extension from output container %q" , settings .Container )
327+ }
328+ }
329+
330+ func containerIdentifierFrom (settings * mediaconvert.ContainerSettings ) (string , error ) {
331+ if settings == nil {
332+ return "" , errors .New ("container settings were nil" )
333+ }
334+
335+ switch settings .Container {
336+ case mediaconvert .ContainerTypeMp4 :
337+ return "mp4" , nil
338+ default :
339+ return "" , fmt .Errorf ("could not determine container identifier from output container %q" , settings .Container )
340+ }
267341}
268342
269343func statusMsgFrom (job * mediaconvert.Job ) string {
0 commit comments