Editing Audio Tags editor script

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 24: Line 24:
 
song_attrs = [] # Dictionaries containing attributes to be inspected
 
song_attrs = [] # Dictionaries containing attributes to be inspected
  
ff = sys.argv[1]
 
default_album_name = os.path.basename(os.path.dirname(os.path.abspath(ff)))
 
 
# Make sure mutagen uses the easy version, as
 
# Make sure mutagen uses the easy version, as
 
# it uses the normal one by default
 
# it uses the normal one by default
extension = os.path.splitext(ff)[1]  
+
if os.path.splitext(sys.argv[1])[1] == ".mp3":
if extension == ".mp3":
 
 
     import mutagen.easyid3
 
     import mutagen.easyid3
 
     mut_init = mutagen.easyid3.EasyID3
 
     mut_init = mutagen.easyid3.EasyID3
elif extension == ".m4a":
 
    import mutagen.easymp4
 
    mut_init = mutagen.easymp4.EasyMP4
 
 
else:
 
else:
 
     mut_init = mutagen.File
 
     mut_init = mutagen.File
Line 43: Line 37:
 
     for attr in attrs:
 
     for attr in attrs:
 
         song_attrs[-1][attr] = songs[-1].get(attr, [''])[0]
 
         song_attrs[-1][attr] = songs[-1].get(attr, [''])[0]
         if not song_attrs[-1][attr]:
+
         if attr == 'artist' and not song_attrs[-1][attr]:
             if attr == 'artist':
+
             del song_attrs[-1][attr]
                _attr = 'albumartist'
+
            _attr = 'albumartist'
                song_attrs[-1][attr] = songs[-1].get(_attr, [''])[0]
+
            song_attrs[-1][attr] = songs[-1].get(_attr, [''])[0]
            if attr == 'title':
+
        if attr == 'title' and not song_attrs[-1][attr]:
                song_attrs[-1][attr] = os.path.splitext(f)[0]
+
            del song_attrs[-1][attr]
            if attr == 'album':
+
            song_attrs[-1][attr] = os.path.splitext(f)[0]
                song_attrs[-1][attr] = default_album_name
+
 
  
 
with tempfile.NamedTemporaryFile('w+', suffix='.csv') as tmpf:
 
with tempfile.NamedTemporaryFile('w+', suffix='.csv') as tmpf:
     csvwriter = csv.writer(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape,
+
     csvwriter = csv.writer(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape)
            skipinitialspace=True)
 
 
     csvwriter.writerows([row.values() for row in song_attrs])
 
     csvwriter.writerows([row.values() for row in song_attrs])
 
     # Ensure that the file has been written to disk
 
     # Ensure that the file has been written to disk
Line 60: Line 53:
 
     os.system("{} {}".format(editor, tmpf.name))
 
     os.system("{} {}".format(editor, tmpf.name))
 
     tmpf.seek(0)
 
     tmpf.seek(0)
     csvreader = csv.reader(tmpf, quoting=csv.QUOTE_NONE,
+
     csvreader = csv.reader(tmpf, quoting=csv.QUOTE_NONE, escapechar=escape)
            escapechar=escape, skipinitialspace=True)
 
 
     for song,row in zip(songs, csvreader):
 
     for song,row in zip(songs, csvreader):
 
         new_song_metadata = dict(zip(attrs, row))
 
         new_song_metadata = dict(zip(attrs, row))

Please note that all contributions to Vifm Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Vifm:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)