skinner.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. f = open('transparent_header.css','r')
  25. self.transparent_header = f.read()
  26. f.close()
  27. self.skin()
  28. def debug_print(self, text):
  29. print(text)
  30. def load_config(self):
  31. f = open('config.json','r')
  32. conf = json.load(f)
  33. f.close()
  34. return(conf)
  35. def replace_into_template(self, template, theme_config):
  36. out = str(template)
  37. for key in theme_config:
  38. out = out.replace('###'+key+'###',theme_config[key])
  39. return(out)
  40. def skin(self):
  41. selected_theme = self.config['selected_theme']
  42. if selected_theme in self.config['themes']:
  43. theme_config = self.config['themes'][selected_theme]
  44. f = open('output.css','w')
  45. output = self.replace_into_template(self.template, theme_config)
  46. if self.config['transparent_header']:
  47. output = output+self.replace_into_template(self.transparent_header, theme_config)
  48. f.write(output)
  49. self.debug_print('Done!')
  50. else:
  51. self.debug_print('Bad theme selected.')
  52. if 'f' in locals():
  53. f.close()
  54. def main():
  55. a = skinner()
  56. if __name__=='__main__':
  57. main()