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

viaplay.py 22KB

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