Skip to content

Conversation

@Zzackllack
Copy link
Owner

This pull request updates the Megakino provider integration to improve domain resolution and update the default domain from megakino.lol to megakino1.to. It also enhances the logic for discovering and validating Megakino mirror domains, updates related documentation, and adjusts tests and configuration to match the new defaults.

Megakino domain resolution and configuration:

  • Changed the default Megakino base URL from https://megakino.lol to https://megakino1.to in environment variables, configuration, and documentation. (.env.example, app/config.py, docs/src/api/environment.md, docs/src/guide/configuration.md, docs/src/guide/troubleshooting.md, [1] [2] [3] [4] [5]
  • Updated the Megakino domain resolution logic to use a mirrors.txt file from known domains and validate each candidate by checking for a valid sitemap, rather than following HTTP redirects. (app/utils/domain_resolver.py, [1] [2] [3]
  • Added logic to fetch and parse Megakino mirror domains, and to validate a domain by confirming its sitemap payload, improving reliability in finding a working mirror. (app/utils/domain_resolver.py, app/utils/domain_resolver.pyL100-R249)

Code and environment variable cleanup:

  • Removed the now-unnecessary MEGAKINO_SITEMAP_URL environment variable and related code; the sitemap URL is now always derived from the resolved base URL. (app/config.py, app/providers/megakino/client.py, app/utils/domain_resolver.py, [1] [2] [3] [4] [5]

Documentation updates:

  • Updated documentation to reflect the new Megakino default domain, the new mirror-based resolution process, and troubleshooting instructions. (docs/src/api/environment.md, docs/src/guide/configuration.md, docs/src/guide/troubleshooting.md, [1] [2] [3] [4]

Test updates:

  • Updated all tests and test fixtures to use megakino1.to instead of megakino.lol in URLs and environment variables. (tests/test_megakino_sitemap.py, tests/test_title_resolver_megakino.py, [1] [2] [3] [4] [5]## Description

Zzackllack and others added 2 commits January 7, 2026 22:36
Changed the default Megakino base URL to "https://megakino1.to" and updated related configurations and documentation. Adjusted the sitemap URL generation to reflect the new base URL and improved domain resolution logic to utilize mirror domains.
@Zzackllack Zzackllack self-assigned this Jan 7, 2026
Copilot AI review requested due to automatic review settings January 7, 2026 21:43
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added automatic mirror discovery and sitemap-based validation for improved Megakino domain resolution and reliability.
  • Documentation

    • Updated Megakino configuration and troubleshooting guides to reflect new domain resolution method.
  • Tests

    • Added test coverage for domain resolver utilities.
  • Chores

    • Updated default Megakino domain and expanded list of supported mirror domains for better availability.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Megakino default base URL changed from megakino.lol to megakino1.to. Static MEGAKINO_SITEMAP_URL removed; sitemap URL is now composed from the resolved base URL. Domain resolution now uses mirrors.txt discovery and sitemap-based probing instead of token-endpoint checks.

Changes

Cohort / File(s) Summary
Configuration & Env
\.env\.example, app/config.py
Removed MEGAKINO_SITEMAP_URL and its logging; updated MEGAKINO_BASE_URL default to https://megakino1.to.
Client Implementation
app/providers/megakino/client.py
get_default_client resolves base_url at init and composes sitemap_url as {base_url}/sitemap.xml instead of using a static config value.
Domain Resolution Logic
app/utils/domain_resolver.py
Added mirror discovery and sitemap validation helpers (_is_sitemap_payload, _looks_like_html, _probe_megakino_sitemap, _parse_mirror_domains, fetch_megakino_mirror_domains, fetch_megakino_domain); expanded MEGAKINO_DOMAIN_CANDIDATES and changed MEGAKINO_DEFAULT_DOMAIN; added MEGAKINO_MIRRORS_PATH; removed token-path probing and stopped writing sitemap URL in _apply_megakino_base_url.
Documentation
docs/src/api/environment.md, docs/src/guide/configuration.md, docs/src/guide/troubleshooting.md
Updated default MEGAKINO_BASE_URL to https://megakino1.to and documented the new resolution flow (mirrors.txt + sitemap validation); troubleshooting now references "mirrors" log entries.
Tests
tests/test_megakino_sitemap.py, tests/test_title_resolver_megakino.py, tests/test_megakino_domain_resolver.py
Updated test fixtures and expected URLs from megakino.lol to megakino1.to; added tests/test_megakino_domain_resolver.py covering sitemap payload validation, mirror parsing, and fetch_megakino_mirror_domains with mocked HTTP responses.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant App as Application
    participant Resolver as Domain Resolver
    participant Mirrors as Mirrors Endpoint
    participant Site as Candidate Site
    participant Sitemap as /sitemap.xml

    App->>Resolver: fetch_megakino_domain()
    activate Resolver

    Resolver->>Resolver: build candidate list (defaults + mirrors)
    Resolver->>Mirrors: fetch_megakino_mirror_domains()
    activate Mirrors
    Mirrors-->>Resolver: mirror domain list
    deactivate Mirrors

    loop each candidate
        Resolver->>Site: _probe_megakino_sitemap(candidate)
        activate Site
        Site->>Sitemap: GET candidate + /sitemap.xml
        activate Sitemap
        Sitemap-->>Site: content / redirect / error
        deactivate Sitemap

        Site->>Site: validate sitemap payload & final domain
        alt valid sitemap & domain consistent
            Site-->>Resolver: success (use this base URL)
            Resolver->>Resolver: set MEGAKINO_BASE_URL, stop
        else invalid or mismatch
            Site-->>Resolver: failure (continue)
        end
        deactivate Site
    end

    Resolver-->>App: resolved base URL or None
    deactivate Resolver
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description is comprehensive and well-structured, covering all major changes. However, it does not follow the repository's template structure (missing checkboxes for Type of Change and Testing sections). Use the repository's PR template format with checkboxes for Type of Change, Testing, and other sections to ensure consistency and clarity for reviewers.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: updating Megakino's base URL and improving sitemap handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch megakino-better-domain-resolution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 7, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
anibridge-docs 374691d Jan 07 2026, 10:20 PM

coderabbitai[bot]

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

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.

Pull request overview

This pull request updates the Megakino provider integration by changing the default domain from megakino.lol to megakino1.to and completely reworking the domain resolution strategy. The new approach uses a mirrors.txt file to discover valid Megakino domains and validates each candidate by checking for a valid sitemap, replacing the previous redirect-following mechanism.

Key changes:

  • Replaced redirect-based domain discovery with mirrors.txt fetching and sitemap validation
  • Updated default domain to megakino1.to across all configuration, documentation, and tests
  • Removed MEGAKINO_SITEMAP_URL environment variable (now derived from base URL)

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
app/utils/domain_resolver.py Implements new mirror-based domain resolution with sitemap validation; adds helper functions for parsing mirrors.txt and validating sitemap payloads
app/providers/megakino/client.py Updates client initialization to derive sitemap URL from base URL instead of using separate config variable
app/config.py Changes default domain to megakino1.to and removes MEGAKINO_SITEMAP_URL configuration
.env.example Updates default domain example and removes deprecated MEGAKINO_SITEMAP_URL variable
docs/src/api/environment.md Updates environment variable documentation to reflect new default domain
docs/src/guide/configuration.md Documents new mirror-based resolution approach and updates default domain
docs/src/guide/troubleshooting.md Updates troubleshooting guidance to mention mirrors log entries
tests/test_title_resolver_megakino.py Updates test fixtures to use new default domain
tests/test_megakino_sitemap.py Updates sample URLs in tests to use new domain
Comments suppressed due to low confidence (1)

app/utils/domain_resolver.py:253

  • The modified fetch_megakino_domain function now uses a completely different resolution strategy (mirrors.txt + sitemap validation instead of redirects) but lacks test coverage for this new behavior. Tests should verify the priority order (mirrors first, then candidates), deduplication logic, and sitemap validation.
def fetch_megakino_domain(timeout: float | int = 15) -> Optional[str]:
    """
    Resolve the active Megakino domain by checking the sitemap across mirror and candidate domains.

    Parameters:
        timeout (float | int): Request timeout in seconds for HTTP probes.

    Returns:
        resolved_domain (str | None): The resolved domain without a URL scheme (for example, "example.com"), or `None` if no candidate could be validated.
    """
    logger.info("Resolving megakino domain via sitemap checks.")
    seen: set[str] = set()
    candidates: list[str] = []
    mirror_domains = fetch_megakino_mirror_domains(timeout=timeout)
    if mirror_domains:
        candidates.extend(mirror_domains)
    candidates.extend(MEGAKINO_DOMAIN_CANDIDATES)
    for candidate in candidates:
        domain = _normalize_domain(candidate)
        if not domain or domain in seen:
            continue
        seen.add(domain)
        base_url = _build_base_url(domain)
        try:
            final_domain = _probe_megakino_sitemap(base_url, timeout=timeout)
            if final_domain:
                logger.success("Megakino domain resolved: {}", final_domain)
                return final_domain
            logger.warning("Megakino candidate failed validation: {}", domain)
        except Exception as exc:
            logger.warning("Megakino candidate check failed for {}: {}", base_url, exc)
    logger.warning("Megakino domain resolution failed; no candidate succeeded.")
    return None

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Docstrings generation was requested by @Zzackllack.

* #32 (comment)

The following files were modified:

* `app/providers/megakino/client.py`
* `app/utils/domain_resolver.py`
github-actions bot and others added 6 commits January 7, 2026 21:50
…ching

Added comprehensive docstrings to several functions in the domain resolver to clarify their purpose and usage. Improved the mirror fetching logic to handle HTML responses more effectively, ensuring only valid domains are returned.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @app/utils/domain_resolver.py:
- Around line 164-166: Replace the broad "except Exception as exc:" in the
Megakino probe block with a network-specific exception catch (e.g., "except
requests.RequestException as exc:" or "except requests.exceptions.HTTPError as
exc:" depending on which errors the HTTP client raises) to avoid masking
programming errors; update imports to include RequestException/HTTPError from
requests.exceptions and keep the existing logger.warning call (referencing
probe_url and exc) so only network-related failures are handled here.
- Around line 268-269: The current except block for the Megakino mirrors fetch
catches all Exceptions (the except Exception as exc handling mirrors_url) which
can hide non-network bugs; change it to catch only network/HTTP-related
exceptions used by your HTTP client (e.g., requests.exceptions.RequestException
or httpx.RequestError) and update the logger.debug call to log the error as
before; locate the try/except around the Megakino mirrors fetch that references
mirrors_url and replace the broad Exception with the specific client exception
type(s) your codebase uses.
🧹 Nitpick comments (1)
app/utils/domain_resolver.py (1)

237-270: Consider concurrent mirror fetching for improved performance.

The function iterates through candidates sequentially, which can be slow if early candidates are unreachable or have high latency. For a better user experience at startup, consider using asyncio or concurrent.futures to check multiple candidates in parallel.

♻️ Example concurrent approach
from concurrent.futures import ThreadPoolExecutor, as_completed

def fetch_megakino_mirror_domains(timeout: float | int = 15) -> list[str]:
    """..."""
    logger.info("Fetching megakino mirror list.")
    
    def try_candidate(candidate):
        base_url = _build_base_url(candidate)
        if not base_url:
            return None
        mirrors_url = f"{base_url.rstrip('/')}{MEGAKINO_MIRRORS_PATH}"
        try:
            resp = http_get(
                mirrors_url,
                timeout=timeout,
                allow_redirects=True,
                headers={"User-Agent": USER_AGENT},
            )
            if resp.status_code >= 400:
                return None
            if _looks_like_html(resp.text or ""):
                return None
            domains = _parse_mirror_domains(resp.text or "")
            if domains:
                logger.info(
                    "Megakino mirrors loaded from {} ({} entries)",
                    mirrors_url,
                    len(domains),
                )
                return domains
        except Exception as exc:
            logger.debug("Megakino mirrors fetch failed for {}: {}", mirrors_url, exc)
        return None
    
    with ThreadPoolExecutor(max_workers=3) as executor:
        futures = {executor.submit(try_candidate, c): c for c in MEGAKINO_DOMAIN_CANDIDATES}
        for future in as_completed(futures):
            result = future.result()
            if result:
                return result
    
    return []

As per coding guidelines, use asyncio or multiprocessing for I/O-bound tasks to avoid bottlenecks.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9bff497 and 2103479.

📒 Files selected for processing (2)
  • app/utils/domain_resolver.py
  • tests/test_megakino_domain_resolver.py
🧰 Additional context used
📓 Path-based instructions (6)
**/*.py

📄 CodeRabbit inference engine (.github/instructions/Performance-Optimization-Best-Practices.instructions.md)

**/*.py: Use functools.lru_cache for memoization of expensive pure functions
Use asyncio or multiprocessing for I/O-bound and CPU-bound tasks respectively; avoid GIL bottlenecks in CPU-bound code

**/*.py: Write clear and concise comments for each function
Ensure functions have descriptive names and include type hints
Provide docstrings following PEP 257 conventions
Use the typing module for type annotations (e.g., List[str], Dict[str, int])
Break down complex functions into smaller, more manageable functions
Always prioritize readability and clarity
For algorithm-related code, include explanations of the approach used
Write code with good maintainability practices, including comments on why certain design decisions were made
Handle edge cases and write clear exception handling
For libraries or external dependencies, mention their usage and purpose in comments
Use consistent naming conventions and follow language-specific best practices
Write concise, efficient, and idiomatic code that is also easily understandable
Follow the PEP 8 style guide for Python
Maintain proper indentation (use 4 spaces for each level of indentation)
Ensure lines do not exceed 79 characters
Place function and class docstrings immediately after the def or class keyword
Use blank lines to separate functions, classes, and code blocks where appropriate
Account for common edge cases like empty inputs, invalid data types, and large datasets
Include comments for edge cases and the expected behavior in those cases

Files:

  • tests/test_megakino_domain_resolver.py
  • app/utils/domain_resolver.py
**/*.{js,jsx,ts,tsx,py,java,cs}

📄 CodeRabbit inference engine (.github/instructions/Performance-Optimization-Best-Practices.instructions.md)

Minimize logging in hot paths and prefer structured logging

Files:

  • tests/test_megakino_domain_resolver.py
  • app/utils/domain_resolver.py
**/*.{py,toml,txt,cfg}

📄 CodeRabbit inference engine (AGENTS.md)

Use Python 3.12 as the baseline runtime version for the AniBridge application

Files:

  • tests/test_megakino_domain_resolver.py
  • app/utils/domain_resolver.py
tests/test_*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/test_*.py: Use pytest for testing with fixtures defined in tests/conftest.py
Test API endpoints using FastAPI TestClient fixture from conftest.py

Files:

  • tests/test_megakino_domain_resolver.py
app/**

📄 CodeRabbit inference engine (.github/instructions/Next.js-Tailwind-Development-Instructions.instructions.md)

app/**: Use Next.js App Router with server and client components
Group routes by feature/domain within the app directory

Files:

  • app/utils/domain_resolver.py
app/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

app/**/*.py: Organize Python code into layered modules: API layer (app/api), Core services (app/core), Domain models (app/domain), Persistence layer (app/db), Infrastructure (app/infrastructure), and Utilities (app/utils)
Use Loguru for structured logging with duplication to daily rotating files via TerminalLogger
Document code with docstrings and maintain type hints throughout Python modules
Maintain type hints in all Python functions for IDE support and type checking
Use black code formatter for Python code style consistency
Use isort or standard library import ordering for Python import statements
Maintain modular boundaries between API layer, Core services, Domain models, Persistence, and Infrastructure
Keep logging structured with contextual fields for job IDs, provider names, and progress metrics
Store no secrets or credentials in code; use environment variables exclusively

Files:

  • app/utils/domain_resolver.py
🧠 Learnings (3)
📚 Learning: 2025-12-27T19:00:58.975Z
Learnt from: CR
Repo: Zzackllack/AniBridge PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-27T19:00:58.975Z
Learning: Applies to tests/test_title_resolver*.py : Test title resolution logic mapping for edge cases in test_title_resolver*.py

Applied to files:

  • tests/test_megakino_domain_resolver.py
📚 Learning: 2025-10-10T20:57:55.343Z
Learnt from: CR
Repo: Zzackllack/AniBridge PR: 0
File: .github/instructions/Python-Coding-Conventions.instructions.md:0-0
Timestamp: 2025-10-10T20:57:55.343Z
Learning: Applies to **/*.py : Provide docstrings following PEP 257 conventions

Applied to files:

  • app/utils/domain_resolver.py
📚 Learning: 2025-10-10T20:57:55.343Z
Learnt from: CR
Repo: Zzackllack/AniBridge PR: 0
File: .github/instructions/Python-Coding-Conventions.instructions.md:0-0
Timestamp: 2025-10-10T20:57:55.343Z
Learning: Applies to **/*.py : Handle edge cases and write clear exception handling

Applied to files:

  • app/utils/domain_resolver.py
🧬 Code graph analysis (1)
tests/test_megakino_domain_resolver.py (1)
app/utils/domain_resolver.py (3)
  • _is_sitemap_payload (75-98)
  • _parse_mirror_domains (194-221)
  • fetch_megakino_mirror_domains (224-270)
🪛 Ruff (0.14.10)
tests/test_megakino_domain_resolver.py

49-49: Unused function argument: timeout

(ARG001)


49-49: Unused function argument: allow_redirects

(ARG001)


49-49: Unused function argument: headers

(ARG001)

app/utils/domain_resolver.py

94-94: Do not catch blind exception: Exception

(BLE001)


164-164: Do not catch blind exception: Exception

(BLE001)


268-268: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Workers Builds: anibridge-docs
🔇 Additional comments (8)
app/utils/domain_resolver.py (6)

16-28: LGTM: Domain candidates and mirrors path properly configured.

The expanded domain candidate list and new mirrors path constant align well with the mirror-based discovery strategy described in the PR objectives.


101-106: LGTM: Regex pattern is well-documented.

The inline comment clearly explains the validation rules, making the pattern easier to understand and maintain.


109-126: LGTM: HTML detection logic is appropriate.

The function correctly identifies common HTML patterns and handles edge cases like empty strings.


169-191: LGTM: Domain validity check is comprehensive.

The function properly validates both sitemap availability and domain consistency, preventing incorrect redirects.


194-221: LGTM: Mirror domain parsing is robust.

The function handles various input formats well and filters out invalid entries (comments, HTML, malformed domains).


273-306: LGTM: Domain resolution flow is well-designed.

The function effectively combines mirror-based discovery with fallback candidates, uses deduplication to avoid redundant checks, and implements smart timeout management for the mirror fetch phase.

tests/test_megakino_domain_resolver.py (2)

8-36: LGTM: Test coverage for sitemap and mirror parsing is comprehensive.

The tests effectively cover positive cases (valid sitemap), negative cases (invalid XML, HTML), and edge cases (mixed mirror file content with comments and invalid entries).


46-64: LGTM: Mock-based test validates HTML skipping and mirror fetching.

The test effectively verifies that fetch_megakino_mirror_domains correctly:

  • Skips HTML responses
  • Parses valid mirror files
  • Makes expected HTTP calls

The unused function arguments in fake_get (line 49) flagged by static analysis are acceptable—mock functions often need to match the signature of the real function they're replacing, even if not all parameters are used in the test logic.

Zzackllack and others added 2 commits January 7, 2026 23:18
Updated exception handling in the domain resolver to specifically catch
RequestException instead of a generic Exception. This improves error
logging and makes the code more robust against network-related issues.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/utils/domain_resolver.py (1)

298-305: Consider narrowing or documenting the broad exception handler.

The _probe_megakino_sitemap function already handles RequestException internally and returns None on failure. This outer except Exception catch appears to be a safety net for unexpected errors, but it could mask programming bugs during development.

♻️ Suggestion

Since network errors are handled inside _probe_megakino_sitemap, this outer handler likely catches only unexpected errors. Consider either:

  1. Removing it if the inner handling is sufficient:
-        try:
-            final_domain = _probe_megakino_sitemap(base_url, timeout=timeout)
-            if final_domain:
-                logger.success("Megakino domain resolved: {}", final_domain)
-                return final_domain
-            logger.warning("Megakino candidate failed validation: {}", domain)
-        except Exception as exc:
-            logger.warning("Megakino candidate check failed for {}: {}", base_url, exc)
+        final_domain = _probe_megakino_sitemap(base_url, timeout=timeout)
+        if final_domain:
+            logger.success("Megakino domain resolved: {}", final_domain)
+            return final_domain
+        logger.warning("Megakino candidate failed validation: {}", domain)
  1. Or adding a comment explaining it's an intentional safety net for the candidate loop.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2103479 and 374691d.

📒 Files selected for processing (1)
  • app/utils/domain_resolver.py
🧰 Additional context used
📓 Path-based instructions (5)
app/**

📄 CodeRabbit inference engine (.github/instructions/Next.js-Tailwind-Development-Instructions.instructions.md)

app/**: Use Next.js App Router with server and client components
Group routes by feature/domain within the app directory

Files:

  • app/utils/domain_resolver.py
**/*.py

📄 CodeRabbit inference engine (.github/instructions/Performance-Optimization-Best-Practices.instructions.md)

**/*.py: Use functools.lru_cache for memoization of expensive pure functions
Use asyncio or multiprocessing for I/O-bound and CPU-bound tasks respectively; avoid GIL bottlenecks in CPU-bound code

**/*.py: Write clear and concise comments for each function
Ensure functions have descriptive names and include type hints
Provide docstrings following PEP 257 conventions
Use the typing module for type annotations (e.g., List[str], Dict[str, int])
Break down complex functions into smaller, more manageable functions
Always prioritize readability and clarity
For algorithm-related code, include explanations of the approach used
Write code with good maintainability practices, including comments on why certain design decisions were made
Handle edge cases and write clear exception handling
For libraries or external dependencies, mention their usage and purpose in comments
Use consistent naming conventions and follow language-specific best practices
Write concise, efficient, and idiomatic code that is also easily understandable
Follow the PEP 8 style guide for Python
Maintain proper indentation (use 4 spaces for each level of indentation)
Ensure lines do not exceed 79 characters
Place function and class docstrings immediately after the def or class keyword
Use blank lines to separate functions, classes, and code blocks where appropriate
Account for common edge cases like empty inputs, invalid data types, and large datasets
Include comments for edge cases and the expected behavior in those cases

Files:

  • app/utils/domain_resolver.py
**/*.{js,jsx,ts,tsx,py,java,cs}

📄 CodeRabbit inference engine (.github/instructions/Performance-Optimization-Best-Practices.instructions.md)

Minimize logging in hot paths and prefer structured logging

Files:

  • app/utils/domain_resolver.py
**/*.{py,toml,txt,cfg}

📄 CodeRabbit inference engine (AGENTS.md)

Use Python 3.12 as the baseline runtime version for the AniBridge application

Files:

  • app/utils/domain_resolver.py
app/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

app/**/*.py: Organize Python code into layered modules: API layer (app/api), Core services (app/core), Domain models (app/domain), Persistence layer (app/db), Infrastructure (app/infrastructure), and Utilities (app/utils)
Use Loguru for structured logging with duplication to daily rotating files via TerminalLogger
Document code with docstrings and maintain type hints throughout Python modules
Maintain type hints in all Python functions for IDE support and type checking
Use black code formatter for Python code style consistency
Use isort or standard library import ordering for Python import statements
Maintain modular boundaries between API layer, Core services, Domain models, Persistence, and Infrastructure
Keep logging structured with contextual fields for job IDs, provider names, and progress metrics
Store no secrets or credentials in code; use environment variables exclusively

Files:

  • app/utils/domain_resolver.py
🧠 Learnings (2)
📚 Learning: 2025-10-10T20:57:55.343Z
Learnt from: CR
Repo: Zzackllack/AniBridge PR: 0
File: .github/instructions/Python-Coding-Conventions.instructions.md:0-0
Timestamp: 2025-10-10T20:57:55.343Z
Learning: Applies to **/*.py : Provide docstrings following PEP 257 conventions

Applied to files:

  • app/utils/domain_resolver.py
📚 Learning: 2025-10-10T20:57:55.343Z
Learnt from: CR
Repo: Zzackllack/AniBridge PR: 0
File: .github/instructions/Python-Coding-Conventions.instructions.md:0-0
Timestamp: 2025-10-10T20:57:55.343Z
Learning: Applies to **/*.py : Handle edge cases and write clear exception handling

Applied to files:

  • app/utils/domain_resolver.py
🪛 Ruff (0.14.10)
app/utils/domain_resolver.py

95-95: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Workers Builds: anibridge-docs
🔇 Additional comments (10)
app/utils/domain_resolver.py (10)

17-29: LGTM!

The updated default domain and expanded candidate list are well-structured for the new mirror-based discovery approach. The MEGAKINO_MIRRORS_PATH constant provides good maintainability.


56-73: LGTM!

The updated docstring now accurately describes the normalization behavior and return conditions. Edge cases are properly handled.


102-127: LGTM!

The _HOST_RE regex is now well-documented with an inline comment explaining the DNS hostname validation rules. The _looks_like_html helper has appropriate docstring and logic for detecting HTML responses.


130-167: LGTM!

The sitemap probing logic is well-structured with proper docstring, specific RequestException handling, and appropriate validation of the response payload before returning the resolved domain.


170-192: LGTM!

The domain validity check properly detects cross-domain redirects and provides informative logging when mismatches occur.


195-222: LGTM!

The mirror domains parser correctly handles various input formats with consistent normalization. The suggestion to wrap bare hosts in a scheme before normalization has been addressed.


225-271: LGTM!

The mirror fetching logic is well-documented with proper RequestException handling and HTML response filtering. The sequential iteration is acceptable for a startup-time operation that returns early on the first valid result.


310-341: LGTM!

The configuration application logic is clean with appropriate separation of concerns between config updates and client reset. The updated docstring correctly reflects the removal of MEGAKINO_SITEMAP_URL.


344-385: LGTM!

The resolution and retrieval functions implement a sensible priority order with proper fallback to the default domain. The caching via module-level variables provides efficiency for repeated access.


388-428: LGTM!

The background domain monitoring thread is well-implemented with:

  • Daemon thread for clean application shutdown
  • Config-driven interval with ability to disable (interval=0)
  • Interruptible sleep using stop_event.wait()
  • Clear docstrings for both the outer function and inner loop

@Zzackllack Zzackllack merged commit f03083d into main Jan 7, 2026
7 checks passed
@Zzackllack Zzackllack deleted the megakino-better-domain-resolution branch January 7, 2026 22:32
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