윈도우(asp, vbscript)에서 mp3 id3 정보 쉽게 얻기

mp3 id3를 정보를 얻으려면 약간의 작업이 필요하다 바이너리로 읽어들이고 tag정보만 추출하거나 한다. 원래 대부분 이런식으로 얻고 있다. 그런나 윈도우 시스템에서는 약간 편한 방법으로 얻을수 있다. 윈도우 쉘개체를 이용하면 손쉽게 얻을수 있다. 이미지를 참조하면 금방 이해 될꺼다. 쉘개체에  GetDetailsOf라는 메서드를 이용하면 이 정보를 가지고 올수 있다. 운영체제마다 이 정보가 틀리니 먼저 정보를 테스트해본다










getDetailsOfTest.vbs
strFolder = "E:\music\즐겨듣기" '임의 폴더 지정
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)
For N = 0 To 100
    WScript.Echo N & vbTab & objFolder.GetDetailsOf(Nothing, N)
Next
Set objFolder = Nothing
Set objShell  = Nothing

출력물 결과 : 

0 이름
1 크기
2 항목 유형
3 수정한 날짜
4 만든 날짜
5 액세스한 날짜
6 특성
7 오프라인 상태
8 오프라인 사용 가능
9 인식 유형
10 소유자
11 종류
12 찍은 날짜
13 참여 음악가
14 앨범
이런식의 정보가 100개까지 있다.

mp3Id3Info.vbs 
strFolder  = "E:\music\즐겨듣기"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)
Set colFiles = objFolder.Items
 
If Not objFolder Is Nothing Then
 For Each objFile In colFiles
  strType = objFolder.GetDetailsOf(objFile, 2)
  'If strType = "MP3 Format Sound" Then
   WScript.Echo "Name:", objFile.Name 
   WScript.Echo "Size:", objFolder.GetDetailsOf(objFile, 1)
   WScript.Echo "Title:", objFolder.GetDetailsOf(objFile, 10)
   WScript.Echo "Comments:", objFolder.GetDetailsOf(objFile, 14)
   WScript.Echo "Artist:", objFolder.GetDetailsOf(objFile, 16)
   WScript.Echo "Album Title:", objFolder.GetDetailsOf(objFile, 17)
   WScript.Echo "Year:", objFolder.GetDetailsOf(objFile, 18)
   WScript.Echo "Track Number:", objFolder.GetDetailsOf(objFile, 19)
   WScript.Echo "Genre:", objFolder.GetDetailsOf(objFile, 20)
   WScript.Echo "Duration:", objFolder.GetDetailsOf(objFile, 21)
   WScript.Echo "Bit Rate:", objFolder.GetDetailsOf(objFile, 22)
   WScript.Echo "**************************************************"
  'Else
  ' WScript.Echo "no" & strType
  'End If
 Next
End If
Set colFiles = Nothing
Set objFolder = Nothing
Set objShell = Nothing

출력결과 : 

Name: 001_고진영_-_비연_(Drama_Ver.)(With_정주희)_(짝패_OST_Part.1).mp3
Size: 9.20MB
Title: Administrators
Comments: 짝패 OST Part.1
Artist: 드라마
Album Title:
Year:
Track Number: 등급이 지정되지 않음
Genre: Various Artists
Duration: 비연 (Drama Ver.)
Bit Rate:
**************************************************
Name: 2NE1 - FIRE.mp3
Size: 5.20MB
Title: Administrators
Comments: Fire (Digital Single)
Artist: Hip-Hop
Album Title:
Year:
Track Number: 등급이 지정되지 않음
Genre: 2NE1
Duration: Fire
Bit Rate:
**************************************************
Name: 2PM Again Again.mp3
Size: 9.32MB
Title: Administrators
Comments: 2:00PM Time For Change (Single
Artist:
Album Title:
Year:
Track Number: 등급이 지정되지 않음
Genre: 2PM
Duration: Again & Again
Bit Rate:
**************************************************

정말 간단하게 mp3정보를 가지고 올수 있다. 지금 생각해보닝 이 밖에도 꽤 응용할수 있을꺼 같다. 이미지의 사이즈 정보나 크기를 가지고 온다든가. .net환경에서도 쉘개체를 사용할수 있다.
(참조 .net사용법 : http://lifehack.kr/90017399118)

지금 이건 wsf를 이용한거다. asp에서 쓰려면 엑세스 제한이 있다. wsc로 만들어서 콜하던가 아니면 wsf개체를 컴퍼넌트로 등록한 해서 사용하면 가능함.

댓글