Diana (Cda) Posted September 4, 2009 Share Posted September 4, 2009 (edited) I've come up with this and it works very well: expandcollapse popup; ; AutoIt 3x ; #include <_PartitionLetters.au3> ; this replaces drive letters #include<_WEReplacement.au3> ; references a Windows Explorer replacement program #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon("Shell32.dll", 153) ; changes the icon displayed in the systray AutoItSetOption("WinTitleMatchMode", 2) ; this allows partial window titles to be valid! ;------------------------------------------------------------------------------------------------------ ; 0. Preliminary cleanup; delete the bat file if below done before but it wasn't erased: $file2write = @ScriptDir & "\M3U file.bat" If FileExists($file2write) Then FileDelete($file2write) ;------------------------------------------------------------------------------------------------------ #cs @echo off del filelist.txt 2>nul if exist *.ini for /f "delims=" %%d in ('dir /b *.ini') do echo %%~fd>>filelist.txt for /f "delims=" %%d in ('dir /a:d/b') do if exist "%%~fd\*.ini" for /f "delims=" %%i in ('dir /b "%%~fd\*.ini"') do echo %%~fi>>filelist.txt #ce $M3Ufile = @ScriptDir & '\(02) - Stargate music.m3u' $TEXTtoDUMPintoBAT = '@echo off' & @CRLF & _ 'del ' & '"' & $M3Ufile & '" 2>nul' & @CRLF & _ 'if exist *.mp3 for /f "delims=" %%d in (''dir /b *.mp3'') do echo %%~fd>>' & '"' & $M3Ufile & '"' & @CRLF & _ 'for /f "delims=" %%d in (''dir /a:d/b'') do if exist "%%~fd\*.mp3" for /f "delims=" %%i in (''dir /b "%%~fd\*.mp3"'') do echo %%~fi>>' & '"' & $M3Ufile & '"' FileWrite($file2write, $TEXTtoDUMPintoBAT) ;------------------------------------------------------------------------------------------------------ ; 2. Launch it: If FileExists($file2write) Then ShellExecute($file2write) Sleep(5000) ;------------------------------------------------------------------------------------------------------ ; 3. Execute: ShellExecute($M3Ufile) #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon(@ScriptDir & "\(01) - Stargate music- create M3U.ico") If FileExists($file2write) Then FileDelete($file2write) Sleep(4500)But, of course, this isn't a completely AI solution. I've just finished searching and looking for an AI way and even tried out a filearray approach but kept getting errors. In the end, I've only kept my script above but was hoping someone knew how to do the FileWrite portion strictly in AI so that I can avoid using the "M3U file.bat" approach. Thanks! Edited September 4, 2009 by Diana (Cda) Link to comment Share on other sites More sharing options...
NEO12 Posted September 4, 2009 Share Posted September 4, 2009 (edited) i did a playlist creator to export a list of songs to M3U:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SliderConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <ProgressConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> #include <Constants.au3> #include <GuiListView.au3> #include <File.au3> #include <Timers.au3> #include <WinAPI.au3> #include <Array.au3> #include <Misc.au3> #include "Includes\GDIPlus.au3" #include "Includes\Recursive.au3" #include "Includes\ModernMenuFixed.au3" #include "Includes\ExtProp.au3" #include "Includes\GUIEnhance.au3" #include "Includes\GUICtrlSetOnHover_UDF.au3" Dim $updater_gui,$backbuffer,$backbuffer2,$szDrive, $szDir, $szFName, $szExt , $brush,$stop_btn,$fwd_btn,$ini_sleep,$bitmap,$graphics,$gui_artist_txt,$ar,$gui_title_txt,$ti,$gui_album_txt,$search_array_orig, $al,$aaaa,$ai_Handle,$ai_Return,$status_txt Opt("TrayMenuMode",1) $playlist_gui = GUICreate("Playlist Creator(*.m3u", 350, 407, -1, -1, $WS_SIZEBOX, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE)) GUISetBkColor(0x000000) _SetMenuBkColor(0x000000) _SetMenuIconBkColor(0x000000) _SetMenuTextColor(0xFFFFFF) _SetMenuSelectRectColor(0x555555) _SetMenuSelectTextColor(0xFFFFFF) $playlist = GUICtrlCreateListView("Artist|Title|Album|Location", 8, 38, 335, 341) GUICtrlSendMsg(-1, 0x101E, 0, 92) GUICtrlSendMsg(-1, 0x101E, 1, 92) GUICtrlSendMsg(-1, 0x101E, 2, 92) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM) GUICtrlSetOnEvent(-1, "pevent") ;Creating context menu $playlist_menu = GUICtrlCreateContextMenu($playlist) $pls_addfile = _GUICtrlCreateODMenuItem("Add file", $playlist_menu) $pls_addfolder = _GUICtrlCreateODMenuItem("Add folder", $playlist_menu) $pls_delentry = _GUICtrlCreateODMenuItem("delete entry", $playlist_menu) _GUICtrlCreateODMenuItem("", $playlist_menu) $pls_save = _GUICtrlCreateODMenuItem("Save playlist (*.pls)", $playlist_menu) $pls_load = _GUICtrlCreateODMenuItem("Load playlist (*.pls)", $playlist_menu) $pls_export = _GUICtrlCreateODMenuItem("Export Playlist to *.m3u", $playlist_menu) $pls_clear = _GUICtrlCreateODMenuItem("Clear playlist", $playlist_menu) $searchi = GUICtrlCreateInput("", 8, 8, 203, 21) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHEIGHT) $searchbtn = GUICtrlCreateButton("Search", 220, 7, 50, 24, 0) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH) $resetbtn = GUICtrlCreateButton("Reset", 270, 7, 75, 24, 0) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH) _GUICtrlListView_RegisterSortCallBack($playlist) pls_load() GUISetState(@SW_SHOW) $tabout = TrayCreateItem("About") TrayCreateItem("") $texit = TrayCreateItem("Exit") While 1 $msg = GUIGetMsg() $tmsg = TrayGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $pls_addfile pls_addfile() Case $msg = $pls_addfolder pls_addfolder() Case $msg = $pls_delentry pls_delentry() Case $msg = $pls_save pls_save() Case $msg = $pls_load pls_load() Case $msg = $pls_export pls_export() Case $msg = $pls_clear pls_clear() Case $msg = $searchbtn pls_search() Case $msg = $resetbtn pls_reset() Case $tmsg = $tabout _about() Case $tmsg = $texit _Exit() EndSelect WEnd ;===================== Playlist functions ==================== Func pls_addfile() $sFile = FileOpenDialog("Chosse audio file ", "", "Audio Files (*.mp3;*.mp2;*.mp1;*.wav;*.ogg;*.aiff)|MP3 (*.mp3)|MP2 (*.mp1)|MP3 (*.mp1)|WAV (*.wav)|OGG (*.ogg)AIFF (*.aiff)|") If FileExists($sFile) Then $path = $sFile If @OSVersion = "WIN_VISTA" Then $ar = _GetExtProperty($path, 13) $ti = _GetExtProperty($path, 21) $al = _GetExtProperty($path, 14) Else $ar = _GetExtProperty($path, 16) $ti = _GetExtProperty($path, 10) $al = _GetExtProperty($path, 17) EndIf $artist1 = $ar & "|" $title1 = $ti & "|" $album1 = $al & "|" GUICtrlCreateListViewItem($artist1 & $title1 & $album1 & $path, $playlist) GUICtrlSendMsg($playlist, 0x101E, 0, 92) GUICtrlSendMsg($playlist, 0x101E, 1, 92) GUICtrlSendMsg($playlist, 0x101E, 2, 92) GUICtrlSendMsg($playlist, 0x101E, 3, 92) EndIf EndFunc Func pls_addfolder() $pcdir = FileSelectFolder("Select Folder", "") If $pcdir <> "" Then $filesArray = RecursiveFileSearch($pcdir, "(?i)\.(mp3)") If Not IsArray($filesArray) Then TrayTip("", "Folder empty !", 2, 1) Else _GUICtrlListView_BeginUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_DISABLE) For $i = 1 To $filesArray[0] $path = $filesArray[$i] If @OSVersion = "WIN_VISTA" Then $ar = _GetExtProperty($path, 13) $ti = _GetExtProperty($path, 21) $al = _GetExtProperty($path, 14) Else $ar = _GetExtProperty($path, 16) $ti = _GetExtProperty($path, 10) $al = _GetExtProperty($path, 17) EndIf GUICtrlCreateListViewItem($ar & "|" & $ti & "|" & $al & "|" & $path, $playlist) Next _GUICtrlListView_EndUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_ENABLE) EndIf GUICtrlSendMsg($playlist, 0x101E, 0, 92) GUICtrlSendMsg($playlist, 0x101E, 1, 92) GUICtrlSendMsg($playlist, 0x101E, 2, 92) GUICtrlSendMsg($playlist, 0x101E, 3, 92) EndIf EndFunc Func pls_delentry() _GUICtrlListView_BeginUpdate($playlist) _GUICtrlListView_DeleteItemsSelected($playlist) _GUICtrlListView_EndUpdate($playlist) EndFunc Func pls_save() $pls_save_max = _GUICtrlListView_GetItemCount($playlist) $pls_loc = @ScriptDir & "\playlist.pls" If FileExists($pls_loc) = 0 Then _FileCreate($pls_loc) $pls_file = FileOpen($pls_loc, 2) ;~ GUICtrlSetState($playlist,$GUI_HIDE) ;~ GUICtrlSetState($searchbtn,$GUI_DISABLE) For $i = 0 To $pls_save_max FileWrite($pls_loc, _GUICtrlListView_GetItemTextString($playlist,$i) & @CRLF) Next FileClose($pls_file) ;~ GUICtrlSetState($playlist,$GUI_SHOW) ;~ GUICtrlSetState($searchbtn,$GUI_ENABLE) EndFunc Func pls_load() pls_clear() $pls_loc = @ScriptDir & "\playlist.pls" $pls_file = FileOpen($pls_loc, 0) $pls_load_max = _FileCountLines($pls_loc) - 1 ;~ GUICtrlSetState($playlist, $GUI_HIDE) _GUICtrlListView_BeginUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_DISABLE) For $i = 1 To $pls_load_max $pls_read = FileReadLine($pls_file, $i) GUICtrlCreateListViewItem($pls_read, $playlist) Next ;~ GUICtrlSetState($playlist, $GUI_SHOW) _GUICtrlListView_EndUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_ENABLE) GUICtrlSendMsg($playlist, 0x101E, 0, 92) GUICtrlSendMsg($playlist, 0x101E, 1, 92) GUICtrlSendMsg($playlist, 0x101E, 2, 92) GUICtrlSendMsg($playlist, 0x101E, 3, 92) _Optimize() EndFunc Func pls_clear() GUICtrlSetState($searchbtn,$GUI_DISABLE) _GUICtrlListView_BeginUpdate($playlist) _GUICtrlListView_DeleteAllItems($playlist) _GUICtrlListView_EndUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_ENABLE) EndFunc Func pls_search() GUICtrlSetState($searchbtn,$GUI_DISABLE) ;Create array with playlist contents Dim $search_array_orig[1],$search_array[1] For $i = 0 To _GUICtrlListView_GetItemCount($playlist) _ArrayAdd($search_array_orig, _GUICtrlListView_GetItemTextString($playlist, $i)) Next $search_string = GUICtrlRead($searchi) If @error = 1 Then Else $sa = _GUICtrlListView_FindInText($playlist, $search_string) $sa1 = _GUICtrlListView_GetItemTextString($playlist, $sa) _ArrayAdd($search_array, $sa1) If $sa = -1 Then MsgBox(32, "Playlist creator (*.m3u;*.pls)", "None file containing '" & $search_string & "' has been found !") pls_reset() Else $sa2 = True Dim $sb While $sb <> -1 If $sa2 = True Then $sb = _GUICtrlListView_FindInText($playlist, $search_string, $sa, FALSE) Else $sb = _GUICtrlListView_FindInText($playlist, $search_string, $sb, FALSE) EndIf $sb1 = _GUICtrlListView_GetItemTextString($playlist, $sb) _ArrayAdd($search_array, $sb1) $sa2 = False WEnd $search_array[0] = _ArrayMaxIndex($search_array) pls_clear() _GUICtrlListView_BeginUpdate($playlist) For $i = 1 To $search_array[0] GUICtrlCreateListViewItem($search_array[$i], $playlist) Next GUICtrlSendMsg($playlist, 0x101E, 0, 92) GUICtrlSendMsg($playlist, 0x101E, 1, 92) GUICtrlSendMsg($playlist, 0x101E, 2, 92) GUICtrlSendMsg($playlist, 0x101E, 3, 92) _GUICtrlListView_EndUpdate($playlist) EndIf EndIf EndFunc Func pls_reset() pls_clear() _GUICtrlListView_BeginUpdate($playlist) For $i = 1 To _ArrayMaxIndex($search_array_orig) GUICtrlCreateListViewItem($search_array_orig[$i],$playlist) Next _GUICtrlListView_EndUpdate($playlist) GUICtrlSetState($searchbtn,$GUI_ENABLE) EndFunc Func pls_export() $plsloc2 = FileSaveDialog(" Export playlist", "", "M3U (*.m3u)", "", ".m3u") If StringRight($plsloc2, 3) = "m3u" Then $plsloc3 = FileOpen($plsloc2, 2) $max3 = _GUICtrlListView_GetItemCount($playlist) - 1 FileWrite($plsloc3, "#EXTM3U" & @CRLF) For $i = 0 To $max3 $text = _GUICtrlListView_GetItemTextArray($playlist, $i) $atext = _PathSplit($text[4], $szDrive, $szDir, $szFName, $szExt) FileWrite($plsloc3, "#EXTINF:0," & $atext[3] & @CRLF) FileWrite($plsloc3, $text[4] & @CRLF) FileWrite($plsloc3, @CRLF & @CRLF) Next FileClose($plsloc3) EndIf EndFunc ;==>plsexport Func pevent() _GUICtrlListView_SortItems($playlist, GUICtrlGetState($playlist)) EndFunc ;==>pevent Func _Optimize($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_Optimize Func _about() MsgBox(64,"About","Playlist creator " & @CRLF & " Author: neo2606") EndFunc Func _Exit() Exit EndFunci've added a zip file so you can download all the needed includesPlaylist crea.zipEdit: to export or save playlist : right clic with mouse in the gui. S.B. Edited September 4, 2009 by NEO12 Link to comment Share on other sites More sharing options...
smashly Posted September 4, 2009 Share Posted September 4, 2009 (edited) Hi, just run the script from any folder that contains music.Global $NewM3U ; Create a new m3u if the directory contains music files $NewM3U = _FindMusic(@ScriptDir, "mp3|wma|mp4|wav") ; If the new m3u is created then ShellExecute it. If FileExists($NewM3U) Then ShellExecute($NewM3U) ; $sPath = directory to look for music ; $sFilter = The type of music to look for, if there's more then one format to look for use | as a delimiter. ; On succes the function will create a .m3u file with the same name as it's containing folder. ; on failure it returns nothing. Func _FindMusic($sPath, $sFilter = "mp3") Local $sHold = '', $hFind, $sFile, $sM3U, $FO If StringRight($sPath, 1) <> "\" Then $sPath &= "\" $hFind = FileFindFirstFile($sPath & "*") If $hFind = -1 Then Exit While 1 $sFile = FileFindNextFile($hFind) If @error Then ExitLoop If StringInStr(FileGetAttrib($sPath & $sFile), "D") Then ContinueLoop If StringRegExp($sFile, "(?i)\.(" & $sFilter & ")", 0) Then $sHold &= $sPath & $sFile & @CRLF WEnd FileClose($hFind) If $sHold <> "" Then $sM3U = StringTrimLeft(StringTrimRight($sPath, 1), StringInStr(StringTrimRight($sPath, 1), "\", 0, -1)) & ".m3u" $FO = FileOpen($sPath & $sM3U, 2) FileWrite($FO, StringStripWS($sHold, 2)) FileClose($FO) Return $sPath & $sM3U EndIf EndFunc Edit: Or if you want it to recurse directories you can use this version. (It's same as above but offers the option to do a recursive directory search)expandcollapse popup#NoTrayIcon Global $NewM3U ; Create a new m3u if the directory contains music files $NewM3U = _CreateM3U(@ScriptDir, "mp3|wma|mp4|wav", 1) ; If the new m3u is created then ShellExecute it. If FileExists($NewM3U) Then ShellExecute($NewM3U) ; $sPath = directory to look for music ; $sFilter = The type of music to look for, if there's more then one format to look for use | as a delimiter. ; $iRecurse = 0 to not recurse, 1 To recurse through all folders in the current directory. ; $iDepth = leave it alone.. it's for internal use of the function and should not be changed by the user... ; On succes the function will create a .m3u file with the same name as it's containing folder. ; on failure it returns nothing. Func _CreateM3U($sPath, $sFilter = "mp3", $iRecurse = 0, $iDepth = 0) Local $hFind, $sFile, $sM3U, $sRet, $hFO If Not $iDepth Then Global $sHold = '' If StringRight($sPath, 1) <> "\" Then $sPath &= "\" $hFind = FileFindFirstFile($sPath & "*") If $hFind = -1 Then Return While 1 $sFile = FileFindNextFile($hFind) If @error Then ExitLoop If StringInStr(FileGetAttrib($sPath & $sFile), "D") Then If $iRecurse Then _CreateM3U($sPath & $sFile, $sFilter, $iRecurse, $iDepth + 1) Else ContinueLoop EndIf EndIf If StringRegExp($sFile, "(?i)\.(" & $sFilter & ")", 0) Then $sHold &= $sPath & $sFile & @CRLF WEnd FileClose($hFind) If Not $iDepth And $sHold <> "" Then $sM3U = StringTrimLeft(StringTrimRight($sPath, 1), StringInStr(StringTrimRight($sPath, 1), "\", 0, -1)) & ".m3u" $sRet = StringStripWS($sHold, 2) $sHold = "" $hFO = FileOpen($sPath & $sM3U, 2) FileWrite($hFO, StringStripWS($sRet, 2)) FileClose($hFO) Return $sPath & $sM3U EndIf EndFunc Cheers Edited September 5, 2009 by smashly Link to comment Share on other sites More sharing options...
llewxam Posted September 5, 2009 Share Posted September 5, 2009 Might as well throw mine in... expandcollapse popupglobal $m3ucount,$mp3count $basedir="c:\mp3" $action="del" theheart($basedir) $action="m3u" theheart($basedir) $action="html" FileDelete($basedir&"\masmo.html") $html=FileOpen($basedir&"\masmo.html",1) FileWriteLine($html,"<body bgcolor=""black"" link=""14ff00"">"&@CRLF) theheart($basedir) FileClose($html) $action="count" theheart($basedir) msgbox(0,"M3Us Created:",$m3ucount) msgbox(0,"MP3s Found:",$mp3count) func theheart($basedir) $basesearch = fileFindFirstFile($basedir & "\*.*") if $basesearch==-1 then return 0 ; specified folder is empty! while @error<>1 $basefile = fileFindNextFile($basesearch) ; skip these if $basefile=="." or $basefile==".." or $basefile=="" then continueLoop endIf ; if it's a dir then call this function again (nesting the function is clever ;) if stringInStr(fileGetAttrib($basedir & "\" & $basefile), "D") > 0 then if $action="del" then FileDelete($basedir&"\"&$basefile&"\*.m3u") EndIf if $action="count" then $m3ucount+=1 EndIf if $action="html" then $formattedfile=""""&$basedir&"\"&$basefile&"""" $trim=StringRight($formattedfile,(stringlen($formattedfile)-8)) $slashpos=StringInStr($trim,"\") $folder=StringLeft($trim,$slashpos-1) FileWriteLine($html,"<br><br><center><font size=""+3""><a href="""&$basedir&"\"&$basefile&"\"&$basefile&".m3u"""&">"&$basefile&"</a></center></font><br>") EndIf theheart($basedir & "\" & $basefile) else ; Files we need to deal with if $action="m3u" Then $extension=StringLower(Stringright($basefile,4)) if $extension=".mp3" or $extension=".wma" Then $mp3count+=1 $formattedfile=""""&$basedir&"\"&$basefile&"""" $trim=StringRight($formattedfile,(stringlen($formattedfile)-8)) $slashpos=StringInStr($trim,"\") $folder=StringLeft($trim,$slashpos-1) $m3u=fileopen($basedir&"\"&$folder&".m3u",1) FileWriteLine($m3u,$basedir&"\"&$basefile) fileclose($m3u) EndIf EndIf if $action="html" Then $ext=StringRight($basefile,4) FileWriteLine($html,"<a href="""&$basedir&"\"&$basefile&""">"&StringTrimRight($basefile,4)&"</a><br>") EndIf EndIf wEnd fileClose($basesearch) return 1 endFunc Just change the $basedir to where your files are, it will: Delete any previous M3Us incase of name changes, added files, etc Make new M3Us for each folder Make an HTML page for easy access to the files, use search to find files within the browser. Folders/M3Us and individual files are links The only asssumption for the HTML page is no subdirs, it should still work fine but may look a bit odd.... But if you don't want that anyway then omit that part. Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now