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

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