Changeset 3e86f1c in Klonkt for src/routes/admin-audio.js


Ignore:
Timestamp:
06/15/2026 03:23:29 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
7f46817d
Parents:
4c9f29a
Message:

feat: automatic track duration — no more manually entering seconds

The duration of an audio track is now determined automatically instead of manually:

  • On upload: read from ffmpeg's codecData event during the existing transcode (no extra ffprobe binary). The upload INSERT never set duration before -> every track started as NULL ('--:--'); that is now fixed.
  • In the track editor: a hidden <audio preload=metadata> reads the duration and fills the field if it's still empty (manual override still possible).
  • Backfill: npm run backfill:durations fills existing tracks without duration via ffmpeg (probeDuration reads only codecData and stops immediately -> fast).

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/admin-audio.js

    r4c9f29a r3e86f1c  
    185185      `).run(mediaId, site.id, transcoded.filename, transcoded.mimeType, transcoded.size, transcoded.path);
    186186
    187       console.log('[admin-audio] inserting audio_tracks row');
     187      // Duur automatisch: primair uit de transcode (ffmpeg codecData), anders een
     188      // optionele client-side waarde (bulk-uploader leest <audio>.duration uit),
     189      // anders NULL (UI toont dan '—:—', handmatig bij te werken in de editor).
     190      const clientDur = req.body.duration != null ? parseInt(req.body.duration, 10) : NaN;
     191      const finalDuration =
     192        (transcoded.durationSec != null && transcoded.durationSec > 0) ? transcoded.durationSec
     193        : (Number.isFinite(clientDur) && clientDur > 0) ? clientDur
     194        : null;
     195
     196      console.log('[admin-audio] inserting audio_tracks row (duration=' + finalDuration + ')');
    188197      db.prepare(`
    189         INSERT INTO audio_tracks (id, site_id, title, artist, album, cover_url, media_id, position)
    190         VALUES (?, ?, ?, ?, ?, ?, ?, COALESCE(
     198        INSERT INTO audio_tracks (id, site_id, title, artist, album, duration, cover_url, media_id, position)
     199        VALUES (?, ?, ?, ?, ?, ?, ?, ?, COALESCE(
    191200          (SELECT MAX(position) + 1 FROM audio_tracks WHERE site_id = ?),
    192201          0
     
    195204        trackId, site.id,
    196205        finalTitle, finalArtist, finalAlbum,
     206        finalDuration,
    197207        coverUrl,
    198208        mediaId, site.id
Note: See TracChangeset for help on using the changeset viewer.