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
|
||||
|
||||
# $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
|
||||
# zu transkodieren.
|
||||
|
@ -11,6 +11,7 @@ import anydbm
|
|||
import cookielib
|
||||
import datetime
|
||||
import getopt
|
||||
import mechanize
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
|
@ -37,21 +38,26 @@ includes['Breaking Bad'] = 1
|
|||
includes['Castle'] = 1
|
||||
includes['Dirty Jobs'] = 1
|
||||
includes['Family Guy'] = 1
|
||||
includes['Flying Wild Alaska'] = 1
|
||||
includes['Futurama'] = 1
|
||||
includes["John Oliver's New York Stand-Up Show"] = 1
|
||||
includes['Late Show With David Letterman'] = 1
|
||||
includes['Louie'] = 1
|
||||
includes['Mad Men'] = 1
|
||||
includes['Mockingbird Lane'] = 1
|
||||
includes['Modern Family'] = 1
|
||||
includes['MythBusters'] = 1
|
||||
includes['NCIS'] = 1
|
||||
includes['NFL Football'] = 1
|
||||
includes['Sesame Street'] = 1
|
||||
includes['The Big Bang Theory'] = 1
|
||||
includes['The Colbert Report'] = 1
|
||||
includes['The Daily Show With Jon Stewart'] = 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):
|
||||
def __init__(self, f):
|
||||
|
@ -65,14 +71,15 @@ try:
|
|||
os.makedirs("tivo")
|
||||
except OSError:
|
||||
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"
|
||||
|
||||
# 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):
|
||||
desc = desc.strip()
|
||||
i = desc.rfind(". Copyright Tribune Media Services, Inc.");
|
||||
|
@ -117,15 +124,46 @@ class TivoItem:
|
|||
def __str__(self):
|
||||
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)
|
||||
h = urllib2.urlopen(req)
|
||||
r = h.read()
|
||||
h.close()
|
||||
return r
|
||||
def makeCookie(name, value):
|
||||
return cookielib.Cookie(
|
||||
version=0,
|
||||
name=name,
|
||||
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):
|
||||
rc = ""
|
||||
|
@ -182,13 +220,15 @@ def waitForProcs(pids):
|
|||
|
||||
|
||||
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", "krokodil-vpn.zs64.net:8888", url)
|
||||
print "--- downloading \"%s\"" % (url)
|
||||
start = time.time()
|
||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
||||
"--insecure", "--cookie", "sid=%s" % sidcookie, \
|
||||
"--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 ], \
|
||||
stdout=subprocess.PIPE)
|
||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||
|
@ -331,7 +371,6 @@ def main():
|
|||
toc = gettoc()
|
||||
savetoc(toc)
|
||||
dom = xml.dom.minidom.parseString(toc)
|
||||
cookiejar.save()
|
||||
|
||||
if len(remainder) == 1:
|
||||
if remainder[0] == "list":
|
||||
|
|
Loading…
Reference in a new issue