Attach media metadata to downloaded files: probe on completion + inherit preview from search results - #321
Merged
Conversation
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
force-pushed
the
fix/mediaprobe-on-completion
branch
from
July 6, 2026 10:31
2b86bb7 to
dabc94a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:MaybeScheduleMediaProbeonly runs when a file is first inserted into the shared list. A download is shared as a partfile while transferring, so on completionCompleteFileEnded → SafeAddKFilere-adds it,AddFile's insert no-ops (hash already present — thealreadyCanonicalbranch), and the probe is never scheduled.FT_MEDIA_LENGTH/BITRATE/CODEC), butCPartFile(CSearchFile*)copied onlyFT_FILETYPE/FT_FILEFORMATand 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.QueueProbeonly enqueues, so it never stalls completion (rides on #319's isolation). The completion call forces the probe (newbForceReprobearg bypasses the already-has-FT_MEDIAgate) 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 onMaybeScheduleMediaProbe:AddFilecalls 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.Commit 2 — inherit a preview from search results (
PartFile.cpp): addFT_MEDIA_LENGTH/BITRATE/CODECto the tagsCPartFile(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 sameCSearchFilepath, 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)
queueing → extracted → Media metadata, and known.met gainsFT_MEDIA_*.0xD3/D4/D5: the partfile carries the tags during download, and on completion the probe still runs (extracted, notskip) and overwrites with local values.