Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mp3 tag reader
01-14-2010, 01:14 PM (This post was last modified: 01-14-2010 01:54 PM by codecaine.)
Post: #1
mp3 tag reader
I was on the wiki for mp3s and I saw that the last 128 bytes of a mp3 is the tag information. So I made a script to get the tag information. The code is also attached in a zip.

Code:
#This program was coded by codecaine aka "Jerome Scott II"

import sys;
import os;

#check if the user inputed a argument
if len(sys.argv) < 1:
    print('Error: No mp3 file given as a argument');
    sys.exit(1);
    
#holds the file extension to check if the file is a mp3
fileExtension = sys.argv[1][-3:];
    
#check if the file is a mp3
if fileExtension != 'mp3':
    print('Error: This program only reads mp3s');
    sys.exit(1)

#Hold the location of the last 128 bytes a mp3
last128 = os.path.getsize(sys.argv[1]) - 128;

#read mp3 in binary mode
f = open(sys.argv[1],'rb')

#go to the last 128 bytes in the file
f.seek(last128);

#read 3 bytes for the tag
tag = f.read(3);

#read 30 bytes for title
title = f.read(30);

#read 30 bytes for artist name
artist = f.read(30);

#read 30 bytes for album name
album = f.read(30);

#read 4 bytes the year of album
year = f.read(4);

#read 30 bytes for mp3 comment
comment = f.read(30);

#read 1 byte for the genre
genre = ord(f.read(1));

#close the file
f.close();

print('########################################################');
#print the mp3 file name without directory path
print('Filename: ' + os.path.basename(f.name));

#print mp3 tag information
print('Title: ' + title);
print('Artist: ' + artist);
print('Album: ' + album);
print('Year: ' + year);
print('Comment: ' + comment);
print('Genre: ' + str(genre));
print('########################################################');


Attached File(s)
.zip  mp3TagReader.py.zip (Size: 1.12 KB / Downloads: 4)
Visit this user's website Find all posts by this user
Quote this message in a reply
01-14-2010, 01:23 PM
Post: #2
RE: mp3 tag reader
Now this is a great example to show what python can do!

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
01-14-2010, 10:20 PM
Post: #3
RE: mp3 tag reader
OMG i have to check this out!

a little help please. which python are you using? mine is 2.5.4 and i hope there wont be any type missmatch.
and, why do i get this message?
Code:
Traceback (most recent call last):
  File "C:\Documents and Settings\Radic\Desktop\mp3TagReader.py", line 12, in <module>
    fileExtension = sys.argv[1][-3:];
IndexError: list index out of range
Find all posts by this user
Quote this message in a reply
01-15-2010, 02:32 AM
Post: #4
RE: mp3 tag reader
I had reposted the source I had that sys.argv to check if the user enter the mp3 on the command line. to use the program you have to do it like so:

python mp3TagReader.py c:\myfile.mp3

if you don't put the mp3 path and file name on the command line you get a error. because then the system argument is 0 but with the repost it tell you you about it instead of the error
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2010, 12:24 AM
Post: #5
RE: mp3 tag reader
Oh I see. Thanks.
Find all posts by this user
Quote this message in a reply
01-16-2010, 02:35 AM
Post: #6
RE: mp3 tag reader
You put you python in you system environment variables? so its global you can run python anywhere in terminal?
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2010, 10:47 PM
Post: #7
RE: mp3 tag reader
(01-16-2010 02:35 AM)codecaine Wrote:  You put you python in you system environment variables? so its global you can run python anywhere in terminal?

i think i saw a thread about it. i will look up for it...
Find all posts by this user
Quote this message in a reply
01-17-2010, 04:50 AM
Post: #8
RE: mp3 tag reader
If you install this python it should automatic set environment variables and win32api http://www.activestate.com/activepython/
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: