intro-skipper/README.md

177 lines
11 KiB
Markdown
Raw Normal View History

2019-02-21 00:36:01 -08:00
# So you want to make a Jellyfin plugin
2020-01-21 13:03:21 +09:00
2020-12-09 16:29:14 -07:00
Awesome! This guide is for you. Jellyfin plugins are written using the dotnet standard framework. What that means is you can write them in any language that implements the CLI or the DLI and can compile to net5.0. The examples on this page are in C# because that is what most of Jellyfin is written in, but F#, Visual Basic, and IronPython should all be compatible once compiled.
2019-02-21 00:36:01 -08:00
## 0. Things you need to get started
2020-01-21 13:03:21 +09:00
- [Dotnet SDK 5.0](https://dotnet.microsoft.com/download)
2019-02-21 00:36:01 -08:00
- An editor of your choice. Some free choices are:
2021-01-10 20:23:01 +09:00
[Visual Studio Code](https://code.visualstudio.com)
2020-03-09 21:17:32 +01:00
2021-01-10 20:23:01 +09:00
[Visual Studio Community Edition](https://visualstudio.microsoft.com/downloads)
2019-02-21 00:36:01 -08:00
2021-01-10 20:23:01 +09:00
[Mono Develop](https://www.monodevelop.com)
2019-02-21 00:36:01 -08:00
## 0.5. Quickstarts
2020-01-21 13:03:21 +09:00
We have a number of quickstart options available to speed you along the way.
2019-02-21 00:36:01 -08:00
2019-08-17 15:52:46 +05:30
- [Download the Example Plugin Project](https://github.com/jellyfin/jellyfin-plugin-template/tree/master/Jellyfin.Plugin.Template) from this repository, open it in your IDE and go to [step 3](https://github.com/jellyfin/jellyfin-plugin-template#3-customize-plugin-information)
2020-01-21 13:03:21 +09:00
- Install our dotnet template by [downloading the dotnet-template/content folder from this repo](https://github.com/jellyfin/jellyfin-plugin-template/tree/master/dotnet-template/content) or off of Nuget (Coming soon)
2020-01-21 13:03:21 +09:00
2019-03-03 01:51:09 -08:00
```
dotnet new -i /path/to/templatefolder
```
2020-01-21 13:03:21 +09:00
- Run this command then skip to step 4
2020-03-09 21:17:32 +01:00
2019-03-03 01:51:09 -08:00
```
2019-02-21 00:36:01 -08:00
dotnet new Jellyfin-plugin -name MyPlugin
2019-03-03 01:51:09 -08:00
```
2019-02-21 00:36:01 -08:00
2021-01-10 20:23:01 +09:00
If you'd rather start from scratch keep going on to step one. This assumes no specific editor or IDE and requires only the command line with dotnet in the path.
2019-02-21 00:36:01 -08:00
2021-01-10 20:23:01 +09:00
## 1. Initialize Your Project
2020-01-21 13:03:21 +09:00
2021-01-10 20:23:01 +09:00
Make a new dotnet standard project with the following command, it will make a directory for itself.
2019-02-21 00:36:01 -08:00
2020-01-21 13:03:21 +09:00
```
2021-01-10 20:23:01 +09:00
dotnet new classlib -f net5.0 -n MyJellyfinPlugin
2020-01-21 13:03:21 +09:00
```
2019-02-21 00:36:01 -08:00
2020-01-21 13:03:21 +09:00
Now add the Jellyfin shared libraries.
2020-03-09 21:17:32 +01:00
2019-02-21 00:36:01 -08:00
```
dotnet add package Jellyfin.Model
dotnet add package Jellyfin.Controller
```
2020-01-21 13:03:21 +09:00
2021-01-10 20:23:01 +09:00
You have an autogenerated Class1.cs file. You won't be needing this, so go ahead and delete it.
2019-02-21 00:36:01 -08:00
2021-01-10 20:23:01 +09:00
## 2. Set Up the Basics
2019-02-21 00:36:01 -08:00
There are a few mandatory classes you'll need for a plugin so we need to make them.
2020-01-21 13:03:21 +09:00
2021-01-10 20:23:01 +09:00
### PluginConfiguration
2020-01-21 13:03:21 +09:00
2020-12-09 16:29:14 -07:00
You can call it whatever you'd like really. This class is used to hold settings your plugin might need. We can leave it empty for now. This class should inherit from `MediaBrowser.Model.Plugins.BasePluginConfiguration`
2020-03-09 21:17:32 +01:00
2021-01-10 20:23:01 +09:00
### Plugin
2020-01-21 13:03:21 +09:00
2021-01-10 20:30:04 +09:00
This is the main class for your plugin. It will define your name, version and Id. It should inherit from `MediaBrowser.Common.Plugins.BasePlugin<PluginConfiguration>`
2020-03-09 21:17:32 +01:00
2019-02-21 00:36:01 -08:00
Note: If you called your PluginConfiguration class something different, you need to put that between the <>
2020-03-09 21:17:32 +01:00
2019-02-21 00:36:01 -08:00
### Implement Required Properties
2020-01-21 13:03:21 +09:00
2020-03-09 21:17:32 +01:00
The Plugin class needs a few properties implemented before it can work correctly.
2019-02-21 00:36:01 -08:00
2021-01-10 20:23:01 +09:00
It needs an override on ID, an override on Name, and a constructor that follows a specific model. To get started you can use the following section.
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
```c#
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer){}
public override string Name => throw new System.NotImplementedException();
public override Guid Id => Guid.Parse("");
```
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
## 3. Customize Plugin Information
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
You need to populate some of your plugin's information. Go ahead a put in a string of the Name you've overridden name, and generate a GUID
2021-01-10 20:23:01 +09:00
2020-07-17 14:49:55 -04:00
- **Windows Users**: you can use the Powershell command `New-Guid`, `[guid]::NewGuid()` or the Visual Studio GUID generator
2021-01-10 20:23:01 +09:00
2020-07-17 14:49:55 -04:00
- **Linux and OS X Users**: you can use the Powershell Core command `New-Guid` or this command from your shell of choice:
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
```bash
od -x /dev/urandom | head -1 | awk '{OFS="-"; srand($6); sub(/./,"4",$5); sub(/./,substr("89ab",rand()*4,1),$6); print $2$3,$4,$5,$6,$7$8$9}'
```
2020-07-17 14:49:55 -04:00
or
```bash
uuidgen
```
2019-02-21 00:36:01 -08:00
- Place that guid inside the `Guid.Parse("")` quotes to define your plugin's ID.
2020-03-09 21:17:32 +01:00
## 4. Adding Functionality
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
Congratulations, you now have everything you need for a perfectly functional functionless Jellyfin plugin! You can try it out right now if you'd like by compiling it, then placing the dll you generate in the plugins folder under your Jellyfin config directory. If you want to try and hook it up to a debugger make sure you copy the generated PDB file alongside it.
Most people aren't satisfied with just having an entry in a menu for their plugin, most people want to have some functionality, so lets look at how to add it.
2021-01-10 20:23:01 +09:00
### 4a. Implement Interfaces
2020-01-21 13:03:21 +09:00
2020-03-09 21:17:32 +01:00
If the functionality you are trying to add is functionality related to something that Jellyfin has an interface for you're in luck. Jellyfin uses some automatic discovery and injection to allow any interfaces you implement in your plugin to be available in Jellyfin.
2019-02-21 00:36:01 -08:00
Here's some interfaces you could implement for common use cases:
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
- **IAuthenticationProvider** - Allows you to add an authentication provider that can authenticate a user based on a name and a password, but that doesn't expect to deal with local users.
- **IBaseItemComparer** - Allows you to add sorting rules for dealing with media that will show up in sort menus
- **IIntroProvider** - Allows you to play a piece of media before another piece of media (i.e. a trailer before a movie, or a network bumper before an episode of a show)
- **IItemResolver** - Allows you to define custom media types
- **ILibraryPostScanTask** - Allows you to define a task that fires after scanning a library
- **IMetadataSaver** - Allows you to define a metadata standard that Jellyfin can use to write metadata
- **IResolverIgnoreRule** - Allows you to define subpaths that are ignored by media resolvers for use with another function (i.e. you wanted to have a theme song for each tv series stored in a subfolder that could be accessed by your plugin for playback in a menu).
- **IScheduledTask** - Allows you to create a scheduled task that will appear in the scheduled task lists on the dashboard.
2020-01-21 13:03:21 +09:00
2020-01-21 12:40:24 +09:00
There are loads of other interfaces that can be used, but you'll need to poke around the API to get some info. If you're an expert on a particular interface, you should help [contribute some documentation](https://docs.jellyfin.org/general/contributing/index.html)!
2019-02-21 00:36:01 -08:00
### 4b. Use plugin aimed interfaces to add custom functionality
If your plugin doesn't fit perfectly neatly into a predefined interface, never fear, there are a set of interfaces and classes that allow your plugin to extend Jellyfin any which way you please. Here's a quick overview on how to use them
2020-01-21 13:03:21 +09:00
2019-02-21 00:36:01 -08:00
- **IPluginConfigurationPage** - Allows you to have a plugin config page on the dashboard. If you used one of the quickstart example projects, a premade page with some useful components to work with has been created for you! If not you can check out this guide here for how to whip one up.
2019-02-21 00:36:01 -08:00
- **IServerEntryPoint** - Allows you to run code at server startup that will stay in memory. You can make as many of these as you need and it is wildly useful for loading configs or persisting state.
2020-01-21 13:03:21 +09:00
- **BaseController** - Allows you to define custom REST-API endpoints. This is the default ASP.NET Web-API controller. You can use it exactly as you would in a normal Web-API project. Learn more about it [here](https://docs.microsoft.com/aspnet/core/web-api/?view=aspnetcore-5.0).
2019-02-21 00:36:01 -08:00
Likewise you might need to get data and services from the Jellyfin core, Jellyfin provides a number of interfaces you can add as parameters to your plugin constructor which are then made available in your project (you can see the 2 mandatory ones that are needed by the plugin system in the constructor as is).
- **IBlurayExaminer** - Allows you to examine blu-ray folders
2020-01-21 13:03:21 +09:00
- **IDtoService** - Allows you to create data transport objects, presumably to send to other plugins or to the core
2019-02-21 00:36:01 -08:00
- **ILibraryManager** - Allows you to directly access the media libraries without hopping through the API
- **ILocalizationManager** - Allows you tap into the main localization engine which governs translations, rating systems, units etc...
- **INetworkManager** - Allows you to get information about the server's networking status
- **IServerApplicationPaths** - Allows you to get the running server's paths
- **IServerConfigurationManager** - Allows you to write or read server configuration data into the application paths
- **ITaskManager** - Allows you to execute and manipulate scheduled tasks
- **IUserManager** - Allows you to retrieve user info and user library related info
2020-01-21 13:03:21 +09:00
- **IXmlSerializer** - Allows you to use the main xml serializer
2019-02-21 00:36:01 -08:00
- **IZipClient** - Allows you to use the core zip client for compressing and decompressing data
2021-01-10 20:23:01 +09:00
## 5. Create a Repository
2020-01-21 13:03:21 +09:00
2020-12-09 16:29:14 -07:00
- [See blog post](https://jellyfin.org/posts/plugin-updates/)
2020-06-16 12:31:21 -04:00
## 6. Set Up Debugging
Debugging can be set up by creating tasks which will be executed when running the plugin project. The specifics on setting up these tasks are not included as they may differ from IDE to IDE. The following list describes the general process:
- Compile the plugin in debug mode.
- Create the plugin directory if it doesn't exist.
- Copy the plugin into your server's plugin directory. The server will then execute it.
- Make sure to set the working directory of the program being debugged to the working directory of the Jellyfin Server.
- Start the server.
Some IDEs like Visual Studio Code may need the following compile flags to compile the plugin:
```shell
dotnet build Your-Plugin.sln /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary
```
These flags generate the full paths for file names and **do not** generate a summary during the build process as this may lead to duplicate errors in the problem panel of your IDE.
2021-01-10 20:23:01 +09:00
## Licensing
2020-06-16 12:31:21 -04:00
Licensing is a complex topic. This repository features a GPLv3 license template that can be used to provide a good default license for your plugin. You may alter this if you like, but if you do a permissive license must be chosen.
Due to how plugins in Jellyfin work, when your plugin is compiled into a binary, it will link against the various Jellyfin binary NuGet packages. These packages are licensed under the GPLv3. Thus, due to the nature and restrictions of the GPL, the binary plugin you get will also be licensed under the GPLv3.
If you accept the default GPLv3 license from this template, all will be good. However if you choose a different license, please keep this fact in mind, as it might not always be obvious that an, e.g. MIT-licensed plugin would become GPLv3 when compiled.
Please note that this also means making "proprietary", source-unavailable, or otherwise "hidden" plugins for public consumption is not permitted. To build a Jellyfin plugin for distribution to others, it must be under the GPLv3 or a permissive open-source license that can be linked against the GPLv3.