Repo Util
#1
First of all I'm sorry if I'm posting this in the wrong section.

Repo Util

Recently I've been playing around with kodi and decided its time to host my own personal repo, I wrote a simple php script I'd like share, I won't be going in to detail about how to create a repo, just how to use the script with your repo and how it works, this requires your repo is hosted on a server that supports php.

It works by listing all the folders in the same directory as the script and searching them for an addon.xml file and builds an addons.xml/addons.xml.md5 file every time the script is called to save you having to regenerate them every time you add an addon to your repo, you simply just need to upload the addon and the script will automatically add it for you when kodi checks the repo for updates =)

The script
Code:
<?php
/*
    Copyright (C) 2016 michael craig
*/

    $exeptions = array('.', '..'
                            , 'plugin.program.dont_include'
                            , 'plugin.program.dont_include_0'
                        );
    
    $out = "<addons>\n";
    $file_list = scandir('.');
    foreach ($file_list as $file_name) {
        if (is_dir($file_name) && !in_array($file_name, $exeptions)  ) {    
            $fname = $file_name . '/addon.xml';
            if (file_exists($fname)) {
                $in_file = fopen($fname, "r") or die("Unable to open file!");
                $content = fread($in_file,filesize($fname));
                fclose($in_file);
                
                $ptr = strpos($content,"<addon");
                $out .= trim(substr ($content, $ptr), " \t\n\r\0\x0B") . "\n";
            }
        }
    }
    $out .= '</addons>';
    if (isset($_GET['md5'])) echo md5($out);
    else echo $out;
?>

You'll notice at the top of the script you'll see an exceptions array, this can be used to omit addons from your repo, note these are folder names that will be skipped when the script searches for the addon.xml files.

Code:
$exeptions = array('.', '..'
                             , 'plugin.program.dont_include'
                             , 'plugin.program.dont_include_0'
                         );

So the addons "plugin.program.dont_include" and "plugin.program.dont_include_0" will be skipped when generating the addons.xml/md5 files so they won't be accessible via your repo.

Now how to use it with your repo, copy/paste the script into a file and save it as "addons.php", set your repo up as you normally would when using addons.xml and addons.xml.md5 files, but instead of uploading those files to your server upload the addons.php file in their place.

Now in your repo's addon.xml we must point to our addons.php in the info/checksum tags, please take note that in the checksum tag we also call the script with an argument telling the script we want the md5 checksum and not the addons.xml string (?md5=0)

repo/addon.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="repository.example" name="Example Repository" version="1.0" provider-name="example">
    <extension point="xbmc.addon.repository" name="eZistence Repository">
        <info compressed="false">http://example.com/zips/addons.php</info>
        <checksum>http://example.com/zips/addons.php?md5=0</checksum>
        <datadir zip="true">http://example.com/zips/</datadir>
    </extension>
    <extension point="xbmc.addon.metadata">
        <summary>example summery</summary>
        <description>example description</description>
        <platform>all</platform>
    </extension>
</addon>

Now that that is out the way and your repo is set up, every time you want to add an addon to your repo you simple need to upload the addons zip/addon.xml/changelog.txt etc and the addons.xml and addons.xml.md5 files are taken care of for you, and if you want to remove an addon from your repo you simply delete the addons folder from your server or add it to the exceptions array,

I hope this is as useful to others as it is for me as I do all my addon development using kodi and it saves me firing up cmd prompt and python every time I want to generate the files =)


Repo Admin Util

Here's a simple web util for adding/updating addons in your repo, this to be used with the addon script as it does not update the addons.xml/md5 files.

I got sick of logging into my web host every time I wanted to add/update an addon in my repo so I created a simple admin page for updating my repo.

Image

When you upload an addon, the script unzips the file to a temp folder, creates a new folder in your zips directory (if needed) using the addon id within the addon.xml "within" the zip file you uploaded.

Then it moves the addon.xml/changelog/icon/fanart etc to the addon folder, then moves the actual zip to the addon directory, the zip will be named according the id/version that is defined in the addon.xml file for the addon, if the changlog within the zip file is simply called changelog.txt then the extracted changelog will have the version number appended to it so kodi can read it from your repo (does not affect the changelog name within the actual zip file).

2 checkbox's

"Replace old addon if present" if this option is checked, when you upload an addon, if there is already an addon present with the same name/directory it will be deleted and replaced by the newly uploaded addon, if its not checked and there is already an addon present the process will be skipped, this options is not checking addon versions,

"Backup existing addon if present" if this option is checked and there is an addon already present it will be copied to a back up directory defined in the config.php file, if there is already a file present in the back up dir, copy action will be skipped (this will probably change to overwrite in the future)

location of the zips/back up folder can be configured in config.php

SECURITY

ALWAYS protect the admin folder/files on your webhost with password as it can be accessed by any browser, even simple htaccess login if you don't have ssl etc available on your webhost


DISCLAIMER

This is still WIP util so you use it at your own risk

If your interested in using this util I recommend installing xampp and testing on a localhost to see how it works before adding to your webhost and using with your released repo, to do this.

1: download and install xampp
2: extract the example repo to xampp_install_dir/htdocs
3: start xampp.
4: start apache service
5: open your web browser and type localhost/repo/admin.php into the addressbar

download
https://www.sendspace.com/file/u1bfhi

I hope anyone finds it useful =)
Reply
#2
Great little util diezil, thanks for sharing! Would you be able to adapt this so that any time a new version of an addon is uploaded the addons.xml and addons.xml.md5 in the /addons directory on the repo get automatically updated with the new info? That would be awesome!
Reply
#3
@Electroid

Sorry for such late reply, I've been a little busy lately, I'm still new to kodi repo's so I'm not exactly sure what you mean, can you give an example of how you want it to work?

If you correctly edited your repo's addon.xml to point to the script then the script is called every time kodi checks your repo for updates, the script is simple and requires that only 1 addon is present in the addons directory so if you want to update the addon you simply need to replace the addons files in its directory and when kodi checks your repo for updates the script will be run by your server automatically and kodi will see that your addon has been updated =)

/********************************************************************************/

First post updated with admin util for adding addons to your repo =)
Reply
#4
Awesome, you rock! Thanks a million for this very handy tool.
Reply
#5
Anyone have the download?
Reply

Logout Mark Read Team Forum Stats Members Help
Repo Util1