mirror of
https://github.com/ivuorinen/aeonview.git
synced 2026-02-19 07:49:21 +00:00
Whitespace trimming
This commit is contained in:
53
aeonview.py
53
aeonview.py
@@ -7,13 +7,13 @@ def aeonview(argv):
|
|||||||
videos of elapsing time. works best with webcam-images from the net.
|
videos of elapsing time. works best with webcam-images from the net.
|
||||||
"""
|
"""
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
|
||||||
parser = optparse.OptionParser(
|
parser = optparse.OptionParser(
|
||||||
usage="Usage: %prog [options]",
|
usage="Usage: %prog [options]",
|
||||||
description="aeonview for timelapses",
|
description="aeonview for timelapses",
|
||||||
version="%prog v"+version
|
version="%prog v"+version
|
||||||
)
|
)
|
||||||
|
|
||||||
basicopts = optparse.OptionGroup(
|
basicopts = optparse.OptionGroup(
|
||||||
parser, "Basic settings", "These effect in both modes."
|
parser, "Basic settings", "These effect in both modes."
|
||||||
)
|
)
|
||||||
@@ -39,7 +39,7 @@ def aeonview(argv):
|
|||||||
default=os.getcwdu()+'/mencoder')
|
default=os.getcwdu()+'/mencoder')
|
||||||
|
|
||||||
parser.add_option_group(basicopts)
|
parser.add_option_group(basicopts)
|
||||||
|
|
||||||
# When mode is: image
|
# When mode is: image
|
||||||
imageopts = optparse.OptionGroup(
|
imageopts = optparse.OptionGroup(
|
||||||
parser, "Options for --mode: image", "When we are gathering images.")
|
parser, "Options for --mode: image", "When we are gathering images.")
|
||||||
@@ -47,8 +47,7 @@ def aeonview(argv):
|
|||||||
imageopts.add_option("--url", help="Webcam URL", type="string")
|
imageopts.add_option("--url", help="Webcam URL", type="string")
|
||||||
|
|
||||||
parser.add_option_group(imageopts)
|
parser.add_option_group(imageopts)
|
||||||
|
|
||||||
|
|
||||||
# When mode is: video
|
# When mode is: video
|
||||||
videoopts = optparse.OptionGroup(parser,
|
videoopts = optparse.OptionGroup(parser,
|
||||||
"Options for --mode: video", "When we are making movies.")
|
"Options for --mode: video", "When we are making movies.")
|
||||||
@@ -79,86 +78,84 @@ def aeonview(argv):
|
|||||||
|
|
||||||
parser.add_option("-v", help="Verbose", action="store_true", dest="verbose", default=False)
|
parser.add_option("-v", help="Verbose", action="store_true", dest="verbose", default=False)
|
||||||
parser.add_option("-q", help="Quiet", action="store_false", dest="verbose", default=True)
|
parser.add_option("-q", help="Quiet", action="store_false", dest="verbose", default=True)
|
||||||
|
|
||||||
parser.add_option("-s", "--simulate",
|
parser.add_option("-s", "--simulate",
|
||||||
help="Demostrates what will happen (good for checking your settings and destinations)",
|
help="Demostrates what will happen (good for checking your settings and destinations)",
|
||||||
default=False,
|
default=False,
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
(options, args) = parser.parse_args(argv[1:])
|
(options, args) = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
if options.simulate == True:
|
if options.simulate == True:
|
||||||
print
|
print
|
||||||
print "--- Starting simulation, just echoing steps using your parameters."
|
print "--- Starting simulation, just echoing steps using your parameters."
|
||||||
print
|
print
|
||||||
print "(!) You are running aeonview from", os.getcwdu()
|
print "(!) You are running aeonview from", os.getcwdu()
|
||||||
|
|
||||||
|
|
||||||
if options.mode == 'image':
|
if options.mode == 'image':
|
||||||
# We are now in the gathering mode.
|
# We are now in the gathering mode.
|
||||||
|
|
||||||
if options.url == None and options.simulate == True:
|
if options.url == None and options.simulate == True:
|
||||||
options.url = "http://example.com/webcam.jpg"
|
options.url = "http://example.com/webcam.jpg"
|
||||||
print "(!) Simulation: Using " + options.url + " as webcam url"
|
print "(!) Simulation: Using " + options.url + " as webcam url"
|
||||||
|
|
||||||
if options.url == None:
|
if options.url == None:
|
||||||
print "(!) Need a webcam url, not gonna rock before that!"
|
print "(!) Need a webcam url, not gonna rock before that!"
|
||||||
print
|
print
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
if options.project == None:
|
if options.project == None:
|
||||||
import hashlib # not needed before
|
import hashlib # not needed before
|
||||||
m = hashlib.md5(options.url).hexdigest()
|
m = hashlib.md5(options.url).hexdigest()
|
||||||
options.project = m[:5] # 5 first characters of md5-hash
|
options.project = m[:5] # 5 first characters of md5-hash
|
||||||
if options.verbose == True or options.simulate == True:
|
if options.verbose == True or options.simulate == True:
|
||||||
print "(!) No project defined, using part of md5-hash of the webcam url:", options.project
|
print "(!) No project defined, using part of md5-hash of the webcam url:", options.project
|
||||||
|
|
||||||
if options.path == None:
|
if options.path == None:
|
||||||
if options.verbose == True or options.simulate == True:
|
if options.verbose == True or options.simulate == True:
|
||||||
print "(!) No destination defined, using:", options.path
|
print "(!) No destination defined, using:", options.path
|
||||||
else:
|
else:
|
||||||
if options.verbose == True or options.simulate == True:
|
if options.verbose == True or options.simulate == True:
|
||||||
print "(!) Using destination:", options.path
|
print "(!) Using destination:", options.path
|
||||||
|
|
||||||
# If you want to change the path structure, here's your chance.
|
# If you want to change the path structure, here's your chance.
|
||||||
options.imgpath = time.strftime("/img/%Y-%m/%d/")
|
options.imgpath = time.strftime("/img/%Y-%m/%d/")
|
||||||
options.imgname = time.strftime("%H-%M-%S")
|
options.imgname = time.strftime("%H-%M-%S")
|
||||||
|
|
||||||
# Let us build the destination path and filename
|
# Let us build the destination path and filename
|
||||||
options.fileext = os.path.splitext(options.url)[1]
|
options.fileext = os.path.splitext(options.url)[1]
|
||||||
options.destdir = options.path + "/" + options.project + options.imgpath
|
options.destdir = options.path + "/" + options.project + options.imgpath
|
||||||
options.destination = options.destdir + options.imgname + options.fileext
|
options.destination = options.destdir + options.imgname + options.fileext
|
||||||
getit = options.url + " -o " + options.destination
|
getit = options.url + " -o " + options.destination
|
||||||
|
|
||||||
# Crude, but works.
|
# Crude, but works.
|
||||||
if options.simulate == False:
|
if options.simulate == False:
|
||||||
os.system("curl --create-dirs --silent %s" % getit)
|
os.system("curl --create-dirs --silent %s" % getit)
|
||||||
else:
|
else:
|
||||||
print "(!) Simulation: Making path:", options.destdir
|
print "(!) Simulation: Making path:", options.destdir
|
||||||
print "(!) Simulation: curl (--create-dirs and --silent)", getit
|
print "(!) Simulation: curl (--create-dirs and --silent)", getit
|
||||||
|
|
||||||
elif options.mode == "video":
|
elif options.mode == "video":
|
||||||
# We are now in the video producing mode
|
# We are now in the video producing mode
|
||||||
|
|
||||||
vid_extension = ".avi"
|
vid_extension = ".avi"
|
||||||
#m = os.getcwd() + "/mencoder"
|
#m = os.getcwd() + "/mencoder"
|
||||||
m = options.mencoder
|
m = options.mencoder
|
||||||
mencoder = m + " -really-quiet -mf fps="+ str(options.fps) +" -nosound -ovc lavc -lavcopts vcodec=mpeg4"
|
mencoder = m + " -really-quiet -mf fps="+ str(options.fps) +" -nosound -ovc lavc -lavcopts vcodec=mpeg4"
|
||||||
|
|
||||||
if options.project == None:
|
if options.project == None:
|
||||||
print "(!) No project defined, please specify what project you are working on."
|
print "(!) No project defined, please specify what project you are working on."
|
||||||
print
|
print
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
if options.videorun == "daily":
|
if options.videorun == "daily":
|
||||||
vid_date = str(options.generate).split("-")
|
vid_date = str(options.generate).split("-")
|
||||||
year = vid_date[0]
|
year = vid_date[0]
|
||||||
month = vid_date[1]
|
month = vid_date[1]
|
||||||
day = vid_date[2]
|
day = vid_date[2]
|
||||||
|
|
||||||
if check_date(int(year), int(month), int(day)):
|
if check_date(int(year), int(month), int(day)):
|
||||||
proj_dir = options.path + "/" + options.project
|
proj_dir = options.path + "/" + options.project
|
||||||
video_dir = proj_dir + "/img/" + year + "-" + month + "/" + day + "/*"
|
video_dir = proj_dir + "/img/" + year + "-" + month + "/" + day + "/*"
|
||||||
@@ -166,7 +163,7 @@ def aeonview(argv):
|
|||||||
video_out_day = video_out_dir + day + vid_extension
|
video_out_day = video_out_dir + day + vid_extension
|
||||||
mfdir = os.path.dirname(os.path.realpath(video_dir))
|
mfdir = os.path.dirname(os.path.realpath(video_dir))
|
||||||
command = mencoder + " -o " + video_out_day + " 'mf://" + mfdir + "/*'"
|
command = mencoder + " -o " + video_out_day + " 'mf://" + mfdir + "/*'"
|
||||||
|
|
||||||
if options.simulate == False:
|
if options.simulate == False:
|
||||||
mkdir_p( video_out_dir )
|
mkdir_p( video_out_dir )
|
||||||
os.system(command)
|
os.system(command)
|
||||||
@@ -175,10 +172,10 @@ def aeonview(argv):
|
|||||||
print "(!) Video output-file:", video_out_day
|
print "(!) Video output-file:", video_out_day
|
||||||
print "(!) Made directory structure:", video_out_dir
|
print "(!) Made directory structure:", video_out_dir
|
||||||
print "(!) Command to run", command
|
print "(!) Command to run", command
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "(!) Error: check your date. Value provided:", options.generate
|
print "(!) Error: check your date. Value provided:", options.generate
|
||||||
|
|
||||||
elif options.videorun == "monthly":
|
elif options.videorun == "monthly":
|
||||||
print "Monthly: TODO"
|
print "Monthly: TODO"
|
||||||
# TODO Monthly script. Joins daily movies of that month.
|
# TODO Monthly script. Joins daily movies of that month.
|
||||||
@@ -186,14 +183,14 @@ def aeonview(argv):
|
|||||||
elif options.videorun == "yearly":
|
elif options.videorun == "yearly":
|
||||||
print "Yearly: TODO"
|
print "Yearly: TODO"
|
||||||
# TODO Yearly script. Joins monthly movies together.
|
# TODO Yearly script. Joins monthly movies together.
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "(!) What? Please choose between -r daily/montly/yearly"
|
print "(!) What? Please choose between -r daily/montly/yearly"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612
|
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612
|
||||||
def mkdir_p(path):
|
def mkdir_p(path):
|
||||||
|
|||||||
Reference in New Issue
Block a user