import json
import os
import xbmc

from devhelper.pykodi import log

class ProcessedItems(object):
    version = 1
    def __init__(self, directory):
        self.tvshow = {}
        self.movie = []
        self.episode = []
        self.filename = os.path.join(directory, 'processeditems.json')

    def extend(self, extender):
        for tvshowid, seasons in extender.get('tvshow', {}).iteritems():
            if seasons > self.tvshow.get(tvshowid):
                self.tvshow[tvshowid] = seasons
        self.movie.extend(extender.get('movie', ()))
        self.episode.extend(extender.get('episode', ()))

    def set(self, setter):
        self.tvshow = setter.get('tvshow', {})
        self.movie = setter.get('movie', [])
        self.episode = setter.get('episode', [])

    def clear(self):
        self.tvshow = {}
        self.movie = []
        self.episode = []

    def save(self):
        with open(self.filename, 'w') as jsonfile:
            json.dump({'tvshow': self.tvshow, 'movie': self.movie, 'episode': self.episode, 'version': self.version}, jsonfile)

    def load(self):
        if os.path.exists(self.filename):
            with open(self.filename, 'r') as jsonfile:
                try:
                    processed = json.load(jsonfile)
                except ValueError:
                    self.clear()
                    log("Had trouble loading ProcessedItems, starting fresh.", xbmc.LOGWARNING, tag='json')
                    return

                if processed.get('version') == self.version:
                    self.tvshow = dict((int(tvshowid), seasons) for tvshowid, seasons in processed.get('tvshow', {}).iteritems())
                else:
                    self.tvshow = {}
                self.movie = processed.get('movie', [])
                self.episode = processed.get('episode', [])
        else:
            self.clear()

@@ -4,20 +4,19 @@
 ort 
-json
+sys
 %0Aimport 
 os%0Ai
@@ -11,18 +11,20 @@
 %0Aimport 
-os
+xbmc
 %0Aimport 
@@ -27,16 +27,133 @@
 ort xbmc
+vfs%0Afrom contextlib import closing%0A%0Aif sys.version_info %3C (2, 7):%0A    import simplejson as json%0Aelse:%0A    import json
 %0A%0Afrom d
@@ -364,21 +364,8 @@
 e = 
-os.path.join(
 dire
@@ -369,17 +369,18 @@
 irectory
-,
+ +
  'proces
@@ -393,17 +393,16 @@
 ms.json'
-)
 %0A%0A    de
@@ -1002,36 +1002,52 @@
 ):%0A        with 
-open
+closing(xbmcvfs.File
 (self.filename, 
@@ -1050,16 +1050,17 @@
 me, 'w')
+)
  as json
@@ -1229,15 +1229,15 @@
  if 
-os.path
+xbmcvfs
 .exi
@@ -1277,12 +1277,28 @@
 ith 
-open
+closing(xbmcvfs.File
 (sel
@@ -1311,13 +1311,9 @@
 name
-, 'r'
+)
 ) as

Use xbmcvfs to save processed items And simplejson for Python 2.6