code: def backup_watched(plex, opts):
      
      data = defaultdict(lambda: dict())
      for section in _iter_sections(plex, opts):
          print('Fetching watched status for %s..' % section.title)
          skey = section.title.lower()
          for item in _iter_items(section):
              if not opts.watchedonly or item.isWatched:
                  ikey = _item_key(item)
                  data[skey][ikey] = item.isWatched
                  import pprint; pprint.pprint(item.__dict__); break
      print('Writing backup file to %s' % opts.filepath)
      with open(opts.filepath, 'w') as handle:
          json.dump(dict(data), handle, sort_keys=True, indent=2)
docs: Backup watched status to the specified filepath.