/[soapbox]/prolatio/music_tagger/tagging.py
ViewVC logotype

Diff of /prolatio/music_tagger/tagging.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3039 by tadas, Mon Sep 13 22:02:17 2010 UTC revision 3040 by tadas, Tue Sep 14 15:42:58 2010 UTC
# Line 42  class TagExtBase(object): Line 42  class TagExtBase(object):
42          self.map = map          self.map = map
43          self.cache = dict()          self.cache = dict()
44    
45      album = Def.default_property('album')      album = Def.default_property('album') # FIXME: problema del utf !!!
46    
47      comment = Def.default_property('comment')      comment = Def.default_property('comment') # FIXME: problema del utf !!!
48    
49      title = Def.default_property('title')      title = Def.default_property('title') # FIXME: problema del utf !!!
50    
51      track = Def.default_property('track')      track = Def.default_property('track')
52    
# Line 131  class TagExtXiph(TagExtBase): Line 131  class TagExtXiph(TagExtBase):
131          return None          return None
132    
133      def set_field(self, key, value_list):      def set_field(self, key, value_list):
134          from _tagpy import StringList # very hacky stuff, but no other way to do it :D          #from _tagpy import StringList # very hacky stuff, but no other way to do it :D
135    
136          if not key:          if not key:
137              raise TypeError('key not given')              raise TypeError('key not given')
# Line 146  class TagExtXiph(TagExtBase): Line 146  class TagExtXiph(TagExtBase):
146          for value in value_list:          for value in value_list:
147              if isinstance(value, str) or isinstance(value, unicode) and len(value.strip()):              if isinstance(value, str) or isinstance(value, unicode) and len(value.strip()):
148                  to_add.append(value)                  to_add.append(value)
149          if not len(to_add):          #if not len(to_add):
150              self.tag.removeField(key)          self.tag.removeField(key)
151          else:          for value in to_add:
152              str_list = StringList()              self.tag.addField(key, value, False)
153              for value in to_add:          #else:
154                  str_list.append(value)              #str_list = StringList()
155              self.map[key] = str_list              #for value in to_add:
156                #    str_list.append(value)
157                #self.map[key] = str_list
158    
159      def set_field_int(self, key, number):      def set_field_int(self, key, number):
160          if not key:          if not key:
# Line 205  class TagExtXiph(TagExtBase): Line 207  class TagExtXiph(TagExtBase):
207    
208      def disc_get(self):      def disc_get(self):
209          str = self.get_first_field('DISCNUMBER')          str = self.get_first_field('DISCNUMBER')
210            if not str:
211                return 0
212          num = self.try_int(str)          num = self.try_int(str)
213          if num:          if num:
214              return num              return num
# Line 398  class TagExtID3v2(TagExtBase): Line 402  class TagExtID3v2(TagExtBase):
402          if frame_class == 'TextIdentificationFrame':          if frame_class == 'TextIdentificationFrame':
403              self.tag.removeFrames(frame_type) # trash old values              self.tag.removeFrames(frame_type) # trash old values
404              frame = TextIdentificationFrame(frame_type)              frame = TextIdentificationFrame(frame_type)
405                str_list = StringList()
406                for value in to_add:
407                    str_list.append(value)
408                frame.setTextEncoding(tagpy.StringType.UTF8)
409                frame.setText(str_list)
410          elif frame_class == 'UserTextIdentificationFrame':          elif frame_class == 'UserTextIdentificationFrame':
411              frame = UserTextIdentificationFrame()              frame = UserTextIdentificationFrame()
412                frame_type = frame_type.encode('ascii', 'ignore')
413              frame.setDescription(frame_type)              frame.setDescription(frame_type)
414                frame.setTextEncoding(tagpy.StringType.UTF8)
415                frame.setText(to_add[0])
416          elif frame_class == 'UniqueFileIdentifierFrame':          elif frame_class == 'UniqueFileIdentifierFrame':
417              # UFID frame doesn't like UTF, so make sure we give only ascii as it's value              # UFID frame doesn't like UTF, so make sure we give only ascii as it's value
418              ufid_value = to_add[0].encode('ascii', 'ignore')              ufid_value = to_add[0].encode('ascii', 'ignore')
419              frame = UniqueFileIdentifierFrame(frame_type, ufid_value)              frame = UniqueFileIdentifierFrame(frame_type, ufid_value)
             self.tag.addFrame(frame)  
             return  
420          else:          else:
421              return              return
422          str_list = StringList()  
         for value in to_add:  
             str_list.append(value)  
         frame.setTextEncoding(tagpy.StringType.UTF8)  
         frame.setText(str_list)  
423          self.tag.addFrame(frame)          self.tag.addFrame(frame)
424    
425      # set TextIdentification frame (value can be either string or list of strings)      # set TextIdentification frame (value can be either string or list of strings)
# Line 608  class TagExtAPE(TagExtBase): Line 614  class TagExtAPE(TagExtBase):
614          for value in value_list:          for value in value_list:
615              if isinstance(value, str) or isinstance(value, unicode) and len(value.strip()):              if isinstance(value, str) or isinstance(value, unicode) and len(value.strip()):
616                  to_add.append(value)                  to_add.append(value)
617          if not len(to_add):          self.tag.removeItem(key) # trash old values
618              self.tag.removeItem(key)          if len(to_add):
         else:  
619              str_list = StringList()              str_list = StringList()
620              for value in to_add:              for value in to_add:
621                  str_list.append(value)                  str_list.append(value)

Legend:
Removed from v.3039  
changed lines
  Added in v.3040

tadas_AT_dailyda_DOT_com
ViewVC Help
Powered by ViewVC 1.1.8