Getting full file path in Python Addon
#1
How do I get the full file name and path of a ‘TV Show’ recording within a Python addon?

I am using KODI v19.4.0 on LibreELEC v10.0.3.

I’m writing my first Kodi addon.  It is a TV scraper using python.  When I ‘Scan for new content’, I can see the log entries that I expect, so I know that the basics are working.  My scraper is heavily based on the ‘metadata.demo.tv’ demo addon found in Github.

The source that I am trying to scrape has 2 files per recording, one is the actual media and the other contains the EPG data.  For example: ‘my recording name.mpg’ and ‘my recording name.mpg.inf’.

I need to be able to get the full file name and path of the recording currently being scraped so that I can open the associated information file, extract the required EPG details and return them to Kodi.

My addon is receiving both the ‘find’ and ‘getdetails’ actions.  With ‘find’, the closest I get is the ‘title’ which is just the recording file name without the file extension, in my previous example it would be ‘my recording name’.

With both actions, the ‘pathSettings’ property always seems to be a null object.  With ‘getdetails’, the url is always just ‘/path/to/show’ regardless of where the actual recording is located.

I would appreciate some help or guidance in obtaining the full path and file name.  Alternatively, perhaps I don’t understand KODI well enough and a scraper is the wrong strategy in this instance and a different approach can be suggested.

Thanks in advance.
Reply
#2
There is no way. Kodi does all filename parsing internally.
Reply
#3
The brute force way you could try and do it is to load and parse the sources.xml file.  That has the path of all the sources, and you'd have to go through each one and try to see if there is a folder in that source with the right name (I think during the initial find call the folder name is what is passed). You still won't know if the episodes are in season folders or not.  So you either have to force people using your scraper into a certain storage convention or you have to figure out all the permutations to check for.  It's going to be really messy and maybe not consistent, but it's the only thing I can think of to try.

BTW, the sources.xml file is in the userdata directory.  You should be able to get that using the special:// path of special://userdata.

https://kodi.wiki/view/Special_protocol

P.S. If you actually do it this way, I don't think we'd accept it into the Kodi repo.  Using the sources.xml in the way I have described isn't supported at all.  It doesn't mean you couldn't distribute it, I just don't think it would be able to be in the official repo.  Honestly, I'd have to ask some of the other Team members about that.  I just don't want you to get this working only to find out later we won't accept it for distribution.
Reply
#4
For completeness of information alone.

Paths are also stored in the MyVideos database in the path table.

This is still not an advised method though, I would uninstall any addon I found out was arbitrarily scanning my file system to find things.
Reply
#5
Thank you to everyone who has commented, I appreciate your time and effort.

I have come up with 3 possible alternatives:

1) I could write a TAP (addon for Topfield PVR) that walks its HDD tree and creates .NFO files for every recording.  If a user copies a recording, they will need to copy the NFO too.  I am currently having problems with NFOs for recordings with multiple episodes, but I will post that as a separate question.

2) I could do something similar to 1) on KODI: Write a script addon to scan KODI’s file system for all INF files and then create a corresponding NFO.  I’ve already written some prototype python code to extract the information that I need from the INF.  I’d just need to clean that up a bit.

3) I have some TAPs on the Topfield that enable NFS and a Web Interface.  I could try a ‘Videos’ addon.  For an NFS source, I could parse the IP address and then try the web interface at that address.  If successful, I could extract the recordings list plus INF data via the web interface, but use the NFS url to actually play the media.
Reply

Logout Mark Read Team Forum Stats Members Help
Getting full file path in Python Addon0