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

context_menu.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. try:
  6. import wingdbstub
  7. except:
  8. pass
  9. plugin = Plugin(addon_id="plugin.video.playstream")
  10. #plugin.load_addon_settings()
  11. #playlist = plugin.get_setting("general_playlist",str)
  12. #proxy_url = plugin.get_setting("general_proxy_url",str)
  13. streams_file = plugin.get_setting("general_streams_file",str)
  14. streams_file_remote = plugin.get_setting("general_streams_file_remote",str)
  15. use_streams_file_remote = plugin.get_setting("general_use_streams_file_remote",bool)
  16. cmd = sys.argv[1]
  17. #title = sys.argv[2]
  18. #data = sys.argv[3]
  19. #img = sys.argv[4]
  20. #desc = sys.argv[5]
  21. if cmd in ("add", "delete", "move"):
  22. from resources.lib.content.sources.config import Source
  23. fname = streams_file_remote if use_streams_file_remote else streams_file
  24. try:
  25. cfg = Source(cfg_file=fname)
  26. except Exception as e:
  27. plugin.notify("Cannot open content config file %s" % fname)
  28. lists = cfg.get_lists()
  29. titles = [cfg.get_title(name) for name in lists]
  30. if cmd == "add":
  31. if not CLI_MODE:
  32. ret = xbmcgui.Dialog().select("Select menu",titles)
  33. else:
  34. ret = 3
  35. if ret > 0:
  36. cfg.add_item(lists[ret],sys.argv[2:])
  37. cfg.write_streams()
  38. elif cmd == "delete":
  39. cfg.del_item(sys.argv[2], int(sys.argv[3]))
  40. cfg.write_streams()
  41. xbmc.executebuiltin("Container.Refresh")
  42. elif cmd == "move":
  43. name = sys.argv[2]
  44. pos = int(sys.argv[3])
  45. item = cfg.get_list_items(name)[pos]
  46. cfg.del_item(name, pos)
  47. ret = xbmcgui.Dialog().select("Select menu",titles)
  48. if ret > 0:
  49. name2 = lists[ret]
  50. items2 = cfg.get_list_items(name)
  51. items2 = [it[0] for it in items2]
  52. ret = xbmcgui.Dialog().select("Select position before item will be insert",items2)
  53. if ret > 0:
  54. cfg.add_item(name2, item, ret)
  55. cfg.write_streams()
  56. xbmc.executebuiltin("Container.Refresh")
  57. elif cmd == "playlist":
  58. title = sys.argv[2]
  59. data = sys.argv[3]
  60. playlist = sys.argv[4]
  61. proxy_url = sys.argv[5]
  62. if not os.path.exists(playlist):
  63. pl = open(playlist,"wb")
  64. pl.write('#EXTM3U\n')
  65. else:
  66. pl = open(playlist,"a")
  67. urlp = util.streamproxy_encode2(data,{},proxy_url)
  68. if isinstance(urlp,unicode):
  69. urlp = urlp.encode("utf8")
  70. if isinstance(title,unicode):
  71. title = title.encode("utf8")
  72. pl.write("#EXTINF:0,%s\n%s\n"%(title,urlp))
  73. pl.close()
  74. #plugin.notify("Item '%s' added to %s"%(title,playlist), "Info", 10000, xbmcgui.NOTIFICATION_INFO)
  75. elif cmd == "download":
  76. xbmcgui.Dialog().ok("Info","Not yet implemented!")
  77. else:
  78. xbmcgui.Dialog().ok("Error","Wrong command")
  79. #mode = "a" if os.path.exists("context_menu.log") else "w"
  80. #with open("context_menu.log", mode) as f:
  81. # f.write("%s %s %s %s", sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])