Jump to content

Tutorial/exemple on plugins/channel creation


AMenard
Go to solution Solved by Luke,

Recommended Posts

TallBoiDez
3 hours ago, chef said:

Yes to the first question.

Place you thumb image as an embedded resource in your solution ,then you can use reflection to grab the resource  stream in the methods created by implementing the interface.

Let me know if I should go more indepth on that.

 

For the second question... no I don't think so.

IHasWebpage usually points to html and js pages for your plugin configuration in the dashboard.

When I used an SQLite database in the past, I had to write my own implementation to use it. (In actual fact I used an implementation found inside the auto organizer plugin on GitHub).

Emby uses SQLite, so the libraries to access these types of data tables are available with emby.

 

"<PackageReference Include="SQLitePCL.pretty.core" Version="1.2.2" />" is this what I need to reference my database 

Link to comment
Share on other sites

5 hours ago, TallBoiDez said:

I want certain Library to be able to access my database would I put that code in the configuration.cs or the plugin.cs?

I think what you want to look at is the IChannel interface.

This creates libraries (of a sort).

Then you could read you db items into a channel.

On 9/11/2022 at 11:18 PM, TallBoiDez said:

"<PackageReference Include="SQLitePCL.pretty.core" Version="1.2.2" />" is this what I need to reference my database 

That looks right. 

Link to comment
Share on other sites

TallBoiDez
4 minutes ago, bakes82 said:

I thought he was making a meta provider not a channel. But his requirements don’t seem clear on the one post.

Basically I want specific libraries to be able to access and retrieve actor Metadata (image, overview, birthday, and place of birth) from my database. I'm completely new to c# and emby plug-in development so I'm sorry any confusion I may have caused. 

Link to comment
Share on other sites

You want to build a metadata agent.  Idk if chef has built one. I haven’t. But you don’t need to be making channels for it 😛  it’s still a plug-in but the wiring Is different 

Link to comment
Share on other sites

TallBoiDez
32 minutes ago, bakes82 said:

You want to build a metadata agent.  Idk if chef has built one. I haven’t. But you don’t need to be making channels for it 😛  it’s still a plug-in but the wiring Is different 

Yeah, I've been looking at other similar plugin to get an idea of what I need to do. 

Link to comment
Share on other sites

a good place to have a look at are some of the plugins in the MediaBrowser GitRepo

The Nfo one might be something you can use to model your plugin:

https://github.com/MediaBrowser/NfoMetadata

there is also the anime one:

https://github.com/MediaBrowser/Emby.Plugins.Anime/tree/master/MediaBrowser.Plugins.Anime

I think the main service logic is in the ILocalMetadataProvider interface:

https://github.com/MediaBrowser/NfoMetadata/blob/master/NfoMetadata/Providers/BaseNfoProvider.cs

 

Edited by TeamB
  • Agree 1
Link to comment
Share on other sites

5 minutes ago, TeamB said:

a good place to have a look at are some of the plugins in the MediaBrowser GitRepo

The Nfo one might be something you can use to model your plugin:

https://github.com/MediaBrowser/Emby.Plugins.Anime/tree/master/MediaBrowser.Plugins.Anime

I think the main service logic is in the ILocalMetadataProvider interface

https://github.com/MediaBrowser/NfoMetadata/blob/master/NfoMetadata/Providers/BaseNfoProvider.cs

 

Agreed.

Link to comment
Share on other sites

If you are going to make some kind of metadata provider then TeamB is right, those links are good resources.

 

 

Link to comment
Share on other sites

7 minutes ago, TallBoiDez said:

@bakes82 i was able to get it. can someone take a look at my code

I might have time tomorrow for a code review. 

Unless someone gets to it before me.

You can either post it on GitHub... Or you can zip up the solution and post it here.

 

Link to comment
Share on other sites

25 minutes ago, TallBoiDez said:

Can anyone tell or show me how i would implement an SQL Database

I can show you how to implement a database with SQLite.

https://github.com/chefbennyj1/Emby.AutoOrganize/blob/chef_changes_2/Emby.AutoOrganize/Data/SqliteFileOrganizationRepository.cs

 

 

 

Edited by chef
Link to comment
Share on other sites

First I would copy this class into your solution

https://github.com/chefbennyj1/Emby.AutoOrganize/blob/chef_changes_2/Emby.AutoOrganize/Data/BaseSqliteRepository.cs

 

That is the Base class for the SQLite repository.

 

Next step would be to create a class that is the Repository (controller of sorts).

This Repository class will handle your connection strings, database creation, all your gets, and saves.

I'm not sure I'm the guy that it going to explain ( well enough) serializing and deserializing classes to and from a data table.

Perhaps, read through the Auto organizer plugin, and see what you find.

I can try to answer questions.

 

 

Edited by chef
Link to comment
Share on other sites

TallBoiDez
6 hours ago, chef said:

First I would copy this class into your solution

https://github.com/chefbennyj1/Emby.AutoOrganize/blob/chef_changes_2/Emby.AutoOrganize/Data/BaseSqliteRepository.cs

 

That is the Base class for the SQLite repository.

 

Next step would be to create a class that is the Repository (controller of sorts).

This Repository class will handle your connection strings, database creation, all your gets, and saves.

I'm not sure I'm the guy that it going to explain ( well enough) serializing and deserializing classes to and from a data table.

Perhaps, read through the Auto organizer plugin, and see what you find.

I can try to answer questions.

 

 

So, I would create a new class and copy and paste that into the new class

Link to comment
Share on other sites

1 hour ago, TallBoiDez said:

So, I would create a new class and copy and paste that into the new class

That BaseRespository class has some methods that will help build out your database. 

Have you put you code on GitHub yet?

That would be helpful because otherwise its like the blind leading the blind. 😆

You'll have to build out the class that mirrors your data table as well.

All the columns are properties in you class.

This way we can serialize the data base into your plugin.

 

Whatever you do, don't give up. Once you figure it out,  it's going to all make sense. 

The project is a bit advanced for when you are just learning c# (I think you said you are just learning). But, you can definitely do this! 

👍

Edited by chef
Link to comment
Share on other sites

TallBoiDez
1 hour ago, chef said:

That BaseRespository class has some methods that will help build out your database. 

Have you put you code on GitHub yet?

That would be helpful because otherwise its like the blind leading the blind. 😆

You'll have to build out the class that mirrors your data table as well.

All the columns are properties in you class.

This way we can serialize the data base into your plugin.

 

Whatever you do, don't give up. Once you figure it out,  it's going to all make sense. 

The project is a bit advanced for when you are just learning c# (I think you said you are just learning). But, you can definitely do this! 

👍

Haven't yet and I just start learning c# currently at work, but I'll put it up on git hub when I get home and thanks for the encouragement. 

Link to comment
Share on other sites

TallBoiDez
4 hours ago, chef said:

That BaseRespository class has some methods that will help build out your database. 

Have you put you code on GitHub yet?

That would be helpful because otherwise its like the blind leading the blind. 😆

You'll have to build out the class that mirrors your data table as well.

All the columns are properties in you class.

This way we can serialize the data base into your plugin.

 

Whatever you do, don't give up. Once you figure it out,  it's going to all make sense. 

The project is a bit advanced for when you are just learning c# (I think you said you are just learning). But, you can definitely do this! 

👍

So, the columns in my database, so based on what I just read about properties and from your telling me an example of one property for my plugin would be:

 public class Actor

 {

      public string name

      {get; set;}

}

Where "Actor" would be a column in my database and the public string "name" would read the name of the actor and write it as per the {get; set;} perimeter. Am I correct?

Link to comment
Share on other sites

4 minutes ago, TallBoiDez said:

So, the columns in my database, so based on what I just read about properties and from your telling me an example of one property for my plugin would be:

 public class Actor

 {

      public string name

      {get; set;}

}

Where "Actor" would be a column in my database and the public string "name" would read the name of the actor and write it as per the {get; set;} perimeter. Am I correct?

Not quite.

The top level class would be called something like "PluginRespositoryResult" since we are going to serialize the repo into this class.

 

public class PluginRepositoryResult

{

       public List<Actor> actors { get; set; }

}

 

public class Actor

{

       public string Name { get; set; }

}

 

 

However, there are some issues with this that you need to be aware of because a data table is one dimensional. 😬

 

Note: Right off the top, it might be best to use the same naming as emby. Instead of "Actor",  use "Person". But... That's not the big issue you are about run into here...

 

Because the database is one dimensional, serializing "Actor" into the table with a bunch of properties is going to be difficult.

 

I'm going to try and not sound over top here and try to explain it (probabaly poorly).... So here we go...

 

There are two ways to serialize a multi level class system into a database. 

Here is the easiest one... In my opinion (someone might chime in and say otherwise, or have a better way).

If you are going to serialize Actor, then really what you might consider is serializing the Actor object to a JSON string, and place it in the database cell under "Actors".

This way all the data can still be serialized back to the class object later. 

 

I just realized that I'm not going to even mention multiple tables in your .db file referencing each other. That $#!t get complicated.

 

Serializing sub classes to JSON is best, strictly in my opinion.

 

 

Link to comment
Share on other sites

TallBoiDez
44 minutes ago, chef said:

Not quite.

The top level class would be called something like "PluginRespositoryResult" since we are going to serialize the repo into this class.

 

public class PluginRepositoryResult

{

       public List<Actor> actors { get; set; }

}

 

public class Actor

{

       public string Name { get; set; }

}

 

 

However, there are some issues with this that you need to be aware of because a data table is one dimensional. 😬

 

Note: Right off the top, it might be best to use the same naming as emby. Instead of "Actor",  use "Person". But... That's not the big issue you are about run into here...

 

Because the database is one dimensional, serializing "Actor" into the table with a bunch of properties is going to be difficult.

 

I'm going to try and not sound over top here and try to explain it (probabaly poorly).... So here we go...

 

There are two ways to serialize a multi level class system into a database. 

Here is the easiest one... In my opinion (someone might chime in and say otherwise, or have a better way).

If you are going to serialize Actor, then really what you might consider is serializing the Actor object to a JSON string, and place it in the database cell under "Actors".

This way all the data can still be serialized back to the class object later. 

 

I just realized that I'm not going to even mention multiple tables in your .db file referencing each other. That $#!t get complicated.

 

Serializing sub classes to JSON is best, strictly in my opinion.

 

 

So, if I change it from "Actor" to "Person" then the code would look like this 

public class PluginRepositoryResult

 

{

 

       public List<Person> actor { get; set; }

 

}

 

 

 

public class Person 

 

{

 

       public string Name { get; set; }

 

}

 

 Correct?

Would it be easier to pull data from a .xml file or should I stick with the SQL database route?

Edited by TallBoiDez
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...