Python module (submodule repositary), which provides content (video streams) from various online stream sources to corresponding Enigma2, Kodi, Plex plugins

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: UTF-8 -*-
  2. import re,os,sys
  3. import json
  4. try:
  5. import util
  6. except:
  7. pp = os.path.dirname(os.path.abspath(__file__))
  8. sys.path.insert(0,os.sep.join(pp.split(os.sep)[:-1]))
  9. import util
  10. import urllib2
  11. import requests
  12. try:
  13. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  14. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  15. except:
  16. pass
  17. #from aadecode import AADecoder
  18. __author__ = 'ivars777'
  19. __name__ = 'cloudsany' if __name__ <> "__main__" else __name__
  20. def supports(url):
  21. # https://cloudsany.com/i/b4kt66gm2sw4
  22. return re.search(r'cloudsany\.\w+/\w/.+', url) is not None
  23. #INFO_URL = API_BASE_URL + '/streaming/info'
  24. def resolve(url):
  25. headers = {
  26. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0',
  27. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  28. 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
  29. 'Accept-Encoding': 'none',
  30. 'Accept-Language': 'en-US,en;q=0.8',
  31. 'Referer': url} # 'Connection': 'keep-alive'
  32. # https://cloudsany.com/i/b4kt66gm2sw4
  33. m = re.search('cloudsany\.\w+/i/(\w+)', url)
  34. if not m:
  35. return stream
  36. vid = str(m.group(1))
  37. r = requests.get(url, headers=headers)
  38. if r.status_code <> 200:
  39. raise Exception("Error getting stream")
  40. r = r.content
  41. m = re.search(r"'(https\|.+?jwplayer)'", r)
  42. if not m:
  43. print url
  44. if "File was deleted" in r:
  45. raise Exception("File was deleted")
  46. else:
  47. raise Exception("Can not find stream")
  48. p = m.group(1).split("|")
  49. p0 = m.group(1)
  50. # Subtitles #
  51. subs = []
  52. # https://cloudsany.com/subtitles/0w3y7su4c2ko.srt
  53. # Latvian|label|srt|subtitles
  54. #url_sub = "https://cloudsany.com/subtitles/%s.%s" % (vid, "srt")
  55. url_sub = "https://cloudsany.com/subtitles/%s.srt" % vid
  56. r2 = requests.head(url_sub)
  57. m = re.search(r"(\w+)\|label\|(\w+)\|(\w+)\|subtitles", p0)
  58. if r2.status_code == 200 and m:
  59. sub = {}
  60. #url_sub = "https://cloudsany.com/subtitles/%s.%s" % (vid, "srt")
  61. url_title = m.group(1)
  62. print url_title
  63. sub["url"] = url_sub
  64. sub["lang"] = m.group(1)
  65. sub["name"] = m.group(1)
  66. sub["type"] = m.group(2)
  67. subs = [sub]
  68. # Stream URL
  69. # co|sanii|dl1|file
  70. m1 = re.search("\|(co)\|(\w*)\|(\w*)\|(\w*)\|", p0)
  71. # tracks|mp4|video|ut4dluxu56tyll|files
  72. m2 = re.search(r"tracks\|(\w+)\|(\w+)\|(\w+)\|files", p0)
  73. # 0://c.b.a/1t/6/1s/1r.1q
  74. m3 = re.search(r"0://\w+\.\w+\.\w+/\w+/(\d+)/", r)
  75. if not (m1 and m2 and m3):
  76. raise Exception("Can not find stream url")
  77. # https://dl1.sanii.co/files/6/ut4dluxu56tyll/video.mp4
  78. l1 = list(m1.groups())
  79. if "" in l1: l1.remove("")
  80. url = "https://%s.%s.%s/files/%s/%s/%s.%s" % (
  81. l1[2], l1[1], l1[0], m3.group(1), m2.group(3), m2.group(2), m2.group(1))
  82. print url
  83. s = util.item()
  84. s["url"] = url
  85. s["type"] = util.stream_type(s["url"])
  86. s["resolver"] = __name__
  87. #s["lang"] = lang
  88. s["subs"] = subs
  89. s["name"] = url
  90. return [s]
  91. if __name__ == "__main__":
  92. from subprocess import call
  93. url = "https://cloudsany.com/i/b4kt66gm2sw4"
  94. url = "https://cloudsany.com/i/jqfm2sqwar22" # teorija par visu/SUB
  95. streams = resolve(url)
  96. if not streams:
  97. print "No streams found"
  98. sys.exit()
  99. for s in streams:
  100. print s
  101. from run import player
  102. player(streams[0]["url"])
  103. #print streams[0]["url"]
  104. #call([r"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe",streams[0]["url"]])
  105. pass