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

context_menu.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import sys, os, os.path
  2. from kodiswift import xbmc, xbmcgui, CLI_MODE
  3. from kodiswift import Plugin, storage
  4. from resources.lib.content import util
  5. #plugin = Plugin()
  6. #plugin.load_addon_settings()
  7. #playlist = plugin.get_setting("general_playlist",str)
  8. #proxy_url = plugin.get_setting("general_proxy_url",str)
  9. cmd = sys.argv[1]
  10. #title = sys.argv[2]
  11. #data = sys.argv[3]
  12. #img = sys.argv[4]
  13. #desc = sys.argv[5]
  14. if cmd in ("add", "delete"):
  15. from resources.lib.content.sources.config import Source
  16. cfg = Source()
  17. lists = cfg.get_lists()
  18. titles = [cfg.get_title(name) for name in lists]
  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 == "delete":
  27. xbmcgui.Dialog().ok("Info","Not yet implemented!")
  28. elif cmd == "playlist":
  29. title = sys.argv[2]
  30. data = sys.argv[3]
  31. playlist = sys.argv[4]
  32. proxy_url = sys.argv[5]
  33. if not os.path.exists(playlist):
  34. pl = open(playlist,"wb")
  35. pl.write('#EXTM3U\n')
  36. else:
  37. pl = open(playlist,"a")
  38. urlp = util.streamproxy_encode2(data,{},proxy_url)
  39. if isinstance(urlp,unicode):
  40. urlp = urlp.encode("utf8")
  41. if isinstance(title,unicode):
  42. title = title.encode("utf8")
  43. pl.write("#EXTINF:0,%s\n%s\n"%(title,urlp))
  44. pl.close()
  45. #plugin.notify("Item '%s' added to %s"%(title,playlist), "Info", 10000, xbmcgui.NOTIFICATION_INFO)
  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])