#!/usr/bin/env python3
"""
tv_grab_gracenote2epg - XMLTV grabber wrapper script for source distribution

This script allows running gracenote2epg directly from the source distribution
without installation. It follows XMLTV naming conventions for grabber scripts.

Usage:
  # From source directory (no installation needed)
  ./tv_grab_gracenote2epg --capabilities

  # After pip install, both commands work:
  gracenote2epg --version
  tv_grab_gracenote2epg --version
"""

import sys
from pathlib import Path

# Add the package directory to sys.path if running from source
script_dir = Path(__file__).parent
package_dir = script_dir / "gracenote2epg"

if package_dir.exists():
    # Running from source distribution
    sys.path.insert(0, str(script_dir))
    from gracenote2epg.__main__ import main
else:
    # Try installed package
    try:
        from gracenote2epg.__main__ import main
    except ImportError:
        print("Error: gracenote2epg package not found.", file=sys.stderr)
        print(
            "Please install gracenote2epg or run from the source directory.",
            file=sys.stderr,
        )
        sys.exit(1)

if __name__ == "__main__":
    sys.exit(main())
