Trees | Indices | Help |
|
---|
|
1 __author__ = 'Dennis Wallace' 2 3 import tempfile 46 """Base Media class. All media objects should inherit from this class 7 to allow common functions to be used in core code. See MP3 and OGG classes 8 for examples on how to configure a subclass.""" 913411 object.__init__(self) 12 13 # Set the following five values in an inherited subclass. 14 15 # A text string describing this media type 16 self.description = '' 17 18 # A text string declaring the MIME Type for this media type 19 self.mime_type = '' 20 21 # A text string declaring the common file extension for this media type 22 self.extension = '' 23 24 # A text string declaring the media format. The self.format property 25 # should be unique across all subclasses inherited from MediaBase. 26 self.format = '' 27 28 # tagdata contains a dictionary of tags to use to gather metadata from the sourceobj 29 self.tagdata = {} 30 31 self.media = '' 32 self.item_id = '' 33 self.source = '' 34 self.options = {} 35 self.bitrate_default = 0 36 self.info = {} 37 self.bitrate = 0 38 self.length = 0 39 40 # sourceobj contains the metadata information for the referenced object 41 self.sourceobj = {} 42 43 self.media_info = [] 44 self.file_name = '' 45 self.file_title = '' 46 self.file_ext = '' 47 self.size = 0 48 self.metadata = {} 49 50 # A more cross-platform way to do this 51 self.cache_dir = tempfile.gettempdir()52 56 60 64 6870 """Sets an alternate location for temporary cache files used in this media object""" 71 self.cache_dir = path7274 """Returns the metadata for the media, filtered by the tagdata dictionary for this media type. Return value is 75 read from cache if possible (or unless clear_cache is set to True)""" 76 if not self.metadata or clear_cache: 77 self.read_file_metadata() 78 return self.metadata7981 """Reads the metadata for the media, filtered by the tagdata dictionary for this media type""" 82 self.metadata = {} 83 for key in self.tagdata.keys(): 84 self.metadata[key] = '' 85 try: 86 self.metadata[key] = self.sourceobj[key][0] 87 except: 88 pass 89 90 try: 91 if self.tagdata[key] != '' and self.metadata[key] == "": 92 self.metadata[key] = self.sourceobj[self.tagdata[key]][0] 93 except: 94 pass9597 """Returns a metadata value for a give key. If clean is True, then the resulting string will 98 be cleaned before it is returned. If the key does not exist, an empty string is returned. Return 99 value is read from cache if possible (or unless clear_cache is set to True)""" 100 if not self.metadata or clear_cache: 101 self.read_file_metadata() 102 103 if key not in self.metadata: 104 return '' 105 r = self.metadata[key] 106 if not r: 107 r = ""; 108 if clean: 109 r = r.replace('_',' ').strip() 110 return r.encode('utf-8')111113 """Returns the cleaned title for this media""" 114 return self.get_metadata_value('title', True)115117 """Returns the cleaned artist for this media""" 118 return self.get_metadata_value('artist', True)119121 """Returns a string in the form "artist - title" for this media. If either artist or title are blank, 122 only the non-blank field is returned. If both fields are blank, and the usefn parameter is True, then 123 the filename is returned instead. Otherwise, an empty string is returned.""" 124 a = self.get_metadata_value('artist', True) 125 t = self.get_metadata_value('title', True) 126 if len(a) == 0 and len(t) == 0 and usefn: 127 if self.file_name: 128 a = self.file_name.encode('utf-8') 129 r = a 130 if len(a) > 0 and len(t) > 0: 131 r += ' - ' 132 r += t 133 return r
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Jan 31 00:38:01 2015 | http://epydoc.sourceforge.net |