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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. #!/usr/bin/env python
  2. # coding=utf8
  3. #
  4. # This file is part of PlayStream - enigma2 plugin to play video streams from various sources
  5. # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
  6. # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
  7. #
  8. try:
  9. import json
  10. except:
  11. import simplejson as json
  12. import requests, urlparse, urllib
  13. import datetime, time,re, sys,os
  14. from collections import OrderedDict
  15. from SourceBase import SourceBase
  16. try:
  17. import util
  18. except:
  19. parent = os.path.dirname(os.path.abspath(__file__))
  20. parent = os.sep.join(parent.split(os.sep)[:-1])
  21. sys.path.insert(0,parent)
  22. import util
  23. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  24. class Source(SourceBase):
  25. def __init__(self,language="en"):
  26. self.name = "viaplay"
  27. self.title = "viaplay.lv"
  28. self.img = "https://yt3.ggpht.com/-noVdjbNR-V8/AAAAAAAAAAI/AAAAAAAAAAA/yZ9XNP5urLY/s900-c-k-no-mo-rj-c0xffffff/photo.jpg"
  29. self.desc = "Viaplay.lv saturs"
  30. self.url = "https://viaplay.lv/"
  31. self.headers = headers2dict("""
  32. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
  33. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  34. Connection: keep-alive
  35. Upgrade-Insecure-Requests: 1
  36. """)
  37. #self.language=language
  38. cur_directory = os.path.dirname(os.path.abspath(__file__))
  39. self.config_file = os.path.join(cur_directory,self.name+".cfg")
  40. self.options = OrderedDict([("user","change_user"),("password","change_password"),("device","")])
  41. self.options_read()
  42. self.device = self.options["device"]
  43. self.r = None # requests
  44. self.play_session = None
  45. self.s = None
  46. def login(self,user="",password=""):
  47. self.options_read()
  48. if not user: user=self.options["user"]
  49. if not password: password = self.options["password"]
  50. self.s = requests.Session()
  51. ### Dabu sesijas ID ===
  52. headers = headers2dict("""
  53. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
  54. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  55. Accept-Language: en-US,en;q=0.5
  56. Accept-Encoding: gzip, deflate, br
  57. Referer: https://viaplay.lv/
  58. Cookie: ott_cookies_confirmed=1;
  59. DNT: 1
  60. Connection: keep-alive
  61. Upgrade-Insecure-Requests: 1
  62. """)
  63. r = requests.get(self.url,headers=headers)
  64. if not "PLAY_SESSION" in r.cookies:
  65. return False
  66. self.play_session = r.cookies["PLAY_SESSION"]
  67. self.csrfToken = re.search("csrfToken=(.+)",self.play_session).group(1)
  68. ### Ielogojamies ###
  69. headers = headers2dict("""
  70. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
  71. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  72. Accept-Language: en-US,en;q=0.5
  73. Accept-Encoding: gzip, deflate, br
  74. Referer: https://viaplay.lv/
  75. Cookie: ott_cookies_confirmed=1; PLAY_SESSION=e618c42b377a65021298ff63309d5a907988ed1b-PSESSIONID=b010ea1b-fc5e-4a18-aa15-ebbe8b57b3f0&csrfToken=b4eb35263d9be16ef9f7b2f5d10a8ee99dfe75a8-1478051634814-63682b20f1e7e5579de6d056
  76. DNT: 1
  77. Connection: keep-alive
  78. Upgrade-Insecure-Requests: 1
  79. Content-Type: application/x-www-form-urlencoded
  80. """)
  81. url = "https://viaplay.lv/tdi/login/nav/formular?csrfToken=%s"%self.csrfToken
  82. params = "nav_redirectUri=https%3A%2F%2Fviaplay.lv%2F&nav_email={}&nav_password={}".format(urllib.quote(user),urllib.quote(password))
  83. headers["Cookie"] = "ott_cookies_confirmed=1; PLAY_SESSION=%s;"%self.play_session
  84. if self.device:
  85. headers["Cookie"] += "ott_dids=%s"%self.device
  86. #cookie = dict(PLAY_SESSION=self.play_session,_hjIncludedInSample=1, mobileAppPromo="shown")
  87. r = requests.post(url,params,headers=headers,allow_redirects=False)
  88. if not "Set-Cookie" in r.headers:
  89. self.play_session = None
  90. return False
  91. self.ott = r.cookies["ott_web_sac"]
  92. ### Dabu iekārtas ID ###
  93. if not self.device:
  94. headers = headers2dict("""
  95. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
  96. Accept: application/xml, text/xml, */*; q=0.01
  97. Accept-Language: en-US,en;q=0.5
  98. Accept-Encoding: gzip, deflate, br
  99. Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  100. X-Requested-With: XMLHttpRequest
  101. Referer: https://viaplay.lv/movies/me-and-earl-and-the-dying-girl
  102. DNT: 1
  103. Connection: keep-alive """)
  104. url = "https://viaplay.lv/tdi/account/device/create?_infuse=1&csrfToken=%s"%self.csrfToken
  105. params = "successRedirectUri=https%3A%2F%2Fviaplay.lv%2Fmovies%2F&slotId=&title=Enigma2"
  106. headers["Cookie"] = "PLAY_SESSION=%s; ott_cookies_confirmed=1; ott_web_sac=%s;"%(self.play_session,self.ott)
  107. #cookie = dict(PLAY_SESSION=self.play_session,_hjIncludedInSample=1, mobileAppPromo="shown")
  108. r = requests.post(url,params,headers=headers,allow_redirects=False)
  109. if not ("Set-Cookie" in r.headers and "ott_dids" in r.headers["Set-Cookie"]):
  110. self.play_session = None
  111. return False
  112. self.device = r.cookies["ott_dids"]
  113. self.options["device"] = self.device
  114. self.options_write(self.options)
  115. return True
  116. def logout(self):
  117. return True
  118. def is_logedin(self):
  119. if self.play_session:
  120. return True
  121. else:
  122. return False
  123. def get_video_info(self,vid):
  124. import demjson
  125. ### Dabu strimus ###
  126. headers = headers2dict("""
  127. Host: viaplay.lv
  128. User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/47.0.2526.70 Mobile/13C71 Safari/601.1.46
  129. Accept: application/xml, text/xml, */*; q=0.01
  130. Accept-Language: en-US,en;q=0.5
  131. Accept-Encoding: gzip, deflate, br
  132. X-Requested-With: XMLHttpRequest
  133. DNT: 1
  134. Connection: keep-alive
  135. Referer: https://viaplay.lv/
  136. """)
  137. url = "https://viaplay.lv/prehravac/init?_infuse=1&productId=%s"%vid #t110623
  138. headers["Cookie"] = "ott_cookies_confirmed=1; ott_dids=%s; PLAY_SESSION=%s"%(self.device,self.play_session)
  139. r = requests.get(url,headers=headers,allow_redirects=False)
  140. statuss = re.search("<status>(.+?)</status>", r.content).group(1)
  141. if statuss.lower() <> "ok":
  142. raise Exception(statuss)
  143. #print r.content
  144. m = re.search(r"<!\[CDATA\[\s+var TDIPlayerOptions = (.+?);[\n\t\s]+\]\]>\s+</script>", r.content, re.DOTALL)
  145. if not m:
  146. raise "Can not find stream info"
  147. txt = m.group(1)
  148. txt = re.sub("// .+$", "", txt, flags=re.MULTILINE)
  149. #print txt
  150. #for m in re.finditer("// .+$", txt, re.MULTILINE):
  151. # txt = txt[:m.start()] + txt[m.end():]
  152. #print txt
  153. js = demjson.decode(txt)
  154. return js
  155. #return txt
  156. def get_content(self, data):
  157. print "[%s] get_content:"%self.name, data
  158. source,data,path,plist,clist,params,qs = self.parse_data(data)
  159. content=[]
  160. content.append(("..return", "back","","Return back"))
  161. if clist=="home":
  162. content.extend([
  163. ("Search", "viaplay::search-results-all?query={0}",self.img,"Meklēt"),
  164. ("Filmas", "viaplay::movies",self.img,"Filmas"),
  165. ("Seriāli", "viaplay::series",self.img,"Seriāli"),
  166. ("Bērniem", "viaplay::kids",self.img,"Bērniem"),
  167. ("Dokumentalās filmas", "viaplay::documentary",self.img,"Dokumentalās filmas"),
  168. ("Sports", "viaplay::live",self.img,"Sports"),
  169. ])
  170. return content
  171. ### Meklēt ###
  172. elif clist=="search-results-all":
  173. url = "https://viaplay.lv/"+data
  174. r = self._http_request(url)
  175. result = re.findall(r'<div id="product-(\w+)".+?<a href="([^"]+)">.+?<img data-srcset="([^ ]+).+?alt="([^"]+)">.+?<h3 class="is-size-h6">([^<]+)</h3>.*?<p>([^<]+).+?</p>.+?<p class="promo-notice">([^<]+)</p>.+?<p class="info">([^<]+)</p>', r, re.DOTALL)
  176. for item in result:
  177. vid = item[0]
  178. data2 = item[1].replace("https://viaplay.lv/","")
  179. img = item[2]
  180. ep = item[3]
  181. title= item[4]
  182. seas = item[5].replace("\n","").replace("\t","")
  183. desc = item[6]
  184. desc2 = item[7]
  185. if ep==title:
  186. title = "%s (%s)"%(title,seas)
  187. else:
  188. title = "%s - %s%s"%(title,seas,ep)
  189. desc = "%s\n%s\n%s"%(title,desc2,desc)
  190. content.append((title,self.name+"::"+data2,img,desc))
  191. return content
  192. ### Sadalas ##
  193. elif data in ["movies","series","kids","documentary"]:
  194. r = self._http_request(self.url+data)
  195. # https://viaplay.lv/tdi/movies/next?sections[]=MOVIES&genres[]=a3591&sort[]=latest&offset=0
  196. # https://viaplay.lv/tdi/series/next?sections[]=SERIES&sort[]=latest&offset=0
  197. # https://viaplay.lv/tdi/kids/next?sections[]=KIDS&cat[]=SERIES&cat[]=MOVIE&sort[]=latest&offset=18
  198. # https://viaplay.lv/kids?sections[]=KIDS&cat[]=SERIES&sort[]=latest
  199. sections = {"movies":"MOVIES","series":"SERIES","kids":"KIDS","documentary":"DOCUMENTS"}
  200. nosaukums = {"movies":"Flmas","series":"Seriāli","kids":"Bērnu","documentary":"Dokumentalās"}
  201. #availability = {"new":"jaunākās","last":"pēdējā iespēja"}
  202. sort = OrderedDict([("latest","jaunākais"),("title","pēc nosaukuma"),("popular","pēc popularitātes"),("year","pēc gada")])
  203. for s in sort:
  204. if data in ("movies","series"):
  205. title = "%s - %s"%(nosaukums[data],sort[s])
  206. data2 = "%s/next?sections[]=%s&sort[]=%s"%(data,sections[data],s)
  207. content.append((title,self.name+"::"+data2,self.img,title))
  208. else:
  209. title = "%s filmas - %s"%(nosaukums[data],sort[s])
  210. data2 = "%s/next?sections[]=%s&cat[]=MOVIE&sort[]=%s"%(data,sections[data],s)
  211. content.append((title,self.name+"::"+data2,self.img,title))
  212. title = "%s seriāli - %s"%(nosaukums[data],sort[s])
  213. data2 = "%s/next?sections[]=%s&cat[]=SERIES&sort[]=%s"%(data,sections[data],s)
  214. content.append((title,self.name+"::"+data2,self.img,title))
  215. # Pievienojam žanru sarakstu
  216. result = re.findall(r'name="genres\[\]" value="([^"]+)">.+?class="">([^<]+)</label>', r, re.DOTALL)
  217. for item in result:
  218. s = "latest"
  219. genre = item[1].replace("&amp;","&")
  220. title = "%s: %s"%(nosaukums[data],genre)
  221. data2 = "%s/next?sections[]=%s&genres[]=%s&sort[]=%s"%(data,sections[data],item[0],s)
  222. content.append((title,self.name+"::"+data2,self.img,title))
  223. return content
  224. ### Filmu/seriālu/sēriju saraksts ###
  225. elif clist in ("movies","series","kids","documentary") and plist[1] == "next":
  226. url = "https://viaplay.lv/tdi/"+data
  227. r = self._http_request(url)
  228. if clist == "series" and "season" in qs:
  229. result = re.findall(r'<div id="product-(\w+)".+?<a href="([^"]+)">.+?<img data-srcset="([^ ]+).+?alt="([^"]+)">.+?<h3 class="is-size-h6">([^<]+)</h3>.*?<p>([^<]+).+?</p>.+?<p class="promo-notice">([^<]+)</p>.+?<p class="info">([^<]+)</p>', r, re.DOTALL)
  230. for item in result:
  231. vid = item[0]
  232. data2 = item[1].replace("https://viaplay.lv/","")
  233. img = item[2]
  234. ep = item[3]
  235. title= item[4]
  236. seas = item[5]
  237. desc = item[6]
  238. desc2 = item[7]
  239. title = "%s - %s%s"%(title,seas,ep)
  240. desc = "%s\n%s\n%s"%(title,desc2,desc)
  241. content.append((title,self.name+"::"+data2,img,desc))
  242. else: # filmas
  243. result = re.findall(r'<div id="product-(\w+)".+?<a href="([^"]+)">.+?<img data-srcset="([^ ]+).+?alt="([^"]+)">.+?<p>([^<]+)</p>.+?<p class="promo-notice">([^<]+).+?<p class="is-strong detail">(.+?)</p>.+?<p class="info">([^<]+)</p>', r, re.DOTALL)
  244. for item in result:
  245. vid = item[0]
  246. data2 = item[1].replace("https://viaplay.lv/","")
  247. img = item[2]
  248. title = item[3]
  249. year = item[4]
  250. year = year.replace("\n","").replace("\t","")
  251. title = title +"(%s)"%year
  252. desc= item[5]
  253. genre = re.findall(">([^<]+)<", item[6], re.DOTALL)
  254. genre = ("".join(genre)).replace("&amp;","&")
  255. desc2 = item[7]
  256. desc = "%s\n%s\n%s"%(genre,desc2,desc)
  257. content.append((title,self.name+"::"+data2, img,desc))
  258. m = re.search(r"data\('href', 'https://viaplay\.lv/tdi/([^']+)'\)", r, re.DOTALL)
  259. if m:
  260. data2 = m.group(1)
  261. content.append(("Next page",self.name+"::"+data2,img,"Next page"))
  262. return content
  263. ### Seriāls ###
  264. elif clist == "series" and len(plist)==2:
  265. url = "https://viaplay.lv/"+data
  266. r = self._http_request(url)
  267. result = re.findall(r'<li>.*?<a class="tdi" href="https://viaplay\.lv/([^"]+)" data-related-ancestor="\.js-tdi-items-filter-and-items">([^<]+)</a>.*?</li>', r, re.DOTALL)
  268. for item in result:
  269. title = item[1]
  270. data2 = item[0]
  271. data2 = data2.replace("series/","series/next/")
  272. data2 = data2+"&sort[]=ord"
  273. #series/littlest-pet-shop?season=t6821
  274. #series/next/peppa-pig?season=t8430
  275. # &sort[]=ord
  276. if "availability=" in data2: continue
  277. content.append((title,self.name+"::"+data2,self.img,title)) #TODO bilde
  278. return content
  279. def is_video(self,data):
  280. source,data,path,plist,clist,params,qs = self.parse_data(data)
  281. if clist in ("movies","documentary","kids") and len(plist)>1 and plist[1]<>"next":
  282. return True
  283. elif clist == "series" and len(plist)>1 and plist[1] == "episode":
  284. return True
  285. else:
  286. return False
  287. def get_streams(self, data):
  288. print "[viaplay] get_streams:", data
  289. if not self.is_video(data):
  290. return []
  291. source,data,path,plist,clist,params,qs = self.parse_data(data)
  292. if not self.is_logedin():
  293. self.login()
  294. if not self.is_logedin():
  295. raise Exception("Could not login to viaplay.lv, check username/password in options")
  296. streams = []
  297. url = "https://viaplay.lv/"+data
  298. r = self._http_request(url)
  299. if clist=="series":
  300. m = re.search(r'<h1 class="is-bottom-sticked is-size-h2">(.+?)</h1>.*?<h2 class="is-size-h4">.*?<p class="is-size-h6 is-strong is-bottom-sticked">(.+?)<div class="toggler-content">\s+<p>(.+?)</p>', r, re.DOTALL)
  301. if not m:
  302. raise Exception("Problem getting video information")
  303. title = m.group(1).replace("\n"," ").replace("\t","").strip()
  304. title = re.sub("<[^>]+>","",title).strip()
  305. desc2 = m.group(2).replace("\n"," ").replace("\t","").strip()
  306. desc2 = re.sub("<[^>]+>","",desc2).strip()
  307. desc = m.group(3)
  308. desc = "%s\n%s"%(desc2,desc)
  309. vid = re.search('data-productid="(\w+)"',r).group(1)
  310. else:
  311. m = re.search(r'<h1 class="is-strong is-bottom-sticked is-size-h2" jnp-id="(\w+)">([^<]+)</h1>.*?<h2 class="is-strong is-size-h4">([^<]+)</h2>.*?<p class="is-size-h6 is-strong is-bottom-sticked">(.+?)<div class="toggler-content">\s+<p>(.+?)</p>', r, re.DOTALL)
  312. if not m:
  313. raise Exception("Problem getting video information")
  314. title = m.group(2).strip()
  315. title2 = m.group(3).strip()
  316. title = "%s | %s"%(title,title2)
  317. desc = m.group(5).strip()
  318. desc2 = m.group(4).strip()
  319. desc2 = re.sub("<[^>]+>","",desc2)
  320. desc2 = desc2.replace("\n"," ").replace("\t","")
  321. desc = "%s\n%s"%(desc2,desc)
  322. vid = m.group(1)
  323. js = self.get_video_info(vid)
  324. #for m in re.finditer(r"lang: '(?P<lang>\w+)',\s+src: '(?P<url>[^']+)',\s+type: '(?P<mime>[^']+)',\s+drm: \[(?P<drm>.+?)\]\s*\}", r, re.DOTALL):
  325. if not js:
  326. return []
  327. tracks = js["tracks"]
  328. #if not tracks["HLS"]:
  329. # raise Exception("Encrypted DASH playing not yet implemented")
  330. captions = []
  331. llist = ["fr","en","ru","lv"]
  332. for st in js["plugins"]["settings"]["subtitles"]:
  333. sub = {}
  334. sub["url"] = st["src"]
  335. sub["lang"] = st["srclang"]
  336. sub["name"] = st["label"]
  337. sub["type"] = "vtt"
  338. sub["order"] = llist.index(sub["lang"])*10 if sub["lang"] in llist else 0
  339. captions.append(sub)
  340. captions = sorted(captions,key=lambda item: item["order"],reverse=True)
  341. for s in tracks["HLS"] if tracks["HLS"] else tracks["DASH"] :
  342. stype = "DASH" if "dash" in s["type"] else "HLS"
  343. if "drm" in s: ###
  344. # TODO, encrypted stream
  345. continue
  346. url = s["src"]
  347. urlp = util.streamproxy_encode(s["src"])
  348. stream = util.item()
  349. stream["url"]=urlp
  350. stream["lang"]=s["lang"]
  351. stream["quality"]="variant"
  352. stream["bitrate"]= "1000000"
  353. stream["name"]= title
  354. stream["desc"]=desc
  355. stream["type"]=stype
  356. stream["subs"] = captions
  357. print urlp
  358. if stype=="DASH": streams.append(stream)
  359. if stype == "HLS": # izvelkam individuālos strimus
  360. r = requests.get(url)
  361. result = re.findall("#EXT-X-STREAM-INF:BANDWIDTH=(\d+),RESOLUTION=(\d+x\d+)\n(\w+.m3u8)", r.content)
  362. if not result:
  363. continue
  364. for s2 in result:
  365. ### TODO vajag lietot cookie ar tokenu no playlista requesta
  366. if "set-cookie" in r.headers:
  367. headers = {"Cookie":r.headers["set-cookie"]}
  368. else:
  369. headers={}
  370. #url2 = re.sub(r"(http.*://.+/)\w+.m3u8", r"\1"+s2[2], url)
  371. url2 = "/".join(url.split("/")[:-1])+"/"+s2[2]
  372. #r2 = requests.get(url2,headers=headers)
  373. #if "set-cookie" in r2.headers:
  374. #headers = {"Cookie":r2.headers["set-cookie"]}
  375. #else:
  376. #headers={}
  377. url2p=util.streamproxy_encode(url2,headers)
  378. stream = util.item()
  379. stream["url"]=url2p
  380. stream["lang"]=s["lang"]
  381. stream["quality"]="%s"%(s2[1])
  382. stream["name"]= title
  383. stream["desc"]=desc
  384. stream["bitrate"]=s2[0]
  385. stream["type"]="DASH" if "dash" in s["type"] else "HLS"
  386. streams.append(stream)
  387. ### TODO - sakārtot sarakstu, lai pirmais ir labakais video
  388. qlist = ["","512","640","758","1024","variant"]
  389. llist = ["lt","et","fr","en","ru","lv"]
  390. for s in streams:
  391. lv = llist.index(s["lang"])*10000000 if s["lang"] in llist else 0
  392. #qv=qlist.index(s["quality"]) if s["quality"] in qlist else 0
  393. qv = int(s["bitrate"]) if s["bitrate"] else 0
  394. s["order"] = lv+qv
  395. #print s["lang"],s["quality"],s["bitrate"],s["order"]
  396. streams = sorted(streams,key=lambda item: item["order"],reverse=True)
  397. return streams
  398. def call(self, data,params = None, headers=None):
  399. if not headers: headers = self.headers
  400. #if not lang: lang = self.country
  401. url = "https://viaplay.lv/tdi/" + data
  402. content = self._http_request(url, params, headers)
  403. return content
  404. if __name__ == "__main__":
  405. if len(sys.argv)>1:
  406. data= sys.argv[1]
  407. else:
  408. data = "kids/child-and-karlson"
  409. c = Source()
  410. print "login: %s"%c.login()
  411. if "/" in data:
  412. streams = c.get_streams(data)
  413. util.play_video(streams)
  414. else:
  415. vinfo = c.get_video_info(data)
  416. if "HLS" in vinfo["tracks"] and vinfo["tracks"]["HLS"]:
  417. url = vinfo["tracks"]["HLS"][0]["src"]
  418. urlp = util.streamproxy_encode(url)
  419. util.player(urlp)
  420. else:
  421. print "No HLS stream"
  422. sys.exit()
  423. r = requests.get("https://viaplay.lv/movies?sections[]=MOVIES")
  424. result = re.findall(r'<div id="product-(\w+)".+?<a href="([^"]+)">.+?<img data-srcset="([^ ]+).+?alt="([^"]+)">.+?<p class="promo-notice">([^<]+)<', r.content, re.DOTALL)
  425. for item in result:
  426. vid = item[0]
  427. url = item[1]
  428. img = item[2]
  429. title = item[3]
  430. desc= item[4]
  431. print "\n%s (%s):"%(title,vid)
  432. vinfo = c.get_video_info(vid)
  433. if "HLS" in vinfo["tracks"]:
  434. for s in vinfo["tracks"]["HLS"]:
  435. print "HLS %s: \n%s"%(s["lang"],s["src"])
  436. if "DASH" in vinfo["tracks"]:
  437. for s in vinfo["tracks"]["DASH"]:
  438. print "DASH %s: \n%s"%(s["lang"],s["src"])
  439. #except Exception,ex:
  440. #print ex.message
  441. #content = c.get_content(data)
  442. #for item in content:
  443. # print item
  444. pass