]> diplodocus.org Git - flac-archive/blobdiff - flac2mp3
pointless quote change
[flac-archive] / flac2mp3
index 982a0120dbdd37832a3c1dd521e946e6b63aac52..1e29ad0bc04f727d947667bf6dc8107d747cc02e 100755 (executable)
--- a/flac2mp3
+++ b/flac2mp3
@@ -1,6 +1,6 @@
 #! /usr/bin/env python2.4
 
-'''
+"""
 =head1 NAME
 
 B<flac2mp3> - transcode FLAC file to MP3 files
@@ -48,7 +48,7 @@ Written by Eric Gillespie <epg@pretzelnet.org>.
 
 =cut
 
-''' #' # python-mode is sucks
+"""
 
 import re, sys, traceback
 from optparse import OptionParser
@@ -62,12 +62,10 @@ from org.diplodocus.util import run_or_die
 # The child processes
 
 def flac2mp3(fn, title, artist, album, date, track, skip_until, pics=None):
-    (title, artist, album, date) = [(x == None and 'unknown') or x
-                                    for x in (title, artist, album, date)]
-    try:
-        (skip_arg, until_arg) = skip_until
-    except ValueError:
-        skip_arg = until_arg = ''
+    (title, artist, album) = [(x == None and 'unknown') or x
+                              for x in (title, artist, album)]
+    if date == None:
+        date = ''
 
     if quiet:
         flac_options = '--silent'
@@ -95,8 +93,8 @@ def flac2mp3(fn, title, artist, album, date, track, skip_until, pics=None):
     quoted_outfile = ('%s (%s) %02d %s.mp3' % (artist, album,
                                                track, title)).replace('/', '_')
 
-    run_or_die(3, "flac %s -cd %s %s '%s' | lame --add-id3v2 %s --tt '%s' --ta '%s' --tl '%s' --ty '%s' --tn %d - '%s'"
-               % (flac_options, skip_arg or '', until_arg or '', fn,
+    run_or_die(3, "flac %s -cd %s '%s' | lame --add-id3v2 %s --tt '%s' --ta '%s' --tl '%s' --ty '%s' --tn %d - '%s'"
+               % (flac_options, ' '.join(skip_until), fn,
                   lame_options, title, artist, album, date, track,
                   quoted_outfile))
 
@@ -152,18 +150,18 @@ def get_decode_args(fn):
 # get PART as part of the filelname, same as mp3s.
 class Tags(object):
     def __init__(self):
+        self._global = {}
         self._tags = {}
     def __len__(self):
-        return len(self._tags)
+        # All files have at least one track.
+        return max(1, len(self._tags))
     def get(self, key, track=None):
         key = key.upper()
         try:
-            if track == None:
-                return self._tags[None][key]
             try:
                 return self._tags[track][key]
             except KeyError:
-                return self._tags[None][key]
+                return self._global[key]
         except KeyError:
             return None
     def gets(self, key, track=None):
@@ -172,15 +170,21 @@ class Tags(object):
             return None
         return '\n'.join(value)
     def set(self, key, value, track=None):
-        if track not in self._tags:
-            self._tags[track] = {}
-        if key not in self._tags[track]:
-            self._tags[track][key] = []
-        self._tags[track][key].append(value)
+        key = key.upper()
+        if track == None:
+            tags = self._global
+        else:
+            try:
+                tags = self._tags[track]
+            except KeyError:
+                tags = self._tags[track] = {}
+        if key not in tags:
+            tags[key] = []
+        tags[key].append(value)
 
 def get_tags(fn):
-    '''Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags
-    in the file FN.'''
+    """Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags
+    in the file FN."""
 
     tags = Tags()
 
@@ -201,15 +205,6 @@ def get_tags(fn):
 
     return tags
 
-def find_pics(fn, tags):
-    pics = tags.get('__flac2mp3_PICTURE')
-
-    if not isinstance(pics, list):
-        pics = flac.get_pictures(fn)
-        tags.set('__flac2mp3_PICTURE', pics)
-
-    return pics
-
 def main(argv):
     # Control the exit code for any uncaught exceptions.
     try:
@@ -263,6 +258,8 @@ def main(argv):
                 else:
                     track = int(track)
 
+                pics = flac.get_pictures(fn)
+
                 for i in range(len(tags)):
                     title = tags.gets('TITLE', track)
                     part = tags.gets('PART', track)
@@ -272,7 +269,7 @@ def main(argv):
                                  tags.gets('ARTIST', track),
                                  album,
                                  tags.gets('DATE', track),
-                                 track, args[i], find_pics(fn, tags)])
+                                 track, args[i], pics])
                     track = i + 2
             except Exception, error:
                 sys.stderr.write(getattr(error, 'msg', ''))