markitdown
markitdown copied to clipboard
fix(youtube): recognise youtu.be / shorts / embed / live URL shapes
Summary
- Centralise YouTube URL → video_id extraction in a single
_extract_video_idhelper - Accept
youtu.be/<id>short links,/shorts/<id>,/embed/<id>,/live/<id>in addition to the canonical/watch?v=... - Accept
m.youtube.comandmusic.youtube.comhosts - Have
convert()reuse the same helper so it no longer silently skips the transcript path for valid non-canonical URLs
Previously YouTubeConverter.accepts() only matched https://www.youtube.com/watch?, so any other valid YouTube URL shape fell through to the generic HTML converter and lost the YouTube-specific title / description / transcript handling. convert() duplicated the ?v= parsing and had the same blind spot.
Fixes #1775.
Test plan
- [x] New unit-test module
tests/test_youtube_url_shapes.pycovers all accepted shapes plus negative cases (vimeo, bare/watchwith nov, channel URL, empty string, unknown host) — 14/14 pass - [x] Existing YouTube behaviour for
www.youtube.com/watch?v=...unchanged - [ ] Maintainer review of the host allowlist (I kept it conservative — happy to widen if there are other YouTube hosts you'd like to support)
@microsoft-github-policy-service agree