Skip to content

Instantly share code, notes, and snippets.

@davidzou2131
Created April 23, 2016 07:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidzou2131/aca97ac6a9d5ee01f3362529e6799b58 to your computer and use it in GitHub Desktop.
Save davidzou2131/aca97ac6a9d5ee01f3362529e6799b58 to your computer and use it in GitHub Desktop.
iTunes m4a Personal Information Remover

What this script does

This script removes all the personal information linked to the iTunes account which purchased the song. This includes your full name and email address. This script losslessly remuxes the mp4 (m4a) into a new mp4 container. avconv is used because a file stripped of all personal information tags with AtomicParsley will still contain the owner's full name if the file is viewed with a hex editor. avconv will only preserve standard metadata tags, thus removing all personal information plus some iTunes specific information.

Requirements/Dependencies

  • Python 3 (compatible with v2)
  • avconv (Successor to ffmpeg)
  • AtomicParsley

Setup

Notes

  • The original file will get overwritten once complete
  • If a directory is provided, it will be recursively scanned for *.m4a files

Usage

Windows users must place the avconv and AtomicParsley binaries in a directory that is in the OS PATH variable or create a new PATH entry. A workaround would be to hardcode the full path of the binaries into the script (the AVCONV and ATOMICPARSLEY variables). Please note that avconv.exe is not standalone and requires all the *.dll files in the bin folder.

Command Line

m4aRemux.py input_file0 [input_file1 ...]

where input_file can be a directory and can contain wildcards (? and *) such as *.m4a or D:\path\*.m4a. If a directory is provided, that directory will be recursed for *.m4a files.

Shell

If python is installed properly, simply drag and drop m4a files directly onto the python script.

Metadata

Tags that are preserved

  • Album
  • Album/Performer
  • Track name
  • Track name/Position (Track Number)
  • Performer
  • Composer
  • Genre
  • Recorded date
  • Album Art

Useful info that is removed

  • Sorting information (only useful when non-alphanumeric characters are present)
    • Album/Sorted by
    • Composer/Sort
    • Performer/Sorted by
  • Track/Album stats
    • Part/Position
    • Part/Total
    • Track name/Total
  • iTunes store and catalogue info
  • Copyright info
  • iTunes/iOS specific info
    • iTunSMPB - whether the file is a part of many parts
    • iTunNORM - Volume normalization (replay gain)
#!/usr/bin/env python3
import os
import sys
import glob
import subprocess
# Binaries/Commands
# Ensure binaries are available in the OS PATH variable, or change the following to a full path
# Linux: commands are case sensitive
AVCONV = "avconv"
ATOMICPARSLEY = "AtomicParsley"
# Find files with these extensions only
EXTENSIONS_TO_FIND = [".m4a"]
# Files to process
files = []
# Func to recursively find *.m4a files
# For windows cmd only as cmd does not expand wildcards
def find_files(path):
f = []
for p in glob.glob(path):
if os.path.isdir(p):
f += find_files(p + "/*")
elif os.path.splitext(p)[1] in EXTENSIONS_TO_FIND:
f.append(p)
return f
# Parse for files by expand wildcards and recursing directories
for arg in sys.argv[1:]:
if "*" in arg or "?" in arg or os.path.isdir(arg):
files += find_files(arg)
else:
files.append(arg)
# Print list of files to process
print("Files to process:\n")
print("\n".join(files) + '\n')
# Process
for f_orig in files:
f_name, f_ext = os.path.splitext(f_orig)
f_remux = f_name + "_remuxed" + f_ext
# Remux file with standard mp4 metadata
if subprocess.call('%s -i "%s" -vn -acodec copy -movflags faststart "%s"' % (AVCONV, f_orig, f_remux)):
sys.stderr.write("Error remuxing '%s', skipping." % (f_orig))
continue
# Extract album artwork from original file
subprocess.call('%s "%s" -E' % (ATOMICPARSLEY, f_orig))
# Get a list of all album artwork files
artwork = glob.glob(f_name + "_artwork*.*")
# Add album artwork to the remuxed file
if artwork:
arg_art = ' '.join(['--artwork "%s"' % (i) for i in artwork])
subprocess.call('%s "%s" %s --encodingTool "" --overWrite -o "%s"' % (ATOMICPARSLEY, f_remux, arg_art, f_orig))
# Remove temporary files
os.remove(f_remux)
for f in artwork:
os.remove(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment