Kodi plugin to to play various online streams (mostly Latvian)

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import sys, os, os.path
  2. from kodiswift import xbmc, xbmcgui, CLI_MODE
  3. from kodiswift import Plugin, storage
  4. from resources.lib.sources.config import Source
  5. from resources.lib import util
  6. #plugin = Plugin()
  7. #plugin.load_addon_settings()
  8. #playlist = plugin.get_setting("general_playlist",str)
  9. #proxy_url = plugin.get_setting("general_proxy_url",str)
  10. # PlaysTream streams.cfg
  11. cfg = Source()
  12. lists = cfg.get_lists()
  13. titles = [cfg.get_title(name) for name in lists]
  14. cmd = sys.argv[1]
  15. #title = sys.argv[2]
  16. #data = sys.argv[3]
  17. #img = sys.argv[4]
  18. #desc = sys.argv[5]
  19. if cmd == "add":
  20. if not CLI_MODE:
  21. ret = xbmcgui.Dialog().select("Select menu",titles)
  22. else:
  23. ret = 3
  24. cfg.add_item(lists[ret],sys.argv[2:])
  25. cfg.write_streams()
  26. elif cmd == "playlist":
  27. title = sys.argv[2]
  28. data = sys.argv[3]
  29. playlist = sys.argv[4]
  30. proxy_url = sys.argv[5]
  31. if not os.path.exists(playlist):
  32. pl = open(playlist,"wb")
  33. pl.write('#EXTM3U\n')
  34. else:
  35. pl = open(playlist,"a")
  36. urlp = util.streamproxy_encode2(data,{},proxy_url)
  37. if isinstance(urlp,unicode):
  38. urlp = urlp.encode("utf8")
  39. if isinstance(title,unicode):
  40. title = title.encode("utf8")
  41. pl.write("#EXTINF:0,%s\n%s\n"%(title,urlp))
  42. pl.close()
  43. #plugin.notify("Item '%s' added to %s"%(title,playlist), "Info", 10000, xbmcgui.NOTIFICATION_INFO)
  44. elif cmd == "delete":
  45. xbmcgui.Dialog().ok("Info","Not yet implemented!")
  46. elif cmd == "download":
  47. xbmcgui.Dialog().ok("Info","Not yet implemented!")
  48. else:
  49. xbmcgui.Dialog().ok("Error","Wrong command")
  50. #mode = "a" if os.path.exists("context_menu.log") else "w"
  51. #with open("context_menu.log", mode) as f:
  52. # f.write("%s %s %s %s", sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])