added parse_drive utils

This commit is contained in:
sanj 2010-07-23 05:37:38 +05:30
parent 8d2b78f53d
commit d5bc4156e1
2 changed files with 64 additions and 0 deletions

View File

View File

@ -0,0 +1,64 @@
import os
import shutil
def isVideo(path):
basename, ext = os.path.splitext(path)
if ext.lower() in ['.vob', '.avi', '.mp4', '.mov']:
return True
else:
return False
def isAudio(path):
basename, ext = os.path.splitext(path)
if ext.lower() in ['.wav', '.mp3', '.ac3', '.wmv']:
return True
else:
return False
def spider(path, fn):
# path = self.archives()[archive]
path = os.path.normpath(path)
for dirpath, dirnames, filenames in os.walk(path):
if filenames:
# prefix = dirpath[len(path)+1:]
for filename in filenames:
if not filename.startswith('._') and not filename in ('.DS_Store', ):
# print dirpath + " + " + filename
fn(dirpath, filename)
def mvFile(dirpath, filename):
path = os.path.join(dirpath, filename)
if isVideo(path) or isAudio(path):
new_path = os.path.join("/srv2/EdgwareNTFS/RawMedia/Edgware Road SMS/", filename)
shutil.move(path, new_path)
return True
def cleanFile(dirpath, filename):
if filename.startswith("~$"):
path = os.path.join(dirpath, filename)
os.remove(path)
def encodeFile(dirpath, filename):
path = os.path.join(dirpath, filename)
if isVideo(path):
return encodeVideo(path)
if isAudio(path):
return encodeAudio(path)
else:
return None
def encodeVideo(path):
# print "Video: " + path
cmd = 'ffmpeg2theora -p padma "%s"' % (path,)
print cmd
os.system(cmd)
return True
def encodeAudio(path):
basename, ext = os.path.splitext(path)
outpath = basename + ".ogg"
cmd = 'ffmpeg2theora --novideo "%s" -o "%s"' % (path, outpath,)
print cmd
os.system(cmd)
return True