* @brief Universal media duration getter (supports both patterns) * * @param file_path [in] Path to media file * @param done [opt] Optional callback for non-Promise usage * @return Promise Duration in seconds * @return void if callback provided * * Usage Examples: * ```js * //
(file_path, done)
| 152 | * @note Validates media type before processing |
| 153 | */ |
| 154 | function get_media_duration(file_path, done) { |
| 155 | const run = () => new Promise((resolve, reject) => { |
| 156 | get_media_duration_callback(file_path, (err, result) => { |
| 157 | if (err) |
| 158 | reject(err); |
| 159 | else |
| 160 | resolve(result?.duration ?? 0); |
| 161 | }); |
| 162 | }) |
| 163 | |
| 164 | if (typeof done === 'function') { |
| 165 | run().then((duration) => done(null, duration)).catch((e) => done(e)); |
| 166 | } else { |
| 167 | return run(); |
| 168 | } |
| 169 | |
| 170 | // return new Promise((resolve, reject) => { |
| 171 | // ffprobe.ffprobe(file_path, (err, metadata) => { |
| 172 | // if (err) { |
| 173 | // reject(err); |
| 174 | // } else { |
| 175 | // const duration = metadata.format.duration; |
| 176 | // resolve(duration); |
| 177 | // } |
| 178 | // }); |
| 179 | // }); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @brief Translates IPv6 addresses to IPv4 format when applicable |
no test coverage detected