Skip to content

fix(video_learning): ignore a superscript-digit timestamp instead of raising - #3278

Open
XAE-A-Xii wants to merge 1 commit into
HKUDS:devfrom
XAE-A-Xii:fix/youtube-timestamp-unicode-digits
Open

XAE-A-Xii wants to merge 1 commit into
HKUDS:devfrom
XAE-A-Xii:fix/youtube-timestamp-unicode-digits

Conversation

@XAE-A-Xii

Copy link
Copy Markdown

Description

A YouTube URL whose t value contains a superscript digit made parse_youtube_url raise a bare ValueError. parse_timestamp (deeptutor/video_learning/service.py) checked raw.isdigit() before calling int(raw), but isdigit() is also True for characters int() rejects:

>>> parse_timestamp("²")
ValueError: invalid literal for int() with base 10: '²'
>>> parse_youtube_url("https://youtu.be/dQw4w9WgXcQ?t=²")
ValueError: invalid literal for int() with base 10: '²'

Callers only expect this module's own errors. For example, reading/ingestion.youtube_video_id catches ReadingError, so the ValueError escapes instead of the timestamp being ignored.

The check is now isdecimal(), which is exactly the set of characters int() accepts. "²" falls through to the h/m/s pattern and parses as 0, like any other unreadable value ("1.5" → 0). Decimal digits from other scripts, such as Arabic-Indic "١٢", still parse as 12, which an ASCII-only [0-9]+ check would have broken.

>>> parse_youtube_url("https://youtu.be/dQw4w9WgXcQ?t=²")   # after
YouTubeRequest(video_id='dQw4w9WgXcQ', entry_time_seconds=0, ...)

Related Issues

  • None filed; this is a small, self-contained fix.

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: video_learning

Checklist

  • This PR targets dev (not main — see the base-branch selector above).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary). (Not needed.)
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

Tests in tests/video_learning/test_service.py:

  • test_parse_supported_youtube_urls gains a t=² row (start 0).
  • The new test_parse_timestamp_ignores_digit_like_characters_int_rejects covers "82", "1m2s", "²", "³⁴", "١٢" and "1.5".

Before the fix the three superscript cases fail. A check limited to ASCII [0-9]+ fails the "١٢" case, so the test pins the isdecimal() choice.

$ python -m pytest tests/video_learning -q
104 passed
$ python -m pytest tests/reading -q -k "youtube or video or timestamp or url"
33 passed

Out of scope for this PR (one module per PR): deeptutor/reading/ingestion.py:651 has its own copy of parse_timestamp with the same isdigit() → int() pattern, and reading/references.py:171 and textbook_struct/page_headers.py have similar checks. I'm happy to follow up on those separately if you'd like.

pre-commit run --files on both changed files passes every hook. --all-files fails mypy on dev itself in services/embedding/adapters/volcengine.py, from #1015, which this PR doesn't touch.

🤖 Generated with Claude Code

@github-actions github-actions Bot added backend Python runtime, capabilities, tools, API & CLI bug Something isn't working labels Dec 5, 2026
…raising

`parse_timestamp` checked `raw.isdigit()` before `int(raw)`, but
isdigit is True for digits int() rejects, such as "²". A YouTube URL
with `t=²` therefore made `parse_youtube_url` raise a bare ValueError
instead of a TimedMediaError, so callers that catch the module's own
errors (e.g. reading's `youtube_video_id`, which catches ReadingError)
let it escape.

The check is now `isdecimal()`, exactly the characters int() accepts:
"²" falls through to the h/m/s pattern and parses as 0 like any other
unreadable value, while decimal digits from other scripts (e.g. "١٢")
still parse as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XAE-A-Xii
XAE-A-Xii force-pushed the fix/youtube-timestamp-unicode-digits branch from 29c1843 to 9c938d3 Compare December 5, 2026 12:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Python runtime, capabilities, tools, API & CLI bug Something isn't working

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant