Python script.module addon not working in built addon

  • I've been successfully using the tvheadend42 addon built from the git repository checked out to 9.2.0, patched to compile to tvheadend version 4.3.

    In order to use the fanart scraping feature for recordings, I built the tvh addon again with a couple more tweaks. The built in tvh python scripts were copied to the tvh addon by including

    cp -P $PKG_BUILD/lib/py/tvh/tv_meta_* $ADDON_BUILD/$PKG_ADDON_ID/bin

    in the tvheadend package.mk. These scripts require the 'requests' module so I included a dependency in the tvheadend addon.xml

    <import addon="script.module.requests" version="2.22.0"/>

    The tvh addon built and installed successfully and it pulled in the required script.module.* addons which are all showing in /storage/.kodi/addons, and showing in the Kodi GUI "Addons/Manage dependencies" with ticks.

    However the tv_meta_* scripts fail with

    Code
    Traceback (most recent call last):
    File "/storage/.kodi/addons/service.tvheadend42/bin/tv_meta_tvdb.py", line 29, in <module>
    import requests
    ImportError: No module named requests

    and if I type 'python' at the command prompt and type help ("modules") none of the addon modules are listed. A test python script with 'import requests' also fails.

    What have I done wrong? :dodgy:

    Cheers,

    Simon

    Edited once, last by sihy: typo (January 26, 2020 at 5:00 PM).

  • It's a python path problem.

    Adding the following:

    sys.path.append('/storage/.kodi/addons/script.module.requests/lib/')

    sys.path.append('/storage/.kodi/addons/script.module.urllib3/lib/')

    sys.path.append('/storage/.kodi/addons/script.module.chardet/lib/')

    sys.path.append('/storage/.kodi/addons/script.module.certifi/lib/')

    sys.path.append('/storage/.kodi/addons/http://script.module.idna/lib/')

    in the tv_meta_tvdb.py (tvheadend) script prior to the import requests statement fixes it.

    $PYTHONPATH is empty.

    Politely asking for a piece of advice from the (LE) coders out there...

    What's the best way to solve this question - should I just patch the tv_meta_*.py scripts with the above at LE addon compile time, or is there a better way?

    Setting any global python $PYTHONPATH is probably bad because that assumes the script.modules are installed which they might not be. Maybe a systemd service edit for service.tvheadend42.service to set PYTHONPATH for TVH only, but would that work because python has already started? And it would need incorporating into the addon at compile time. Can $PYTHONPATH be changed at any point, or does something to do with python (I know nothing about python!) need to be restarted so $PYTHONPATH can be set with the new values?

    Have I missed something with the kodi script.module addons, is that the root cause? All the other modules apart from requests are dependencies for requests anyway, so why doesn't the requests module know the paths to it's own dependencies?

    Is this a kodi question? ;)

    Any input appreciated, cheers.

  • For anyone else finding this ....

    I couldn't get the $PYTHONPATH environment variable to work, so I just applied patches to tv_meta_tmdb.py and tv_meta_tvdb.py to append the paths as above.

    In order for the grabbing to work tvhmeta also needs to be copied into the addon's bin folder (it's in the support directory). It also needs the paths patched with the above.

    Note that this all works through localhost HTTP connections so make sure you have an API key to authenticate with the movie database and also permissions for 127.0.0.0/24 to access your tvh server (if you use a password only setup then you also need to supply --user and --password in the recording config additional command line options for tvh).

    Note also that despite what tvh help says only the movie database works, not the tv database so you only need an API key for that.

    Anyway, it now seems to be working - I don't have any errors (except it saying 'We have both image and fanart_image already', when it doesn't), but I still don't have any art either. Sigh.

    Edit:

    This is an issue with the upstream. I patched tvhmeta with pastebin-link to make it work.

    CvH you might be interested in this as you supply a TVH4.3 addon.

    Edited 2 times, last by sihy (January 28, 2020 at 12:10 PM).

  • Hi cvH.

    I downloaded your zipped addon for TVH 4.3 (I assume this is your work! link to addon) and checked the contents to see if it had the fanart scripts included and couldn't find them. I didn't actually install and use your addon, so maybe they are included but just not in the bin directory, or maybe I missed it, it was just a quick look.

    I built a TVH4.3 addon (using some info you gave somebody else on a thread here somewhere I think) and included them, the (pretty poor admittedly) instructions are above and thought you might be interested in case you decided to include the fanart in a future edition.

    Cheers,

    Simon

    Edited once, last by sihy: included link to the addon (February 2, 2020 at 5:34 PM).