Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for querycd.vbs

(view source code of querycd.vbs as plain text)

  1. Option Explicit
  2.  
  3. If WScript.Arguments.Count > 0 Then Syntax
  4.  
  5. Dim arrCDROMs, i, j, k, objFreeDB, strMsg
  6. i = 0
  7.  
  8. Const CDDB_MODE_TEST   = 0
  9. Const CDDB_MODE_SUBMIT = 1
  10.  
  11. ' Create a uFREEDB object
  12. Set objFreeDB = CreateObject( "FREEDBControl.uFREEDB" )
  13.  
  14. With objFreeDB
  15. 	' Mandatory properties, freedb.freedb.org does not seem to accept the defaults
  16. 	.AppName      = "QueryCD"
  17. 	.AppVersion   = "1.01"
  18. 	.EmailAddress = "test@scripting.eu"
  19. 	.CDDBServer   = "freedb.freedb.org"
  20. 	.CDDBMode     = CDDB_MODE_TEST  ' Use CDDB_MODE_SUBMIT only if you need to
  21. 	                                ' submit new or modified CD data to freedb.org
  22.  
  23. 	' Get an array with all CDROM drive letters
  24. 	arrCDROMs = Split( .GetCdRoms, "|" )
  25.  
  26. 	' Loop through the array of CDROM drives
  27. 	For j = 0 To UBound( arrCDROMs )
  28. 		' Media Info "" means there is no CD in drive
  29. 		If .GetMediaInfo( arrCDROMs(j) ) <> "" Then
  30. 			' Count the number of CDs found
  31. 			i = i + 1
  32. 			' Query the freedb.org database for the CD, based on its TOC
  33. 			.LookupMediaByToc .GetMediaTOC( arrCDROMs(j) )
  34. 			' Return Album properties
  35. 			strMsg = "The CD in drive " & UCase( arrCDROMs(j) ) _
  36. 			       & ": is """ & .GetAlbumName & """ by " _
  37. 			       & .GetArtistName & " (" & .GetAlbumYear & ", " _
  38. 			       & .GetAlbumGenre & ", " _
  39. 			       & .SecondsToTimeString( .GetAlbumLength ) & ")" & vbCrLf & vbCrLf
  40. 			' Loop through the list of tracks
  41. 			For k = 1 To .GetAlbumTracks
  42. 				' Append track properties
  43. 				strMsg = strMsg & "Track " & Right( " " & k, 2 ) & ":  " _
  44. 				       & .GetTrackName( CInt(k) ) _
  45. 				       & " (" & .SecondsToTimeString( .GetTrackTime( CInt(k) ) ) & ")" _
  46. 				       & vbCrLf
  47. 			Next
  48. 		End If
  49. 	Next
  50. 	If i = 0 Then
  51. 		strMsg = "No CD found."
  52. 	End If
  53. End With
  54.  
  55. ' Display the result
  56. WScript.Echo strMsg
  57.  
  58. ' Release the object
  59. Set objFreeDB = Nothing
  60.  
  61.  
  62. Sub Syntax
  63. 	strMsg = "QueryCD.vbs,  Version 1.01" & vbCrLf _
  64. 	       & "Display album and track properties for all CDs in all CDROM drives" _
  65. 	       & vbCrLf & vbCrLf _
  66. 	       & "Usage:  QUERYCD.VBS" & vbCrLf & vbCrLf _
  67. 	       & "Note:   This script requires ufreedb.ocx" & vbCrLf _
  68. 	       & "        by Jon F. Zahornacky and Peter Schmiedseder" & vbCrLf _
  69. 	       & "        http://www.robvanderwoude.com/vbstech_multimedia_freedb.html" _
  70. 	       & vbCrLf & vbCrLf _
  71. 	       & "Written by Rob van der Woude" & vbCrLf _
  72. 	       & "http://www.robvanderwoude.com" & vbCrLf
  73. 	WScript.Echo strMsg
  74. 	WScript.Quit 1
  75. End Sub
  76.  

page last uploaded: 2017-04-06, 13:33