Click Here
home features news forums classifieds faqs links search
6071 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
8 crawler(s) on-line.
 89 guest(s) on-line.
 0 member(s) on-line.



You are an anonymous user.
Register Now!
 amigakit:  6 mins ago
 pixie:  24 mins ago
 ncafferkey:  24 mins ago
 Hypex:  31 mins ago
 DiscreetFX:  36 mins ago
 Maijestro:  47 mins ago
 pavlor:  53 mins ago
 wakido:  1 hr 5 mins ago
 Rob:  1 hr 29 mins ago
 kriz:  1 hr 52 mins ago

/  Forum Index
   /  General Technology (No Console Threads)
      /  Python -> Mutagen
Register To Post

PosterThread
djrikki 
Python -> Mutagen
Posted on 3-Jun-2011 23:05:50
#1 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

Hi,

I was hoping someone may have some Python experience here on AW or elsewhere. I have also posted the question on the dedicated forum, but perhaps someone here can help me solve this problem: and so I'll paste in the same error message encountered.

http://www.flickr.com/photos/61283734@N03/5793026249/ - Error message shown here

----

I am trying to read artwork from an itunes mp4a file and came across an example on the web that lead me to Mutagen. Mutagen built just fine with no errors and I a proceeded to run the python example script given and tweaked it to a given m4a I have stuck on a USB stick.

The Script:
from mutagen import File
file = File('FLASH DRIVE:CD Pool Radio-April 2010/10 Some People.m4a') # mutagen can automatically detect format and type of tags
artwork = file.tags['APIC:'].data # access APIC frame and grab the image
with open('image.jpg', 'wb') as img:
img.write(artwork) # write artwork to new image

Error Message:
Downloads:mutagen-1.20/getartwork.py:5: Warning: 'with' will become a
reserved keyword in Python 2.6
  File "Downloads:mutagen-1.20/getartwork.py", line 5
    with open('image.jpg', 'wb') as img:
            ^
SyntaxError: invalid syntax

Questions:
What does this mean!
Also what does this script do in fact - does it write image.jpg to
disk or something?

-----

Hope someone can help with some words of wisdom.

Last edited by djrikki on 03-Jun-2011 at 11:07 PM.
Last edited by djrikki on 03-Jun-2011 at 11:06 PM.

_________________

 Status: Offline
Profile     Report this post  
Snuffy 
Re: Python -> Mutagen
Posted on 3-Jun-2011 23:36:31
#2 ]
Super Member
Joined: 25-Oct-2005
Posts: 1121
From: Michigan, USA

@djrikki

I play in PyGame on Amiga and Python is a stickler for indention. Try indenting line six a couple of spaces ? Is this your script or from where?

_________________

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 4-Jun-2011 0:33:36
#3 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@Snuffy

I've got passed the indentation problem, now I have a new error:

Traceback (most recent call last):
File "Downloads:mutagen-1.20/getartwork.py", line 5, in
artwork = file.tags['APIC:'].data # access APIC frame and grab the image
TypeError: 'NoneType' object is unsubscriptable

Original link is here: http://stackoverflow.com/questions/6171565/how-do-i-read-album-artwork-using-python

I've updated the script to:

from __future__ import with_statement # this first line means it can now use the 'with' command
from mutagen import File

file = File('WORK:Home Directory/User Files/Music/03 Common People.m4a') # mutagen can automatically detect format and type of tags
artwork = file.tags['APIC:'].data # access APIC frame and grab the image
with open('image.jpg', 'wb') as img:
img.write(artwork) # write artwork to new image

I am pretty sure these m4as have album artwork because they appear in MacOS X Finder... although there is strangely an Album Artwork folder in iTunes/Music/iTunes Media...

Last edited by djrikki on 04-Jun-2011 at 12:39 AM.
Last edited by djrikki on 04-Jun-2011 at 12:35 AM.
Last edited by djrikki on 04-Jun-2011 at 12:34 AM.

_________________

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 4-Jun-2011 1:26:39
#4 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@snuffy

Okay I think why it is failing is the APIC tag is empty. It appears iTunes doesn't by default embed artwork into the files... >.<

So I've downloaded this great applescript which will go through my entire 9000+ songs and embed images lol

http://dougscripts.com/itunes/scripts/download.php?sc=embedart

_________________

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 4-Jun-2011 2:51:49
#5 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@Snuffy

Success!

http://www.flickr.com/photos/61283734@N03/5795379692/

_________________

 Status: Offline
Profile     Report this post  
opi 
Re: Python -> Mutagen
Posted on 4-Jun-2011 6:32:20
#6 ]
Team Member
Joined: 2-Mar-2005
Posts: 2752
From: Poland

@djrikki

Quote:
artwork = file.tags['APIC:'].data # access APIC frame and grab the image


I don't know what type .tags has, but I assume it's a subclass of dictionary. Then, you should modify your code to either return default value by using .get method or handle an exception.

>>> postamiga = {'OS4':'AmigaOne','AROS':'Everything','MorphOS':{'Mac','Efika','Pegasos'}}
>>> postamiga['OS7']
Traceback (most recent call last):
File "", line 1, in
KeyError: 'OS7'
>>> postamiga.get('OS7',None)
>>> print postamiga.get('OS7',None)
None
>>> try:
... print postamiga['OS7']
... except KeyError:
... print "I HAS FAILED"
...
I HAS FAILED

_________________
OpenWindows Initiative. Port PS3 hardware to bananas. For free. Join today and receive expired $50 cupon from AI!

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 4-Jun-2011 14:36:04
#7 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@opi

I don't want to get too deep in python, but how I handle if an audio file does not contain an APIC is simplistic - if image.jpg is not found then the running python clearly couldn't find an attached picture in the audio file.

@ All

Atm I am using Mplayer to return the Duration of an audio file as this isn't (generally) found in the ID3 Tags. I had hoped Hollywood would support mp3s, but the ones I am throwing at it are identified as 'Unknown'...


......is there an alternative command line proggy someone can suggest to return the duration of an mp3/m4a? Must be quick, mplayer always takes 3-4 seconds to even load.

_________________

 Status: Offline
Profile     Report this post  
broadblues 
Re: Python -> Mutagen
Posted on 4-Jun-2011 18:40:42
#8 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4446
From: Portsmouth England

@djrikki

investigate mpega it has options to display file info, can't remeber if it;ll do durartion or not, but it'll certainly load faster than mplayer.

It's on aminet.

However it's a 68k executable.

There is a PPC replacement for mpega.library though, if hollywood allows acccess to system libraries, then you might be able to use that from within your app.

Or maybe consider writing a small helper program using mpega.library, could be your introduction to programming in C...


Last edited by broadblues on 04-Jun-2011 at 07:15 PM.
Last edited by broadblues on 04-Jun-2011 at 07:15 PM.

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
Snuffy 
Re: Python -> Mutagen
Posted on 5-Jun-2011 1:02:35
#9 ]
Super Member
Joined: 25-Oct-2005
Posts: 1121
From: Michigan, USA

@djrikki

Re: Python -> Mutagen

Success!

Glad to hear! Opi brought the next idea...data and None in retrievals.

@opi
... you should modify your code to either return default value by using .get method or handle an exception...
Good note! When retrieving data, it's good to know you caught something or nothing!

_________________

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 5-Jun-2011 4:01:04
#10 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@Snuffy

Yeah making some headway.

Looking into adding an iTunes player into Jack, by that I mean, if you have a PC or Mac on the network grab the itunes music library.xml across the network and parse through the data.

Atm I have no idea about sound playback, but that will probably come from mplayer.

Just early stages atm, might not be very effective, definitely worth a try though!

I have thus far made a script that will go through args sent to it (in this case paths to mp3s) and from each arg scan it for album artwork and save it locally to disk.

I am probably an exception to the rule cause I have so much music, cos it currently takes Jack about 45 seconds just to parse through a 14mb XML file containing data on nearly 10000 tracks even before I reach the python script.

Some initial questions:

1) Is there a maximum string length I can pass through on the command line?

eg. whatever.exe "fullpathname.mp3" "fullpathname2.mp3" "fullpathname3.mp3" .... etc ... etc

2) I am having trouble at the moment with quotation marks appearing in filenames, eg. 12" Club Mix, 7" Radio Edit.. I don't know how to a) format that correctly for the command line and b) for the python script itself.

Last edited by djrikki on 05-Jun-2011 at 04:19 AM.
Last edited by djrikki on 05-Jun-2011 at 04:18 AM.
Last edited by djrikki on 05-Jun-2011 at 04:17 AM.
Last edited by djrikki on 05-Jun-2011 at 04:16 AM.

_________________

 Status: Offline
Profile     Report this post  
broadblues 
Re: Python -> Mutagen
Posted on 5-Jun-2011 10:28:37
#11 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4446
From: Portsmouth England

@djrikki

You know that comment I made about "Eval" and "*" on one of your other threads?

This is where it comes in, to quote a '"' in a double quated string do

"this string has a *" in it"

eg


4.AmigaOS4:> echo "this string has a *" in it"
this string has a " in it
4.AmigaOS4:>

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 5-Jun-2011 13:27:32
#12 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@broadblues

So asterisk followed by a double quotation mark... thanks!

_________________

 Status: Offline
Profile     Report this post  
djrikki 
Re: Python -> Mutagen
Posted on 5-Jun-2011 13:41:40
#13 ]
Elite Member
Joined: 22-Jun-2010
Posts: 2077
From: Grimsby, UK

@broadblues

Okay so I have that in place now, but it appears now on closer expection that it wasn't a double quotation mark, but two single quotation marks next to each other! I think single quotation marks are accepted as normal in Amiga filename correct?

(See Twilight Zone)

But python doesn't appear to like it... notice at the end - two single quotation marks - so um not sure what to do - play around I guess until it is accepted.

"SMBFS5:itunes/iTunes Media/Music/2 Unlimited/The Complete History/04 Faces [Radio Edit].mp3" "SMBFS5:itunes/iTunes Media/Music/2 Unlimited/The Complete History/05 Twilight Zone [7'' Vocal].mp3" "SMBFS5:itunes/iTunes Media/Music/2 Unlimited/The Complete History/06 Maximum Overdrive.mp3" "SMBFS5:itunes/iTunes Media/Music/2 Unlimited/The Complete History/08 Get Ready For This [Radio Edit].mp3" "SMBFS5:itunes/iTunes Media/Music/2 Unlimited/The Complete History/07 Let The Beat Control Your Body [Airplay Edit].mp3"
Traceback (most recent call last):
File "python:scripts/jack_getalbumartwork.py", line 10, in
file = File(filename)
File "PYTHON:Lib/site-packages/mutagen/__init__.py", line 203, in File
fileobj = file(filename, "rb")
IOError: [Errno 20] Not a directory: ''


OFFTOPIC: And yes I have their whole album

Last edited by djrikki on 05-Jun-2011 at 01:43 PM.
Last edited by djrikki on 05-Jun-2011 at 01:42 PM.

_________________

 Status: Offline
Profile     Report this post  

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle