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

service.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. import os,os.path,sys, urllib, traceback
  3. from kodiswift import Plugin, ListItem, storage
  4. from kodiswift import xbmc, xbmcgui, xbmcplugin, xbmcvfs, CLI_MODE
  5. #from resources.lib import ContentSources, util
  6. #sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),"resources","lib","sources"))
  7. plugin = Plugin()
  8. plugin.load_addon_settings()
  9. addon = xbmcaddon.Addon()
  10. host = addon.getSetting('host')
  11. port = int(addon.getSetting('port'))
  12. channels_file = addon.getSetting('playlist_path') + 'iptv_channels.m3u'
  13. plugin_path = xbmc.translatePath(addon.getAddonInfo('path'))
  14. tv_services = []
  15. #Kodi < v17 workaround
  16. redirect_url = ''
  17. class httpHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  18. def do_GET(self):
  19. global redirect_url
  20. p = urlparse.urlparse(self.path)
  21. params = urlparse.parse_qs(p.query)
  22. if p.path == '/channel.m3u8':
  23. if 'sid' in params:
  24. for tvs in tv_services:
  25. if tvs.serviceId == params['sid'][0]:
  26. tvs.current_channel_id = params['cid']
  27. redirect_url = tvs.getChannelUrl()
  28. break
  29. self.send_response(301)
  30. self.send_header('Location', redirect_url)
  31. self.end_headers()
  32. if addon.getSetting('ewetv') == 'true':
  33. ewetv = ewetv.EWETV(addon.getSetting('user_ewe'), addon.getSetting('pass_ewe'))
  34. if ewetv.login():
  35. tv_services.append(ewetv)
  36. if addon.getSetting('netcologne') == 'true':
  37. nc = netcologne.NetCologne(addon.getSetting('user_nc'), addon.getSetting('pass_nc'))
  38. if nc.login():
  39. tv_services.append(nc)
  40. if addon.getSetting('zattoo') == 'true':
  41. zattoo = zattoo.Zattoo(addon.getSetting('user_zattoo'), addon.getSetting('pass_zattoo'))
  42. if zattoo.login():
  43. tv_services.append(zattoo)
  44. if len(tv_services)>0:
  45. print tv_services
  46. if channellist.generateM3U(tv_services):
  47. xbmcgui.Dialog().notification('IPTV Proxy', 'Senderliste aktualisiert. Neustart erforderlich!', xbmcgui.NOTIFICATION_INFO, 5000, True)
  48. xbmc.log('Starting IPTV Proxy on port ' + str(port))
  49. SocketServer.TCPServer.allow_reuse_address = True
  50. handler = SocketServer.TCPServer((host, port), httpHandler)
  51. handler.serve_forever()
  52. monitor = xbmc.Monitor()
  53. while not monitor.abortRequested():
  54. # Sleep/wait for abort for 10 seconds
  55. if monitor.waitForAbort(10):
  56. # Abort was requested while waiting. We should exit
  57. handler.shutdown()
  58. break