Enigma2 plugin to to play various online streams (mostly Latvian).

config.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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"):
  14. self.name = "config"
  15. self.country=country
  16. cur_directory = os.path.dirname(os.path.abspath(__file__))
  17. self.streams_file = os.path.join(cur_directory,"streams.cfg")
  18. self.lists = collections.OrderedDict()
  19. self.read_streams()
  20. def get_content(self, data):
  21. self.read_streams()
  22. if "::" in data:
  23. data = data.split("::")[1]
  24. if not data in self.lists:
  25. return []
  26. return self.lists[data]
  27. def is_video(self,data):
  28. return False
  29. def read_streams(self):
  30. for line in open(self.streams_file,"r"):
  31. r = re.search("^\[(\w+)\]", line)
  32. if r:
  33. name = r.group(1)
  34. self.lists[name] = []
  35. else:
  36. if len(line)<10 or line[0] in ("#"): continue
  37. items = tuple(line.strip().split("|"))
  38. if len(items)<2:
  39. continue
  40. self.lists[name].append(items)
  41. def write_streams(self):
  42. f = open(self.streams_file,"w")
  43. for l in self.lists.keys():
  44. f.write("[%s]\n"%l)
  45. for item in self.lists[l]:
  46. f.write("%s|%s|%s|%s\n"%(item[0],item[1],item[2],item[3]))
  47. f.write("\n")
  48. f.close()
  49. def get_lists(self):
  50. return self.lists.keys()
  51. def get_list_items(self,name):
  52. return self.lists[name]
  53. def add_list(self,name):
  54. if not name in self.lists.keys():
  55. self.lists[name] = []
  56. def del_list(self,name):
  57. if name in self.lists.keys():
  58. del self.lists[name]
  59. def add_item(self,name,item,pos=None):
  60. if name in self.lists.keys():
  61. if pos==None:
  62. self.lists[name].append(item)
  63. else:
  64. self.lists[name].insert(pos,item)
  65. def del_item(self,name,pos):
  66. self.lists[name].pop(pos)
  67. def replace_item(self,name,item,pos):
  68. self.lists[name][pos]=item
  69. if __name__ == "__main__":
  70. c = Source()
  71. content = c.get_content("home")
  72. for item in content: print item
  73. #c.del_item("home",0)
  74. #c.del_list("favorites")
  75. #c.add_item("home",("My Streams","config::favorites","","Mani saglabātie TV kanāli un video"),0)
  76. c.replace_item("home",("My Streams","config::my_streams","default","Mani saglabātie TV kanāli un video"),0)
  77. #c.add_list("favorites")
  78. #c.add_item("favorites",("..return","back","","Atgriezties atpakaļ"))
  79. #c.add_item("favorites",("LTV1","http://streamltv.cloudy.services/ltv/LTV02.smil/playlist.m3u8","picons/latvia1.png", "Latvijas televīzijas 1.kanāls"))
  80. c.write_streams()
  81. for item in content: print item