How to use id3 for a single mp3 file

The place for "I can't figure out how to..." questions.
Post Reply
tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

How to use id3 for a single mp3 file

Post by tony98 » Sun May 07, 2006 10:51 am

Hi i want to output id3 tangs information for a single mp3 but i do not know how to do this in php. Could any one show me how this can be then , i already installed id3 .Thanks

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Sun May 07, 2006 12:28 pm

Examine /demos/demo.basic.php

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Sun May 07, 2006 3:34 pm

James Heinrich wrote:Examine /demos/demo.basic.php
thank u for u reply. i tried that and it only displays artist name and title but not the album , year,track,genere and comments. Could u tell me how to output those info aswell.Thanks

Code: Select all

/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org>               //
//  available at http://getid3.sourceforge.net                 //
//            or http://www.getid3.org                         //
/////////////////////////////////////////////////////////////////
//                                                             //
// /demo/demo.basic.php - part of getID3()                     //
// Sample script showing most basic use of getID3()            //
// See readme.txt for more details                             //
//                                                            ///
/////////////////////////////////////////////////////////////////

// include getID3() library (can be in a different directory if full path is specified)
require_once('../getid3/getid3.php');

// Initialize getID3 engine
$getID3 = new getID3;

// Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze($tempname);

// Optional: copies data from all subarrays of [tags] into [comments] so
// metadata is all available in one location for all tag formats
// metainformation is always available under [tags] even if this is not called
getid3_lib::CopyTagsToComments($ThisFileInfo);

// Output desired information in whatever format you want
// Note: all entries in [comments] or [tags] are arrays of strings
// See structure.txt for information on what information is available where
// or check out the output of /demos/demo.browse.php for a particular file
// to see the full detail of what information is returned where in the array
echo @$ThisFileInfo['comments_html']['artist'][0]; // artist from any/all available tag formats
echo @$ThisFileInfo['tags']['id3v2']['title'][0];  // title from ID3v2
echo @$ThisFileInfo['audio']['bitrate'];           // audio bitrate
echo @$ThisFileInfo['playtime_string']; 

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Mon May 08, 2006 9:50 am

Refer to structure.txt as the comment says or add this line to the bottom:

print_r($ThisFileInfo);

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Mon May 08, 2006 7:01 pm

Allan Hansen wrote:Refer to structure.txt as the comment says or add this line to the bottom:

print_r($ThisFileInfo);
i look at the structure i do not know what lines should i use to output albumname,artsit and full info. THe code u give me only prints out the location of the tempfile is stored!! I do not need that data!! As i mentioned i need full mp3 info outputed .

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Tue May 09, 2006 9:09 am

print_r($ThisFileInfo); (if put at the end of the demo file) will output *EVERYTHING* getID3() was able to extract.

Should look like

Code: Select all

Array
(
    [GETID3_VERSION] => 1.7.2
    [filesize] => 7395284
    [avdataoffset] => 0
    [avdataend] => 7395284
    [fileformat] => mp3
    [audio] => Array
        (
            [dataformat] => mp3
            [channels] => 2
            [sample_rate] => 44100
            [bitrate] => 216810.81035803
            [channelmode] => stereo
            [bitrate_mode] => vbr
            [codec] => LAME
            [encoder] => LAME3.91
            [lossless] =>
            [encoder_options] => --alt-preset standard
            [compression_ratio] => 0.15363577831493
            [streams] => Array
                (
                    [0] => Array
                        (
                            [dataformat] => mp3
                            [channels] => 2
                            [sample_rate] => 44100
                            [bitrate] => 216810.81035803
                            [channelmode] => stereo
                            [bitrate_mode] => vbr
                            [codec] => LAME
                            [encoder] => LAME3.91
                            [lossless] =>
                            [encoder_options] => --alt-preset standard
                            [compression_ratio] => 0.15363577831493
                        )

                )

        )

    [encoding] => ISO-8859-1
    [filename] => mp3_lame391-aps.mp3
    [filepath] => /data/getid3
    [filenamepath] => /data/getid3/mp3_lame391-aps.mp3
    [mime_type] => audio/mpeg
    [mpeg] => Array
        (
            [audio] => Array
                (
                    [raw] => Array
                        (
                            [synch] => 4094
                            [version] => 3
                            [layer] => 1
                            [protection] => 1
                            [bitrate] => 9
                            [sample_rate] => 0
                            [padding] => 0
                            [private] => 0
                            [channelmode] => 1
                            [modeextension] => 2
                            [copyright] => 0
                            [original] => 1
                            [emphasis] => 0
                        )

                    [version] => 1
                    [layer] => 3
                    [channelmode] => joint stereo
                    [channels] => 2
                    [sample_rate] => 44100
                    [protection] =>
                    [private] =>
                    [modeextension] => MS
                    [copyright] =>
                    [original] => 1
                    [emphasis] => none
                    [padding] =>
                    [bitrate] => 216810.81035803
                    [framelength] => 707
                    [bitrate_mode] => vbr
                    [VBR_method] => Xing
                    [xing_flags_raw] => 15
                    [xing_flags] => Array
                        (
                            [frames] => 1
                            [bytes] => 1
                            [toc] => 1
                            [vbr_scale] => 1
                        )

                    [VBR_frames] => 10446
                    [VBR_bytes] => 7395284
                    [toc] => Array
                        (
                            [0] => 0
                            [1] => 2
                            [2] => 5
                            [3] => 7
                            [4] => 10
                            [5] => 12
                            [6] => 15
                            [7] => 17
                            [8] => 20
                            [9] => 22
                            [10] => 24
                            [11] => 27
                            [12] => 29
                            [13] => 32
                            [14] => 34
                            [15] => 37
                            [16] => 40
                            [17] => 42
                            [18] => 45
                            [19] => 47
                            [20] => 51
                            [21] => 53
                            [22] => 56
                            [23] => 58
                            [24] => 61
                            [25] => 63
                            [26] => 66
                            [27] => 69
                            [28] => 71
                            [29] => 73
                            [30] => 76
                            [31] => 79
                            [32] => 82
                            [33] => 84
                            [34] => 86
                            [35] => 90
                            [36] => 92
                            [37] => 95
                            [38] => 97
                            [39] => 101
                            [40] => 103
                            [41] => 105
                            [42] => 107
                            [43] => 110
                            [44] => 112
                            [45] => 115
                            [46] => 117
                            [47] => 120
                            [48] => 122
                            [49] => 124
                            [50] => 127
                            [51] => 130
                            [52] => 132
                            [53] => 134
                            [54] => 138
                            [55] => 140
                            [56] => 143
                            [57] => 145
                            [58] => 148
                            [59] => 150
                            [60] => 152
                            [61] => 155
                            [62] => 158
                            [63] => 160
                            [64] => 162
                            [65] => 165
                            [66] => 168
                            [67] => 170
                            [68] => 173
                            [69] => 175
                            [70] => 178
                            [71] => 180
                            [72] => 183
                            [73] => 185
                            [74] => 188
                            [75] => 190
                            [76] => 193
                            [77] => 196
                            [78] => 198
                            [79] => 201
                            [80] => 203
                            [81] => 206
                            [82] => 209
                            [83] => 211
                            [84] => 214
                            [85] => 217
                            [86] => 220
                            [87] => 223
                            [88] => 225
                            [89] => 228
                            [90] => 231
                            [91] => 233
                            [92] => 235
                            [93] => 239
                            [94] => 241
                            [95] => 244
                            [96] => 246
                            [97] => 249
                            [98] => 252
                            [99] => 254
                        )

                    [LAME] => Array
                        (
                            [short_version] => LAME3.91
                            [raw] => Array
                                (
                                    [vbr_method] => 3
                                    [RGAD_track] => 0
                                    [RGAD_album] => 0
                                    [abrbitrate_minbitrate] => 0
                                    [noise_shaping] => 2
                                    [stereo_mode] => 3
                                    [not_optimal_quality] => 0
                                    [source_sample_freq] => 1
                                    [mp3_gain] => 0
                                    [surround_info] => 0
                                )

                            [vbr_quality] => 78
                            [tag_revision] => 0
                            [vbr_method] => vbr-old / vbr-rh
                            [lowpass_frequency] => 19000
                            [encoding_flags] => Array
                                (
                                    [nspsytune] => 1
                                    [nssafejoint] => 1
                                    [nogap_next] =>
                                    [nogap_prev] =>
                                )

                            [ath_type] => 4
                            [encoder_delay] => 576
                            [end_padding] => 1560
                            [noise_shaping] => 2
                            [stereo_mode] => joint stereo
                            [not_optimal_quality] =>
                            [source_sample_freq] => 44.1 kHz
                            [mp3_gain_db] => 0
                            [mp3_gain_factor] => 1
                            [surround_info] => no surround info
                            [preset_used_id] => 0
                            [preset_used] =>
                            [audio_bytes] => 7395284
                            [music_crc] => 12776
                            [lame_tag_crc] => 37898
                        )

                    [VBR_bitrate] => 216810.81035803
                )

        )

    [playtime_seconds] => 272.87510204082
    [bitrate] => 216810.81035803
    [playtime_string] => 4:33
)
If you get something else, you have not "installed" getID3() correctly.

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Tue May 09, 2006 9:17 am

Many thank fo u reply. Well i got similer to that but all of them one after another . Could u tell me how i only print those info i want in readable format ?Forexample artist,albumname,title,duration,... Just these info in one at each new line :

Code: Select all

Title:

Artist:

Album:

Year: 

Track:

Genre:

Comment:

djuk
User
Posts: 3
Joined: Tue Jan 23, 2007 3:10 pm
Location: UK

Post by djuk » Wed Jan 24, 2007 3:06 am

Hi....

Is there a script which would permit me to paste the url of a single mp3 FILE (as opposed to a directory), returning tag / bitrate results.

For example, if I wanted to get the info about this file... http://www.ismartguys.com/MP3s/ABBA/Gre ... %20All.mp3 how could I go about it.
(supposing that I *don't* have rights to view the parent directory)

Is there a way?

Many thanks.

djuk
User
Posts: 3
Joined: Tue Jan 23, 2007 3:10 pm
Location: UK

Post by djuk » Wed Jan 24, 2007 3:49 am

Ah! Now I've spotted the appropraite bit in "readme.txt" (soory!)

To analyze remote files over HTTP or FTP you need to copy the file
locally first before running getID3(). Your code would look something
like this:

// Copy remote file locally to scan with getID3()
$remotefilename = 'http://www.example.com/filename.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
etc.

Is it really necessary to copy the WHOLE file across (forgive my ignorance). The problem with this is that it takes sooooo long that my routine times out. I am really ignorant of this, but doesn't the bitspeed info occur very early on in the mp3 file so we could just look at that part?

Apologies if this is gross stupidity!

Post Reply