17
17
18
18
class MediaConversionAudio extends MediaConversionDefinition
19
19
{
20
+ /**
21
+ * @param null|string|(Closure(Media $media, ?MediaConversion $parent):string) $fileName
22
+ */
20
23
public function __construct (
21
24
public string $ name ,
22
25
public null |bool |Closure $ when = null ,
@@ -25,7 +28,7 @@ public function __construct(
25
28
public bool $ queued = true ,
26
29
public ?string $ queue = null ,
27
30
public array $ conversions = [],
28
- public ? string $ fileName = null ,
31
+ public null | Closure | string $ fileName = null ,
29
32
public FormatInterface $ format = new Mp3 ,
30
33
) {
31
34
@@ -64,6 +67,17 @@ public function hasFileAudioStream(string $path): bool
64
67
return (bool ) $ streams ->audios ()->count ();
65
68
}
66
69
70
+ public function getFileName (Media $ media , ?MediaConversion $ parent ): string
71
+ {
72
+ if ($ fileName = $ this ->fileName ) {
73
+ return is_string ($ fileName ) ? $ fileName : $ fileName ($ media , $ parent );
74
+ }
75
+
76
+ $ source = $ parent ?? $ media ;
77
+
78
+ return "{$ source ->name }.mp3 " ;
79
+ }
80
+
67
81
public function handle (
68
82
Media $ media ,
69
83
?MediaConversion $ parent ,
@@ -78,13 +92,11 @@ public function handle(
78
92
/**
79
93
* Videos do not always have an audio stream
80
94
*/
81
- if (! $ this ->hasFileAudioStream (
82
- $ filesystem ->path ($ file )
83
- )) {
95
+ if (! $ this ->hasFileAudioStream ($ filesystem ->path ($ file ))) {
84
96
return null ;
85
97
}
86
98
87
- $ fileName = $ this ->fileName ?? "{ $ media-> name } .mp3 " ;
99
+ $ fileName = $ this ->getFileName ( $ media, $ parent ) ;
88
100
89
101
$ ffmpeg = FFMpeg::fromFilesystem ($ filesystem )
90
102
->open ($ file )
0 commit comments