mirror of
https://github.com/Dasemu/x-space-downloader.git
synced 2026-11-27 15:56:42 +00:00
feat: add URL validator for X Space URLs
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
07814e10b4
commit
52ee05e009
3 files changed
+35
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
import re
|
||||||
|
from typing import Tuple, Optional
|
||||||
|
|
||||||
|
|
||||||
|
def validate_space_url(url: str) -> Tuple[bool, Optional[str], Optional[str]]:
|
||||||
|
"""
|
||||||
|
Validates X Space URL format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The URL to validate
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple of (is_valid, space_id, error_message)
|
||||||
|
"""
|
||||||
|
# Pattern for X Space URLs
|
||||||
|
pattern = r"https://x\.com/i/spaces/([a-zA-Z0-9]+)"
|
||||||
|
match = re.match(pattern, url)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
return False, None, "Invalid URL format. Expected: https://x.com/i/spaces/{SPACE_ID}"
|
||||||
|
|
||||||
|
space_id = match.group(1)
|
||||||
|
return True, space_id, None
|
||||||
Whitespace-only changes.
@@ -0,0 +1,12 @@
|
|||||||
|
import pytest
|
||||||
|
from src.validator import validate_space_url
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_space_url_valid():
|
||||||
|
"""Test that valid X Space URL is accepted."""
|
||||||
|
url = "https://x.com/i/spaces/1ZkKzZWnVRRKv"
|
||||||
|
is_valid, space_id, error = validate_space_url(url)
|
||||||
|
|
||||||
|
assert is_valid is True
|
||||||
|
assert space_id == "1ZkKzZWnVRRKv"
|
||||||
|
assert error is None
|
||||||
Reference in new issue
Block a user