{"id":13466366,"url":"https://github.com/Stremio/stremio-php-addon-example","last_synced_at":"2025-03-25T21:32:10.495Z","repository":{"id":86484274,"uuid":"149131697","full_name":"Stremio/stremio-php-addon-example","owner":"Stremio","description":"PHP Add-on Example for Stremio","archived":false,"fork":false,"pushed_at":"2019-02-18T19:00:49.000Z","size":15,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T19:18:28.580Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stremio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-17T13:44:32.000Z","updated_at":"2024-07-13T08:48:08.000Z","dependencies_parsed_at":"2023-03-02T18:00:30.728Z","dependency_job_id":null,"html_url":"https://github.com/Stremio/stremio-php-addon-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stremio%2Fstremio-php-addon-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stremio%2Fstremio-php-addon-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stremio%2Fstremio-php-addon-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stremio%2Fstremio-php-addon-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stremio","download_url":"https://codeload.github.com/Stremio/stremio-php-addon-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245548232,"owners_count":20633544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:00:43.037Z","updated_at":"2025-03-25T21:32:10.231Z","avatar_url":"https://github.com/Stremio.png","language":"PHP","funding_links":[],"categories":["Addon Developer Resources"],"sub_categories":["Catalogs"],"readme":"# Stremio PHP Add-on Example\n\nThis example add-on uses files from [Stremio Static Add-on Example](https://github.com/Stremio/stremio-static-addon-example)\n\n**Important: Remote Stremio Add-ons only work through HTTPS**\n\n\nWhat this example covers:\n\n- Configuring Apache Web Server's `.htaccess` to route the HTTP(s) requests that are expected from Stremio Add-ons to our PHP files\n- Declaring the Add-on Manifest with PHP's `stdClass` and converting it to a JSON string in order to reply with it when requested\n- Reading from static JSON files and replying with their contents on request\n- Setting correct Headers for responses (`CORS`, `Content-Type`)\n- Getting request parameters from requests\n\n\nWhat this example does not cover:\n\n- Getting information from a DB in order to reply to requests\n- Searching for items in catalogs\n- Responding to subtitle requests\n\n\n## Configuring Apache Web Server's `.htaccess`\n\n**.htaccess** file contents:\n\n```\nRewriteEngine On\nRewriteBase /\n\nRewriteRule ^manifest.json manifest.php\n\nRewriteRule ^catalog/(.*)/(.*)/(.*).json catalogs.php?type=$1\u0026id=$2\u0026extra=$3 [B]\nRewriteRule ^meta/(.*)/(.*)/(.*).json meta.php?type=$1\u0026id=$2\u0026extra=$3 [B]\nRewriteRule ^stream/(.*)/(.*)/(.*).json streams.php?type=$1\u0026id=$2\u0026extra=$3 [B]\n\nRewriteRule ^catalog/(.*)/(.*).json catalogs.php?type=$1\u0026id=$2\nRewriteRule ^meta/(.*)/(.*).json meta.php?type=$1\u0026id=$2\nRewriteRule ^stream/(.*)/(.*).json streams.php?type=$1\u0026id=$2\n```\n\nThis will route all required requests for `catalog`, `meta` and `stream` to the PHP files that will handle the requests.\n\nNote:\n\n- you can also add `subtitle` requests in the same pattern as the others, this is not part of `.htaccess` as this resource is not handled in this example\n- if you want to add this example in a sub-folder on your server, it will need to be specified in the `RewriteBase`, for example, if this add-on is uploaded to `/stremio-php-addon-example/` on your server, then set `RewriteBase /stremio-php-addon-example/` instead of `RewriteBase /` in your `.htaccess` file\n\n\n## Declaring the Add-on Manifest\n\n**manifest.php** file contents:\n\n```php\n\u003c?php\ninclude 'helpers.php';\n\n// enable CORS and set JSON Content-Type\n\nsetHeaders();\n\n// declare manifest\n\n$manifest = new stdClass();\n$manifest-\u003eid = \"com.stremio.phpexample\";\n$manifest-\u003eversion = \"1.0.0\";\n$manifest-\u003ename = \"PHP Add-on Example\";\n$manifest-\u003edescription = \"Example Add-on made with PHP that server the Big Buck Bunny video.\";\n$manifest-\u003eresources = array(\"catalog\", \"meta\", \"stream\");\n$manifest-\u003etypes = array(\"movie\");\n\n\n// define catalog\n\n$catalog = new stdClass();\n$catalog-\u003etype = \"movie\";\n$catalog-\u003eid = \"BigBuckBunnyCatalog\";\n$catalog-\u003ename = \"Big Buck Bunny Catalog\";\n\n\n// set catalogs in manifest\n\n$manifest-\u003ecatalogs = array($catalog);\n\n\n// print manifest in JSON format\n\necho json_encode((array)$manifest);\n?\u003e\n```\n\nThis will create an `stdClass` (PHP Object Class) with the required `manifest.json` parameters and respond with a JSON string based on the PHP object.\n\nFor the complete list of parameters that can be set in `manifest.json`, please see [this page](https://github.com/Stremio/stremio-addon-sdk/tree/master/docs/api/responses/manifest.md).\n\n\n## Reading from static JSON files\n\n**catalogs.php** file contents:\n\n```php\n\u003c?php\ninclude 'helpers.php';\n\n// get request parameters\n$catalog = getRequestParams();\n\n// returns $catalog-\u003etype , $catalog-\u003eid and (if applicabale) $catalog-\u003eextra\n\n// we will not go into the details of using a database, instead we will serve JSON files located at: \n// \"./catalog/\" . $catalog-\u003etype . \"/\" . $catalog-\u003eid . \".json\"\n// ex: \"./catalog/movie/BigBuckBunnyCatalog.json\"\n\n$jsonPath = dirname(__FILE__) . '/catalog/' . $catalog-\u003etype . '/' . $catalog-\u003eid . '.json';\n\nif (realpath($jsonPath)) {\n\n\t// file exists\n\n\t// enable CORS and set JSON Content-Type\n\tsetHeaders();\n\n\t// respond with json file from file system\n\techo file_get_contents($jsonPath);\n\n} else {\n\n\t// respond with 404 page\n\tpage404();\n\n}\n?\u003e\n```\n\n`meta.php`, `catalogs.php` and `streams.php` all work with this same pattern, they simply read from a JSON file on disk and reply with it's contents in case it exists, otherwise it shows a 404 page.\n\nThis add-on example does not go in the details of using a database, although, based on `$catalog-\u003etype` and `$catalog-\u003eid` a database query could be easily added to this example.\n\nThis add-on also does not show an example of handling search requests, which would normally be implemented in `catalogs.php` by checking for the existence of a search query in `$catalog-\u003eextra-\u003esearch`. Searching would also require a change in the manifest, more specifically setting `$catalog-\u003eextraSupported = array('search')` to the catalog definition.\n\nAll requests expect a response in the JSON string format.\n\n\n## Testing the add-on\n\nSimply upload this example to an Apache Web Server with PHP support. If you add this example to a sub-folder instead of the main web server folder, make sure to make the required `.htaccess` changes as mentioned above.\n\nThen open Stremio, go to the add-ons page (puzzle icon button in the top right), and write your `manifest.json` URL in the top left side input field (where it writes \"Add-On Repository Url\").\n\nYour `manifest.json` URL should be relative to the directory where you uploaded the example on your web server, for example it would be `https://www.mydomain.com/manifest.json` if you uploaded to your primary folder, or `https://www.mydomain.com/stremio-php-addon-example/manifest.json` if you uploaded to the `/stremio-php-addon-example/` folder.\n\n\n### Don't know where to add the Add-on Repository URL?\n\n![add-on-repository-url](https://user-images.githubusercontent.com/1777923/43146711-65a33ccc-8f6a-11e8-978e-4c69640e63e3.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStremio%2Fstremio-php-addon-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStremio%2Fstremio-php-addon-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStremio%2Fstremio-php-addon-example/lists"}