skinner.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # Jellyfin-seymour
  3. # Copyright (C) 2019 Red_M ( http://bitbucket.com/Red_M )
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License along
  13. # with this program; if not, write to the Free Software Foundation, Inc.,
  14. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. import os
  16. import sys
  17. import json
  18. class skinner(object):
  19. def __init__(self):
  20. self.config = self.load_config()
  21. f = open('template.css','r')
  22. self.template = f.read()
  23. f.close()
  24. self.skin()
  25. def debug_print(self, text):
  26. print(text)
  27. def load_config(self):
  28. f = open('config.json','r')
  29. conf = json.load(f)
  30. f.close()
  31. return(conf)
  32. def replace_into_template(self, theme_config):
  33. out = str(self.template)
  34. for key in theme_config:
  35. out = out.replace('###'+key+'###',theme_config[key])
  36. return(out)
  37. def skin(self):
  38. selected_theme = self.config['selected_theme']
  39. if selected_theme in self.config['themes']:
  40. theme_config = self.config['themes'][selected_theme]
  41. f = open('output.css','w')
  42. f.write(self.replace_into_template(theme_config))
  43. self.debug_print('Done!')
  44. else:
  45. self.debug_print('Bad theme selected.')
  46. if 'f' in locals():
  47. f.close()
  48. def main():
  49. a = skinner()
  50. if __name__=='__main__':
  51. main()