Skip to content

Attach media metadata to downloaded files: probe on completion + inherit preview from search results - #321

Merged
got3nks merged 2 commits into
amule-org:masterfrom
got3nks:fix/mediaprobe-on-completion
Jul 6, 2026
Merged

Attach media metadata to downloaded files: probe on completion + inherit preview from search results#321
got3nks merged 2 commits into
amule-org:masterfrom
got3nks:fix/mediaprobe-on-completion

Conversation

@got3nks

@got3nks got3nks commented Jul 6, 2026

Copy link
Copy Markdown

Problem

After #319, media-metadata probing works, but a downloaded media file didn't get its FT_MEDIA_* tags until the next daemon restart. Two gaps:

  1. MaybeScheduleMediaProbe only runs when a file is first inserted into the shared list. A download is shared as a partfile while transferring, so on completion CompleteFileEnded → SafeAddKFile re-adds it, AddFile's insert no-ops (hash already present — the alreadyCanonical branch), and the probe is never scheduled.
  2. The search result the download came from already carried the file's media metadata (a source running feat(metadata): advertise Length / Bitrate / Codec for shared media files via ffprobe #280 advertises FT_MEDIA_LENGTH/BITRATE/CODEC), but CPartFile(CSearchFile*) copied only FT_FILETYPE/FT_FILEFORMAT and dropped it (ignored tag 0xD3…), so nothing was shown while downloading either.

Fix

Commit 1 — probe on completion (SharedFileList.cpp/.h): schedule the probe from the completion (alreadyCanonical) branch, once the file is complete on disk in Incoming. QueueProbe only enqueues, so it never stalls completion (rides on #319's isolation). The completion call forces the probe (new bForceReprobe arg bypasses the already-has-FT_MEDIA gate) so the authoritative local ffprobe is the source of truth — it always runs on completion and overwrites anything inherited from the network; startup rescans stay probe-once. Two guards on MaybeScheduleMediaProbe:

  • Never probe an in-progress download — a partfile is shared while transferring, so AddFile calls this during the download when there is no complete file to read (<hash>.part). Skip any non-forced probe of a partfile unconditionally (the completion re-enters with the force flag); metadata is derived exactly once, on completion.
  • Skip when the resolved path isn't on disk — so a stale known.met record that outlived its deleted file never hands ffprobe a path that can't succeed.

Commit 2 — inherit a preview from search results (PartFile.cpp): add FT_MEDIA_LENGTH/BITRATE/CODEC to the tags CPartFile(CSearchFile*) inherits, so a download shows media metadata immediately while transferring, with no local ffprobe. This is a preview only — the authoritative completion probe re-derives and overwrites it. Source-agnostic: ed2k and Kad share the same tag IDs (TAG_MEDIA_* == FT_MEDIA_* == 0xD3/D4/D5) and the same CSearchFile path, so one change covers both.

Model: inherited network tags give an instant, free preview during the download; on completion the local ffprobe always runs and replaces them with verified values. A media download ends up authoritatively tagged whether or not its source advertised anything — and the network is never trusted as the final answer.

Test plan (macOS, Linux, Windows)

  1. Probe on completion — download a media file; on completion (no restart) the log shows queueing → extracted → Media metadata, and known.met gains FT_MEDIA_*.
  2. Inherit preview — download one whose search result carried 0xD3/D4/D5: the partfile carries the tags during download, and on completion the probe still runs (extracted, not skip) and overwrites with local values.
  3. No stall — completions flow normally throughout (rides on Make media metadata probing safe: dedicated worker, ffprobe timeout, CTag + codec fixes #319).
  4. Existence guard — a still-downloading partfile / stale known.met entry is not probed.

got3nks added 2 commits July 6, 2026 12:31
Media-metadata probing (amule-project#280) only scheduled a probe when a file was first
inserted into the shared list. A download is shared as a partfile while
transferring, so on completion CPartFile::CompleteFileEnded -> SafeAddKFile
re-adds it, AddFile's insert no-ops (the hash is already present), and the
probe was never scheduled -- a downloaded media file only got its FT_MEDIA_*
tags on the next daemon restart.

Schedule the probe from the completion (alreadyCanonical) branch, now that the
file is complete on disk at its Incoming path. QueueProbe only enqueues, so it
never stalls completion. Force it (bypassing the already-has-FT_MEDIA gate via
a new bForceReprobe argument) so the authoritative local probe overwrites any
metadata inherited from the search result; startup rescans stay probe-once.

Also add two guards to MaybeScheduleMediaProbe:
 * Never probe an in-progress download: a partfile is shared while
   transferring, so this fires from AddFile() during the download when there is
   no complete file to read (the on-disk name is <hash>.part). Skip any
   non-forced probe of a partfile unconditionally -- the completion re-enters
   with bForceReprobe set. Metadata is derived exactly once, on completion.
 * Skip when the resolved path is not on disk, so a stale known.met record that
   outlived its deleted file never hands ffprobe a path that cannot succeed.
A search result from a source running amule-project#280 carries the file's FT_MEDIA_LENGTH
/ _BITRATE / _CODEC tags, but CPartFile(CSearchFile*) copied only FT_FILETYPE
/ FT_FILEFORMAT and dropped the rest. Add the media tags to the inherited set
so a download shows media metadata immediately while transferring, without a
local ffprobe. The authoritative probe on completion re-derives and overwrites
these values, so the inherited data is only a during-download preview.

Source-agnostic: ed2k and Kad use the same media tag IDs (TAG_MEDIA_* ==
FT_MEDIA_* == 0xD3/D4/D5) and share the CSearchFile construction path, so this
one change covers both.
@got3nks
got3nks force-pushed the fix/mediaprobe-on-completion branch from 2b86bb7 to dabc94a Compare July 6, 2026 10:31
@got3nks
got3nks merged commit 97a91d3 into amule-org:master Jul 6, 2026
12 checks passed
@got3nks
got3nks deleted the fix/mediaprobe-on-completion branch July 6, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant