3 __author__ = "Artur Duque de Souza"
4 __author_email__ = "artur.souza@indt.org.br"
12 import lib.utils as utils
16 __all__ = ("FileList", "list_media_files")
19 class TranscodedFile(object):
20 """This class creates and reads information about transcoded files."""
22 log = logging.getLogger("gms.file_handler")
24 def __init__(self, filename, args):
25 if filename == "" or not os.path.exists(filename):
26 self.opts = args.copy()
28 if self.opts["type"][0] != "myth":
29 self.opts["original_mtime"] = os.path.getmtime(
32 name = os.path.basename(self.opts["uri"][0])
33 self.opts["original"] = [name]
34 output_file = os.path.basename(self.opts["outfile"][0])
35 output = open(".transcoded/%s.dat" % \
36 os.path.splitext(output_file)[0], "wb")
37 # dumps data using the highest protocol
38 pickle.dump(self.opts, output, -1)
41 name = os.path.splitext(os.path.basename(filename))[0]
42 pkl_file = open(".transcoded/%s.dat" % name, "rb")
43 self.opts = pickle.load(pkl_file)
50 """Class to hold file's list - reimplements str and repr."""
55 ret = ret + "%s" % item
65 def list_media_files(directory, file_list):
66 """Show all the media files with extension defined in the var 'ext'
67 that are in the directory, appending each one to 'file_list'."""
68 ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
69 for root, dirs, files in os.walk(directory):
71 if os.path.splitext(name)[1].strip(".") in ext:
72 dat_file = os.path.join(sys.path[0],root,
73 os.path.splitext(name)[0]+".dat")
75 if name not in file_list and \
76 os.path.exists(dat_file):
77 file_list.append(name)