morphbr@565: import time morphbr@565: import logging morphbr@565: import os morphbr@565: import stat morphbr@565: morphbr@565: ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov'] morphbr@565: morphbr@565: def now(): morphbr@565: return time.strftime("%Y-%m-%d %H:%M:%S"); morphbr@565: morphbr@565: def log(msg): morphbr@565: logging.log(logging.DEBUG, msg) morphbr@565: new_msg = "[%s] %s" % (now(), msg) morphbr@565: return new_msg morphbr@565: morphbr@565: morphbr@565: bin_path_list = os.environ["PATH"].split(os.pathsep) morphbr@565: def which(prg): morphbr@565: for d in bin_path_list: morphbr@565: path = os.path.join(d, prg) morphbr@565: if os.path.exists(path): morphbr@565: st = os.stat(path) morphbr@565: if st[stat.ST_MODE] & 0111: morphbr@565: return path morphbr@565: return "" morphbr@565: morphbr@565: def list_media_files(directory, file_list): morphbr@565: for root, dirs, files in os.walk(directory): morphbr@565: for name in files: morphbr@565: if os.path.splitext(name)[1].strip(".") in ext: morphbr@565: media = os.path.join(root,name) morphbr@565: if media not in file_list: morphbr@565: file_list.append(os.path.join(root,name)) morphbr@565: morphbr@565: return True morphbr@565: