Convert all string formatting to new format.
This commit is contained in:
parent
eaef3a88bf
commit
be05ae538f
1 changed files with 33 additions and 33 deletions
|
@ -168,9 +168,9 @@ def trimDescription(desc):
|
|||
def saveCookies(session, filename):
|
||||
cj = cookielib.MozillaCookieJar(filename)
|
||||
for cookie in session.cookies:
|
||||
logger.debug("storing cookie %s" % (cookie))
|
||||
logger.debug("storing cookie {}".format(cookie))
|
||||
cj.set_cookie(cookie)
|
||||
logger.debug("Saving cookies to %s" % (cj))
|
||||
logger.debug("Saving cookies to {}".format(cj))
|
||||
cj.save(ignore_discard=True, ignore_expires=True)
|
||||
|
||||
|
||||
|
@ -215,17 +215,17 @@ class TivoItem:
|
|||
if self.episodeNumber and self.episodeNumber != u'0':
|
||||
en = int(self.episodeNumber)
|
||||
if en >= 100:
|
||||
self.name = "%s S%02dE%02d %s" % (self.title, en / 100, en % 100, self.episode)
|
||||
self.name = "{} S{:02d}E{:02d} {}".format(self.title, en / 100, en % 100, self.episode)
|
||||
else:
|
||||
self.name = "%s E%s %s" % (self.title, self.episodeNumber, self.episode)
|
||||
self.name = "{} E{} {}".format(self.title, self.episodeNumber, self.episode)
|
||||
elif self.unique:
|
||||
self.name = "%s - %s" % (self.title, self.episode)
|
||||
self.name = "{} - {}".format(self.title, self.episode)
|
||||
else:
|
||||
self.name = "%s - %s - %s" % (self.title, self.datestr, self.episode)
|
||||
self.dir = "%s/%s" % (targetdir, re.sub("[:/]", "-", self.title))
|
||||
self.file = "%s/%s" % (self.dir, re.sub("[:/]", "-", self.name))
|
||||
self.name = "{} - {} - {}".format(self.title, self.datestr, self.episode)
|
||||
self.dir = "{}/{}".format(targetdir, re.sub("[:/]", "-", self.title))
|
||||
self.file = "{}/{}".format(self.dir, re.sub("[:/]", "-", self.name))
|
||||
self.name = self.name.encode("utf-8");
|
||||
self.dir = self.dir.encode("utf-8");
|
||||
self.dir = self.dir.encode("utf-8");
|
||||
self.file = self.file.encode("utf-8");
|
||||
def getPath(self, options):
|
||||
title = self.title
|
||||
|
@ -234,14 +234,14 @@ class TivoItem:
|
|||
if self.episodeNumber and self.episodeNumber != u'0':
|
||||
en = int(self.episodeNumber)
|
||||
if en >= 100:
|
||||
name = "%s S%02dE%02d %s" % (title, en / 100, en % 100, self.episode)
|
||||
name = "{} S{:02d}E{:02d} {}".format(title, en / 100, en % 100, self.episode)
|
||||
else:
|
||||
name = "%s E%s %s" % (title, self.episodeNumber, self.episode)
|
||||
name = "{} E{} {}".format(title, self.episodeNumber, self.episode)
|
||||
elif self.unique:
|
||||
name = "%s - %s" % (title, self.episode)
|
||||
name = "{} - {}".format(title, self.episode)
|
||||
else:
|
||||
name = "%s - %s %s" % (title, self.shortdate, self.episode)
|
||||
path = "%s/%s" % (self.dir, re.sub("[:/]", "-", name))
|
||||
name = "{} - {} {}".format(title, self.shortdate, self.episode)
|
||||
path = "{}/{}".format(self.dir, re.sub("[:/]", "-", name))
|
||||
return path.encode("utf-8");
|
||||
def __str__(self):
|
||||
return repr(self.title)
|
||||
|
@ -277,7 +277,7 @@ class TivoToc:
|
|||
'AnchorOffset': offset
|
||||
}
|
||||
url = "https://{}/TiVoConnect".format(host)
|
||||
logger.debug(" offset %d" % (offset))
|
||||
logger.debug(" offset {}".format(offset))
|
||||
r = session.get(url, params=params, timeout=30, verify=False, proxies=proxies, headers=headers)
|
||||
if r.status_code != 200:
|
||||
r.raise_for_status()
|
||||
|
@ -382,7 +382,7 @@ def download_item(item, mak, target):
|
|||
upd = start
|
||||
url = item.url
|
||||
#url = re.sub("tivo.lassitu.de:80", "wavehh.lassitu.de:30080", url)
|
||||
logger.info("--- downloading \"%s\"" % (url))
|
||||
logger.info("--- downloading \"{}\"".format(url))
|
||||
logger.info(" {}".format(target))
|
||||
start = time.time()
|
||||
r = session.get(url, stream=True, verify=False, proxies=proxies, headers=headers)
|
||||
|
@ -398,7 +398,7 @@ def download_item(item, mak, target):
|
|||
upd = time.time()
|
||||
dur = now - start
|
||||
mb = count / 1e6
|
||||
print "%5.1f%% %5.3f GB downloaded in %.0f min, %.3f MB/s" % (
|
||||
print "{:5.1f}% {:5.3f} GB downloaded in {:.0f} min, {.3f} MB/s".format(
|
||||
100.0 * count / item.sourcesize,
|
||||
mb / 1e3, dur / 60, mb / dur)
|
||||
try:
|
||||
|
@ -417,11 +417,11 @@ def download_item(item, mak, target):
|
|||
upd = now
|
||||
dur = now - start
|
||||
mb = count / 1e6
|
||||
logger.debug(" %5.1f%% %5.3f GB downloaded in %.0f min, %.3f MB/s" % (
|
||||
logger.debug(" {:5.1f}% {:5.3f} GB downloaded in {:.0f} min, {:.3f} MB/s".format(
|
||||
100.0 * count / item.sourcesize,
|
||||
mb / 1e3, dur / 60, mb / dur))
|
||||
except Exception as e:
|
||||
logger.error("problem decoding: %s" % (e))
|
||||
logger.error("problem decoding: {}".format(e))
|
||||
raise
|
||||
finally:
|
||||
try:
|
||||
|
@ -430,7 +430,7 @@ def download_item(item, mak, target):
|
|||
pass
|
||||
elapsed = time.time() - start
|
||||
throughput = count / elapsed
|
||||
logger.info("%5.3fGB transferred in %d:%02d, %.1f MB/s" % (
|
||||
logger.info("{:5.3f} GB transferred in {:d}:{:02d}, {:.1f} MB/s".format(
|
||||
count/1e9, int(elapsed/3600), int(elapsed / 60) % 60, throughput/1e6))
|
||||
try:
|
||||
p_decode.stdin.close()
|
||||
|
@ -444,7 +444,7 @@ def download_item(item, mak, target):
|
|||
except Exception, e:
|
||||
pass
|
||||
p_decode.wait()
|
||||
logger.info("tivodecode exited with %s" % (p_decode.returncode))
|
||||
logger.info("tivodecode exited with {}".format(p_decode.returncode))
|
||||
size = os.path.getsize(target)
|
||||
if size < 1024 or size < item.sourcesize * 0.8:
|
||||
logger.error("error downloading file: too small")
|
||||
|
@ -453,7 +453,7 @@ def download_item(item, mak, target):
|
|||
|
||||
|
||||
def download_decode(item, options, mak):
|
||||
target = "%s.mpg" % item.getPath(options)
|
||||
target = "{}.mpg".format(item.getPath(options))
|
||||
try:
|
||||
os.makedirs(item.dir)
|
||||
except OSError:
|
||||
|
@ -475,7 +475,7 @@ def download_decode(item, options, mak):
|
|||
|
||||
def download_one(item, downloaddb, options):
|
||||
global logger, mak
|
||||
logger.info("*** downloading \"%s\": %.3fGB" % (item.name, item.sourcesize / 1e9))
|
||||
logger.info("*** downloading \"{}\": {:.3f} GB".format(item.name, item.sourcesize / 1e9))
|
||||
try:
|
||||
download_decode(item, options, mak)
|
||||
downloaddb[item.name] = item.datestr
|
||||
|
@ -484,7 +484,7 @@ def download_one(item, downloaddb, options):
|
|||
logger.debug("Sleeping 30 seconds before moving on...")
|
||||
time.sleep(30)
|
||||
except TivoException, e:
|
||||
logger.info("Error processing \"%s\": %s" % (item.name, e))
|
||||
logger.info("Error processing \"{}\": {}".format(item.name, e))
|
||||
|
||||
|
||||
def wantitem(item, downloaddb):
|
||||
|
@ -503,16 +503,16 @@ def wantitem(item, downloaddb):
|
|||
def mirror(toc, downloaddb, one=False):
|
||||
avail = getAvail(targetdir)
|
||||
if avail < minfree:
|
||||
logger.error("%s: %.1fG available, at least %.1fG needed, stopping" % \
|
||||
logger.error("{}: {:.1f} GB available, at least {:.1f} GB needed, stopping".format\
|
||||
(targetdir, avail / gig, minfree / gig))
|
||||
sys.exit(1)
|
||||
|
||||
items = toc.getItems()
|
||||
logger.info("*** %d shows listed" % (len(items)))
|
||||
logger.info("*** {} shows listed".format(len(items)))
|
||||
for item in items:
|
||||
options = wantitem(item, downloaddb)
|
||||
if isinstance(options, basestring):
|
||||
logger.debug("*** skipping \"%s\": %s" % (item.name, options))
|
||||
logger.debug("*** skipping \"{}\": {}".format(item.name, options))
|
||||
else:
|
||||
download_one(item, downloaddb, options)
|
||||
if one:
|
||||
|
@ -528,7 +528,7 @@ def download_episode(toc, downloaddb, episode):
|
|||
|
||||
def printtoc(toc, downloaddb):
|
||||
items = toc.getItems()
|
||||
print "*** %d shows listed" % (len(items))
|
||||
print "*** {} shows listed".format(len(items))
|
||||
shows = {}
|
||||
for item in items:
|
||||
if item.title not in shows:
|
||||
|
@ -538,9 +538,9 @@ def printtoc(toc, downloaddb):
|
|||
for item in sorted(shows[title], key=lambda i: i.name):
|
||||
options = wantitem(item, downloaddb)
|
||||
if isinstance(options, basestring):
|
||||
print "%-7.7s: %s" % (options, item.name)
|
||||
print "{:>7.7s}: {}".format(options, item.name)
|
||||
continue
|
||||
print "*** downloading %s (%.3fGB)" % (item.name, item.sourcesize / 1e9)
|
||||
print "*** downloading %s ({:.3f} GB)".format(item.name, item.sourcesize / 1e9)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -548,7 +548,7 @@ def main():
|
|||
curdir = os.getcwd()
|
||||
os.chdir(os.path.expanduser("~") + "/.tivo")
|
||||
handler = logging.handlers.RotatingFileHandler("tivomirror.log", maxBytes=2*1024*1024, backupCount=5)
|
||||
handler.setFormatter(logging.Formatter(fmt='tivomirror[%d] %%(asctime)s %%(levelname)6.6s %%(message)s' % (os.getpid()),
|
||||
handler.setFormatter(logging.Formatter(fmt='tivomirror[{}] %(asctime)s %(levelname)6.6s %(message)s'.format(os.getpid()),
|
||||
datefmt='%H:%M:%S'))
|
||||
logger.addHandler(handler)
|
||||
downloaddb = anydbm.open("downloads.db", "c")
|
||||
|
@ -589,8 +589,8 @@ def main():
|
|||
elif cmd == "download":
|
||||
download_episode(toc, downloaddb, remainder[1])
|
||||
else:
|
||||
logger.error("invalid command %s" % (cmd))
|
||||
print >>sys.stderr, "invalid command %s" % (cmd)
|
||||
logger.error("invalid command {}".format(cmd))
|
||||
print >>sys.stderr, "invalid command {}".format(cmd)
|
||||
sys.exit(64)
|
||||
|
||||
downloaddb.close()
|
||||
|
|
Loading…
Reference in a new issue