123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- # coding: utf-8
- import sys, os, os.path, re, sys
- import urllib,urllib2
- from xml.sax.saxutils import unescape,escape
- from urllib import quote, unquote
-
- user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; da-dk) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
- headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
-
- ########################################################################
- class LattelecomTV(object):
- """www.lattelecom.tv video server handling object"""
-
- #----------------------------------------------------------------------
- def __init__(self):
- self.name = "ltc"
- self.title = "lattelecom.tv"
- self.headers = headers2dict("""
- Host: m.lattelecom.tv
- User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile Safari/600.1.4
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- DNT: 1
- Connection: keep-alive""")
-
-
- #----------------------------------------------------------------------
- def login(self,user,password):
- """Login in to site, create session cookies"""
- url0 = "https://m.lattelecom.tv"
- class NoRedirectHandler(urllib2.HTTPRedirectHandler):
- def http_error_302(self, req, fp, code, msg, headers):
- infourl = urllib.addinfourl(fp, headers, req.get_full_url())
- infourl.status = code
- infourl.code = code
- return infourl
- http_error_300 = http_error_302
- http_error_301 = http_error_302
- http_error_303 = http_error_302
- http_error_307 = http_error_302
-
- # Dabūjam sesijas id un url_gif, kas redirektējas uz auth_url
- headers = headers2dict("""
- Host: m.lattelecom.tv
- User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile Safari/600.1.4
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- DNT: 1
- Connection: keep-alive
- """)
- response = urllib2.urlopen(urllib2.Request(url0+"/authorization", headers=headers))
- session_id = response.headers["set-cookie"].split(";")[0]
- html = response.read()
- url_gif = url0 + re.search('(/auth/\d+.gif)', html).group(1)
-
- # Dabūtjam auth_url
- headers = headers2dict("""
- Host: m.lattelecom.tv
- User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile Safari/600.1.4
- Accept: image/png,image/*;q=0.8,*/*;q=0.5
- Accept-Language: en-US,en;q=0.5
- Accept-Encoding: gzip, deflate
- DNT: 1
- Referer: https://m.lattelecom.tv/authorization
- Connection: keep-alive
- """)
- headers["Cookie"] = session_id
- urllib2.install_opener(urllib2.build_opener(NoRedirectHandler()))
- response = urllib2.urlopen(urllib2.Request(url_gif, headers=headers))
- if response.code == 302:
- url_auth = response.headers["location"]
- else:
- self.error = u"auth.gif nenostrādāja"
- #raise u"auth.gif nenostrādāja"
- return False
-
- # Pierakstāmies iekš auth.lattelecom.lv
- headers = headers2dict("""
- Host: auth.lattelecom.lv
- User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- Accept-Encoding: gzip, deflate
- DNT: 1
- Referer: http://m.lattelecom.tv/authorization
- Connection: keep-alive
- """)
- response = urllib2.urlopen(urllib2.Request(url_auth, headers=headers))
- if not response.code == 302:
- self.error = u"pierakstīšanās auth.lattelecom.lv nenostrādāja"
- return False
- #raise "pierakstīšanās auth.lattelecom.lv nenostrādāja"
-
- # nolasām auth_gif
- ## headers = headers2dict("""
- ## Host: m.lattelecom.tv
- ## User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
- ## Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- ## Accept-Language: en-US,en;q=0.5
- ## Accept-Encoding: gzip, deflate
- ## DNT: 1
- ## Referer: http://m.lattelecom.tv/authorization
- ## """)
- ## headers["Cookie"] = session_id
- ## response = urllib2.urlopen(urllib2.Request(url_gif, headers=headers))
- ## if not response.code == 200:
- ## raise u"kļūda lasot auth_gif"
-
- # Mēģinam ielogoties
- headers = headers2dict("""
- Host: m.lattelecom.tv
- User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-US,en;q=0.5
- Accept-Encoding: deflate
- DNT: 1
- Referer: http://m.lattelecom.tv/authorization
- Connection: keep-alive
- Content-Type: application/x-www-form-urlencoded""")
- headers["Cookie"] = session_id
- data = "login=yes&email=%s&passw=%s"%(user,password)
- req = urllib2.Request(url0+"/authorization", data, headers)
- response = urllib2.urlopen(req)
- #with open("auth.htm","w") as f: f.write(response.read())
- if not response.code == 302:
- self.error = u"kļūda ielogojoties"
- #raise u"kļūda ielogojoties"
- return False
- mobtv = response.headers["set-cookie"].split(";")[0]
- if not mobtv.split("=")[0]=="mobtv_cache":
- #raise "nav mobtv cookie!"
- self.error = "nav mobtv cookie!"
- return False
-
- # atveram /account
- ## headers = headers2dict("""
- ## Host: m.lattelecom.tv
- ## User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
- ## Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- ## Accept-Language: en-US,en;q=0.5
- ## Accept-Encoding: deflate
- ## DNT: 1
- ## Referer: http://m.lattelecom.tv/authorization
- ## Connection: keep-alive """)
- ## headers["Cookie"] = "%s; %s"%(session_id,mobtv)
- ## response = urllib2.urlopen(urllib2.Request(url0+"/account", headers=headers))
- ## if not response.code == 302:
- ## raise u"kļūda atverot /account"
-
- # atveram /profils
- ## headers = headers2dict("""
- ## Host: m.lattelecom.tv
- ## User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
- ## Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- ## Accept-Language: en-US,en;q=0.5
- ## Accept-Encoding: deflate
- ## DNT: 1
- ## Referer: http://m.lattelecom.tv/authorization
- ## Connection: keep-alive
- ## """)
- ## headers["Cookie"] = "%s; %s"%(session_id,mobtv)
- ## response = urllib2.urlopen(urllib2.Request(url0+"/profils", headers=headers))
- ## if not response.code == 200:
- ## raise u"kļūda atverot /profils"
- ## with open("profils.htm","w") as f: f.write(response.read())
-
- self.mobtv_cache = mobtv
- self.session_id = session_id
- self.error = ""
- return True
-
- #----------------------------------------------------------------------
- def get_tv_channels(self,):
- """Get tv channels list"""
- url = "https://m.lattelecom.tv/tiesraide"
- response = urllib2.urlopen(urllib2.Request(url, headers=self.headers))
- html = response.read()
- channels = re.findall(r'(?si)data-url="/tiesraide/(.*?)"><div title="(.*?)" class="channel-placeholder" style="width: 131px; height: 131px; background-image:url\(/media/imse/105x105s/channels/(.*?)\)', html)
- for i in range(len(channels)):
- channels[i]=[channels[i][0],channels[i][1],"https://m.lattelecom.tv/media/imse/100x100s/channels/"+channels[i][2]]
- return channels
-
- #----------------------------------------------------------------------
- def get_tv_url(self,video_id):
- """Get m3u8 url for given live tv channel"""
- url = "https://m.lattelecom.tv/tiesraide/%s"%video_id
- headers = self.headers
- headers["Cookie"] = "%s; %s; _hjIncludedInSample=0; MobBitr=1; MobRentBitr=hq; MobRentLang=lv;"%(self.session_id,self.mobtv_cache)
- response = urllib2.urlopen(urllib2.Request(url, headers=headers))
- html = response.read()
- m3u8 = re.search('x-mpegURL" src="(.*?)"', html).group(1) if "x-mpegURL" in html else ""
- return unescape(m3u8)
-
- #----------------------------------------------------------------------
- def get_noma_url(self,video_id,quality="hq",language="lv"):
- """Get m3u8 url for given rental video"""
- url = "https://m.lattelecom.tv/free_origin?show_origin=1&type=4&video_url=%s&bitrate=%s&lng=%s"%(video_id,quality,language)
- headers = self.headers
- headers["Cookie"] = "%s; %s; MobRentBitr=%s; MobBitr=1; MobRentLang=%s"%(self.session_id,self.mobtv_cache,quality,language)
- response = urllib2.urlopen(urllib2.Request(url, headers=headers))
- m3u8 = response.read()
- return unescape(m3u8)
-
- #----------------------------------------------------------------------
- def get_arhivs_url(self,video_id):
- """Get m3u8 url for given archive video"""
- url = "https://m.lattelecom.tv/free_origin?show_origin=1&type=arhivs&event_id=%s&bitrate=mhq"%video_id
- headers = self.headers
- headers["Cookie"] = "%s; %s; MobBitr=1; "%(self.session_id,self.mobtv_cache)
- response = urllib2.urlopen(urllib2.Request(url, headers=headers))
- m3u8 = response.read()
- return unescape(m3u8)
-
- def create_bouquet(ltc,fname,bname):
- import codecs
- import enigma2_api
- e2 = enigma2_api.DBServices()
- e2.create_bouqet(self.name, self.title)
- with open(fname,"w") as f:
- f.write("#NAME %s\n"%bname)
- channels = ltc.get_tv_channels()
- for i,(ch,title,picon_url) in enumerate(channels):
- url=ltc.get_tv_url(ch)
- print title #, url, picon_url
- sref = "1:0:1:%i:777:777:0:0:0:0:"%i
- #sref = e2.get_service_by_name(title.lower())
- #if sref:
- # sref = sref[0]["sref"]
- f.write("#SERVICE %s%s:%s\n"%(sref,quote(url),title))
- f.write("#DESCRIPTION %s\n"%title)
- pass
-
- if __name__ == "__main__":
- #sys.exit(main(sys.argv))
- #import enigma2_api
- #e2 = enigma2_api.DBServices()
- ltc = LattelecomTV()
- if not ltc.login("ivars777","kaskade7"):
- print "Error during login"
- sys.exit()
- else:
- print 'Logged in'
- service_path = "enigma2" if sys.platform=="win32" else "/etc/enigma2"
- create_bouquet(ltc, os.path.join(service_path,"userbouquet.ltc.tv"), "lattelecom.tv")
-
-
|