Raised This Month: $28 Target: $400
 7% 

Read MP3 ID3 tag / metadata from .mp3


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RaZ_HU
Senior Member
Join Date: May 2015
Location: Hungary
Old 11-01-2019 , 04:31   Read MP3 ID3 tag / metadata from .mp3
Reply With Quote #1

Is it possible using AMXX to read ID3 tags (metadata?) from .mp3 files?
RaZ_HU is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-01-2019 , 16:10   Re: Read MP3 ID3 tag / metadata from .mp3
Reply With Quote #2

PHP Code:
#include <amxmodx>

public plugin_init()
{
    
readDataFromMp3("sound/...")
}

readDataFromMp3(const fileName[])
{
    new 
filePointer fopen(fileName"rb")
    if(!
filePointer)
    {
        
server_print("failed to open file")
        return 
0
    
}
    
    
fseek(filePointerfile_size(fileName) - 128SEEK_SET)
    
    new 
tag[4]
    
fread_blocks(filePointertagcharsmax(tag), BLOCK_CHAR)
    
server_print("tag: %s"tag)

    new 
songTitle[31]
    
fread_blocks(filePointersongTitlecharsmax(songTitle), BLOCK_CHAR)
    
server_print("songTitle: %s"songTitle)
    
    new 
artist[31]
    
fread_blocks(filePointerartistcharsmax(artist), BLOCK_CHAR)
    
server_print("artist: %s"artist)
    
    new 
album[31]
    
fread_blocks(filePointeralbumcharsmax(album), BLOCK_CHAR)
    
server_print("album: %s"album)
    
    new 
year[5]
    
fread_blocks(filePointeryearcharsmax(year), BLOCK_CHAR)
    
server_print("year: %s"year)
    
    new 
comment[31]
    
fread_blocks(filePointercomment30BLOCK_CHAR)
    
server_print("comment: %s"comment)
    
    new 
genre
    fread
(filePointergenreBLOCK_BYTE)
    
server_print("genre: %d"genre)

Very basic and unpolished example, but it does the job. In general, you can open and ready any binary file if you know its structure(which you can find with a simple google search). You can also translate the genre byte into its string equivalent if you search for the list and build a table for it.
Here you can find another example(reading animation data from a mdl file): https://forums.alliedmods.net/showthread.php?t=310253 together with an explanation about what I did and why.
__________________

Last edited by HamletEagle; 11-01-2019 at 16:14.
HamletEagle is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-01-2019 , 17:45   Re: Read MP3 ID3 tag / metadata from .mp3
Reply With Quote #3

You can also review nvault utility as this does a similar task of reading binary data based on a defined file structure.
__________________
Bugsy is offline
RaZ_HU
Senior Member
Join Date: May 2015
Location: Hungary
Old 11-02-2019 , 18:38   Re: Read MP3 ID3 tag / metadata from .mp3
Reply With Quote #4

Thank you guys, will check it in the morning.
RaZ_HU is offline
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:59.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode