Skip to content

[FIX] Parse MediaInfo XML that has only one track - #1296

Open
WadekarPrashant wants to merge 1 commit into
CCExtractor:masterfrom
WadekarPrashant:fix/single-track-media-info
Open

WadekarPrashant wants to merge 1 commit into
CCExtractor:masterfrom
WadekarPrashant:fix/single-track-media-info

Conversation

@WadekarPrashant

Copy link
Copy Markdown

Closes #1295

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Cause: xmltodict decodes a single <track> element as a mapping and several as a list. MediaInfoFetcher._process_tracks looped over file_info['track'] directly, so with one track (for example a truncated MP4 where MediaInfo recovers only the General track) it iterated the mapping's keys. _process_track received strings such as '@type' and 'Format', skipped each one as a non-dict, and general_track stayed {}.

Change: _process_tracks wraps the value in a one-element list when it is a mapping, then loops as before. The multi-track path is unchanged.

Tests:

  • test__process_tracks_single_track: a lone General track given as a mapping populates general_track. Fails on master with {} != {'Format': 'MPEG-4', 'FileSize': '1.0 MB'}; passes with this change.
  • test__process_tracks_multiple_tracks: a General + Video list is still parsed track by track. This guards the list case: it fails if the normalisation wraps a list by mistake.

The existing InvalidMediaInfoError tests for missing media and missing track still pass.

xmltodict returns a lone <track> as a mapping, so iterating it yielded
the track's keys instead of the track. Wrap a mapping in a list before
the loop.
@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

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.

[BUG] Sample metadata drops General fields when MediaInfo returns a single track

1 participant