begin process at 2010 09 06 06:22:45
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Fichier / Disque

 > LIRE LES TAGS ID3 DES FICHIERS MP3

LIRE LES TAGS ID3 DES FICHIERS MP3


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Fichier / Disque Niveau :Débutant Date de création :10/03/2003 Date de mise à jour :10/03/2003 08:47:43 Vu :10 527

Auteur : Otaku

Ecrire un message privé
Commentaire sur cette source (7)
Ajouter un commentaire et/ou une note

 Description

Voila une fonction de base qui prend comme paramètre le chemin d'accès a un fichier mp3 et qui retourne la structure du tag formaté (ou 0 si l'operation échoue), il suffit d'utiliser les fonctions list et explode comme dans l'exemple pour séparer les informations (titre, artiste...)

cette fonction de marche qu'avec les tags ID3v1 et ID3v1.1
À propos si quelqu'un connaît un site avec des info sur les tags MP3 ID3v2 (lecture, taille de la structure...)


Désolé pour le manque de commentaires :-/, mais je ne pense pas que ce code soit difficile à comprendre ;-)
  

Source

  • <?
  • function ReadTag($path)
  • {
  • $genre_array = array("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge",
  • "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B",
  • "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska",
  • "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient",
  • "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical",
  • "Instrumental","Acid","House","Game","Sound Clip","Gospel",
  • "Noise","AlternRock","Bass","Soul","Punk","Space","Meditative",
  • "Instrumental Pop","Instrumental Rock","Ethnic","Gothic",
  • "Darkwave","Techno-Industrial","Electronic","Pop-Folk",
  • "Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta",
  • "Top 40","Christian Rap","Pop/Funk","Jungle","Native American",
  • "Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer",
  • "Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro",
  • "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock",
  • "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival",
  • "Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock",
  • "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band",
  • "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson",
  • "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus",
  • "Porn Groove","Satire","Slow Jam","Club","Tango","Samba",
  • "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle",
  • "Duet","Punk Rock","Drum Solo","Acapella","Euro-House","Dance Hall");
  • $file=fopen($path, "rb");
  • if($file)
  • {
  • fseek($file, 0, SEEK_END);
  • fseek($file, -128, SEEK_CUR);
  • $tag=fread($file, 128);
  • fclose($file);
  • }
  • else
  • {
  • return 0;
  • }
  • if ($tag[0]=='T' && $tag[1]=='A' && $tag[2]=='G')
  • {
  • $title=substr($tag,3,30);
  • $artist=substr($tag,33,30);
  • $album=substr($tag,63,30);
  • $year=substr($tag,93,4);
  • $comment=substr($tag,97,30);
  • $type=ord(substr($tag,127,1));
  • if($type >= 0 && $type <= 125)
  • $genre = $genre_array[$type];
  • else
  • $genre = "none";
  • if (ord($comment[28]) == 0 && ord($comment[29]) != 0)
  • {
  • $track = ord($comment[29]);
  • $comment[29] = "\0";
  • }
  • else
  • {
  • $track = 0;
  • }
  • return sprintf("%s-%s-%s-%s-%s-%s-%s",$title, $artist, $album, $year, $comment, $genre, $track);
  • }
  • else
  • {
  • return 0;
  • }
  • }
  • /*Exemple d'utilisation*/
  • $path = "Test.mp3";
  • $tag = ReadTag($path);
  • if($path == 0)
  • print("Lecture du tag impossible");
  • else
  • {
  • list($title, $artist, $album, $year, $comment, $genre, $track) = explode ("-", $tag);
  • print($title);
  • print("<br>");
  • print($artist);
  • print("<br>");
  • print($album);
  • print("<br>");
  • print($year);
  • print("<br>");
  • print($comment);
  • print("<br>");
  • print($genre);
  • print("<br>");
  • print($track);
  • print("<br>");
  • }
  • ?>
<? 
  function ReadTag($path) 
  { 
     
           $genre_array = array("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge", 
                        "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B", 
                  "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska", 
                  "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient", 
                "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical", 
                  "Instrumental","Acid","House","Game","Sound Clip","Gospel", 
                  "Noise","AlternRock","Bass","Soul","Punk","Space","Meditative", 
                  "Instrumental Pop","Instrumental Rock","Ethnic","Gothic", 
                  "Darkwave","Techno-Industrial","Electronic","Pop-Folk", 
                  "Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta", 
                  "Top 40","Christian Rap","Pop/Funk","Jungle","Native American", 
                  "Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer", 
                  "Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro", 
                  "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock", 
                  "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival", 
                  "Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock", 
                  "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band", 
                  "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson", 
                  "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus", 
                  "Porn Groove","Satire","Slow Jam","Club","Tango","Samba", 
                  "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle", 
                  "Duet","Punk Rock","Drum Solo","Acapella","Euro-House","Dance Hall"); 
     
           $file=fopen($path, "rb"); 
     
           if($file) 
           { 
        fseek($file, 0, SEEK_END); 
        fseek($file, -128, SEEK_CUR); 
       
                      $tag=fread($file, 128); 
       
        fclose($file); 
        } 
       else
      {
          return 0;
      }
     
          if ($tag[0]=='T' && $tag[1]=='A' && $tag[2]=='G') 
            { 
                 $title=substr($tag,3,30); 
                 $artist=substr($tag,33,30); 
                 $album=substr($tag,63,30); 
                 $year=substr($tag,93,4); 
                 $comment=substr($tag,97,30); 
                 $type=ord(substr($tag,127,1)); 
       
                  if($type >= 0 && $type <= 125) 
             $genre = $genre_array[$type]; 
               else 
             $genre = "none"; 
       
                      if (ord($comment[28]) == 0 && ord($comment[29]) != 0) 
                      { 
                            $track = ord($comment[29]); 
                            $comment[29] = "\0"; 
                      } 
                      else 
                      { 
                           $track = 0; 
                      } 
       
       
                 return sprintf("%s-%s-%s-%s-%s-%s-%s",$title, $artist, $album, $year, $comment, $genre, $track); 
            } 
            else 
            { 
                 return 0; 
            } 
  } 
   
  /*Exemple d'utilisation*/ 
   
    $path = "Test.mp3"; 
    $tag = ReadTag($path); 

    if($path == 0)
     print("Lecture du tag impossible");
    else
    {
   
       list($title, $artist, $album, $year, $comment, $genre, $track) = explode   ("-", $tag); 
   
       print($title); 
       print("<br>"); 
       print($artist); 
       print("<br>"); 
       print($album); 
       print("<br>"); 
       print($year); 
       print("<br>"); 
       print($comment);   
       print("<br>"); 
       print($genre); 
       print("<br>"); 
       print($track); 
       print("<br>"); 
   }
    
  ?>   

 Conclusion

Pour appeler la fonction faite $tag = ReadTag($path); $path correspond au chemin d'access au fichier mp3

la fonction ReadTag renvoie les informations séparées par des "-" il suffit, d'utiliser les fonctions list et explode comme dans l'exemple pour séparer les informations  

çe code est l'adaptation PHP de la source http://www.cppfrance.com/article.aspx?Val=1386 Merci a sont auteur  


 Sources de la même categorie

Source avec Zip COMPRESSER (MINIMISER) UN FICHIER CSS par shevabam
RÉCUPÉRER UNE IMAGE EN LIGNE (OU AUTRES FICHIERS) par RaftY
Source avec Zip Source avec une capture LISTAGE DE FICHIERS par jeromin75
Source avec Zip CODE POUR HÉBERGEUR D'IMAGE par bonhommecrea
Source avec Zip EFFACER LES FICHIERS IMAGES ( .PNG ), D'UN RÉPERTOIRE TEMPS ... par christophe0511

Commentaires et avis

Commentaire de iubito le 10/03/2003 08:52:39

pas testé, mais ça me semble pas mal :-)

Commentaire de NitRic le 12/03/2003 05:01:15

Voilà, tu voulais un site qui explique le ID3v2 --&gt;&gt; http://www.id3.org


Ce commentaire à été pensé, écrit et posté par NitRic
NitRic© Toute reproduction même partielle est interdite même avec accord écrit de l'auteur


Beubye && @++;

=P

Commentaire de Otaku le 12/03/2003 12:45:58

Merci

Commentaire de Moasky le 16/05/2003 22:30:38

C un bon code. Juste un truc, pour positionner ton pointeur de fichier, au lieu de faire un double fseek, tu peux faire :

if ( fseek( $file, -128L, SEEK_END ) != 0)                                                        
   {                                                                                              
      print ("Erreur en positionnant le pointeur de fichier");                          
      
      return 0;
   }

Bye

Commentaire de BadFox le 24/08/2003 20:34:09

il y a une erreur dans l'exemple :

if($path == 0) print("Lecture du tag impossible"); else...

c'est pas $path qui doit être utilisé, un type chaîne, mais $tag

Commentaire de mrmabo27 le 04/07/2004 21:02:20

Tous ceci est interessant mais je me demande comment ecrire les tags ou les modifier !

Commentaire de gergalp le 02/09/2004 01:16:55

t'as juste à écrire par dessus :)


ou alors, tu peux aller voir cette source :
http://www.phpcs.com/code.aspx?ID=25736

pite pub ;)

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Septembre 2010
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
27282930   

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales