Skip to content

Conversation

Copy link

Copilot AI commented Aug 8, 2025

Fixes a ValueError that occurs when processing torrent titles containing Unicode superscript characters like '²', '³', '¹'.

Problem

The error occurs in app/core/meta/metavideo.py when the code uses isdigit() to check if a string contains only digits, then attempts to convert it with int():

if name.isdigit() \
        and int(name) < 1800 \

Issue: str.isdigit() returns True for Unicode digit characters including superscripts (²), but int() can only parse standard ASCII digits (0-9).

Example failure:

>>> "²".isdigit()
True
>>> int("²")
ValueError: invalid literal for int() with base 10: '²'

Root Cause

When processing torrent titles like "E=mc² The Movie 2023", the parsing logic encounters the superscript '²' character. The isdigit() method incorrectly identifies it as a digit, leading to a failed int() conversion.

Solution

Replace isdigit() with isdecimal() in all locations where the result is passed to int():

  • str.isdecimal() only returns True for characters that can form decimal numbers (0-9)
  • str.isdigit() includes Unicode digit characters like superscripts

Changes Made

Fixed 3 locations in app/core/meta/metavideo.py:

  1. Line 73: File title processing
  2. Line 203: Name fixing function (original reported issue)
  3. Line 346: Year processing

Validation

Before fix:

>>> "²".isdigit()
True
>>> int("²")  # Crashes with ValueError

After fix:

>>> "²".isdecimal()
False
>>> # No int() conversion attempted - safe!

Normal digits continue to work exactly as before:

>>> "1234".isdecimal()
True
>>> int("1234")
1234

This is a minimal, surgical fix that prevents the crash while preserving all existing functionality.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@jxxghp jxxghp closed this Aug 8, 2025
Copilot AI changed the title [WIP] 修复ValueError: invalid literal for int() with base 10: '²'错误 Fix ValueError with Unicode superscript characters in torrent title parsing Aug 8, 2025
Copilot AI requested a review from jxxghp August 8, 2025 02:24
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.

2 participants