Browse plugin KODI/XBMC support

Thought I would raise this for discussion before submitting any of my modified code.

I use caddy to serve media to my KODI instance over the internet, and I need to use a special template to allow KODI to understand the file listing (this is needed because the KODI http scraping code is specialised to apache, nginx, and lighttpd directory indexes). I wrote a template the works around this by mimicking the nginx (simplest) listing.

My solution was very specific and I basically copied the default template and added an if user-agent is kodi block around the whole thing, rendering either the default listing or a super simple kodi-understandable version as needed. It works fine.

My question is:

Given that some software behaves this way do you think it would be beneficial to the browse plugin to have some extra builtin templates that mimic well known other indexes?
Or if not, would the Caddy project be better off if the browse plugin recognized a KODI UA specifically and adapted it’s template accordingly?

The first seems more general, the second would mean KODI specifically would work out of the box.

1 Like

Could you post your template? I am having this issue as well, I’ve tried to make a template mimicking Apaches directory listings, but I can’t get Kodi to enter directories with spaces in the name.

As far as I can tell the issue I’m running into is that .URL in the FileInfo object starts with a “./” which Kodi doesn’t like. But I can’t figure out how to get rid of that, or how to swap the spaces in .Name with “%20”.

Although i changed my approach and just dumped the kodi compatible listing in a hidden div all the time.

Ahh, I see what I was missing now! Didn’t know to put the $ before .Replace.

This is mine now, does sorting properly as well!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
  <title>Index of {{html .Path}}</title>
</head>
<body>
  <h1>Index of {{html .Path}}</h1>
  <table>
   <tr><th></th><th>
    {{- if and (eq .Sort "name") (ne .Order "desc") -}}
    <a href="?sort=name&order=desc">
    {{- else -}}
    <a href="?sort=name&order=asc">{{end}}Name</a></th><th>
    {{- if and (eq .Sort "time") (ne .Order "desc") -}}
    <a href="?sort=time&order=desc">
    {{- else -}}
    <a href="?sort=time&order=asc">{{end}}Last modified</a></th><th>
    {{- if and (eq .Sort "size") (ne .Order "desc") -}}
    <a href="?sort=size&order=desc">
    {{- else -}}
    <a href="?sort=size&order=asc">{{end}}Size</a></th><th></th></tr>
    <tr><th colspan="5"><hr></th></tr>
    {{if .CanGoUp -}}
    <tr><td></td><td><a href="..">Up one level</a></td><td></td><td></td><td></td></tr>
    {{- end}}
    {{- range .Items}}
    <tr><td></td><td><a href="{{$.Replace (urlquery .Name) "+" "%20"}}{{if .IsDir}}/{{end}}">
    {{- .Name}}{{if .IsDir}}/{{end}}</a></td><td align="right">
    {{- .HumanModTime "02-Jan-2006 15:04"}} </td><td align="right">
    {{- if .IsDir}}-{{else}}{{.HumanSize}}{{end}}</td><td></td></tr>
    {{- end}}
    <tr><th colspan="5"><hr></th></tr>
  </table>
  <address>caddy server</address>
</body>
</html>

Kodi does the sorting client side and the rest of the template is the original, so if you use a browser you see the default, but kodi still works.

Sorry to bring up an old thread, but did anyone make the template work on Caddy v2?
None of the suggested ones seem to work as of now.
Thanks!

@intramad please post a help thread – and please fill out the template, mention what didn’t work, what errors you encountered, etc.

Edit: For reference, the followup thread is: