Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'How to convert iTunes album art images to PNG format' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How to convert iTunes album art images to PNG format
Authored by: ctapler on Oct 22, '11 12:22:52PM

I wrote a Python script which converts my (JFIF/JPG-based) itc files to jpg files. It did work for me (using Python 3.2). You can find the code below. Unfortunately the formatting is removed (which is essential for Python). If anybody requires the script and knows how to distribute it in a better way, please let me know.
<code>
import argparse
import os

def convert(inDir, inFile, outDir):
outFile = outDir + inFile + '.jpg'
inFile = inDir + inFile
print("Converting {0:s} to {1:s}: ".format(inFile, outFile), end='')
buffer = open(inFile, "rb").read()
searchBuffer = buffer.decode('ascii', 'replace')
# According to http://de.wikipedia.org/wiki/JPEG_File_Interchange_Format the header
# is as follows:
# FF D8 FF E0 00 10 4A 46 49 46 00 01.
# J F I F
# As we search for JFIF (easier to do), we have to subtract the position of 6 bytes
index = searchBuffer.find('JFIF')
index = index - 6
if index < 0:
print('Unable to find JPEG header. Skipping')
return
print('Found JPEG header position at {0:d}: '.format(index), end='')
outBuf = open(outFile, "wb")
outBuf.write(buffer[index:])
outBuf.close();
print(' Done.')

parser = argparse.ArgumentParser(description='Converts the apple itc format to a jpeg format')
parser.add_argument('--inDir', action='store', dest='inDir', help='Input directory', default='.')
parser.add_argument('--outDir', action='store', dest='outDir', help='Output directory')
args = parser.parse_args()
print('Input directory: {0:s}'.format(args.inDir))
if args.outDir == None:
args.outDir = args.inDir
print('Output directory: {0:s}'.format(args.outDir))
files = os.listdir(args.inDir)
# Filter out files with extension *.itc
convList = []
for item in files:
if item[-4:] == '.itc':
convList += [item]

# Walk through the list of files and convert them
for item in convList:
convert(args.inDir + '/', item, args.outDir + '/')

print('Done.')
</code>
I call the script as follows:
<code>
"c:\Program Files\Python3\python.exe" main.py --inDir c:/temp/in/
</code>
The script takes the *.itc files from the input directory and writes the jpg files into the same directory.



[ Reply to This | # ]
How to convert iTunes album art images to PNG format
Authored by: ctapler on Oct 24, '11 10:03:49AM

Just recognized that it also works for *.itc2 files. Just adapt the script above for itc2 extensions.



[ Reply to This | # ]