3 __author__ = "Artur Duque de Souza"
4 __author_email__ = "artur.souza@indt.org.br"
10 import lib.utils as utils
14 __all__ = ("FileList", "list_media_files")
17 class TranscodedFile(object):
18 """This class creates and reads information about transcoded files."""
21 def __init__(self, filename, args):
23 if filename == "" or not os.path.exists(filename):
24 self.opts = args.copy()
25 self.opts["original"] = self.opts.pop("input", "").split("://")[1]
26 self.opts["original_mtime"] = os.stat(
27 self.opts["original"])[ST_MTIME]
29 name = os.path.splitext(os.path.basename(self.opts["outfile"]))[0]
30 output = open(".transcoded/%s.dat" % name, "wb")
31 # dumps data using the highest protocol
32 pickle.dump(self.opts, output, -1)
35 name = os.path.splitext(os.path.basename(filename))[0]
36 pkl_file = open(".transcoded/%s.dat" % name, "rb")
37 self.opts = pickle.load(pkl_file)
44 """Class to hold file's list - reimplements str and repr."""
49 ret = ret + " %s" % item
59 def list_media_files(directory, file_list):
60 """Show all the media files with extension defined in the var 'ext'
61 that are in the directory, appending each one to 'file_list'."""
62 ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
63 for root, dirs, files in os.walk(directory):
65 if os.path.splitext(name)[1].strip(".") in ext:
66 dat_file = os.path.join(root,name.split(".")[0]+".dat")
67 if name not in file_list and os.path.exists(dat_file):
68 file_list.append(name)