Как прочитать ID-теги у mp3?
От: Konwin Россия  
Дата: 13.11.02 11:19
Оценка:
Госпада, кто в курсе как можно выудить ID-теги из mp3 файла? Буду очень благодарен всем советам...

Re: Как прочитать ID-теги у mp3?
От: Flamer Кипр http://users.livejournal.com/_flamer_/
Дата: 13.11.02 11:25
Оценка:
Здравствуйте Konwin, Вы писали:

K>Госпада, кто в курсе как можно выудить ID-теги из mp3 файла? Буду очень благодарен всем советам...


K>


1. Посмотри здесь.

2. Вот код компонента (сохранить в файле с расширением *.wsc):

<?XML version="1.0" standalone="yes" encoding="UTF-16" ?>
<?component error="true" debug="true"?>

<component>

    <registration
        description="MP3 Tags Reader"
        progid="Scripting.Mp3TagsReader"
        version="1"
        classid="{C2DE6203-17AE-11d5-8CF4-8EBC99C67466}">
    
        <script language="VBScript">
            <![CDATA[

                Option Explicit
                
                Function Register()
                    Dim ScriptFileName
                    Dim Shell
                    Set Shell = CreateObject("WScript.Shell")
                    ScriptFileName = _
                        Shell.RegRead("HKEY_CLASSES_ROOT\CLSID\{C2DE6203-17AE-11D5-8CF4-8EBC99C67466}\ScriptletURL\")
                    Set Shell = Nothing
                    Const Prefix = "file://"
                    If 0 = StrComp(Left(ScriptFileName, Len(Prefix)), Prefix, 1) Then
                        ScriptFileName = Mid(ScriptFileName, Len(Prefix) + 1)
                    End If
                    Dim TypelibFileName
                    TypelibFileName = ScriptFileName
                    Dim I
                    I = InStrRev(TypelibFileName, ".")
                    If I > 0 Then
                        TypelibFileName = Left(TypelibFileName, I - 1)
                    End If
                    TypelibFileName = TypelibFileName & ".tlb"
                
                    Dim GTL
                    Set GTL = CreateObject("Scriptlet.TypeLib")
                    GTL.AddURL ScriptFileName
                    GTL.Path = TypelibFileName
                    GTL.Doc = "MP3 Tags Reader"
                    GTL.GUID = "{C2DE6203-17AE-11d5-8CF4-8EBC99C67467}"
                    GTL.Name = "Mp3TagsReader"
                    GTL.MajorVersion = 1
                    GTL.MinorVersion = 0
                    GTL.Write
                    GTL.Reset
                    Set GTL = Nothing
                End Function

                Function Unregister()
                End Function

            ]]>
        </script>
    
    </registration>

    <public>
        <property name="Title"><get/></property>
        <property name="Artist"><get/></property>
        <property name="Album"><get/></property>
        <property name="Year"><get/></property>
        <property name="Comment"><get/></property>
        <property name="GenreIndex"><get/></property>
        <property name="Genre"><get/></property>
        <property name="Track"><get/></property>
        <property name="FileName"><get/></property>
        <method name="Read">
            <parameter name="FileName"/>
        </method>
    </public>

    <script language="VBScript">
        <![CDATA[

            Option Explicit

            Const AppName = "MP3 Tags Reader"
    
            Dim Title, Artist, Album, Year, Comment, GenreIndex, Genre, Track
            Dim FileName
            
            Function get_Title()
                get_Title = Title
            End Function
    
            Function get_Artist()
                get_Artist = Artist
            End Function
    
            Function get_Album()
                get_Album = Album
            End Function
    
            Function get_Year()
                get_Year = Year
            End Function
    
            Function get_Comment()
                get_Comment = Comment
            End Function
    
            Function get_GenreIndex()
                get_GenreIndex = GenreIndex
            End Function
    
            Function get_Genre()
                get_Genre = Genre
            End Function
    
            Function get_Track()
                get_Track  = Track 
            End Function
    
            Function get_FileName()
                get_FileName = FileName
            End Function
    
            Function Read(FileNameToRead)
                ' function return codes
                Const mp3Success = 0
                Const mp3FileNotFound = 1
                Const mp3FileTooSmall = 2
                Const mp3CannotOpenFile = 3
                Const mp3CannotReadFile = 4
                Const mp3BadFileFormat = 5
                Const mp3CreateObjectFailed = 6

                ' Clear info
                Title = ""
                Artist = ""
                Album = ""
                Year = ""
                Comment = ""
                GenreIndex = 0
                Genre = ""
                Track = 0
                FileName = ""
                
                ' Start handling file errors
                On Error Resume Next
            
                ' Create FileSystemObject
                Dim FSO
                Set FSO = CreateObject("Scripting.FileSystemObject")
                If Err.Number <> 0 Then
                    Read = mp3CreateObjectFailed
                    Exit Function
                End If
            
                ' Test for file existance
                If Not FSO.FileExists(FileNameToRead) Then
                    Read = mp3FileNotFound
                    Exit Function
                End If
            
                ' Get file length and test it
                ' It must be at least 128 bytes long (the size
                ' of the info structure)
                Dim File
                Set File = FSO.GetFile(FileNameToRead)
                Dim FileLength
                FileLength = File.Size
                If FileLength <= 128 Then
                    Read = mp3FileTooSmall
                    Exit Function
                End If
            
                ' Open MP3 file for reading and check for errors
                Dim Stream
                Set Stream = File.OpenAsTextStream(1)    ' 1 = ForReading
                If Err.Number <> 0 Then
                    Read = mp3CannotOpenFile
                    Exit Function
                End If
                
                ' Reserve space for info structure
                Dim Data 
                Data = String(256, 0)
                
                ' Read info structure and check for errors
                Stream.Skip(FileLength - 128)
                Data = Stream.Read(128)
                If Err.Number <> 0 Then
                    Read = mp3CannotReadFile
                    Exit Function
                End If
                
                ' Close stream
                Stream.Close
            
                ' Release file
                Set File = Nothing
            
                ' Release FileSystemObject
                Set FSO = Nothing
            
                ' Stop handling file errors
                On Error GoTo 0
                
                ' Test for proper info structure - it must start with
                ' "TAG" string if it is correct
                If Left(Data, 3) <> "TAG" Then
                    Read = mp3BadFileFormat
                    Exit Function
                End If
                
                ' Get string info
                Title = Trim(Mid(Data, 4, 30))
                Artist = Trim(Mid(Data, 34, 30))
                Album = Trim(Mid(Data, 64, 30))
                Year = Trim(Mid(Data, 94, 4))
                Comment = Trim(Mid(Data, 98, 30))
            
                ' Get track number
                Track = Asc(Mid(Data, 127, 1))
                If Track = 32 Then Track = 0
                
                ' Get genre index
                GenreIndex = Asc(Mid(Data, 128, 1))
            
                ' Make genre names array
                Dim GenreNamesMatrix
                GenreNamesMatrix = "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|Alt. Rock|Bass|Soul|Punk|Space|Meditative|" & _
                    "Instrumental Pop|Instrumental Rock|Ethnic|Gothic|Darkwave|Techno-Industrial|Electronic|" & _
                    "Pop-Folk|Eurodance|Dream|Southern Rock|Comedy|Cult|Gangsta Rap|Top 40|Christian Rap|" & _
                    "Pop/Punk|Jungle|Native American|Cabaret|New Wave|Phychedelic|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|Blue Grass|" & _
                    "Avantegarde|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|A Capella|Euro-House|" & _
                    "Dance Hall|Goa|Drum & Bass|Club-House|Hardcore|Terror|indie|Brit Pop|Negerpunk|Polsk Punk|" & _
                    "Beat|Christian Gangsta Rap|Heavy Metal|Black Metal|Crossover|Comteporary Christian|" & _
                    "Christian Rock|Merengue|Salsa|Trash Metal|Anime|JPop|Synth Pop"
                Dim GenreNamesArray
                GenreNamesArray = Split(GenreNamesMatrix, "|")
                
                ' Get genre name
                If GenreIndex <= UBound(GenreNamesArray) Then
                    Genre = GenreNamesArray(GenreIndex)
                Else
                    Genre = "Unknown"
                End If
            
                ' Save and fix file name
                FileName = FileNameToRead
                FileName = Replace(FileName, "/", "\")
                
                ' Function finished successfully
                Read = mp3Success
            End Function

        ]]>
    </script>

</component>
Re: Как прочитать ID-теги у mp3?
От: Odi$$ey Россия http://malgarr.blogspot.com/
Дата: 13.11.02 11:49
Оценка:
Здравствуйте Konwin, Вы писали:

K>Госпада, кто в курсе как можно выудить ID-теги из mp3 файла? Буду очень благодарен всем советам...


http://www.rsdn.ru/article/?winshell/shlext8.xml
Автор(ы): Michael Dunn
Дата: 05.01.2002
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.