0

I have a problem with writing a kodi plugin.

I am listing an entry to view a stream that provides a preview image. But since kodi caches the images I thought of a way of requesting the image manually every time. To achieve that I want to save the image to the resources/cache directory of my plugin.

But I get the following error:

Error Contents: [Errno 2] No such file or directory: 'special://home/addon_data/[plugin]/resources/caches/preview_de.png'

My code is

f = urlopen(Request(url))
local_file = open(local, 'w'+mode)
local_file.write(f.read())
local_file.close()

I guess the special:// protocol is the problem, but what can I do to not only work on one machine?

Peter Nerlich
  • 225
  • 1
  • 11

1 Answers1

0

You need to call translatePath() and use the returned string as url before you can use it.

Example:

local = xbmc.translatePath('special://home/addon_data/[plugin]/resources/caches/preview_de.png') 
f = urlopen(Request(url))
local_file = open(local, 'w'+mode)
local_file.write(f.read())
local_file.close()

PS. To avoid caching of images, you might be able to archive by adding random GET data into your request.

rasjani
  • 7,372
  • 4
  • 22
  • 35