MCPcopy Create free account
hub / github.com/AS-AIGC/TranscriptHub / get_media_duration

Function get_media_duration

apps/backend/utils.js:154–180  ·  view source on GitHub ↗

* @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)

Source from the content-addressed store, hash-verified

152 * @note Validates media type before processing
153 */
154function 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

Callers 1

Calls 1

runFunction · 0.85

Tested by

no test coverage detected