import sys
import re
import io, gzip
import subprocess
import base64, random
import httplib
# rai.py v0.3
#
# USAGE python rai.py [-vlcdir=
][-uagent=] [(channel|video_on_demand)]
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Notice:
# channel = RaiUno | RaiDue | RaiTre | RaiQuattro
# RaiNews24 | RaiSport+ | RaiStoria | RaiEdu | RaiGulp
# RaiSatExtra | RaiSatPremium | RaiSatCinema | RaiSatYoyo
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Change Log
#
# + 0.3
# - Add Video-On-demand support
# - Update of key in encode2 function
# - Bugfix in encode2 fucntion: j-index rotation is setted by key length
# - Refactoring
#
# + 0.2
# - Update of ttAuth generation algorithm
#
# + 0.1
# - Creation of ttAuth
vlcdir = ""
isVoD = False
stream = "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=983"
agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10"
urls = {
"RaiUno": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=983",
"RaiDue": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=984",
"RaiTre": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=986",
"RaiQuattro": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=75708",
"RaiCinque": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=72382",
"RaiNews24": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=1",
"RaiSport+": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=4145",
"RaiStoria": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=24269",
"RaiEdu": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=24268",
"RaiGulp": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=4119",
"RaiSatExtra": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=72382",
"RaiSatPremium": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=72383",
"RaiSatCinema": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=72381",
"RaiSatYoyo": "http://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=72384",
}
def videoURL(pageURL):
re_page = "^http://(?P[a-zA-Z0-9]*\.([a-zA-Z0-9]*\.)+[a-zA-Z0-9]*)(?P/[\w\-\+\~\%\#\.\/\?\=]*)"
match_page = re.match(re_page, pageURL).groupdict()
request = httplib.HTTPConnection(match_page["host"])
request.putrequest("POST", match_page["path"])
request.putheader("User-Agent", agent)
request.putheader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
request.putheader("Accept-Language", "it-it,it;q=0.8,en-us;q=0.5,en;q=0.3")
request.putheader("Accept-Encoding", "gzip,deflate")
request.putheader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
request.putheader("Keep-Alive", "115")
request.putheader("Connection", "keep-alive")
request.putheader("Cookie", "volume=0,5; ns_cookietest=true; ns_session=true")
request.putheader("Cache-Control", "max-age=0")
request.endheaders()
response = request.getresponse().read()
request.close()
page = str(gzip.GzipFile(fileobj=io.BytesIO(response)).read(), "utf8")
return re.search("(?P