Plex plugin to to play various online streams (mostly Latvian).

test.py 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import os, re, sys, traceback, urllib
  2. from plex_test_case import PlexTestCase, PlexCall
  3. from Framework.api.objectkit import ObjectContainer
  4. from content.util import stream_type
  5. import syspath
  6. #for f in syspath.folders:
  7. def get_content(data, title="Title"):
  8. if not data.startswith("search"):
  9. data = data.replace("/", "%2F")
  10. data = urllib.quote(data)
  11. status, headers, body = t.request(u'/video/playstream/%s?title=%s' % (data, title))
  12. else: # Search object
  13. query = raw_input("Search: ")
  14. data = data.format(query)
  15. status, headers, body = t.request(u'/video/playstream/%s&query=%s' % (data, query))
  16. #print body
  17. #result = re.findall('title="([^"]+)"\s+thumb="([^"]+)"\s+key="([^"]+)"\s+summary="([^"]+)"', body)
  18. result = re.findall('<(\w+)\s(.+?)/>', body)
  19. result2 = []
  20. for item0 in result:
  21. item_type = item0[0]
  22. data2 = re.search('key="(.+?)"', item0[1]).group(1) if re.search('key="(.+?)"',item0[1]) else ""
  23. data2 = data2.replace("/video/playstream/", "")
  24. if not data2.startswith("search"):
  25. data2 = data2.split("?")[0]
  26. data2 = urllib.unquote(data2)
  27. data2 = data2.replace("%2F", "/")
  28. title = re.search('title="(.+?)"', item0[1]).group(1) if re.search('title="(.+?)"',item0[1]) else ""
  29. desc = re.search('summary="(.+?)"', item0[1]).group(1) if re.search('summary="(.+?)"',item0[1]) else ""
  30. result2.append((title, data2, "", desc, item_type))
  31. return result2
  32. def get_streams(data, title="Title"):
  33. data = data.replace("/", "%2F")
  34. data = urllib.quote(data)
  35. status, headers, body = t.request(u'/video/playstream/%s?title=%s' % (data, title))
  36. print body
  37. #TODO
  38. return []
  39. # os.environ["PLEXBUNDLEDPLUGINSPATH"] = r"C:\Data\Programming\Plex"
  40. os.environ["PLEXLOCALAPPDATA"] = r"C:\Data\Programming\Plex"
  41. t = PlexCall()
  42. #for item in get_content("config::home", "Home"):
  43. # print item
  44. if len(sys.argv)>1:
  45. data= sys.argv[1]
  46. else:
  47. data = "config::home"
  48. #options = sources.options_read("ltc")
  49. #print options
  50. history = []
  51. cur = ("Home",data,None,None)
  52. content = get_content(cur[1])
  53. exit_loop = False
  54. while True:
  55. print "\n======================================================="
  56. print "data= ", cur[1]
  57. print "======================================================="
  58. for i,item in enumerate(content):
  59. s = "%i: %s - %s %s"%(i,item[0],item[1],item[2])
  60. print s #.encode(sys.stdout.encoding,"replace")
  61. while True:
  62. a = raw_input("Enter number, (-) for download, q for exit: ")
  63. if a in ("q","Q","x","X"):
  64. exit_loop = True
  65. print "Exiting"
  66. break
  67. try:
  68. n = int(a)
  69. break
  70. except:
  71. print "Not number!"
  72. if exit_loop: break
  73. download = False
  74. if n<0:
  75. n = abs(n)
  76. download = True
  77. cur2 = content[n]
  78. data0 = cur2[1].split("::")[1] if "::" in cur2[1] else cur2[1]
  79. if not data0:
  80. pass
  81. # elif cur2[1] == "back":
  82. # cur = history.pop()
  83. elif cur2[4] == "Video": #is_video(cur2[1]):
  84. if stream_type(cur2[1]):
  85. stream = util.item()
  86. stream["url"] = cur2[1]
  87. stream["name"] = cur2[0]
  88. streams = [stream]
  89. else:
  90. try:
  91. if not download:
  92. streams = get_streams(cur2[1])
  93. else:
  94. stream = util.item()
  95. stream["url"] = cur2[1]
  96. stream["name"] = cur2[0]
  97. stream["url"] = util.streamproxy_encode2(stream["url"])
  98. print stream["url"]
  99. streams = [stream]
  100. except Exception as e:
  101. print unicode(e)
  102. traceback.print_exc()
  103. streams = []
  104. if streams:
  105. if not download:
  106. util.play_video(streams)
  107. else:
  108. #urlp = util.streamproxy_encode2(streams[0]["url"])
  109. #print urlp
  110. #util.player(urlp)
  111. #Downloader.download_video(streams)
  112. pass
  113. else:
  114. print "**No stream to play - %s "%(
  115. cur2[1])
  116. raw_input("Press any key")
  117. #import os
  118. #os.system('"c:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%s"'%cur2[1])
  119. else:
  120. if "{0}" in cur2[1]:
  121. a = raw_input("Enter value:")
  122. cur2 = (cur2[0],cur2[1].format(a),cur2[2],cur2[3])
  123. history.append(cur)
  124. cur = cur2
  125. try:
  126. # Regular item
  127. content = get_content(cur[1])
  128. except Exception as e:
  129. print unicode(e)
  130. traceback.print_exc()
  131. raw_input("Continue?")