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 dat_file = output_file + ".dat";
36 dat_path = os.path.join (utils.config.get_transcoded_location(),
39 output = open(dat_path, "wb")
40 # dumps data using the highest protocol
41 pickle.dump(self.opts, output, -1)
44 name = os.path.splitext(os.path.basename(filename))[0]
45 dat_file = name + ".dat";
46 dat_path = os.path.join (utils.config.get_transcoded_location(),
48 pkl_file = open(dat_path, "rb")
49 self.opts = pickle.load(pkl_file)
56 """Class to hold file's list - reimplements str and repr."""
61 ret = ret + "%s" % item
71 def list_media_files(directory, file_list):
72 """Show all the media files with extension defined in the var 'ext'
73 that are in the directory, appending each one to 'file_list'."""
74 ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
75 for root, dirs, files in os.walk(directory):
77 if os.path.splitext(name)[1].strip(".") in ext:
78 dat_file = os.path.join(sys.path[0],root,
79 os.path.splitext(name)[0]+".dat")
81 if name not in file_list and \
82 os.path.exists(dat_file):
83 file_list.append(name)