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

context_menu.py 3.0KB

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