Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an extensive music collection and want to back up only tags from it (so later, if I lose it, I can find it again). It consists of .m4a and .mp3 files. How can I do this?

share|improve this question

That really depends on the system you are using, for a portable solution - see for example

share|improve this answer
up vote 1 down vote accepted

Here is my simple script, that resolves this problem for me. Thanks for hints.

# coding=utf-8
"""Backs up tags from all m4a and mp3 files in a directory, recursively
and stores them as JSON file."""
import os
import json
import logging
from mutagen.easyid3 import EasyID3
from mutagen.easymp4 import EasyMP4

def backup_tags(directory, outfile):
    """Back up tags from all m4a & mp3 files from 'directory' into 'outfile'"""'Saving started.')
    filenames = []
    for root, _, files in os.walk(directory):
        filenames.extend([os.path.join(root, x) for x in files])

    def tags_dict(filename):
        """Return tags from file 'filename' as python dictionary"""
        _, extension = os.path.splitext(filename)
        if extension == '.mp3':
            return dict(EasyID3(filename))
        elif extension == '.m4a':
            return dict(EasyMP4(filename))
            raise Exception('Not supported file type: %s' % filename)

    with open(outfile, 'w') as out:
        json.dump([tags_dict(x) for x in filenames], out, indent=1)'Tags from %d file(s) saved.', len(filenames))

if __name__ == '__main__':
    backup_tags(u'F:\\Music', 'backup.json')
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.