AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read MP3 ID3 tag / metadata from .mp3 (https://forums.alliedmods.net/showthread.php?t=319436)

RaZ_HU 11-01-2019 04:31

Read MP3 ID3 tag / metadata from .mp3
 
Is it possible using AMXX to read ID3 tags (metadata?) from .mp3 files?

HamletEagle 11-01-2019 16:10

Re: Read MP3 ID3 tag / metadata from .mp3
 
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.

Bugsy 11-01-2019 17:45

Re: Read MP3 ID3 tag / metadata from .mp3
 
You can also review nvault utility as this does a similar task of reading binary data based on a defined file structure.

RaZ_HU 11-02-2019 18:38

Re: Read MP3 ID3 tag / metadata from .mp3
 
Thank you guys, will check it in the morning.


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

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.