Commits

Felix Krull  committed cb31c54

Properly recognise file extensions with different capitalisation.

  • Participants
  • Parent commits c860108

Comments (0)

Files changed (4)

 ------------------------
 - Work around a bug in some pygobject 3.10 releases
   (https://bugzilla.gnome.org/show_bug.cgi?id=710447)
+- Properly recognise file extensions even with different capitalisation.
 
 rgain 1.2.1 (2013-10-18)
 ------------------------

File rgain/rgio.py

             self.more_mappings[".mp3"] = self.MP3_FORMATS[mp3_format]
         else:
             raise ValueError("invalid MP3 format %r" % mp3_format)
-    
-    @property
-    def supported_formats(self):
-        return (set(self.BASE_MAP.iterkeys()) |
-                set(self.more_mappings.iterkeys()))
+
+    def is_supported_format(self, ext):
+        ext_lower = ext.lower()
+        return ext_lower in self.BASE_MAP or ext_lower in self.more_mappings
     
     def read_gain(self, filename):
-        ext = os.path.splitext(filename)[1]
+        ext = os.path.splitext(filename)[1].lower()
         if ext in self.more_mappings:
             accessor = self.more_mappings[ext]
         elif ext in self.BASE_MAP:
         return accessor[0](filename)
     
     def write_gain(self, filename, trackgain, albumgain):
-        ext = os.path.splitext(filename)[1]
+        ext = os.path.splitext(filename)[1].lower()
         if ext in self.more_mappings:
             accessor = self.more_mappings[ext]
         elif ext in self.BASE_MAP:

File rgain/script/collectiongain.py

     return album_id
 
 
-def collect_files(music_dir, files, cache, supported_formats):
+def collect_files(music_dir, files, cache, is_supported_format):
     i = 0
     for dirpath, dirnames, filenames in os.walk(music_dir):
         for filename in filenames:
                     continue
 
             ext = os.path.splitext(filename)[1]
-            if ext in supported_formats:
+            if is_supported_format(ext):
                 i += 1
                 print ou(u"  [%i] %s |" % (i, filepath)),
                 album_id = get_album_id(music_dir, filepath)
     # cache is written to disk so all progress persists
     try:
         collect_files(music_dir, files, cache,
-                      rgio.BaseFormatsMap(mp3_format).supported_formats)
+                      rgio.BaseFormatsMap(mp3_format).is_supported_format)
         # clean cache
         for filepath, visited in cache.items():
             if not visited:

File rgain/script/replaygain.py

     
     newfiles = []
     for filename in files:
-        if not os.path.splitext(filename)[1] in formats_map.supported_formats:
+        if not formats_map.is_supported_format(os.path.splitext(filename)[1]):
             print ou(u"%s: not supported, ignoring it" % filename)
         else:
             newfiles.append(filename)