Skip to content

Main

configure_page(request)

Configuration page with NiceGUI interface.

Source code in src/stremio_addon_python_template/main.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@ui.page("/configure")
def configure_page(request: Request):
    """Configuration page with NiceGUI interface."""
    logger.info("Configure page accessed.")

    # Get the current host from the request to generate the correct manifest URL
    base_url = str(request.url).replace("/configure", "")
    manifest_url = f"{base_url}/manifest.json"

    with ui.card().classes("w-full max-w-md mx-auto mt-10 p-6"):
        ui.label("Stremio Addon Configuration").classes("text-2xl font-bold mb-4")
        ui.label("Configure your addon settings below:").classes("text-gray-600 mb-4")

        api_key_input = ui.input(
            label="API Key",
            placeholder="Enter your API key here",
            password=True,
            password_toggle_button=True,
        ).classes("w-full mb-4")

        addon_name_input = ui.input(
            label="Addon Name", placeholder="My Custom Addon", value="Python UV Template"
        ).classes("w-full mb-4")

        def save_config():
            logger.info(f"Configuration saved: Addon Name={addon_name_input.value}")
            ui.notify("Configuration saved successfully!", type="positive")

        with ui.row().classes("w-full gap-2"):
            ui.button("Save Configuration", on_click=save_config).props("color=primary")
            ui.link("View Manifest", "/manifest.json", new_tab=True).classes(
                "q-btn q-btn-item non-selectable no-outline q-btn--flat q-btn--rectangle bg-secondary text-white q-btn--actionable q-focusable q-hoverable"
            )

        ui.separator().classes("my-4")

        ui.label("Installation").classes("text-lg font-semibold mb-2")
        ui.label("Copy this URL and add it to Stremio:").classes("text-sm text-gray-600 mb-2")
        ui.code(manifest_url).classes("w-full")

get_catalog(type, id) async

Returns catalog items displayed on the Stremio Board.

Source code in src/stremio_addon_python_template/main.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
@app.get("/catalog/{type}/{id}.json")
async def get_catalog(type: str, id: str):
    """Returns catalog items displayed on the Stremio Board."""
    logger.debug(f"Catalog request: Type={type}, ID={id}")
    if type == "movie" and id == "python_movies":
        return {
            "metas": [
                {
                    "id": "tt0096895",  # Batman (1989)
                    "type": "movie",
                    "name": "Batman",
                    "poster": "https://m.media-amazon.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg",
                    "description": "The Dark Knight of Gotham City begins his war on crime.",
                },
                {
                    "id": "tt1254207",  # Big Buck Bunny
                    "type": "movie",
                    "name": "Big Buck Bunny",
                    "poster": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Big_buck_bunny_poster_big.jpg/800px-Big_buck_bunny_poster_big.jpg",
                },
            ]
        }
    return {"metas": []}

get_manifest() async

Returns the addon capabilities.

Source code in src/stremio_addon_python_template/main.py
85
86
87
88
89
@app.get("/manifest.json")
async def get_manifest():
    """Returns the addon capabilities."""
    logger.info("Manifest requested.")
    return MANIFEST

get_stream(type, id) async

Returns stream links for a specific video.

Source code in src/stremio_addon_python_template/main.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@app.get("/stream/{type}/{id}.json")
async def get_stream(type: str, id: str):
    """Returns stream links for a specific video."""
    logger.info(f"Stream request: Type={type}, ID={id}")

    streams = []

    if id == "tt1254207":  # Big Buck Bunny
        streams.append(
            {
                "title": "4K [Python Stream]",
                "url": "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
            }
        )

    elif id == "tt0096895":  # Batman
        streams.append(
            {
                "title": "1080p [Sample File]",
                "infoHash": "c352d6801679cb6561060988a89458f6728b4377",  # Example InfoHash (Magnet)
                "behaviorHints": {"bingeGroup": "batman-movies"},
            }
        )

    logger.debug(f"Returning {len(streams)} streams.")
    return {"streams": streams}

root() async

Root endpoint: Redirects to the configuration page.

Source code in src/stremio_addon_python_template/main.py
36
37
38
39
40
@app.get("/", include_in_schema=False)
async def root():
    """Root endpoint: Redirects to the configuration page."""
    logger.info("Redirecting to configure page.")
    return RedirectResponse(url="/configure")