gmyth-stream/server/0.3/lib/file_handler.py
author morphbr
Thu May 31 14:31:24 2007 +0100 (2007-05-31)
branchtrunk
changeset 724 64b061775d06
parent 723 f5f7abc760aa
child 726 6431b16e18fb
permissions -rw-r--r--
[svn r730] * GMyth-Streamer
- List status of more than 1 tid
- Stream without transcoding
- List files just under .transcoded and that has a .dat
     1 #!/usr/bin/env python
     2 
     3 __author__ = "Artur Duque de Souza"
     4 __author_email__ = "artur.souza@indt.org.br"
     5 __license__ = "GPL"
     6 __version__ = "0.1"
     7 
     8 import os
     9 import pickle
    10 import lib.utils as utils
    11 
    12 from stat import *
    13 
    14 __all__ = ("FileList", "list_media_files")
    15 
    16 
    17 class TranscodedFile(object):
    18     """This class creates and reads information about transcoded files."""
    19     opts = {}
    20 
    21     def __init__(self, filename, args):
    22         print filename
    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]
    28 
    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)
    33             output.close()
    34         else:
    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)
    38     # __init__()
    39 
    40 # TranscodedFile
    41 
    42 
    43 class FileList(list):
    44     """Class to hold file's list - reimplements str and repr."""
    45     def __str__(self):
    46         ret = ""
    47         if len(self) > 0:
    48             for item in self:
    49                 ret = ret + " %s" % item
    50         return ret
    51     # __str__()
    52 
    53     def __repr__(self):
    54         return self.__str__()
    55     # __repr__()
    56 
    57 # FileList
    58 
    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):
    64         for name in files:
    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)
    69 
    70     return True
    71 # list_media_files()