Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: BlackZeroX en 24 Septiembre 2010, 08:48 am



Título: [Source] Tag M4A Format Reader... QuickTime - itunes
Publicado por: BlackZeroX en 24 Septiembre 2010, 08:48 am
Es un Modulod e Clase que sirve para leer el Tag de los archivos de Musica, y extraer toda la informacion posible del mismo...

Saca los bytes del Cover del M4A incluyendo su formato... JPEG / PNG.
Saca el texto "liryc" del M4A (Si existe...)

y toda la informacion posible y de forma existencial!¡.

 * Esta la es la primera version, asi que si tiene errores favor de comunicarlos en este mismo hilo.
 * Deshacer este formato para obtener la información me a costa asi que disfrutenlo!¡.

NOTA: No saca informacion comprimida... para ello usar la Zlib...


Aqui hay varios archivos M4A... xP  --->  http://infrangelux.sytes.net/FileX/index.php?dir=/Musica/Slipknot

FormatM4A.cls

Código
  1.  
  2.  
  3. '
  4. '   /////////////////////////////////////////////////////////////
  5. '   // Autor:   BlackZeroX ( Ortega Avila Miguel Angel )       //
  6. '   //                                                         //
  7. '   // Web:     http://InfrAngeluX.Sytes.Net/                  //
  8. '   //                                                         //
  9. '   //    |-> Pueden Distribuir Este Codigo siempre y cuando   //
  10. '   // no se eliminen los creditos originales de este codigo   //
  11. '   // No importando que sea modificado/editado o engrandesido //
  12. '   // o achicado, si es en base a este codigo es requerido    //
  13. '   // el agradacimiento al autor.                             //
  14. '   /////////////////////////////////////////////////////////////
  15. '   //////////////////////Lector Formato M4A/////////////////////
  16. '   /////////////////////////////////////////////////////////////
  17. '   //  1ra Version...                                         //
  18. '   //      --> Verificación de Formato.                       //
  19. '   //      --> Solo Lectura de Datos (Tag).                   //
  20. '   /////////////////////////////////////////////////////////////
  21.  
  22. Option Explicit
  23. Option Base 0
  24. Option Compare Text
  25.  
  26. Private Str_Album                       As String
  27. Private Str_Artist                      As String
  28. Private Str_AlbumArtist                 As String
  29. Private Str_Comment                     As String
  30. Private Str_Year                        As String
  31. Private Str_Title                       As String
  32. Private Str_Genre                       As String
  33. Private Str_TrackNumber                 As String
  34. Private Str_DiskNumber                  As String
  35. Private Str_Composer                    As String
  36. Private Str_Encoder                     As String
  37. Private Str_BPM                         As String
  38. Private Str_Copyright                   As String
  39. Private Str_Compilation                 As String
  40. Private Arr_Artwork()                   As Byte
  41. Private Str_ArtworkFormat               As String
  42. Private Str_RatingAdvisory              As String
  43. Private Str_Grouping                    As String
  44. Private Str_qq_stik                     As String
  45. Private Str_Podcast                     As String
  46. Private Str_Category                    As String
  47. Private Str_Keyword                     As String
  48. Private Str_PodcastURL                  As String
  49. Private Str_EpisodeGlobalUniqueID       As String
  50. Private Str_Description                 As String
  51. Private Str_Lyrics                      As String
  52. Private Str_TVNetworkName               As String
  53. Private Str_TVShowName                  As String
  54. Private Str_TVEpisodeNumber             As String
  55. Private Str_TVSeason                    As String
  56. Private Str_TVEpisode                   As String
  57. Private Str_PurchaseDate                As String
  58. Private Str_GaplessPlayback             As String
  59.  
  60. Private Const lng_lAtom                 As Long = &H4
  61. Private Const Str_Format                As String = "ftyp"
  62. Private Const cContData                 As String = "udta"
  63. Private Const cMetaData                 As String = "meta"
  64. Private Const ChdlrData                 As String = "hdlr"
  65.  
  66. Private Const cAlbum                    As String = "©alb"
  67. Private Const cArtist                   As String = "©art"
  68. Private Const cAlbumArtist              As String = "aART"
  69. Private Const cComment                  As String = "©cmt"
  70. Private Const cYear                     As String = "©day"
  71. Private Const cTitle                    As String = "©nam"
  72. Private Const cGenre                    As String = "©gen|gnre"
  73. Private Const cTrackNumber              As String = "trkn"
  74. Private Const cDiskNumber               As String = "disk"
  75. Private Const cComposer                 As String = "©wrt"
  76. Private Const cEncoder                  As String = "©too"
  77. Private Const cBPM                      As String = "tmpo"
  78. Private Const cCopyright                As String = "cprt"
  79. Private Const cCompilation              As String = "cpil"
  80. Private Const cArtwork                  As String = "covr"
  81. Private Const cRatingAdvisory           As String = "rtng"
  82. Private Const cGrouping                 As String = "©grp"
  83. Private Const cqq_stik                  As String = "stik"
  84. Private Const cPodcast                  As String = "pcst"
  85. Private Const cCategory                 As String = "catg"
  86. Private Const cKeyword                  As String = "keyw"
  87. Private Const cPodcastURL               As String = "purl"
  88. Private Const cEpisodeGlobalUniqueID    As String = "egid"
  89. Private Const cDescription              As String = "desc"
  90. Private Const cStr_Lyrics               As String = "©lyr"
  91. Private Const cTVNetworkName            As String = "tvnn"
  92. Private Const cTVShowName               As String = "tvsh"
  93. Private Const cTVEpisodeNumber          As String = "tven"
  94. Private Const cTVSeason                 As String = "tvsn"
  95. Private Const cTVEpisode                As String = "tves"
  96. Private Const cPurchaseDate             As String = "purd"
  97. Private Const cGaplessPlayback          As String = "pgap"
  98.  
  99. Private Str_File                        As String
  100. Private Priv_ItsOkFormat                As Boolean
  101.  
  102. Private Function StringToLong(ByVal Str_Data As String) As Long
  103. Dim TMP$, i&
  104. Dim Byte_Str()      As Byte
  105.    TMP$ = String$(Len(Str_Data) * 2 + 2, "0")
  106.    Mid$(TMP$, 1, 2) = "&H"
  107.    Byte_Str = StrConv(Str_Data$, vbFromUnicode)
  108.    For i = LBound(Byte_Str) To UBound(Byte_Str)
  109.        If Byte_Str(i) > 15 Then
  110.            Mid$(TMP$, 3 + i * 2, 2) = Hex(Byte_Str(i))
  111.        Else
  112.            Mid$(TMP$, 3 + i * 2, 2) = "0" & Hex(Byte_Str(i))
  113.        End If
  114.    Next i
  115.    StringToLong& = CLng(TMP$)
  116. End Function
  117.  
  118. Private Function GetStrFromNumFile(ByVal IDFile As Integer, ByVal LngPos As Long, ByRef StrOut As String) As Long
  119.    Get IDFile%, LngPos, StrOut$
  120.    GetStrFromNumFile = LngPos + Len(StrOut$)
  121. End Function
  122.  
  123. Public Property Let This_File(ByVal StrFilePath As String)
  124. Dim Str_PointerStr      As String * lng_lAtom
  125. Dim Str_CatNow          As String * lng_lAtom
  126. Dim Str_DataPos         As String * lng_lAtom
  127. Dim Str_CatData         As String
  128. Dim lng_Pos             As Long
  129. Dim int_FF              As Integer
  130.  
  131.  
  132.    Str_Album$ = ""
  133.    Str_Artist$ = ""
  134.    Str_AlbumArtist$ = ""
  135.    Str_Comment$ = ""
  136.    Str_Year$ = ""
  137.    Str_Title$ = ""
  138.    Str_Genre$ = ""
  139.    Str_TrackNumber$ = ""
  140.    Str_DiskNumber$ = ""
  141.    Str_Composer$ = ""
  142.    Str_Encoder$ = ""
  143.    Str_BPM$ = ""
  144.    Str_Copyright$ = ""
  145.    Str_Compilation$ = ""
  146.    Erase Arr_Artwork
  147.    Str_RatingAdvisory$ = ""
  148.    Str_Grouping$ = ""
  149.    Str_qq_stik$ = ""
  150.    Str_Podcast$ = ""
  151.    Str_Category$ = ""
  152.    Str_Keyword$ = ""
  153.    Str_PodcastURL$ = ""
  154.    Str_EpisodeGlobalUniqueID$ = ""
  155.    Str_Description$ = ""
  156.    Str_Lyrics$ = ""
  157.    Str_TVNetworkName$ = ""
  158.    Str_TVShowName$ = ""
  159.    Str_TVEpisodeNumber$ = ""
  160.    Str_TVSeason$ = ""
  161.    Str_TVEpisode$ = ""
  162.    Str_PurchaseDate$ = ""
  163.    Str_GaplessPlayback$ = ""
  164.  
  165.  
  166.    Str_CatData$ = Space$(lng_lAtom&)
  167.    Priv_ItsOkFormat = False
  168.    Str_File$ = StrFilePath$
  169.    int_FF% = FreeFile%
  170.  
  171.    Open Str_File$ For Binary As int_FF%
  172.  
  173.    If LOF(int_FF%) > 8 Then
  174.  
  175.        Get int_FF%, 5, Str_CatNow$
  176.  
  177.        If StrComp(Str_CatNow$, Str_Format$, vbBinaryCompare) = 0 Then
  178.            'lng_Pos& = 148 '   //  Se puede Obviar, pero mejor comprovamos el formato...
  179.            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + 1, Str_DataPos$) - (lng_lAtom& - 1)
  180.            lng_Pos& = GetStrFromNumFile&(int_FF%, StringToLong&(Str_DataPos$) + ((lng_lAtom& * 2) + 1), Str_DataPos$) + StringToLong&(Str_DataPos$) - lng_lAtom& - 1
  181.            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + 1, Str_DataPos$) + StringToLong&(Str_DataPos$)
  182.            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos&, Str_CatNow$)
  183.  
  184.            If StrComp(Str_CatNow$, cContData$, vbTextCompare) = 0 Then
  185.                lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + lng_lAtom&, Str_DataPos$)
  186.                If StrComp(Str_DataPos$, cMetaData$, vbTextCompare) = 0 Then
  187.                    lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + lng_lAtom&, Str_CatData$)
  188.                    lng_Pos& = lng_Pos& + StringToLong&(Str_CatData$) + lng_lAtom&
  189.                    Do
  190.                        lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + lng_lAtom&, Str_CatNow$)
  191.                        If StrComp(Str_CatNow$, "free", vbTextCompare) = 0 Or StrComp(Str_CatNow$, "name", vbTextCompare) = 0 Then Exit Do
  192.                        Call GetStrFromNumFile&(int_FF%, lng_Pos& + lng_lAtom&, Str_DataPos$)
  193.                        If StrComp(Str_DataPos$, "data", vbTextCompare) = 0 Then '   //  Atom Legible? (Sin Compresion o espesificaciones del Formato...)
  194.                            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos&, Str_PointerStr$)
  195.                            Str_CatData$ = Space$(StringToLong&(Str_PointerStr$) - (lng_lAtom& * 4))
  196.                            If StrComp(Str_CatNow$, cArtwork$, vbTextCompare) = 0 Then
  197.                                GetStrFromNumFile& int_FF%, lng_Pos& + lng_lAtom&, Str_PointerStr$
  198.                                Select Case StringToLong&(Str_PointerStr$)
  199.                                    Case 13
  200.                                        Str_ArtworkFormat$ = "jpeg"
  201.                                    Case 14
  202.                                        Str_ArtworkFormat$ = "png"
  203.                                End Select
  204.                            End If
  205.                            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& + (lng_lAtom * 3), Str_CatData)
  206.                            If Not StrComp(Str_CatNow$, "", vbTextCompare) = 0 Then
  207.                                Select Case Str_CatNow$
  208.                                    Case cAlbum$
  209.                                        Str_Album$ = Str_CatData$
  210.                                    Case cArtist$
  211.                                        Str_Artist$ = Str_CatData$
  212.                                    Case cAlbumArtist$
  213.                                        Str_AlbumArtist$ = Str_CatData$
  214.                                    Case cComment$
  215.                                        Str_Comment$ = Str_CatData$
  216.                                    Case cYear$
  217.                                        Str_Year$ = Str_CatData$
  218.                                    Case cTitle$
  219.                                        Str_Title$ = Str_CatData$
  220.                                    Case Split(cGenre$, "|")(0), Split(cGenre$, "|")(1)                 '  //  "©gen|gnre"
  221.                                        Str_Genre$ = Str_CatData$
  222.                                    Case cTrackNumber$
  223.                                        Str_TrackNumber$ = Str_CatData$
  224.                                    Case cDiskNumber$
  225.                                        Str_DiskNumber$ = Str_CatData$
  226.                                    Case cComposer$
  227.                                        Str_Composer$ = Str_CatData$
  228.                                    Case cEncoder$
  229.                                        Str_Encoder$ = Str_CatData$
  230.                                    Case cBPM$
  231.                                        Str_BPM$ = Str_CatData$
  232.                                    Case cCopyright$
  233.                                        Str_Copyright$ = Str_CatData$
  234.                                    Case cCompilation$
  235.                                        Str_Compilation$ = Str_CatData$
  236.                                    Case cArtwork$
  237.                                        Arr_Artwork = StrConv(Str_CatData$, vbFromUnicode)
  238.                                    Case cRatingAdvisory$
  239.                                        Str_RatingAdvisory$ = Str_CatData$
  240.                                    Case cGrouping$
  241.                                        Str_Grouping$ = Str_CatData$
  242.                                    Case cqq_stik$
  243.                                        Str_qq_stik$ = Str_CatData$
  244.                                    Case cPodcast$
  245.                                        Str_Podcast$ = Str_CatData$
  246.                                    Case cCategory$
  247.                                        Str_Category$ = Str_CatData$
  248.                                    Case cKeyword$
  249.                                        Str_Keyword$ = Str_CatData$
  250.                                    Case cPodcastURL$
  251.                                        Str_PodcastURL$ = Str_CatData$
  252.                                    Case cEpisodeGlobalUniqueID$
  253.                                        Str_EpisodeGlobalUniqueID$ = Str_CatData$
  254.                                    Case cDescription$
  255.                                        Str_Description$ = Str_CatData$
  256.                                    Case cStr_Lyrics$
  257.                                        Str_Lyrics$ = Str_CatData$
  258.                                    Case cTVNetworkName$
  259.                                        Str_TVNetworkName$ = Str_CatData$
  260.                                    Case cTVShowName$
  261.                                        Str_TVShowName$ = Str_CatData$
  262.                                    Case cTVEpisodeNumber$
  263.                                        Str_TVEpisodeNumber$ = Str_CatData$
  264.                                    Case cTVSeason$
  265.                                        Str_TVSeason$ = Str_CatData$
  266.                                    Case cTVEpisode$
  267.                                        Str_TVEpisode$ = Str_CatData$
  268.                                    Case cPurchaseDate$
  269.                                        Str_PurchaseDate$ = Str_CatData$
  270.                                    Case cGaplessPlayback$
  271.                                        Str_GaplessPlayback$ = Str_CatData$
  272.                                End Select
  273.                            End If
  274.                        ElseIf Str_CatNow$ = "----" Then
  275.                            lng_Pos& = GetStrFromNumFile&(int_FF%, lng_Pos& - 8, Str_DataPos$)
  276.                            lng_Pos& = lng_Pos& + StringToLong&(Str_DataPos$) - lng_lAtom&
  277.                        End If
  278.                    Loop
  279.                    Priv_ItsOkFormat = True
  280.                End If
  281.            End If
  282.        End If
  283.    End If
  284.    Close int_FF%
  285. End Property
  286.  
  287. Public Property Get ItsOkFormat() As Boolean
  288.    ItsOkFormat = Priv_ItsOkFormat
  289. End Property
  290.  
  291. Public Property Get This_File() As String
  292.    This_File = Str_File$
  293. End Property
  294.  
  295. Public Property Get Album() As String
  296.    Album = Str_Album
  297. End Property
  298. Public Property Get Artist() As String
  299.    Artist = Str_Artist
  300. End Property
  301. Public Property Get AlbumArtist() As String
  302.    AlbumArtist = Str_AlbumArtist
  303. End Property
  304. Public Property Get Comment() As String
  305.    Comment = Str_Comment
  306. End Property
  307. Public Property Get Year() As String
  308.    Year = Str_Year
  309. End Property
  310. Public Property Get Title() As String
  311.    Title = Str_Title
  312. End Property
  313. Public Property Get Genre() As String
  314.    Genre = Str_Genre
  315. End Property
  316. Public Property Get TrackNumber() As String
  317.    TrackNumber = Str_TrackNumber
  318. End Property
  319. Public Property Get DiskNumber() As String
  320.    DiskNumber = Str_DiskNumber
  321. End Property
  322. Public Property Get Composer() As String
  323.    Composer = Str_Composer
  324. End Property
  325. Public Property Get Encoder() As String
  326.    Encoder = Str_Encoder
  327. End Property
  328. Public Property Get BPM() As String
  329.    BPM = Str_BPM
  330. End Property
  331. Public Property Get Copyright() As String
  332.    Copyright = Str_Copyright
  333. End Property
  334. Public Property Get Compilation() As String
  335.    Compilation = Str_Compilation
  336. End Property
  337. Public Property Get Artwork() As Byte()
  338.    Artwork = Arr_Artwork
  339. End Property
  340. Public Property Get ArtworkFormat() As String
  341.    ArtworkFormat = Str_ArtworkFormat
  342. End Property
  343. Public Property Get RatingAdvisory() As String
  344.    RatingAdvisory = Str_RatingAdvisory
  345. End Property
  346. Public Property Get Grouping() As String
  347.    Grouping = Str_Grouping
  348. End Property
  349. Public Property Get qq_stik() As String
  350.    qq_stik = Str_qq_stik
  351. End Property
  352. Public Property Get Podcast() As String
  353.    Podcast = Str_Podcast
  354. End Property
  355. Public Property Get Category() As String
  356.    Category = Str_Category
  357. End Property
  358. Public Property Get Keyword() As String
  359.    Keyword = Str_Keyword
  360. End Property
  361. Public Property Get PodcastURL() As String
  362.    PodcastURL = Str_PodcastURL
  363. End Property
  364. Public Property Get EpisodeGlobalUniqueID() As String
  365.    EpisodeGlobalUniqueID = Str_EpisodeGlobalUniqueID
  366. End Property
  367. Public Property Get Description() As String
  368.    Description = Str_Description
  369. End Property
  370. Public Property Get Lyrics() As String
  371.    Lyrics = Str_Lyrics
  372. End Property
  373. Public Property Get TVNetworkName() As String
  374.    TVNetworkName = Str_TVNetworkName
  375. End Property
  376. Public Property Get TVShowName() As String
  377.    TVShowName = Str_TVShowName
  378. End Property
  379. Public Property Get TVEpisodeNumber() As String
  380.    TVEpisodeNumber = Str_TVEpisodeNumber
  381. End Property
  382. Public Property Get TVSeason() As String
  383.    TVSeason = Str_TVSeason
  384. End Property
  385. Public Property Get TVEpisode() As String
  386.    TVEpisode = Str_TVEpisode
  387. End Property
  388. Public Property Get PurchaseDate() As String
  389.    PurchaseDate = Str_PurchaseDate
  390. End Property
  391. Public Property Get GaplessPlayback() As String
  392.    GaplessPlayback = Str_GaplessPlayback
  393. End Property
  394.  
  395.  
  396. 'Public Property Let Album(ByVal vData As String)
  397. 'Public Property Let Artist(ByVal vData As String)
  398. 'Public Property Let AlbumArtist(ByVal vData As String)
  399. 'Public Property Let Comment(ByVal vData As String)
  400. 'Public Property Let Year(ByVal vData As String)
  401. 'Public Property Let Title(ByVal vData As String)
  402. 'Public Property Let Genre(ByVal vData As Integer)
  403. 'Public Property Let TrackNumber(ByVal vData As Integer)
  404. 'Public Property Let DiskNumber(ByVal vData As Integer)
  405. 'Public Property Let Composer(ByVal vData As String)
  406. 'Public Property Let Encoder(ByVal vData As String)
  407. 'Public Property Let BPM(ByVal vData As Integer)
  408. 'Public Property Let Copyright(ByVal vData As String)
  409. 'Public Property Let Compilation(ByVal vData As Integer)
  410. 'Public Property Let Artwork(ByRef vData() As Byte)
  411. '   //  Public Property Let ArtworkFormat(ByRef vData As String)
  412. 'Public Property Let RatingAdvisory(ByVal vData As Integer)
  413. 'Public Property Let Grouping(ByVal vData As String)
  414. 'Public Property Let qq_stik(ByVal vData As Integer)
  415. 'Public Property Let Podcast(ByVal vData As Integer)
  416. 'Public Property Let Category(ByVal vData As String)
  417. 'Public Property Let Keyword(ByVal vData As String)
  418. 'Public Property Let PodcastURL(ByVal vData As Integer)
  419. 'Public Property Let EpisodeGlobalUniqueID(ByVal vData As Integer)
  420. 'Public Property Let Description(ByVal vData As String)
  421. 'Public Property Let Lyrics(ByVal vData As String)
  422. 'Public Property Let TVNetworkName(ByVal vData As String)
  423. 'Public Property Let TVShowName(ByVal vData As String)
  424. 'Public Property Let TVEpisodeNumber(ByVal vData As String)
  425. 'Public Property Let TVSeason(ByVal vData As Integer)
  426. 'Public Property Let TVEpisode(ByVal vData As Integer)
  427. 'Public Property Let PurchaseDate(ByVal vData As String)
  428. 'Public Property Let GaplessPlayback(ByVal vData As Integer)
  429.  
  430.  

Ejemplo de uso:

Código
  1.  
  2.  
  3. Option Explicit
  4. Option Base 0
  5.  
  6. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
  7.  
  8. Sub main()
  9. Dim clsFM4A         As Cls_FormatM4A
  10. Dim StrDir          As String
  11. Dim int_FF          As Integer
  12.  
  13.    Set clsFM4A = New Cls_FormatM4A
  14.    With clsFM4A
  15.  
  16.        .This_File = App.Path & "\SCGJ.m4a"
  17.  
  18.        If .ItsOkFormat Then
  19.  
  20.            StrDir$ = Replace$("c:\Musica\" & .Artist & "\" & .Year & "-" & .Album & "\", "\\", "\")
  21.            Call MakeSureDirectoryPathExists(StrDir$)
  22.  
  23.            '   //  extraemos la Imagen Cover
  24.            int_FF% = FileSystem.FreeFile%
  25.            Open StrDir & .Artist & " - " & .Title & "." & .ArtworkFormat For Binary As int_FF%
  26.                Put int_FF%, , .Artwork
  27.            Close int_FF%
  28.  
  29.            '   //  Extraemos la lirica del archivo
  30.            int_FF% = FileSystem.FreeFile%
  31.            Open StrDir & .Artist & " - " & .Title & ".txt" For Binary As int_FF%
  32.                Put int_FF%, , .Lyrics
  33.            Close int_FF%
  34.  
  35.        End If
  36.    End With
  37.    Set clsFM4A = Nothing
  38.  
  39. End Sub
  40.  
  41.  

Dulce Infierno Lunar!¡.