Current location: Hot Scripts Forums » Programming Languages » Other Languages » file.read problem


file.read problem

Reply
  #1 (permalink)  
Old 11-07-06, 11:45 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
file.read problem

Yesterday i builded an id3 tag reader for mp3 files. I used a php class i've written before as base.
The first thing you have to do in order to read the tags is to check if it's id3v1 or id3v2. To do so, you read the first 10 characters of the file.
No here's my problem: when i open the file and read the first 10 characters, only 9 are returned.

this is the code i'm using:
Code:
def id3v2(fpath):
    global tags
    mp3File = open(fpath, "r")
    mp3File.seek(0)
    mp3FileID3 = bin2hex(mp3File.read(10))
It works for 60% of the mp3 files, but with certain files, it only reads 9 characters, even when i attempt to read 50 characters.
Is there a byte character that stops the reading of the file (mp3 is ascii encoded)?

Ow yes: it works fine with all files when i use my php class

EDIT: when i print the ord of every single character, i get an error that the thenth character is a string of length 0
Code:
for i in range(10):
    print ord(mp3File.read(1))
But when i open the file in wordpad, it shows a character on position 10

EDIT 2: i've found it: i just had to open the file in binary mode, not text mode. This is done by adding a "b" to the open-mode:
Code:
mp3File = open(fpath, "rb")
Thanx anyway,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks


Last edited by UnrealEd; 11-07-06 at 12:29 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
Weird mysql_query and Smarty problem Canglan PHP 3 11-15-05 08:49 PM
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 03:40 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.