Kaputten Cookie umgehen
This commit is contained in:
parent
c780833608
commit
4ef5d42b91
1 changed files with 59 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/local/bin/python
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.47 2012/07/27 20:19:03 stb Exp $
|
# $Schlepperbande: src/tivomirror/tivomirror,v 1.48 2012/08/23 19:12:32 stb Exp $
|
||||||
#
|
#
|
||||||
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||||
# zu transkodieren.
|
# zu transkodieren.
|
||||||
|
@ -11,6 +11,7 @@ import anydbm
|
||||||
import cookielib
|
import cookielib
|
||||||
import datetime
|
import datetime
|
||||||
import getopt
|
import getopt
|
||||||
|
import mechanize
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
|
@ -37,21 +38,26 @@ includes['Breaking Bad'] = 1
|
||||||
includes['Castle'] = 1
|
includes['Castle'] = 1
|
||||||
includes['Dirty Jobs'] = 1
|
includes['Dirty Jobs'] = 1
|
||||||
includes['Family Guy'] = 1
|
includes['Family Guy'] = 1
|
||||||
includes['Flying Wild Alaska'] = 1
|
|
||||||
includes['Futurama'] = 1
|
includes['Futurama'] = 1
|
||||||
includes["John Oliver's New York Stand-Up Show"] = 1
|
includes["John Oliver's New York Stand-Up Show"] = 1
|
||||||
includes['Late Show With David Letterman'] = 1
|
includes['Late Show With David Letterman'] = 1
|
||||||
includes['Louie'] = 1
|
includes['Louie'] = 1
|
||||||
includes['Mad Men'] = 1
|
includes['Mad Men'] = 1
|
||||||
|
includes['Mockingbird Lane'] = 1
|
||||||
includes['Modern Family'] = 1
|
includes['Modern Family'] = 1
|
||||||
includes['MythBusters'] = 1
|
includes['MythBusters'] = 1
|
||||||
|
includes['NCIS'] = 1
|
||||||
|
includes['NFL Football'] = 1
|
||||||
includes['Sesame Street'] = 1
|
includes['Sesame Street'] = 1
|
||||||
includes['The Big Bang Theory'] = 1
|
includes['The Big Bang Theory'] = 1
|
||||||
includes['The Colbert Report'] = 1
|
includes['The Colbert Report'] = 1
|
||||||
includes['The Daily Show With Jon Stewart'] = 1
|
includes['The Daily Show With Jon Stewart'] = 1
|
||||||
includes['The Late Late Show With Craig Ferguson'] = 1
|
includes['The Late Late Show With Craig Ferguson'] = 1
|
||||||
includes['Unchained Reaction'] = 1
|
|
||||||
includes["Wait, Wait... Don't Tell Me! A Royal Pain in the News"] = 1
|
includes['The 55th Annual Grammy Awards'] = 1;
|
||||||
|
includes['Live From the Red Carpet: The 2013 Grammy Awards'] = 1
|
||||||
|
includes['Countdown to the Red Carpet: The 2013 Grammy Awards'] = 1
|
||||||
|
|
||||||
|
|
||||||
class flushfile(object):
|
class flushfile(object):
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
|
@ -65,14 +71,15 @@ try:
|
||||||
os.makedirs("tivo")
|
os.makedirs("tivo")
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
pwmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
|
||||||
authhandler = urllib2.HTTPDigestAuthHandler(pwmgr)
|
|
||||||
#cookiejar = cookielib.MozillaCookieJar(os.getcwd() + "/tivo/.cookies.txt")
|
|
||||||
cookiejar = cookielib.MozillaCookieJar(os.path.expanduser("~") + "/.tivocookies.txt")
|
|
||||||
opener = urllib2.build_opener(authhandler, urllib2.HTTPCookieProcessor(cookiejar))
|
|
||||||
urllib2.install_opener(opener)
|
|
||||||
tmp = "/tmp"
|
tmp = "/tmp"
|
||||||
|
|
||||||
|
# use mechanize as a HTTP client
|
||||||
|
browser = mechanize.Browser()
|
||||||
|
browser.add_password("http://%s/" % host, "tivo", mak)
|
||||||
|
browser.add_password("https://%s/" % host, "tivo", mak)
|
||||||
|
browser.set_handle_robots(False)
|
||||||
|
|
||||||
|
|
||||||
def trimDescription(desc):
|
def trimDescription(desc):
|
||||||
desc = desc.strip()
|
desc = desc.strip()
|
||||||
i = desc.rfind(". Copyright Tribune Media Services, Inc.");
|
i = desc.rfind(". Copyright Tribune Media Services, Inc.");
|
||||||
|
@ -117,15 +124,46 @@ class TivoItem:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.title)
|
return repr(self.title)
|
||||||
|
|
||||||
def gettoc():
|
|
||||||
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes&ItemCount=50"
|
|
||||||
pwmgr.add_password(None, url, "tivo", mak)
|
|
||||||
|
|
||||||
req = urllib2.Request(url)
|
def makeCookie(name, value):
|
||||||
h = urllib2.urlopen(req)
|
return cookielib.Cookie(
|
||||||
r = h.read()
|
version=0,
|
||||||
h.close()
|
name=name,
|
||||||
return r
|
value=value,
|
||||||
|
port=None,
|
||||||
|
port_specified=False,
|
||||||
|
domain="",
|
||||||
|
domain_specified=False,
|
||||||
|
domain_initial_dot=False,
|
||||||
|
path="/",
|
||||||
|
path_specified=True,
|
||||||
|
secure=False,
|
||||||
|
expires=None,
|
||||||
|
discard=False,
|
||||||
|
comment=None,
|
||||||
|
comment_url=None,
|
||||||
|
rest=None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def gettoc():
|
||||||
|
global browser, sidcookie
|
||||||
|
|
||||||
|
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes&ItemCount=50"
|
||||||
|
browser.open(url)
|
||||||
|
response = browser.response()
|
||||||
|
headers = response.info()
|
||||||
|
|
||||||
|
# work around Tivo's broken Set-cookie header that has an expiry date in
|
||||||
|
# the past, thus removing the session cookie
|
||||||
|
sidcookie = response.info().getheader("Set-Cookie")
|
||||||
|
if sidcookie != None:
|
||||||
|
sidcookie = re.sub(".*sid=(.*?);.*", "\\1", sidcookie)
|
||||||
|
#print sidcookie
|
||||||
|
browser._ua_handlers['_cookies'].cookiejar.set_cookie(makeCookie("sid", sidcookie))
|
||||||
|
#print browser._ua_handlers['_cookies'].cookiejar
|
||||||
|
return response.read()
|
||||||
|
|
||||||
|
|
||||||
def getText(nodelist):
|
def getText(nodelist):
|
||||||
rc = ""
|
rc = ""
|
||||||
|
@ -182,13 +220,15 @@ def waitForProcs(pids):
|
||||||
|
|
||||||
|
|
||||||
def download(file, url, mak, target):
|
def download(file, url, mak, target):
|
||||||
|
global sidcookie
|
||||||
#url = re.sub("tivo.lassitu.de:80", "localhost:8888", url)
|
#url = re.sub("tivo.lassitu.de:80", "localhost:8888", url)
|
||||||
#url = re.sub("tivo.lassitu.de:80", "krokodil-vpn.zs64.net:8888", url)
|
#url = re.sub("tivo.lassitu.de:80", "krokodil-vpn.zs64.net:8888", url)
|
||||||
print "--- downloading \"%s\"" % (url)
|
print "--- downloading \"%s\"" % (url)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||||
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
"--insecure", "--cookie", "sid=%s" % sidcookie, \
|
||||||
"--silent", "--show-error", \
|
"--silent", "--show-error", \
|
||||||
|
"--user-agent", "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", \
|
||||||
"--user", "tivo:%s" % mak, "--url", url ], \
|
"--user", "tivo:%s" % mak, "--url", url ], \
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||||
|
@ -331,7 +371,6 @@ def main():
|
||||||
toc = gettoc()
|
toc = gettoc()
|
||||||
savetoc(toc)
|
savetoc(toc)
|
||||||
dom = xml.dom.minidom.parseString(toc)
|
dom = xml.dom.minidom.parseString(toc)
|
||||||
cookiejar.save()
|
|
||||||
|
|
||||||
if len(remainder) == 1:
|
if len(remainder) == 1:
|
||||||
if remainder[0] == "list":
|
if remainder[0] == "list":
|
||||||
|
|
Loading…
Reference in a new issue