Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Maury MP3 Tag v2 (Componente) - MauryMp3Tag.pas

MauryMp3Tag.pas

Caricato da: Maury91
Scarica il programma completo

  1. unit MauryMp3Tag;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Classes;
  7.  
  8. type
  9. TTag = packed record
  10.     Tag     : array[0..2] of Char;
  11.     Titolo,
  12.     Artista,
  13.     Album : array[0..29] of Char;
  14.     Anno    : array[0..3] of Char;
  15.     Commento   : array[0..29] of Char;      
  16.     Genere   : Byte;
  17.   end;
  18.   TMauryMp3Tag = class(TComponent)
  19.   private
  20.     FFilename: TFileName;
  21.     ftitolo: string;
  22.     fAlbum: string;
  23.     fartista: string;
  24.     fAnno: string;
  25.     fCommento: string;
  26.     fGenere: string;
  27.     fGenereB: byte;
  28.     procedure Set_Filename(const Value: TFileName);
  29.     procedure GetMp3tag(mp3File: string);
  30.     { Private declarations }
  31.   protected
  32.     { Protected declarations }
  33.   public
  34.     { Public declarations }
  35.   published
  36.     { Published declarations }
  37.     property FileName : TFileName read FFilename write Set_Filename;
  38.     property Titolo : string index 1 read ftitolo write ftitolo;
  39.     property Artista : string index 2 read fartista write fartista;
  40.     property Commento : string index 3 read fCommento write fCommento;
  41.     property Album : string index 4 read fAlbum write fAlbum;
  42.     property Anno : string index 5 read fAnno write fAnno;
  43.     property Genere : string index 6 read fGenere write fGenere;
  44.     property GenereB : byte index 7 read fGenereB write fGenereB;
  45.         procedure SetTag(mp3File, STitolo, SArtista, SAlbum, SAnno,
  46.       SCommento: string; SGenere: byte);
  47.   end;
  48.  
  49. procedure Register;
  50.  
  51. implementation
  52.  
  53. const
  54.   Max=147;
  55.   Generi: array[0..Max] of string = (
  56.     'Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge',
  57.     'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B',
  58.     'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska',
  59.     'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient',
  60.     'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical',
  61.     'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel',
  62.     'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative',
  63.     'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic',
  64.     'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk',
  65.     'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta',
  66.     'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American',
  67.     'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer',
  68.     'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro',
  69.     'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock',
  70.     'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival',
  71.     'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock',
  72.     'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band',
  73.     'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson',
  74.     'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus',
  75.     'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba',
  76.     'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle',
  77.     'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall',
  78.     'Goa', 'Drum & Bass', 'Club-House', 'Hardcore', 'Terror', 'Indie',
  79.     'BritPop', 'Negerpunk', 'Polsk Punk', 'Beat', 'Christian Gangsta Rap',
  80.     'Heavy Metal', 'Black Metal', 'Crossover', 'Contemporary Christian',
  81.     'Christian Rock', 'Merengue', 'Salsa', 'Trash Metal', 'Anime', 'Jpop',
  82.     'Synthpop'  {continua...}
  83.   );
  84.  
  85. procedure Register;
  86. begin
  87.   RegisterComponents('MauryTecnologies', [TMauryMp3Tag]);
  88. end;
  89.  
  90. { TMauryMp3Tag }
  91.  
  92. procedure TMauryMp3Tag.Set_Filename(const Value: TFileName);
  93. begin
  94.   FFilename := Value;
  95.   GetMp3tag(FFilename);
  96. end;
  97.  
  98. procedure TMauryMp3Tag.GetMp3tag(mp3File :string);
  99. var
  100.     Tag : TTag;
  101.     fmp3: TFileStream;
  102. begin
  103.   fmp3:=TFileStream.Create(mp3File, fmOpenRead);
  104.   try
  105.     fmp3.position:=fmp3.size-128;
  106.     fmp3.Read(Tag,SizeOf(Tag));
  107.   finally
  108.     fmp3.free;
  109.   end;
  110.  if Tag.Tag <> 'TAG' then begin
  111.    Titolo :='Informazioni Corrote o Non esistenti';
  112.    Artista :='Informazioni Corrote o Non esistenti';
  113.    Album :='Informazioni Corrote o Non esistenti';
  114.    Anno :='Informazioni Corrote o Non esistenti';
  115.    Genere :='Informazioni Corrote o Non esistenti';
  116.    Commento :='Informazioni Corrote o Non esistenti';
  117.  end else begin
  118.    Titolo :=Tag.Titolo;
  119.    Artista :=Tag.Artista;
  120.    Album :=Tag.Album;
  121.    Anno :=Tag.Anno;
  122.    if Tag.Genere in [0..Max] then
  123.      Genere := Generi[Tag.Genere]
  124.    else
  125.      Genere :='Other';
  126.    GenereB := Tag.Genere;
  127.    Commento :=Tag.Commento;
  128.  end;
  129. end;
  130.  
  131. procedure TMauryMp3Tag.SetTag(mp3File,STitolo,SArtista,SAlbum,SAnno,SCommento : string;SGenere : byte);
  132. var
  133.   fMP3: file of Byte;
  134.   PrecTag,Nuovo : TTag;
  135.   i : integer;
  136. begin
  137.   try
  138.     AssignFile(fMP3, mp3File);
  139.     Reset(fMP3);
  140.     try
  141.       Seek(fMP3, FileSize(fMP3) - 128);
  142.       BlockRead(fMP3, PrecTag, SizeOf(PrecTag));
  143.       if PrecTag.Tag = 'TAG' then
  144.         Seek(fMP3, FileSize(fMP3) - 128)
  145.       else
  146.         Seek(fMP3, FileSize(fMP3));
  147.       Nuovo.Tag := PrecTag.Tag;
  148.       if STitolo = '' then
  149.       STitolo := 'No Title';
  150.       for i := 0 to 29 do
  151.       Nuovo.Titolo[i] := STitolo[i+1];
  152.       if SArtista = '' then
  153.       SArtista := 'No Artist';
  154.       for i := 0 to 29 do
  155.       Nuovo.Artista[i] := SArtista[i+1];
  156.       if SAlbum = '' then
  157.       SAlbum := 'No Album';
  158.       for i := 0 to 29 do
  159.       Nuovo.Album[i] := SAlbum[i+1];
  160.       if SAnno = '' then
  161.       SAnno := 'No Year';
  162.       for i := 0 to 3 do
  163.       Nuovo.Anno[i] := SAnno[i+1];
  164.       if SCommento = '' then
  165.       SCommento := 'No Comment';
  166.       for i := 0 to 29 do
  167.       Nuovo.Commento[i] := SCommento[i+1];
  168.       Nuovo.Genere := SGenere;
  169.       BlockWrite(fMP3, Nuovo, SizeOf(Nuovo));
  170.     finally
  171.     end;
  172.   finally
  173.     CloseFile(fMP3);
  174.   end;
  175. end;
  176.  
  177.  
  178.  
  179. end.