How to link a file to its parent folder - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: How to link a file to its parent folder (/showthread.php?tid=374940) |
How to link a file to its parent folder - Piero4556 - 2023-11-03 Hello I'm figuring out how to link an episode to its parent folder For example, in this code, I created two folders named "Serie1" and "Serie2" My attempt was to create a file named "episode S01E01" inside "Serie1" folder but it failed I can't see the "episode" file Looking at Roman's example, I can't grasp the key step How to link file to its parent folder ? Code addon xml Thank you RE: How to link a file to its parent folder - CrudeCreator - 2023-12-15 So, there's a couple things you're misunderstanding about how a plugin works in the Kodi environment. First, each time your addon is run it needs to add a set of list items for the current URL that is called for your plugin. Second, you NEED to make use of the URL property on each list item. You don't just add infinite endless items and nest them in one program. At the moment you're trying to do the following: 1. Create the folder list items
2. You end the directory
3. And then you try to make more items (This won't work! You've already ended the directory)
So let's start at the beginning, and I think you should do a little more reading and playing around. Do you have much experience programming? Either way, I think this is a great environment to learn in, there's just a few weird hangups about how it works in the Kodi world that's very unlike other implementations. I'm going to change the fewest amount of things possible in your code to get what you want, but please keep reading and playing as there's lots you can improve on. But hey, chastising you and critiquing everything is no fun so I want you to learn and explore how you're doing right now. It's the best way to learn. Firstly when you click an item in your addon, it calls the URL property. It could point anywhere but you want it pointing to your own addon right? So right now your two URL variables are blank:
Let's change these to point at your addon and to also have information on which folder you've clicked. Let's use the get_url function you've copied from the tutorial:
So now when you click these folders it will now call your addon and pass through the values 'plugin://plugin_id?folder=Serie1&action=navigate' <--- THAT'S WHAT EVERY PLUGIN URL IN KODI LOOKS LIKE But that long string isn't a nice set of parameters right? That's why 'parse_qsl' is imported at the top of your python script, for just this purpose! Adding this line to the top turns that '?folder=Serie1&action=navigate' into a nice set of values:
So now we have two actions: Navigate and Play. Let's check if we're doing either of those each time the addon is ran:
Now we want to check if there's a 'folder' parameter. If not we must be at the top and show Serie1 and Serie2 like you're already doing:
And then if the folder is equal to 'Serie1' then the user has clicked a one of those two folders and now this run of your addon you will return what's inside Serie1:
Finally I've moved the End directory to outside the if/else as you will want to end the directory every time you navigate. Additionally, you we're again using 'url1' which was blank for this item.
Now putting that all together you end up with: https://hastebin.com/share/oteheyajag.python As a final note. There's tons I'd improve but you've taken some great first steps. I'm just writing up a starter project in Github that should help a bunch with people getting off the ground with their first plugins. I'll post here once I have the repo up and running and you should take a look as I'm sure it will help with you learning. There's tons of great resources out there for tutorials and you just need to do a bit of reading. Stick at it and hope you make something you're proud of! You're welcome to ask me for more help but I can only spare so much time on detailed guidance like this. My advice is keep playing, reading and looking at other people's code (very important!) |