Created
April 4, 2011 10:11
-
-
Save guyromm/901410 to your computer and use it in GitHub Desktop.
my little digicam photo/movie extractor/resizer/encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import glob,os,commands,re | |
from sys import argv | |
errcnt=0 ; donecnt=0 ; skipcnt=0 | |
for fn in glob.glob('%s/*'%os.getcwd()): | |
bfn = os.path.basename(fn) | |
video=False ; sound=False | |
if re.compile('\.MP4$').search(bfn): video=True | |
if re.compile('\.WAV$').search(bfn): sound=True | |
if video: | |
td = '/home/milez/Videos/incoming-compressed' | |
tfn = os.path.join(td,bfn) | |
elif sound: | |
td = '/home/milez/Music/recordings' | |
tfn = os.path.join(td,bfn.replace('.WAV','.mp3')) | |
else: | |
td = '/home/milez/Pictures/incoming-scaled' | |
tfn = os.path.join(td,bfn) | |
glexpr = os.path.join(td,'..')+'/*/%s'%bfn | |
if os.path.exists(tfn): | |
skipcnt+=1 | |
continue | |
fndcmd = 'find %s -iname "%s*"'%(os.path.join(td,'..'),bfn) | |
st,op = commands.getstatusoutput(fndcmd); | |
oplines = [ln for ln in op.strip().split("\n") if len(ln)] | |
#print('%s: %s => %s (%s)'%(fndcmd,st,op,oplines)) | |
#glex = glob.glob(glexpr) | |
#raise Exception(glexpr) | |
if len(oplines): #len(glex): | |
print ('EXISTS: %s => %s'%(fndcmd,oplines)) | |
skipcnt+=1 | |
continue | |
#print 'os.path.exists(%s)=%s'%(tfn,os.path.exists(tfn)) | |
print "%s => %s"%(bfn,tfn) | |
if video: | |
rcmd = "mencoder -ovc lavc -oac mp3lame %s -o %s"%(bfn,tfn) | |
elif sound: | |
rcmd = 'lame %s %s'%(bfn,tfn) | |
else: | |
rcmd = "convert %s -resize 1024 %s"%(bfn,tfn) | |
if len(argv)>1 and argv[1]=='simulate': | |
st=0 ; op='' | |
#raise Exception('hi') | |
else: | |
st,op = commands.getstatusoutput(rcmd) | |
if st!=0: | |
print "%s returned %s"%(rcmd,st) | |
errcnt+=1 | |
else: | |
donecnt+=1 | |
print "%s done, %s skipped, %s errors"%(donecnt,skipcnt,errcnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment