Last active
December 28, 2015 11:59
-
-
Save bj0/7497386 to your computer and use it in GitHub Desktop.
Getting tags (including coverart) out of .aa file using pyaudibletags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyaudibletags import aafile | |
import Image, sys | |
import io | |
import binascii | |
def main(file): | |
f = aafile(file) | |
print 'Title: {}'.format(f.get_parent_title()) | |
print 'Author: {}'.format(f.get_author()) | |
print 'Date: {}'.format(f.get_pubdate()) | |
print 'Narrator: {}'.format(f.get_narrator()) | |
print unicode('(C): {}').format(f.get_copyright()) | |
print 'Description: {}'.format(f.get_description()) | |
print 'Long Description: {}'.format(f.get_long_description()) | |
try: | |
i, sz = f.toc()['Cover art'] | |
with open(file, 'rb') as fi: | |
fi.seek(i) | |
data = fi.read(sz) | |
if data is not None: | |
# find jpeg header | |
i = data.find('\xff\xd8') | |
if i > -1: | |
data = data[i:] | |
else: | |
print 'no jpeg header in image data' | |
im = Image.open(io.BytesIO(data)) | |
print 'embedded image size: {}x{}'.format(*im.size) | |
im.show() | |
else: | |
print 'no image data' | |
except Exception, e: | |
raise | |
print 'exception: ',e | |
if __name__ == '__main__': | |
print sys.argv | |
if len(sys.argv) != 2: | |
print 'usage: {} <aa file>'.format(sys.argv[0]) | |
else: | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment