StremioDotNet Documentation

This guide explains how to use the core features of the StremioDotNet library, including attributes, builders, predefined responses, and IMDb resolving middleware.


1. Attributes

Attributes in StremioDotNet simplify mapping methods to specific Stremio endpoints.

StreamHandler

Definition:

[StreamHandler(string type, bool resolveImdbId = false)]

Purpose:

Binds a method to handle stream requests in a Stremio service. It maps the method to an HTTP GET request with the URL pattern stream/{type}/{id}.json.

Parameters:

Example Usage:

[StreamHandler("movie", true, typeof(ConfigExample))]
public IActionResult MovieHandler(string id, ConfigExample? config)
{
    var metadata = HttpContext.Items[id];
    if (metadata == null) return Streams();

    Console.WriteLine($"Access API Key: {config?.APIKey}");

    return Streams(new StreamBuilder()
        .SetName("Example Movie")
        .SetUrl("http://example.com/movie.mp4")
        .Build());
}

[Config]
public class ConfigExample
{
    [ConfigPropertyName("apikey")]
    public string? APIKey { get; set; }
}

CatalogHandler

Definition:

[CatalogHandler]

Purpose:

Maps a method to handle catalog requests. This attribute is bound to GET catalog/{type}/{id}.json.

Example Usage:

[CatalogHandler]
public IActionResult CatalogHandler(string type, string id)
{
    return Catalog(new MetaBuilder("example", type, "Catalog Example").Build());
}

MetaHandler

Definition:

[MetaHandler]

Purpose:

Maps a method to handle metadata requests. This attribute is bound to GET meta/{type}/{id}.json.

Example Usage:

[MetaHandler]
public IActionResult MetaHandler(string type, string id)
{
    return Meta(new MetaBuilder("example", type, "Meta Example").Build());
}

2. Builders

Builders in StremioDotNet are designed for constructing complex objects for Stremio responses.

StreamBuilder

Purpose:

Constructs a Stream object for StreamHandler responses.

Methods:

Example:

var streamBuilder = new StreamBuilder()
    .SetName("Example Stream")
    .SetUrl("http://example.com/stream.mp4")
    .SetBehaviorHints(notWebReady: false, bingeGroup: null, null, null)
    .Build();

MetaBuilder

Purpose:

Constructs a Meta object for CatalogHandler and MetaHandler.

Methods:

Example:

var metaBuilder = new MetaBuilder("exampleId", "movie", "Example Movie")
    .SetDescription("A great movie.")
    .SetPoster("http://example.com/poster.png")
    .SetReleaseInfo("2024")
    .Build();

3. Predefined Responses

Streams

Returns a collection of streams for a content item.

return Streams(new StreamBuilder().SetName("Stream 1").SetUrl("http://example.com").Build());

Catalog

Returns a catalog of metadata items.

return Catalog(new MetaBuilder("catalogId", "movie", "Catalog Example").Build());

Meta

Returns metadata for a specific content item.

return Meta(new MetaBuilder("metaId", "movie", "Meta Example").Build());

4. IMDb Resolving Middleware

Automatically resolves IMDb IDs for requests.

Purpose:

Extracts IMDb IDs from request paths and resolves them into metadata, making it available in HttpContext.Items.

Setup:

builder.Services.AddStremio();

Example:

var metadata = HttpContext.Items["imdb_id"];

Summary

With StremioDotNet, creating Stremio addons is streamlined using:


Revision #3
Created 26 December 2024 00:13:02 by Nathan
Updated 4 January 2025 09:05:37 by Nathan