Transkodieren wieder raus, geht nicht zuverlaessig; auf explizite Positivliste fuer den Download umstellen

This commit is contained in:
Stefan Bethke 2011-09-15 11:08:11 +00:00
parent bc44a7f91d
commit 67459fafd8
2 changed files with 73 additions and 61 deletions

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.42 2011/07/04 21:10:43 stb Exp $
# $Schlepperbande: src/tivomirror/tivomirror,v 1.43 2011/09/11 22:05:36 stb Exp $
#
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren.
@ -23,41 +23,29 @@ import tivomp4
host = "tivo.lassitu.de"
mak = "7194378159"
#targetdir = "/mnt/safe/tivo"
targetdir = "/p1/media/TV"
gig = 1024.0 * 1024 * 1024
minfree = 10 * gig
arset = dict()
arset["Family Guy"] = 43
arset["Late Show With David Letterman"] = 43
arset["The Colbert Report"] = 43
arset["The Daily Show With Jon Stewart"] = 43
arset["John Oliver's New York Stand-Up Show"] = 43
arset["John Oliver: Terrifying Times"] = 43
arset["House"] = 43
#arset["The Late Late Show With Craig Ferguson"] = 149
arset["Futurama"] = 169
includes = dict()
includes['Dirty Jobs'] = 1
includes['Family Guy'] = 1
includes['Flying Wild Alaska'] = 1
includes['Futurama'] = 1
includes['House'] = 1
includes['Late Show With David Letterman'] = 1
includes['Louie'] = 1
includes['Mad Men'] = 1
includes['Modern Family'] = 1
includes['MythBusters'] = 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
excludes = dict()
excludes['The 2011 Billboard Music Awards'] = 1
excludes['2011 French Open Tennis'] = 1
excludes['2011 French Open Tennis - Second Round'] = 1
excludes["2011 French Open Tennis - Men's and Women's Quarterfinals"] = 1
excludes['2011 Tour de France - Stage 3'] = 1
excludes['2011 Wimbledon Championships'] = 1
excludes['2011 Tour de France'] = 1
excludes['Cops'] = 1
excludes['Dancing With the Stars'] = 1
excludes['French Open Tonight'] = 1
excludes['Hot Pursuit'] = 1
excludes['Greatest Tank Battles'] = 1
excludes['Judge Judy'] = 1
excludes['Most Shocking'] = 1
excludes['Secrets of World War II'] = 1
excludes['Speeders'] = 1
excludes['Tennis'] = 1
excludes['World War II in Color'] = 1
excludes["World's Wildest Police Videos"] = 1
class flushfile(object):
def __init__(self, f):
@ -77,10 +65,6 @@ cookiejar = cookielib.MozillaCookieJar(os.getcwd() + "/tivo/.cookies.txt")
opener = urllib2.build_opener(authhandler, urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
tmp = "/tmp"
#tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
#tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
tmpmp2 = "/home/stb/tmp.mpg"
tmpmp4 = "/home/stb/tmp.mp4"
class TivoException(Exception):
def __init__(self, value):
@ -185,7 +169,7 @@ def download(file, url, mak, target):
raise
size = os.path.getsize(target)
if size < 1024:
print "error downloadig file: too small"
print "error downloading file: too small"
os.remove(target)
raise TivoException("downloaded file is too small")
elapsed = time.time() - start
@ -195,8 +179,8 @@ def download(file, url, mak, target):
def download_decode(item, mak):
#target = tmpmp2
target = "%s.mpg" % item.file
mp4 = "%s.mp4" % item.file
try:
os.makedirs(item.dir)
except OSError:
@ -209,11 +193,12 @@ def download_decode(item, mak):
except Exception, e:
os.remove(target)
raise
tivomp4.transcode(target, tmpmp4, item.ar)
print "--- copying to \"%s\"" % file
shutil.copy(tmpmp4, "%s.mp4" % file)
os.remove(tmpmp2)
os.remove(tmpmp4)
#tivomp4.transcode(target, mp4, item.ar)
try:
os.utime(target, [item.date, item.date])
#os.utime(mp4, [item.date, item.date])
except Exception, e:
print "Urgh:", e
def savetoc(toc):
@ -258,17 +243,18 @@ def main():
if downloaddb.has_key(item.name):
#print "*** skipping \"%s\": already downloaded" % item.name
continue
if excludes.has_key(item.title) or excludes.has_key(item.episode) or excludes.has_key(item.name):
#print "*** skipping \"%s\": excluded" % name
#if excludes.has_key(item.title) or excludes.has_key(item.episode) or excludes.has_key(item.name):
# #print "*** skipping \"%s\": excluded" % name
# continue
if includes.has_key(item.title) or includes.has_key(item.episode) or includes.has_key(item.name):
pass
else:
print "*** skipping \"%s\": excluded" % item.name
continue
print "*** downloading \"%s\": %.3fGB" % (item.name, item.sourcesize / 1e9)
try:
download_decode(item, mak)
try:
os.utime(item.file, [item.date, item.date])
except Exception, e:
print "Urgh:", e
downloaddb[item.name] = item.datestr
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync()

View file

@ -8,34 +8,57 @@ import sys
def transcode(src, tgt, fmt):
transcode_opts = [ "ffmpeg" ];
#transcode_opts.extend(["-t", "60"]) # testing only: only 60 seconds
transcode_opts.extend(["-loglevel", "error"])
#transcode_opts.extend(["-t", "240"]) # testing only
#transcode_opts.extend(["-loglevel", "error"])
transcode_opts.extend(["-i", src])
#transcode_opts.extend(["-acodec", "libfaac"])
transcode_opts.extend(["-threads", "0"])
transcode_opts.extend(["-y", "-deinterlace"])
transcode_opts.extend(["-ac", "2", "-ab", "128k"])
transcode_opts.extend(["-vcodec", "libx264"])
transcode_opts.extend(["-tune", "film", "-profile", "main"])
if fmt == "hd":
transcode_opts.extend(["-s", "1280x720"])
transcode_opts.extend(["-threads", "0", "-b", "4000k"])
transcode_opts.extend(["-b", "4000k"])
transcode_opts.append(tgt)
else:
transcode_opts.extend(["-threads", "0", "-b", "900k", "-bt", "900k"])
if str(fmt) == "43":
pass
transcode_opts.extend(["-b", "900k", "-bt", "900k"])
if str(fmt) == "169":
transcode_opts.extend(["-vf", "crop=640:360"])
transcode_opts.extend(["-aspect", "16:9"])
elif str(fmt) == "149":
transcode_opts.extend(["-vf", "crop=640:412"])
transcode_opts.extend(["-aspect", "14:9"])
else:
transcode_opts.extend(["-vf", "crop=640:360"])
transcode_opts.extend(["-aspect", "16:9"])
transcode_opts.extend(["-y", "-deinterlace", "-vsync", "1"])
transcode_opts.append(tgt)
transcode_opts.extend(["-vsync", "1"])
transcode_opts.append(tgt)
#if getInfo(src)[0] == "a":
#transcode_opts.extend(["-map", "0.1:0.0", "-map", "0.0:0.0"])
#transcode_opts.extend(["-map", "0.1:0.1", "-map", "0.0:0.1"])
print " %s" % " ".join(transcode_opts)
subprocess.check_call(transcode_opts)
def getInfo(src):
c = []
o = [ "ffmpeg" ];
o.extend(["-i", src])
try:
p = subprocess.Popen(o, stderr=subprocess.PIPE)
(out, err) = p.communicate()
except subprocess.CalledProcessError, e:
pass
for l in err.split("\n"):
if l.find("Stream #") >=0:
w = l.split()
if w[2] == "Audio:":
c.extend(["a"])
elif w[2] == "Video:":
c.extend(["v"])
else:
c.extend(["?"])
return c
class Usage(Exception):
def __init__(self, msg):
self.msg = msg;
@ -48,13 +71,16 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
opts, args = getopt.getopt(argv[1:], "hi:", ["help"])
except getopt.error, msg:
raise Usage(msg)
for (o, v) in opts:
if o == "-h":
print >>sys.stderr, "help text"
return 0
if o == "-i":
print getInfo(v)
return 0
if len(args) != 3:
raise Usage("wrong number of arguments")
transcode(args[1], args[2], args[0])