Python module (submodule repositary), which provides content (video streams) from various online stream sources to corresponding Enigma2, Kodi, Plex plugins

config.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env python
  2. # coding=utf8
  3. #
  4. # This file is part of PlayStream - enigma2 plugin to play video streams from various sources
  5. # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
  6. # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
  7. #
  8. import os.path,re
  9. import collections
  10. from SourceBase import SourceBase
  11. os.path.dirname(os.path.abspath(__file__))
  12. class Source(SourceBase):
  13. def __init__(self,country="lv",cfg_path=None):
  14. self.name = "config"
  15. self.country=country
  16. cur_directory = os.path.dirname(os.path.abspath(__file__))
  17. if not cfg_path: cfg_path = cur_directory
  18. self.streams_file = os.path.join(cfg_path,"streams.cfg")
  19. self.lists = collections.OrderedDict()
  20. self.titles = {}
  21. self.read_streams()
  22. def get_content(self, data):
  23. print "[config] get_content",data
  24. self.read_streams()
  25. if "::" in data:
  26. data = data.split("::")[1]
  27. if not data in self.lists:
  28. return []
  29. return self.lists[data]
  30. def is_video(self,data):
  31. return False
  32. def read_streams(self):
  33. for line in open(self.streams_file,"r"):
  34. r = re.search("^\[(\w+)\]", line)
  35. if r:
  36. name = r.group(1)
  37. self.lists[name] = []
  38. else:
  39. if line[0] in ("#"): continue
  40. items = line.strip().split("|")
  41. if not items[0]: continue
  42. if len(items)==1:
  43. self.titles[name] = items[0]
  44. else:
  45. if len(items) == 4:
  46. items[3] = items[3].replace("\\n","\n")
  47. self.lists[name].append(items)
  48. def write_streams(self):
  49. f = open(self.streams_file,"w")
  50. for l in self.lists.keys():
  51. f.write("[%s]\n"%l)
  52. t = self.get_title(l)
  53. if t<>l:
  54. f.write("%s\n"%t)
  55. for item in self.lists[l]:
  56. f.write("%s|%s|%s|%s\n"%(item[0].replace("\n",""),item[1],item[2],item[3].replace("\n","\\n")))
  57. f.write("\n")
  58. f.close()
  59. def get_lists(self):
  60. return self.lists.keys()
  61. def get_list_items(self,name):
  62. return self.lists[name]
  63. def get_title(self,name):
  64. if name in self.titles:
  65. return self.titles[name]
  66. else:
  67. return name
  68. def add_list(self,name):
  69. if not name in self.lists.keys():
  70. self.lists[name] = []
  71. def del_list(self,name):
  72. if name in self.lists.keys():
  73. del self.lists[name]
  74. def add_item(self,name,item,pos=None):
  75. if name in self.lists.keys():
  76. if pos==None:
  77. self.lists[name].append(item)
  78. else:
  79. self.lists[name].insert(pos,item)
  80. def del_item(self,name,pos):
  81. self.lists[name].pop(pos)
  82. def replace_item(self,name,item,pos):
  83. self.lists[name][pos]=item
  84. if __name__ == "__main__":
  85. c = Source()
  86. content = c.get_content("home")
  87. for item in content: print item
  88. #c.del_item("home",0)
  89. #c.del_list("favorites")
  90. #c.add_item("home",("My Streams","config::favorites","","Mani saglabātie TV kanāli un video"),0)
  91. c.replace_item("home",("My Streams","config::my_streams","default","Mani saglabātie TV kanāli un video"),0)
  92. #c.add_list("favorites")
  93. #c.add_item("favorites",("..return","back","","Atgriezties atpakaļ"))
  94. #c.add_item("favorites",("LTV1","http://streamltv.cloudy.services/ltv/LTV02.smil/playlist.m3u8","picons/latvia1.png", "Latvijas televīzijas 1.kanāls"))
  95. c.write_streams()
  96. for item in content: print item