Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

function GetMP3Len


  • Please log in to reply
30 replies to this topic
Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

this works like a magic!!!

; http://www.autohotkey.com/board/topic/62281-using-mediainfodll-to-get-itunes-info/

; MediaInfo.dll / 'Test Script' - By David Deley : 08-Jan-2011
;
; To Test:
; 1. Download and install MediaInfo
; 2. Set variables MediaInfoDll and File1 below
; 3. Run
;
; Thank you to SKAN for posting his Video Properties - MediaInfo.Dll script
; http://www.autohotkey.com/forum/viewtopic.php?t=66500
#NoTrayIcon
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%

;USER SET THESE TWO VARIABLES
MediaInfoDll := "C:\...\MediaInfo.dll"
File1 := "M:\example.mp3"


; CHECK THAT FILE1 EXISTS
IfNotExist, %File1%
{
    MsgBox % "Unable to locate file:`n" . File1 . "`n`nSet variable 'File1' to point to an audio or video file."
    ExitApp
}


; LOAD MEDIAINFO DLL
hModule := DllCall( "LoadLibrary", Str, MediaInfoDll )
if hModule = 0
{
  Msgbox % "Error loading MediaInfo.dll`n`nWas trying to load file: " . MediaInfoDll . "`n`nError was: " . GetErrorString(A_LastError) . "`n`nDownload and install MediaInfo, then set variable 'MediaInfoDll' to point to file 'MediaInfo.dll'"
  ExitApp
}
FileGetVersion, Ver, MediaInfo.Dll
MsgBox MediaInfo Version = %Ver%

hnd := MediaInfo_New()
;MsgBox hnd = %hnd%

stat := MediaInfo_Open( hnd, File1 )
;MsgBox stat = %stat%


;DISPLAY FILE INFORMATION
;GENERAL
CompleteName     := MediaInfo_Get( hnd, 0,0, "CompleteName",     1 )
FileName         := MediaInfo_Get( hnd, 0,0, "FileName",         1 )
FileExtension    := MediaInfo_Get( hnd, 0,0, "FileExtension",    1 )
Format           := MediaInfo_Get( hnd, 0,0, "Format",           1 )
Format_Info      := MediaInfo_Get( hnd, 0,0, "Format/Info",      1 )
FileSize         := MediaInfo_Get( hnd, 0,0, "FileSize",         1 )
FileSize_String  := MediaInfo_Get( hnd, 0,0, "FileSize/String",  1 )
FileSize_String1 := MediaInfo_Get( hnd, 0,0, "FileSize/String1", 1 )
FileSize_String2 := MediaInfo_Get( hnd, 0,0, "FileSize/String2", 1 )
FileSize_String3 := MediaInfo_Get( hnd, 0,0, "FileSize/String3", 1 )
FileSize_String4 := MediaInfo_Get( hnd, 0,0, "FileSize/String4", 1 )
Duration         := MediaInfo_Get( hnd, 0,0, "Duration",         1 )
Duration_String  := MediaInfo_Get( hnd, 0,0, "Duration/String",  1 )
Duration_String1 := MediaInfo_Get( hnd, 0,0, "Duration/String1", 1 )
Duration_String2 := MediaInfo_Get( hnd, 0,0, "Duration/String2", 1 )
Duration_String3 := MediaInfo_Get( hnd, 0,0, "Duration/String3", 1 )
Title0 := MediaInfo_Get( hnd, 0,0, "Album_ReplayGain_Gain/String", 1 )
MsgBox ,
(
FILE GENERAL PROPERTIES
CompleteName     %A_Tab%= %CompleteName%
FileName         %A_Tab%= %FileName%
FileExtension    %A_Tab%= %FileExtension%
Format           %A_Tab%= %Format%
Format_Info      %A_Tab%= %Format_Info%
FileSize         %A_Tab%= %FileSize%
FileSize_String  %A_Tab%= %FileSize_String%
FileSize_String1 %A_Tab%= %FileSize_String1%
FileSize_String2 %A_Tab%= %FileSize_String2%
FileSize_String3 %A_Tab%= %FileSize_String3%
FileSize_String4 %A_Tab%= %FileSize_String4%
Duration         %A_Tab%= %Duration%
Duration_String  %A_Tab%= %Duration_String%
Duration_String1 %A_Tab%= %Duration_String1%
Duration_String2 %A_Tab%= %Duration_String2%
Duration_String3 %A_Tab%= %Duration_String3%
)


;AUDIO
Format              := MediaInfo_Get( hnd, 2,0, "Format",              1 )
Format_Info         := MediaInfo_Get( hnd, 2,0, "Format/Info",         1 )
Format_Version      := MediaInfo_Get( hnd, 2,0, "Format_Version",      1 )
Format_Profile      := MediaInfo_Get( hnd, 2,0, "Format_Profile",      1 )
CodecID             := MediaInfo_Get( hnd, 2,0, "CodecID",             1 )
CodecID_Hint        := MediaInfo_Get( hnd, 2,0, "CodecID/Hint",        1 )
Duration            := MediaInfo_Get( hnd, 2,0, "Duration",            1 )
Duration_String     := MediaInfo_Get( hnd, 2,0, "Duration/String",     1 )
Duration_String1    := MediaInfo_Get( hnd, 2,0, "Duration/String1",    1 )
Duration_String2    := MediaInfo_Get( hnd, 2,0, "Duration/String2",    1 )
Duration_String3    := MediaInfo_Get( hnd, 2,0, "Duration/String3",    1 )
BitRate_Mode        := MediaInfo_Get( hnd, 2,0, "BitRate_Mode",        1 )
BitRate_Mode_String := MediaInfo_Get( hnd, 2,0, "BitRate_Mode/String", 1 )
BitRate             := MediaInfo_Get( hnd, 2,0, "BitRate",             1 )
BitRate_String      := MediaInfo_Get( hnd, 2,0, "BitRate/String",      1 )
Channels            := MediaInfo_Get( hnd, 2,0, "Channel(s)",          1 )
Channels_String     := MediaInfo_Get( hnd, 2,0, "Channel(s)/String",   1 )
ChannelPositions    := MediaInfo_Get( hnd, 2,0, "ChannelPositions",    1 )
SamplingRate        := MediaInfo_Get( hnd, 2,0, "SamplingRate",        1 )
SamplingRate_String := MediaInfo_Get( hnd, 2,0, "SamplingRate/String", 1 )
StreamSize          := MediaInfo_Get( hnd, 2,0, "StreamSize",          1 )
StreamSize_String   := MediaInfo_Get( hnd, 2,0, "StreamSize/String",   1 )
StreamSize_String1  := MediaInfo_Get( hnd, 2,0, "StreamSize/String1",  1 )
StreamSize_String2  := MediaInfo_Get( hnd, 2,0, "StreamSize/String2",  1 )
StreamSize_String3  := MediaInfo_Get( hnd, 2,0, "StreamSize/String3",  1 )
StreamSize_String4  := MediaInfo_Get( hnd, 2,0, "StreamSize/String4",  1 )
dialnorm            := MediaInfo_Get( hnd, 2,0, "dialnorm",            1 )
dialnorm_String     := MediaInfo_Get( hnd, 2,0, "dialnorm/String",     1 )
crap                := MediaInfo_Get( hnd, 2,0, "crap",     1 )
Album_ReplayGain_Gain_String := MediaInfo_Get( hnd, 2,0, "Album_ReplayGain_Gain/String", 1 )
MsgBox % "AUDIO PROPERTIES"
. "`nFormat"              . A_Tab . A_Tab . " = " . Format
. "`nFormat_Info"                 . A_Tab . " = " . Format_Info
. "`nFormat_Version"              . A_Tab . " = " . Format_Version
. "`nFormat_Profile"              . A_Tab . " = " . Format_Profile
. "`nCodecID"             . A_Tab . A_Tab . " = " . CodecID
. "`nCodecID_Hint"                . A_Tab . " = " . CodecID_Hint
. "`nDuration"            . A_Tab . A_Tab . " = " . Duration
. "`nDuration_String"             . A_Tab . " = " . Duration_String
. "`nDuration_String1"            . A_Tab . " = " . Duration_String1
. "`nDuration_String2"            . A_Tab . " = " . Duration_String2
. "`nDuration_String3"            . A_Tab . " = " . Duration_String3
. "`nBitRate_Mode"                . A_Tab . " = " . BitRate_Mode
. "`nBitRate_Mode_String"         . A_Tab . " = " . BitRate_Mode_String
. "`nBitRate"             . A_Tab . A_Tab . " = " . BitRate
. "`nBitRate_String"              . A_Tab . " = " . BitRate_String
. "`nChannels"            . A_Tab . A_Tab . " = " . Channels
. "`nChannels_String"             . A_Tab . " = " . Channels_String
. "`nChannelPositions"            . A_Tab . " = " . ChannelPositions
. "`nSamplingRate"                . A_Tab . " = " . SamplingRate
. "`nSamplingRate_String"         . A_Tab . " = " . SamplingRate_String
. "`nStreamSize"                  . A_Tab . " = " . StreamSize
. "`nStreamSize_String"           . A_Tab . " = " . StreamSize_String
. "`nStreamSize_String1"          . A_Tab . " = " . StreamSize_String1
. "`nStreamSize_String2"          . A_Tab . " = " . StreamSize_String2
. "`nStreamSize_String3"          . A_Tab . " = " . StreamSize_String3
. "`nStreamSize_String4"          . A_Tab . " = " . StreamSize_String4
. "`ndialnorm"            . A_Tab . A_Tab . " = " . dialnorm
. "`ndialnorm_String"             . A_Tab . " = " . dialnorm_String
. "`ncrap"                        . A_Tab . " = " . crap
. "`nAlbum_ReplayGain_Gain_String" . A_Tab . " = " . Album_ReplayGain_Gain_String



;4. FILE INFO TRANSLATED TO iTunes LINGO
Track            := MediaInfo_Get( hnd, 0,0, "Track"         , 1 ) ;Name
Artist           := MediaInfo_Get( hnd, 0,0, "Artist"        , 1 ) ;Artist
Accompaniment    := MediaInfo_Get( hnd, 0,0, "Accompaniment" , 1 ) ;Album Artist
Album            := MediaInfo_Get( hnd, 0,0, "Album"         , 1 ) ;Album
ContentType      := MediaInfo_Get( hnd, 0,0, "ContentType"   , 1 ) ;Album
Composer         := MediaInfo_Get( hnd, 0,0, "Composer"      , 1 ) ;Composer
Comment          := MediaInfo_Get( hnd, 0,0, "Comment"       , 1 ) ;Comments
Genre            := MediaInfo_Get( hnd, 0,0, "Genre"         , 1 ) ;Genre
Recorded_Date    := MediaInfo_Get( hnd, 0,0, "Recorded_Date" , 1 ) ;Year
MsgBox % "FILE INFO IN iTunes LINGO:"
. "`n Name (Track)"                          . A_Tab . A_Tab . A_Tab . " = " . Track
. "`n Artist"                       . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Artist
. "`n Album Artist (Accompaniment)"                          . A_Tab . " = " . Accompaniment
. "`n Album"                        . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Album
. "`n Grouping (ContentType)"                        . A_Tab . A_Tab . " = " . ContentType
. "`n Composer"                              . A_Tab . A_Tab . A_Tab . " = " . Composer
. "`n Comments (Comment)"                            . A_Tab . A_Tab . " = " . Comment
. "`n Genre"                        . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Genre
. "`n Year (Recorded_Date)"                          . A_Tab . A_Tab . " = " . Recorded_Date


;VIDEO
Format                    := MediaInfo_Get( hnd, 1,0, "Format",                    1 )
Format_Info               := MediaInfo_Get( hnd, 1,0, "Format/Info",               1 )
Format_Version            := MediaInfo_Get( hnd, 1,0, "Format_Version",            1 )
Format_Profile            := MediaInfo_Get( hnd, 1,0, "Format_Profile",            1 )
CodecID                   := MediaInfo_Get( hnd, 1,0, "CodecID",                   1 )
CodecID_Hint              := MediaInfo_Get( hnd, 1,0, "CodecID/Hint",              1 )
Duration                  := MediaInfo_Get( hnd, 1,0, "Duration",                  1 )
Duration_String           := MediaInfo_Get( hnd, 1,0, "Duration/String",           1 )
Duration_String1          := MediaInfo_Get( hnd, 1,0, "Duration/String1",          1 )
Duration_String2          := MediaInfo_Get( hnd, 1,0, "Duration/String2",          1 )
Duration_String3          := MediaInfo_Get( hnd, 1,0, "Duration/String3",          1 )
BitRate_Mode              := MediaInfo_Get( hnd, 1,0, "BitRate_Mode",              1 )
BitRate_Mode_String       := MediaInfo_Get( hnd, 1,0, "BitRate_Mode/String",       1 )
BitRate                   := MediaInfo_Get( hnd, 1,0, "BitRate",                   1 )
BitRate_String            := MediaInfo_Get( hnd, 1,0, "BitRate/String",            1 )
BitRate_Minimum           := MediaInfo_Get( hnd, 1,0, "BitRate_Minimum",           1 )
BitRate_Minimum_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Minimum/String",    1 )
BitRate_Nominal           := MediaInfo_Get( hnd, 1,0, "BitRate_Nominal",           1 )
BitRate_Nominal_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Nominal/String",    1 )
BitRate_Maximum           := MediaInfo_Get( hnd, 1,0, "BitRate_Maximum",           1 )
BitRate_Maximum_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Maximum/String",    1 )
Width                     := MediaInfo_Get( hnd, 1,0, "Width",                     1 )
Width_String              := MediaInfo_Get( hnd, 1,0, "Width/String",              1 )
Height                    := MediaInfo_Get( hnd, 1,0, "Height",                    1 )
Height_String             := MediaInfo_Get( hnd, 1,0, "Height/String",             1 )
PixelAspectRatio          := MediaInfo_Get( hnd, 1,0, "PixelAspectRatio",          1 )
PixelAspectRatio_String   := MediaInfo_Get( hnd, 1,0, "PixelAspectRatio/String",   1 )
DisplayAspectRatio        := MediaInfo_Get( hnd, 1,0, "DisplayAspectRatio",        1 )
DisplayAspectRatio_String := MediaInfo_Get( hnd, 1,0, "DisplayAspectRatio/String", 1 )
FrameRate_Mode            := MediaInfo_Get( hnd, 1,0, "FrameRate_Mode",            1 )
FrameRate_Mode_String     := MediaInfo_Get( hnd, 1,0, "FrameRate_Mode/String",     1 )
FrameRate                 := MediaInfo_Get( hnd, 1,0, "FrameRate",                 1 )
FrameRate_String          := MediaInfo_Get( hnd, 1,0, "FrameRate/String",          1 )
FrameCount                := MediaInfo_Get( hnd, 1,0, "FrameCount",                1 )
Standard                  := MediaInfo_Get( hnd, 1,0, "Standard",                  1 )
Colorimetry               := MediaInfo_Get( hnd, 1,0, "Colorimetry",               1 )
ScanType                  := MediaInfo_Get( hnd, 1,0, "ScanType",                  1 )
ScanType_String           := MediaInfo_Get( hnd, 1,0, "ScanType/String",           1 )
StreamSize                := MediaInfo_Get( hnd, 1,0, "StreamSize",                1 )
StreamSize_String         := MediaInfo_Get( hnd, 1,0, "StreamSize/String",         1 )
StreamSize_String1        := MediaInfo_Get( hnd, 1,0, "StreamSize/String1",        1 )
StreamSize_String2        := MediaInfo_Get( hnd, 1,0, "StreamSize/String2",        1 )
StreamSize_String3        := MediaInfo_Get( hnd, 1,0, "StreamSize/String3",        1 )
StreamSize_String4        := MediaInfo_Get( hnd, 1,0, "StreamSize/String4",        1 )
Language_String           := MediaInfo_Get( hnd, 1,0, "Language/String",           1 )
MsgBox % "VIDEO PROPERTIES"
. "`nFormat"                   . A_Tab . A_Tab . A_Tab . " = " . Format
. "`nFormat_Info"                      . A_Tab . A_Tab . " = " . Format_Info
. "`nFormat_Version"                   . A_Tab . A_Tab . " = " . Format_Version
. "`nFormat_Profile"                   . A_Tab . A_Tab . " = " . Format_Profile
. "`nCodecID"                  . A_Tab . A_Tab . A_Tab . " = " . CodecID
. "`nCodecID_Hint"                     . A_Tab . A_Tab . " = " . CodecID_Hint
. "`nDuration"                 . A_Tab . A_Tab . A_Tab . " = " . Duration
. "`nDuration_String"                  . A_Tab . A_Tab . " = " . Duration_String
. "`nDuration_String1"                 . A_Tab . A_Tab . " = " . Duration_String1
. "`nDuration_String2"                 . A_Tab . A_Tab . " = " . Duration_String2
. "`nDuration_String3"                 . A_Tab . A_Tab . " = " . Duration_String3
. "`nBitRate_Mode"                     . A_Tab . A_Tab . " = " . BitRate_Mode
. "`nBitRate_Mode_String"              . A_Tab . A_Tab . " = " . BitRate_Mode_String
. "`nBitRate"                  . A_Tab . A_Tab . A_Tab . " = " . BitRate
. "`nBitRate_String"                   . A_Tab . A_Tab . " = " . BitRate_String
. "`nBitRate_Minimum"                  . A_Tab . A_Tab . " = " . BitRate_Minimum
. "`nBitRate_Minimum_String"                   . A_Tab . " = " . BitRate_Minimum_String
. "`nBitRate_Nominal"                  . A_Tab . A_Tab . " = " . BitRate_Nominal
. "`nBitRate_Nominal_String"                   . A_Tab . " = " . BitRate_Nominal_String
. "`nBitRate_Maximum"                  . A_Tab . A_Tab . " = " . BitRate_Maximum
. "`nBitRate_Maximum_String"                   . A_Tab . " = " . BitRate_Maximum_String
. "`nWidth"                    . A_Tab . A_Tab . A_Tab . " = " . Width
. "`nWidth_String"                     . A_Tab . A_Tab . " = " . Width_String
. "`nHeight"                   . A_Tab . A_Tab . A_Tab . " = " . Height
. "`nHeight_String"                    . A_Tab . A_Tab . " = " . Height_String
. "`nPixelAspectRatio"                 . A_Tab . A_Tab . " = " . PixelAspectRatio
. "`nPixelAspectRatio_String"                  . A_Tab . " = " . PixelAspectRatio_String
. "`nDisplayAspectRatio"               . A_Tab . A_Tab . " = " . DisplayAspectRatio
. "`nDisplayAspectRatio_String"                . A_Tab . " = " . DisplayAspectRatio_String
. "`nFrameRate_Mode"                   . A_Tab . A_Tab . " = " . FrameRate_Mode
. "`nFrameRate_Mode_String"                    . A_Tab . " = " . FrameRate_Mode_String
. "`nFrameRate"                        . A_Tab . A_Tab . " = " . FrameRate
. "`nFrameRate_String"                 . A_Tab . A_Tab . " = " . FrameRate_String
. "`nFrameCount"                       . A_Tab . A_Tab . " = " . FrameCount
. "`nStandard"                 . A_Tab . A_Tab . A_Tab . " = " . Standard
. "`nColorimetry"                      . A_Tab . A_Tab . " = " . Colorimetry
. "`nScanType"                 . A_Tab . A_Tab . A_Tab . " = " . ScanType
. "`nScanType_String"                  . A_Tab . A_Tab . " = " . ScanType_String
. "`nStreamSize"                       . A_Tab . A_Tab . " = " . StreamSize
. "`nStreamSize_String"                . A_Tab . A_Tab . " = " . StreamSize_String
. "`nStreamSize_String1"               . A_Tab . A_Tab . " = " . StreamSize_String1
. "`nStreamSize_String2"               . A_Tab . A_Tab . " = " . StreamSize_String2
. "`nStreamSize_String3"               . A_Tab . A_Tab . " = " . StreamSize_String3
. "`nStreamSize_String4"               . A_Tab . A_Tab . " = " . StreamSize_String4
. "`nLanguage_String"                  . A_Tab . A_Tab . " = " . Language_String

/*
;Menu (Format used eg: DVD-Video)
Format := MediaInfo_Get( hnd, 3,0, "Format", 1 )
MsgBox % "Menu (Format used eg: DVD-Video)"
. "`nFormat" . A_Tab . " = " . Format
*/

MediaInfo_Close( hnd )
exitapp
Esc::ExitApp  ; Press ESC to cancel this script. Placed after the ExitApp.


;------------------------------------------------------------------------------
MediaInfo_New() {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_New" )
}

;------------------------------------------------------------------------------
MediaInfo_Open( hnd, MediaFile ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Open", UInt,hnd
               , Str,MediaFile, UInt )
}

;------------------------------------------------------------------------------
MediaInfo_Get( hnd, StrK=0, StrN=0, Comm="", InfK=0, Srch=0 ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Get", UInt,hnd
               , Int,StrK, Int,StrN, Str,Comm, Int,InfK, Int,Sech, Str )
}

;------------------------------------------------------------------------------
MediaInfo_Close( hnd ) {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Close", UInt,hnd )
}

;------------------------------------------------------------------------------
GetErrorString(Errornumber)
{
   VarSetCapacity(ErrorString, 1024)      ;String to hold the error-message.

   DllCall("FormatMessage"
         , UINT, 0x00001000    ;FORMAT_MESSAGE_FROM_SYSTEM: The function should search the system message-table resource(s) for the requested message.
         , UINT, NULL          ;A handle to the module that contains the message table to search.
         , UINT, Errornumber
         , UINT, 0             ;Language-ID is automatically retreived
         , Str, ErrorString
         , UINT, 1024          ;Buffer-Length
         , str, "")            ;An array of values that are used as insert values in the formatted message. (not used)

   StringReplace, ErrorString, ErrorString, `r`n, %A_Space%, All      ;Replaces newlines by A_Space for inline-output

   return %ErrorString%
}

; Note the above gets the info from the file itself. Here's an example of getting info from the iTunes program itself in case that's what you wanted to do:

MsgBox Press ESC to abort this script
iTunesApp       := ComObjCreate("iTunes.Application")
iTunesVersion   := iTunesApp.Version
objPlaylist     := iTunesApp.LibraryPlaylist
colTracks       := objPlaylist.Tracks
numiTunesTracks := colTracks.Count
MsgBox iTunes loaded. Version %iTunesVersion%`niTunes has %numiTunesTracks% tracks

LOOP,%numiTunesTracks%
{
  objTrack := colTracks.item(A_Index)
  iTunes_track_Name           := objTrack.Name         ; iTunes Name
  iTunes_track_Artist         := objTrack.Artist       ; iTunes Artist
  iTunes_track_Album          := objTrack.Album        ; iTunes Album Artist
  iTunes_track_Album_Artist   := objTrack.AlbumArtist  ; iTunes Album
  iTunes_track_Grouping       := objTrack.Grouping     ; iTunes Grouping
  iTunes_track_Composer       := objTrack.Composer     ; iTunes Composer
  iTunes_track_Comment        := objTrack.Comment      ; iTunes Comments
  iTunes_track_Genre          := objTrack.Genre        ; iTunes Genre
  iTunes_track_Year           := objTrack.Year         ; iTunes Year
  iTunes_track_Location       := objTrack.Location     ; iTunes track location
  iTunes_track_Format         := objTrack.KindAsString ; e.g. "MPEG Audio"

  MsgBox % "iTunes track info:"
  . "`n Track Name"           . A_Tab . " = " . iTunes_track_Name
  . "`n Artist"       . A_Tab . A_Tab . " = " . iTunes_track_Artist
  . "`n Album Artist"         . A_Tab . " = " . iTunes_track_Album
  . "`n Album"        . A_Tab . A_Tab . " = " . iTunes_track_Album_Artist
  . "`n Grouping"     . A_Tab . A_Tab . " = " . iTunes_track_Grouping
  . "`n Composer"             . A_Tab . " = " . iTunes_track_Composer
  . "`n Comment"              . A_Tab . " = " . iTunes_track_Comment
  . "`n Genre"        . A_Tab . A_Tab . " = " . iTunes_track_Genre
  . "`n Year"         . A_Tab . A_Tab . " = " . iTunes_track_Year
  . "`n Location"     . A_Tab . A_Tab . " = " . iTunes_track_Location
  . "`n Format"       . A_Tab . A_Tab . " = " . iTunes_track_Format
}

ExitApp
;Esc::ExitApp  ; Press ESC to cancel this script. Placed after the ExitApp.


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

thank you , tried works fine with more Info

 

you wrote you have problem with the variable aa:=   , just change this variable or add space

( I have the same version ahk_L 1.1.09.02  and ANSI )

 

;--- versionx ansi or unicode ---------
if (A_IsUnicode)
  codex := " Encoding is Unicode"
else
  codex := " Encoding is ANSI"
aa := "Version: " ( InStr( (v:=A_AhkVersion), "1.1" ) ? "ahk_L " : "ahk_Basic " ) v  codex
msgbox, %aa%
return



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks! is it possible if you posted the complete & updated script (the original but modified to support ANSI/Unicode)? the following did not work (BB value is blank):

SetWorkingDir, %A_ScriptDir%
DllCall("LoadLibrary", Str, "MediaInfo.dll")

If (A_IsUnicode)
  codex := " Encoding is Unicode"
Else
  codex := " Encoding is ANSI"
AA := "Version: " (InStr( (v:=A_AhkVersion), "1.1") ? "ahk_L " : "ahk_Basic " ) v codex
MsgBox, %AA%

FD := "M:\example.mp3"
BB := MediaInfo_DumpInfo(FD)
MsgBox, %BB%

Return

MediaInfo_DumpInfo(MediaFile = "") {
 hnd := DllCall("MediaInfo\MediaInfoA_New")
 DllCall("MediaInfo.dll\MediaInfoA_Open", UInt, hnd, Str, MediaFile)
 Info := DllCall("MediaInfo\MediaInfoA_Inform", UInt, hnd, UInt, 0, Str)
 DllCall("MediaInfo\MediaInfoA_Delete", UInt, hnd)
Return Info
}


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

for me works always ...

are you sure you use drive M:\   ?

FD := "M:\example.mp3"         ; -- < fullpath correct ?

 

;............
FD := "M:\example.mp3"
ifnotexist,%fd%
    {
    msgbox, 262192,File-Error,File=`n%fd%`nNot exist
    exitapp
    }
;-- else
;-- {
;-- ......
;-- }
return



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

still i get Ȁ? when i run the 1st script (correct path). with the same path, i get full info with the 2nd script:

 

1st Script:

SetWorkingDir, %A_ScriptDir%
DllCall("LoadLibrary", Str, "MediaInfo.dll")


If (A_IsUnicode)
  codex := " Encoding is Unicode"
Else
  codex := " Encoding is ANSI"
AA := "Version: " (InStr( (v:=A_AhkVersion), "1.1") ? "ahk_L " : "ahk_Basic " ) v codex
MsgBox, %AA%


FD := "M:\exaple.mp3"

IfNotExist,%fd%
{
MsgBox, 262192, File-Error, File`n%fd%`ndoes not exist!
ExitApp
}
Else


BB := MediaInfo_DumpInfo(FD)
MsgBox, %BB%

Return

MediaInfo_DumpInfo(MediaFile = "") {
 hnd := DllCall("MediaInfo\MediaInfoA_New")
 DllCall("MediaInfo.dll\MediaInfoA_Open", UInt, hnd, Str, MediaFile)
 Info := DllCall("MediaInfo\MediaInfoA_Inform", UInt, hnd, UInt, 0, Str)
 DllCall("MediaInfo\MediaInfoA_Delete", UInt, hnd)
Return Info
}

2nd Script:

; http://www.autohotkey.com/board/topic/62281-using-mediainfodll-to-get-itunes-info/

; MediaInfo.dll / 'Test Script' - By David Deley : 08-Jan-2011
;
; To Test:
; 1. Download and install MediaInfo
; 2. Set variables MediaInfoDll and File1 below
; 3. Run
;
; Thank you to SKAN for posting his Video Properties - MediaInfo.Dll script
; http://www.autohotkey.com/forum/viewtopic.php?t=66500
#NoTrayIcon
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%

;USER SET THESE TWO VARIABLES
MediaInfoDll := "C:\...\MediaInfo.dll"
File1 := "M:\example.mp3"


; CHECK THAT FILE1 EXISTS
IfNotExist, %File1%
{
    MsgBox % "Unable to locate file:`n" . File1 . "`n`nSet variable 'File1' to point to an audio or video file."
    ExitApp
}


; LOAD MEDIAINFO DLL
hModule := DllCall( "LoadLibrary", Str, MediaInfoDll )
if hModule = 0
{
  Msgbox % "Error loading MediaInfo.dll`n`nWas trying to load file: " . MediaInfoDll . "`n`nError was: " . GetErrorString(A_LastError) . "`n`nDownload and install MediaInfo, then set variable 'MediaInfoDll' to point to file 'MediaInfo.dll'"
  ExitApp
}
FileGetVersion, Ver, MediaInfo.Dll
MsgBox MediaInfo Version = %Ver%

hnd := MediaInfo_New()
;MsgBox hnd = %hnd%

stat := MediaInfo_Open( hnd, File1 )
;MsgBox stat = %stat%


;DISPLAY FILE INFORMATION
;GENERAL
CompleteName     := MediaInfo_Get( hnd, 0,0, "CompleteName",     1 )
FileName         := MediaInfo_Get( hnd, 0,0, "FileName",         1 )
FileExtension    := MediaInfo_Get( hnd, 0,0, "FileExtension",    1 )
Format           := MediaInfo_Get( hnd, 0,0, "Format",           1 )
Format_Info      := MediaInfo_Get( hnd, 0,0, "Format/Info",      1 )
FileSize         := MediaInfo_Get( hnd, 0,0, "FileSize",         1 )
FileSize_String  := MediaInfo_Get( hnd, 0,0, "FileSize/String",  1 )
FileSize_String1 := MediaInfo_Get( hnd, 0,0, "FileSize/String1", 1 )
FileSize_String2 := MediaInfo_Get( hnd, 0,0, "FileSize/String2", 1 )
FileSize_String3 := MediaInfo_Get( hnd, 0,0, "FileSize/String3", 1 )
FileSize_String4 := MediaInfo_Get( hnd, 0,0, "FileSize/String4", 1 )
Duration         := MediaInfo_Get( hnd, 0,0, "Duration",         1 )
Duration_String  := MediaInfo_Get( hnd, 0,0, "Duration/String",  1 )
Duration_String1 := MediaInfo_Get( hnd, 0,0, "Duration/String1", 1 )
Duration_String2 := MediaInfo_Get( hnd, 0,0, "Duration/String2", 1 )
Duration_String3 := MediaInfo_Get( hnd, 0,0, "Duration/String3", 1 )
Title0 := MediaInfo_Get( hnd, 0,0, "Album_ReplayGain_Gain/String", 1 )
MsgBox ,
(
FILE GENERAL PROPERTIES
CompleteName     %A_Tab%= %CompleteName%
FileName         %A_Tab%= %FileName%
FileExtension    %A_Tab%= %FileExtension%
Format           %A_Tab%= %Format%
Format_Info      %A_Tab%= %Format_Info%
FileSize         %A_Tab%= %FileSize%
FileSize_String  %A_Tab%= %FileSize_String%
FileSize_String1 %A_Tab%= %FileSize_String1%
FileSize_String2 %A_Tab%= %FileSize_String2%
FileSize_String3 %A_Tab%= %FileSize_String3%
FileSize_String4 %A_Tab%= %FileSize_String4%
Duration         %A_Tab%= %Duration%
Duration_String  %A_Tab%= %Duration_String%
Duration_String1 %A_Tab%= %Duration_String1%
Duration_String2 %A_Tab%= %Duration_String2%
Duration_String3 %A_Tab%= %Duration_String3%
)


;AUDIO
Format              := MediaInfo_Get( hnd, 2,0, "Format",              1 )
Format_Info         := MediaInfo_Get( hnd, 2,0, "Format/Info",         1 )
Format_Version      := MediaInfo_Get( hnd, 2,0, "Format_Version",      1 )
Format_Profile      := MediaInfo_Get( hnd, 2,0, "Format_Profile",      1 )
CodecID             := MediaInfo_Get( hnd, 2,0, "CodecID",             1 )
CodecID_Hint        := MediaInfo_Get( hnd, 2,0, "CodecID/Hint",        1 )
Duration            := MediaInfo_Get( hnd, 2,0, "Duration",            1 )
Duration_String     := MediaInfo_Get( hnd, 2,0, "Duration/String",     1 )
Duration_String1    := MediaInfo_Get( hnd, 2,0, "Duration/String1",    1 )
Duration_String2    := MediaInfo_Get( hnd, 2,0, "Duration/String2",    1 )
Duration_String3    := MediaInfo_Get( hnd, 2,0, "Duration/String3",    1 )
BitRate_Mode        := MediaInfo_Get( hnd, 2,0, "BitRate_Mode",        1 )
BitRate_Mode_String := MediaInfo_Get( hnd, 2,0, "BitRate_Mode/String", 1 )
BitRate             := MediaInfo_Get( hnd, 2,0, "BitRate",             1 )
BitRate_String      := MediaInfo_Get( hnd, 2,0, "BitRate/String",      1 )
Channels            := MediaInfo_Get( hnd, 2,0, "Channel(s)",          1 )
Channels_String     := MediaInfo_Get( hnd, 2,0, "Channel(s)/String",   1 )
ChannelPositions    := MediaInfo_Get( hnd, 2,0, "ChannelPositions",    1 )
SamplingRate        := MediaInfo_Get( hnd, 2,0, "SamplingRate",        1 )
SamplingRate_String := MediaInfo_Get( hnd, 2,0, "SamplingRate/String", 1 )
StreamSize          := MediaInfo_Get( hnd, 2,0, "StreamSize",          1 )
StreamSize_String   := MediaInfo_Get( hnd, 2,0, "StreamSize/String",   1 )
StreamSize_String1  := MediaInfo_Get( hnd, 2,0, "StreamSize/String1",  1 )
StreamSize_String2  := MediaInfo_Get( hnd, 2,0, "StreamSize/String2",  1 )
StreamSize_String3  := MediaInfo_Get( hnd, 2,0, "StreamSize/String3",  1 )
StreamSize_String4  := MediaInfo_Get( hnd, 2,0, "StreamSize/String4",  1 )
dialnorm            := MediaInfo_Get( hnd, 2,0, "dialnorm",            1 )
dialnorm_String     := MediaInfo_Get( hnd, 2,0, "dialnorm/String",     1 )
crap                := MediaInfo_Get( hnd, 2,0, "crap",     1 )
Album_ReplayGain_Gain_String := MediaInfo_Get( hnd, 2,0, "Album_ReplayGain_Gain/String", 1 )
MsgBox % "AUDIO PROPERTIES"
. "`nFormat"              . A_Tab . A_Tab . " = " . Format
. "`nFormat_Info"                 . A_Tab . " = " . Format_Info
. "`nFormat_Version"              . A_Tab . " = " . Format_Version
. "`nFormat_Profile"              . A_Tab . " = " . Format_Profile
. "`nCodecID"             . A_Tab . A_Tab . " = " . CodecID
. "`nCodecID_Hint"                . A_Tab . " = " . CodecID_Hint
. "`nDuration"            . A_Tab . A_Tab . " = " . Duration
. "`nDuration_String"             . A_Tab . " = " . Duration_String
. "`nDuration_String1"            . A_Tab . " = " . Duration_String1
. "`nDuration_String2"            . A_Tab . " = " . Duration_String2
. "`nDuration_String3"            . A_Tab . " = " . Duration_String3
. "`nBitRate_Mode"                . A_Tab . " = " . BitRate_Mode
. "`nBitRate_Mode_String"         . A_Tab . " = " . BitRate_Mode_String
. "`nBitRate"             . A_Tab . A_Tab . " = " . BitRate
. "`nBitRate_String"              . A_Tab . " = " . BitRate_String
. "`nChannels"            . A_Tab . A_Tab . " = " . Channels
. "`nChannels_String"             . A_Tab . " = " . Channels_String
. "`nChannelPositions"            . A_Tab . " = " . ChannelPositions
. "`nSamplingRate"                . A_Tab . " = " . SamplingRate
. "`nSamplingRate_String"         . A_Tab . " = " . SamplingRate_String
. "`nStreamSize"                  . A_Tab . " = " . StreamSize
. "`nStreamSize_String"           . A_Tab . " = " . StreamSize_String
. "`nStreamSize_String1"          . A_Tab . " = " . StreamSize_String1
. "`nStreamSize_String2"          . A_Tab . " = " . StreamSize_String2
. "`nStreamSize_String3"          . A_Tab . " = " . StreamSize_String3
. "`nStreamSize_String4"          . A_Tab . " = " . StreamSize_String4
. "`ndialnorm"            . A_Tab . A_Tab . " = " . dialnorm
. "`ndialnorm_String"             . A_Tab . " = " . dialnorm_String
. "`ncrap"                        . A_Tab . " = " . crap
. "`nAlbum_ReplayGain_Gain_String" . A_Tab . " = " . Album_ReplayGain_Gain_String



;4. FILE INFO TRANSLATED TO iTunes LINGO
Track            := MediaInfo_Get( hnd, 0,0, "Track"         , 1 ) ;Name
Artist           := MediaInfo_Get( hnd, 0,0, "Artist"        , 1 ) ;Artist
Accompaniment    := MediaInfo_Get( hnd, 0,0, "Accompaniment" , 1 ) ;Album Artist
Album            := MediaInfo_Get( hnd, 0,0, "Album"         , 1 ) ;Album
ContentType      := MediaInfo_Get( hnd, 0,0, "ContentType"   , 1 ) ;Album
Composer         := MediaInfo_Get( hnd, 0,0, "Composer"      , 1 ) ;Composer
Comment          := MediaInfo_Get( hnd, 0,0, "Comment"       , 1 ) ;Comments
Genre            := MediaInfo_Get( hnd, 0,0, "Genre"         , 1 ) ;Genre
Recorded_Date    := MediaInfo_Get( hnd, 0,0, "Recorded_Date" , 1 ) ;Year
MsgBox % "FILE INFO IN iTunes LINGO:"
. "`n Name (Track)"                          . A_Tab . A_Tab . A_Tab . " = " . Track
. "`n Artist"                       . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Artist
. "`n Album Artist (Accompaniment)"                          . A_Tab . " = " . Accompaniment
. "`n Album"                        . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Album
. "`n Grouping (ContentType)"                        . A_Tab . A_Tab . " = " . ContentType
. "`n Composer"                              . A_Tab . A_Tab . A_Tab . " = " . Composer
. "`n Comments (Comment)"                            . A_Tab . A_Tab . " = " . Comment
. "`n Genre"                        . A_Tab  . A_Tab . A_Tab . A_Tab . " = " . Genre
. "`n Year (Recorded_Date)"                          . A_Tab . A_Tab . " = " . Recorded_Date


;VIDEO
Format                    := MediaInfo_Get( hnd, 1,0, "Format",                    1 )
Format_Info               := MediaInfo_Get( hnd, 1,0, "Format/Info",               1 )
Format_Version            := MediaInfo_Get( hnd, 1,0, "Format_Version",            1 )
Format_Profile            := MediaInfo_Get( hnd, 1,0, "Format_Profile",            1 )
CodecID                   := MediaInfo_Get( hnd, 1,0, "CodecID",                   1 )
CodecID_Hint              := MediaInfo_Get( hnd, 1,0, "CodecID/Hint",              1 )
Duration                  := MediaInfo_Get( hnd, 1,0, "Duration",                  1 )
Duration_String           := MediaInfo_Get( hnd, 1,0, "Duration/String",           1 )
Duration_String1          := MediaInfo_Get( hnd, 1,0, "Duration/String1",          1 )
Duration_String2          := MediaInfo_Get( hnd, 1,0, "Duration/String2",          1 )
Duration_String3          := MediaInfo_Get( hnd, 1,0, "Duration/String3",          1 )
BitRate_Mode              := MediaInfo_Get( hnd, 1,0, "BitRate_Mode",              1 )
BitRate_Mode_String       := MediaInfo_Get( hnd, 1,0, "BitRate_Mode/String",       1 )
BitRate                   := MediaInfo_Get( hnd, 1,0, "BitRate",                   1 )
BitRate_String            := MediaInfo_Get( hnd, 1,0, "BitRate/String",            1 )
BitRate_Minimum           := MediaInfo_Get( hnd, 1,0, "BitRate_Minimum",           1 )
BitRate_Minimum_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Minimum/String",    1 )
BitRate_Nominal           := MediaInfo_Get( hnd, 1,0, "BitRate_Nominal",           1 )
BitRate_Nominal_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Nominal/String",    1 )
BitRate_Maximum           := MediaInfo_Get( hnd, 1,0, "BitRate_Maximum",           1 )
BitRate_Maximum_String    := MediaInfo_Get( hnd, 1,0, "BitRate_Maximum/String",    1 )
Width                     := MediaInfo_Get( hnd, 1,0, "Width",                     1 )
Width_String              := MediaInfo_Get( hnd, 1,0, "Width/String",              1 )
Height                    := MediaInfo_Get( hnd, 1,0, "Height",                    1 )
Height_String             := MediaInfo_Get( hnd, 1,0, "Height/String",             1 )
PixelAspectRatio          := MediaInfo_Get( hnd, 1,0, "PixelAspectRatio",          1 )
PixelAspectRatio_String   := MediaInfo_Get( hnd, 1,0, "PixelAspectRatio/String",   1 )
DisplayAspectRatio        := MediaInfo_Get( hnd, 1,0, "DisplayAspectRatio",        1 )
DisplayAspectRatio_String := MediaInfo_Get( hnd, 1,0, "DisplayAspectRatio/String", 1 )
FrameRate_Mode            := MediaInfo_Get( hnd, 1,0, "FrameRate_Mode",            1 )
FrameRate_Mode_String     := MediaInfo_Get( hnd, 1,0, "FrameRate_Mode/String",     1 )
FrameRate                 := MediaInfo_Get( hnd, 1,0, "FrameRate",                 1 )
FrameRate_String          := MediaInfo_Get( hnd, 1,0, "FrameRate/String",          1 )
FrameCount                := MediaInfo_Get( hnd, 1,0, "FrameCount",                1 )
Standard                  := MediaInfo_Get( hnd, 1,0, "Standard",                  1 )
Colorimetry               := MediaInfo_Get( hnd, 1,0, "Colorimetry",               1 )
ScanType                  := MediaInfo_Get( hnd, 1,0, "ScanType",                  1 )
ScanType_String           := MediaInfo_Get( hnd, 1,0, "ScanType/String",           1 )
StreamSize                := MediaInfo_Get( hnd, 1,0, "StreamSize",                1 )
StreamSize_String         := MediaInfo_Get( hnd, 1,0, "StreamSize/String",         1 )
StreamSize_String1        := MediaInfo_Get( hnd, 1,0, "StreamSize/String1",        1 )
StreamSize_String2        := MediaInfo_Get( hnd, 1,0, "StreamSize/String2",        1 )
StreamSize_String3        := MediaInfo_Get( hnd, 1,0, "StreamSize/String3",        1 )
StreamSize_String4        := MediaInfo_Get( hnd, 1,0, "StreamSize/String4",        1 )
Language_String           := MediaInfo_Get( hnd, 1,0, "Language/String",           1 )
MsgBox % "VIDEO PROPERTIES"
. "`nFormat"                   . A_Tab . A_Tab . A_Tab . " = " . Format
. "`nFormat_Info"                      . A_Tab . A_Tab . " = " . Format_Info
. "`nFormat_Version"                   . A_Tab . A_Tab . " = " . Format_Version
. "`nFormat_Profile"                   . A_Tab . A_Tab . " = " . Format_Profile
. "`nCodecID"                  . A_Tab . A_Tab . A_Tab . " = " . CodecID
. "`nCodecID_Hint"                     . A_Tab . A_Tab . " = " . CodecID_Hint
. "`nDuration"                 . A_Tab . A_Tab . A_Tab . " = " . Duration
. "`nDuration_String"                  . A_Tab . A_Tab . " = " . Duration_String
. "`nDuration_String1"                 . A_Tab . A_Tab . " = " . Duration_String1
. "`nDuration_String2"                 . A_Tab . A_Tab . " = " . Duration_String2
. "`nDuration_String3"                 . A_Tab . A_Tab . " = " . Duration_String3
. "`nBitRate_Mode"                     . A_Tab . A_Tab . " = " . BitRate_Mode
. "`nBitRate_Mode_String"              . A_Tab . A_Tab . " = " . BitRate_Mode_String
. "`nBitRate"                  . A_Tab . A_Tab . A_Tab . " = " . BitRate
. "`nBitRate_String"                   . A_Tab . A_Tab . " = " . BitRate_String
. "`nBitRate_Minimum"                  . A_Tab . A_Tab . " = " . BitRate_Minimum
. "`nBitRate_Minimum_String"                   . A_Tab . " = " . BitRate_Minimum_String
. "`nBitRate_Nominal"                  . A_Tab . A_Tab . " = " . BitRate_Nominal
. "`nBitRate_Nominal_String"                   . A_Tab . " = " . BitRate_Nominal_String
. "`nBitRate_Maximum"                  . A_Tab . A_Tab . " = " . BitRate_Maximum
. "`nBitRate_Maximum_String"                   . A_Tab . " = " . BitRate_Maximum_String
. "`nWidth"                    . A_Tab . A_Tab . A_Tab . " = " . Width
. "`nWidth_String"                     . A_Tab . A_Tab . " = " . Width_String
. "`nHeight"                   . A_Tab . A_Tab . A_Tab . " = " . Height
. "`nHeight_String"                    . A_Tab . A_Tab . " = " . Height_String
. "`nPixelAspectRatio"                 . A_Tab . A_Tab . " = " . PixelAspectRatio
. "`nPixelAspectRatio_String"                  . A_Tab . " = " . PixelAspectRatio_String
. "`nDisplayAspectRatio"               . A_Tab . A_Tab . " = " . DisplayAspectRatio
. "`nDisplayAspectRatio_String"                . A_Tab . " = " . DisplayAspectRatio_String
. "`nFrameRate_Mode"                   . A_Tab . A_Tab . " = " . FrameRate_Mode
. "`nFrameRate_Mode_String"                    . A_Tab . " = " . FrameRate_Mode_String
. "`nFrameRate"                        . A_Tab . A_Tab . " = " . FrameRate
. "`nFrameRate_String"                 . A_Tab . A_Tab . " = " . FrameRate_String
. "`nFrameCount"                       . A_Tab . A_Tab . " = " . FrameCount
. "`nStandard"                 . A_Tab . A_Tab . A_Tab . " = " . Standard
. "`nColorimetry"                      . A_Tab . A_Tab . " = " . Colorimetry
. "`nScanType"                 . A_Tab . A_Tab . A_Tab . " = " . ScanType
. "`nScanType_String"                  . A_Tab . A_Tab . " = " . ScanType_String
. "`nStreamSize"                       . A_Tab . A_Tab . " = " . StreamSize
. "`nStreamSize_String"                . A_Tab . A_Tab . " = " . StreamSize_String
. "`nStreamSize_String1"               . A_Tab . A_Tab . " = " . StreamSize_String1
. "`nStreamSize_String2"               . A_Tab . A_Tab . " = " . StreamSize_String2
. "`nStreamSize_String3"               . A_Tab . A_Tab . " = " . StreamSize_String3
. "`nStreamSize_String4"               . A_Tab . A_Tab . " = " . StreamSize_String4
. "`nLanguage_String"                  . A_Tab . A_Tab . " = " . Language_String

/*
;Menu (Format used eg: DVD-Video)
Format := MediaInfo_Get( hnd, 3,0, "Format", 1 )
MsgBox % "Menu (Format used eg: DVD-Video)"
. "`nFormat" . A_Tab . " = " . Format
*/

MediaInfo_Close( hnd )
exitapp
Esc::ExitApp  ; Press ESC to cancel this script. Placed after the ExitApp.


;------------------------------------------------------------------------------
MediaInfo_New() {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_New" )
}

;------------------------------------------------------------------------------
MediaInfo_Open( hnd, MediaFile ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Open", UInt,hnd
               , Str,MediaFile, UInt )
}

;------------------------------------------------------------------------------
MediaInfo_Get( hnd, StrK=0, StrN=0, Comm="", InfK=0, Srch=0 ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Get", UInt,hnd
               , Int,StrK, Int,StrN, Str,Comm, Int,InfK, Int,Sech, Str )
}

;------------------------------------------------------------------------------
MediaInfo_Close( hnd ) {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Close", UInt,hnd )
}

;------------------------------------------------------------------------------
GetErrorString(Errornumber)
{
   VarSetCapacity(ErrorString, 1024)      ;String to hold the error-message.

   DllCall("FormatMessage"
         , UINT, 0x00001000    ;FORMAT_MESSAGE_FROM_SYSTEM: The function should search the system message-table resource(s) for the requested message.
         , UINT, NULL          ;A handle to the module that contains the message table to search.
         , UINT, Errornumber
         , UINT, 0             ;Language-ID is automatically retreived
         , Str, ErrorString
         , UINT, 1024          ;Buffer-Length
         , str, "")            ;An array of values that are used as insert values in the formatted message. (not used)

   StringReplace, ErrorString, ErrorString, `r`n, %A_Space%, All      ;Replaces newlines by A_Space for inline-output

   return %ErrorString%
}

; Note the above gets the info from the file itself. Here's an example of getting info from the iTunes program itself in case that's what you wanted to do:

MsgBox Press ESC to abort this script
iTunesApp       := ComObjCreate("iTunes.Application")
iTunesVersion   := iTunesApp.Version
objPlaylist     := iTunesApp.LibraryPlaylist
colTracks       := objPlaylist.Tracks
numiTunesTracks := colTracks.Count
MsgBox iTunes loaded. Version %iTunesVersion%`niTunes has %numiTunesTracks% tracks

LOOP,%numiTunesTracks%
{
  objTrack := colTracks.item(A_Index)
  iTunes_track_Name           := objTrack.Name         ; iTunes Name
  iTunes_track_Artist         := objTrack.Artist       ; iTunes Artist
  iTunes_track_Album          := objTrack.Album        ; iTunes Album Artist
  iTunes_track_Album_Artist   := objTrack.AlbumArtist  ; iTunes Album
  iTunes_track_Grouping       := objTrack.Grouping     ; iTunes Grouping
  iTunes_track_Composer       := objTrack.Composer     ; iTunes Composer
  iTunes_track_Comment        := objTrack.Comment      ; iTunes Comments
  iTunes_track_Genre          := objTrack.Genre        ; iTunes Genre
  iTunes_track_Year           := objTrack.Year         ; iTunes Year
  iTunes_track_Location       := objTrack.Location     ; iTunes track location
  iTunes_track_Format         := objTrack.KindAsString ; e.g. "MPEG Audio"

  MsgBox % "iTunes track info:"
  . "`n Track Name"           . A_Tab . " = " . iTunes_track_Name
  . "`n Artist"       . A_Tab . A_Tab . " = " . iTunes_track_Artist
  . "`n Album Artist"         . A_Tab . " = " . iTunes_track_Album
  . "`n Album"        . A_Tab . A_Tab . " = " . iTunes_track_Album_Artist
  . "`n Grouping"     . A_Tab . A_Tab . " = " . iTunes_track_Grouping
  . "`n Composer"             . A_Tab . " = " . iTunes_track_Composer
  . "`n Comment"              . A_Tab . " = " . iTunes_track_Comment
  . "`n Genre"        . A_Tab . A_Tab . " = " . iTunes_track_Genre
  . "`n Year"         . A_Tab . A_Tab . " = " . iTunes_track_Year
  . "`n Location"     . A_Tab . A_Tab . " = " . iTunes_track_Location
  . "`n Format"       . A_Tab . A_Tab . " = " . iTunes_track_Format
}

ExitApp
;Esc::ExitApp  ; Press ESC to cancel this script. Placed after the ExitApp.


just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011

This will work with both ANSI and U32 versions of AHK 1.1:

 

MediaInfo_DumpInfo(MediaFile := "") {
   Static A := A_IsUnicode ? "" : "A"
   Static New := "MediaInfo.dll\MediaInfo" . A . "_New"
   Static Open := "MediaInfo.dll\MediaInfo" . A . "_Open"
   Static Inform := "MediaInfo.dll\MediaInfo" . A . "_Inform"
   Static Delete := "MediaInfo.dll\MediaInfo" . A . "_Delete"
   hnd := DllCall(New)
   DllCall(Open, "UInt", hnd, "Str", MediaFile)
   Info := DllCall(Inform, "UInt", hnd, "UInt", 0, "Str")
   DllCall(Delete, "UInt", hnd)
   Return Info
}

Prefer ahkscript.org for the time being.


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks, justme! you are the best. the script works flawlessly now (tested). is there any way i get extract the duration in milliseconds only from the info data?



Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
o:=comobjcreate("Shell.Application")
fileselectfile,file,c:\
splitpath,file,file,directory
if errorlevel
	exitapp
od:=o.namespace(directory)
of:=od.parsename(file)
loop,286
	fileappend,% (append:=od.getdetailsof(of,a_index))?a_index " - " od.getdetailsof("",a_index) ": " append "`n":"",% file ".txt"
run,% file ".txt"
I'm sure that's slower, but doesn't that have a lot of it? It includes artist, length, composer, etc.

3nL8f.png


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks! this is the most complete info list so far. it also gives duration in hours, minutes, and seconds (hh:mm:ss).



garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

thank you wicked

result is sometime very different ,  maybe can time duration missing

( maybe that's because I used streamripper ... )

example ...\Taiwan_20130106.mp3

;--- result from mediainfo.dll ----------------------------------------------------

General
Complete name                            : C:\M_MUSIC\ASIA\TAIWAN\Taiwan_20130106.mp3
Format                                   : MPEG Audio
File size                                : 1.77 MiB
Duration                                 : 2mn 34s
Overall bit rate mode                    : Constant
Overall bit rate                         : 96.0 Kbps
Track name                               : ·R±¡
Track name/Position                      : 24
Performer                                : ¤ý¼ü¬Â
Encoded by                               : Ripped with Streamripper
------------
Audio
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Duration                                 : 2mn 34s
Bit rate mode                            : Constant
Bit rate                                 : 96.0 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 1.76 MiB (100%)
-----------------------------------------------------------------------------------


;-- result from script user wicked
;-- http://www.autohotkey.com/board/topic/13878-function-getmp3len/page-2

1 - Größe: 1'809 KB
2 - Typ: VLC media file (.mp3)
3 - Geändert am: 06.01.2013 21:09
4 - Erstellt am: 06.01.2013 21:07
5 - Letzter Zugriff am: 31.03.2013 12:10
6 - Attribute: A
7 - Status: Online
8 - Besitzer: LENOVOS10E\Garry
32 - Abtastgröße: 0 Bit



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

this is what i got:

 

1 - Size: 4,886 KB
2 - Type: MP3 Format Sound
3 - Date Modified: 12/19/2010 8:59 AM
4 - Date Created: 2/25/2011 3:50 PM
5 - Date Accessed: 3/31/2013 12:00 AM
6 - Attributes: A
7 - Status: Online
8 - Owner: Everyone
9 - Author: Michael Jackson
10 - Title: Rockin' Robin
12 - Category: Other
14 - Comments: MCNE Inc.
16 - Artist: Michael Jackson
17 - Album Title: The Ultimate Collection: Jacks
18 - Year: 1996
19 - Track Number: 12
20 - Genre: Other
21 - Duration: 0:02:33
22 - Bit Rate: 256kbps
23 - Protected: No
32 - Audio sample size: 0 bit
33 - Audio sample rate: 44 kHz
34 - Channels: 2 (stereo)



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

any way to get Duration directly from this (Wicked's) script in milliseconds without format (a simple digits string to be used in Sleep command)?



Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
I've been looking through MSDN and it doesn't appear so (without just multiplying the duration), Guest10. sad.png.

Edit: Strange. My Duration is 27, yet yours is 21.
o:=comobjcreate("Shell.Application")
fileselectfile,file,c:\
splitpath,file,file,directory
if errorlevel
	exitapp
od:=o.namespace(directory)
of:=od.parsename(file)
loop,286
	if(od.getdetailsof("",a_index)=="Duration"){
		length:=od.getdetailsof(of,27)
		break
	}
stringsplit,length,length,:
msgbox,% "Duration of " file " in millisceonds is " 3600000*length1+60000*length2+1000*length3 "."

3nL8f.png


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

I ran the script (Script I), but it returns blank unless line 27 is changed to line 21: "Duration of ... in millisceonds is ." Script II works correctly:

 

Script I

#SingleInstance, Force

SetWorkingDir, %A_ScriptDir%

o:=comobjcreate("Shell.Application")
fileselectfile,file,c:\
splitpath,file,file,directory
if errorlevel
	exitapp
od:=o.namespace(directory)
of:=od.parsename(file)
loop,286
	if(od.getdetailsof("",a_index)=="Duration"){
		;length:=od.getdetailsof(of,27)
                length:=od.getdetailsof(of,21)
		break
	}
stringsplit,length,length,:
msgbox,% "Duration of " file " in millisceonds is " 3600000*length1+60000*length2+1000*length3 "."

Script II

#SingleInstance, Force

SetWorkingDir, %A_ScriptDir%

o:=comobjcreate("Shell.Application")
fileselectfile,file,c:\
splitpath,file,file,directory
if errorlevel
	exitapp
od:=o.namespace(directory)
of:=od.parsename(file)
loop,50 ; modify ; 286
	fileappend,% (append:=od.getdetailsof(of,a_index))?a_index " - " od.getdetailsof("",a_index) ": " append "`n":"",% file ".txt"
;run,% file ".txt"

FileRead, Clipboard, % file ".txt"

FileDelete, % file ".txt"
Clipboard = 

data := Clipboard
RegExMatch(data, "Duration:\s*(\d+):(\d+):(\d+)", m)
MsgBox % m1*60*60*1000 + m2*60*1000 + m3*1000


Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
Oh! It was supposed to be:
o:=comobjcreate("Shell.Application")
fileselectfile,file,c:\
splitpath,file,file,directory
if errorlevel
	exitapp
od:=o.namespace(directory)
of:=od.parsename(file)
loop,286
	if(od.getdetailsof("",a_index)=="Duration"){
		length:=od.getdetailsof(of,a_index)
		break
	}
stringsplit,length,length,:
msgbox,% "Duration of " file " in millisceonds is " 3600000*length1+60000*length2+1000*length3 "."
Forgot to change to: length:=od.getdetailsof(of,a_index)

Edit: This method (requires playing the file, unfortunately) will return the duration in seconds (to 6 decimal places) which can then simply be multiplied by 1000 for milliseconds:
#persistent

fileselectfile,file,,c:\
if errorlevel
	exitapp

wmp:=comobjcreate("WMPlayer.OCX")
comobjconnect(wmp, "wmp_")
wmp.settings.autostart:=true
wmp.url:=file

wmp_openstatechange(event){
	global wmp
	if(event==13)
		msgbox,% "Duration String: " wmp.currentmedia.durationstring " -  Duration In Seconds: " wmp.currentmedia.duration
}
Documentation: http://msdn.microsof...esktop/dd563839

Cool thing about that though, you can get durations of audio/video files online. tongue.png. Just replace wmp.url:=file with a URL to the audio/video file.
Spoiler

3nL8f.png