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

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