Sign in to follow this  
Followers 0
buzonjl

program for compress music

1 post in this topic

#1 ·  Posted (edited)

hello boys, i made one program that use total video converter for compress music, the difference with other programs is that it make directory structure of source files, i.e. if you have one disc with very much directories and you dont like make compress file bye file and directory by directory, then this program work for you, in addition I made one interface litle beautifull and i put the funtion of drag and drop files and drag windows. je je i hope being util for anything. and for finish is necesary tell us that is necesary that yours have instaled total video converter.

this is my code:

#include <GUIConstants.au3>
#include <Constants.au3>

GUICreate("Music Resize v1.6",400,247,15,15,$WS_POPUPWINDOW+$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
GUISetBkColor (0xA55D98)

;~ Botones --------------------------------------------------------------------------

$addFiles=GUICtrlCreateButton("Agregar Archivos",300,35,95,25)
GUICtrlSetBkColor($addFiles,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)

$addDirectorys=GUICtrlCreateButton("Agregar Directorios",300,65,95,25)
GUICtrlSetBkColor(-1,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)

$resize=GUICtrlCreateButton("Comprimir",300,120,95,20)
GUICtrlSetBkColor(-1,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)

$cleanBuffer=GUICtrlCreateButton("Limpiar Lista",300,95,95,20)
GUICtrlSetBkColor(-1,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)

$minimize=GUICtrlCreateButton("~",370,0,16,16)
;~ GUICtrlSetOnEvent($minimize,"minimize")
GUICtrlSetBkColor(-1,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)

$close=GUICtrlCreateButton("X",385,0,16,16)
;~ GUICtrlSetOnEvent($close,"close")
GUICtrlSetBkColor(-1,0xD6D7DA)
GUICtrlSetColor(-1,0x000000)


;~ Objetos----------------------------------------------------------------------------------------------

Global $progressBar = GUICtrlCreateProgress (10,45,285,20)
Global $progressBarTotal= GUICtrlCreateProgress(10,35,285,10)

$edit = GUICtrlCreateEdit("", 10, 70, 285, 150,$WS_VSCROLL+$ES_READONLY )
GUICtrlSetState(-1, $GUI_DROPACCEPTED)   

Global $label=GUICtrlCreateLabel("Status: I not make nothing",15,16,380,20)
GUICtrlSetColor(-1,0xffffff)
GUICtrlSetFont (-1,9, 800)

$barTitle=GUICtrlCreateLabel("Music Resize v1.6 by JL",235,0,130,15)
GUICtrlSetColor(-1,0xffffff)
GUICtrlSetFont (-1,9, 400)

;~ variables------------------------------------------------------------------------------------------- 
    
Dim $array[1000]
Dim $buffer[1000]
$x=1 
$allBuffer=""
Global $msg


;~ GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "MousePressWindow")
;~ GUISetOnEvent($GUI_EVENT_PRIMARYUP,"MouseReleaseWindow")


GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $resize
            resizeButton()
            
        Case $msg=$cleanBuffer
                $allBuffer=0
                GUICtrlSetData($edit,"")
                
        Case $msg = $addDirectorys
            addDirectorys()
            
        Case $msg=$addFiles
            addFiles()
            
        Case $msg = $GUI_EVENT_DROPPED
            dropped()
        
        Case $msg = $minimize
            GUISetState(@SW_MINIMIZE)
            
        Case $msg = $close
            Exit
            
        Case $msg=$GUI_EVENT_SECONDARYDOWN
            
            MousePressWindow()
                
        Case Else
            
    EndSelect
    
WEnd


Func resize($allBuffer,$pathSave)

    Local $countsBar=StringInStr($allBuffer,"\",0,1)
    Local $leng=StringLen($allBuffer)
    Local $pathWithoutDrive=StringRight($allBuffer,$leng-$countsBar)
    Local $pathDestination=$pathSave&"\"&$pathWithoutDrive

    Local $n
    
    For $n=1 to 30
        $countsBar=StringInStr($pathDestination,"\",0,$n)
        If $countsBar=0  Then ExitLoop
    Next
    $countsBar=StringInStr($pathDestination,"\",0,$n-1)
    $leng=StringLen($pathDestination)
    Local $nameFile=StringRight($pathDestination,$leng-$countsBar)

    For $n=1 to 30
        $countsBar=StringInStr($pathDestination,"\",0,$n)
        If $countsBar=0  Then ExitLoop
    Next
    $countsBar=StringInStr($pathDestination,"\",0,$n-1)
    Local $path=StringLeft($pathDestination,$countsBar)

    DirCreate($path)
    
    $pathDestination=StringLeft($pathDestination,$leng-4)
    $pathDestination=$pathDestination&".mp3"
;~  test($pathDestination)

    

    Run("C:\Program Files\Total Video Converter\tvc.exe" & " /f "& $allBuffer & " /o "& $pathDestination &" /pi ini\mp3.ini /pn 64kbps","",@SW_HIDE)

    Local $i=0
    Local $msg
    
    While 1
        $msg=GUIGetMsg()
        If $msg=$close Then 
            ProcessClose("tvc.exe")
            Exit
        EndIf
        If $msg=$minimize then GuiSetState(@SW_MINIMIZE)
        If $msg=$GUI_EVENT_SECONDARYDOWN then MousePressWindow()
        
        GUICtrlSetData ($progressBar,$i)
        
        If NOT ProcessExists("tvc.exe") Then ExitLoop
        $i=$i+0.025
    WEnd

    Return 0
    
EndFunc

Func processBuffer($pathSave=0,$allBuffer=0)
    
    $allBuffer=StringSplit($allBuffer,@CRLF,1)

                Dim $directorys[2]
                Dim $files[2]

                Local $d=1
                Local $f=1
                Local $attrib
                
                For $i=1 to $allBuffer[0]-1
                    $attrib = FileGetAttrib($allBuffer[$i])

                    IF $attrib="D" Then 

                        $directorys[$d]='"'&$allBuffer[$i]&'"'
                        ReDim $directorys[UBound($directorys)+1]
                        $d=$d+1
                    Else
                        $files[$f]=$allBuffer[$i]
                        ReDim $files[UBound($files)+1]
                        $f=$f+1
                    EndIf
                Next
                
                Local $filesOnDirectory=""
                Local $foo
                Local $line
                                                
                For $i=1 To $d-1
                    $foo=Run(@ComSpec & " /c dir /B /S "& $directorys[$i],"","", $STDERR_CHILD + $STDOUT_CHILD)
                    While 1
                        $line = StdoutRead($foo)
                        If @error Then ExitLoop
                        $filesOnDirectory= $filesOnDirectory&$line 
                    Wend
                Next    
                                                            
                $filesOnDirectory=StringSplit($filesOnDirectory,@CRLF,1)

                Local $k=1
                
                ReDim $files[UBound($files)+$filesOnDirectory[0]]

                For $i=$f+1 to UBound($files)-1
                    $attrib=FileGetAttrib($filesOnDirectory[$k])

                    If $attrib="A" Then
                        $files[$i]=$filesOnDirectory[$k]
                    EndIf
                    $k=$k+1
                Next

                Local $j=0

                For $i=0 to UBound($files)-1
                    If Not $files[$i]="" Then
            
                        $files[$j]=$files[$i]
                        $j=$j+1
                    EndIf
                Next
                
                ReDim $files[$j]

                $k=1
                Dim $returnFiles[$k]
                Local $leng
                Local $findText
                Local $fileExtension
                
                For $i=0 to UBound($files)-1
                    For $n=1 to 30
                        $findText=StringInStr($files[$i],".",0,$n)
                        If $findText=0  Then ExitLoop
                    Next
                    $findText=StringInStr($files[$i],".",0,$n-1)
                    $leng=StringLen($files[$i])

                    $fileExtension=StringRight($files[$i],$leng-$findText)
;~                  test($fileExtension)
                    

                    
                    If $fileExtension="mp3" OR $fileExtension="wma" OR $fileExtension="wav" OR $fileExtension="mpg" OR $fileExtension="avi" OR $fileExtension="vob" Then
                        
                        $returnFiles[$k-1]=$files[$i]
                        ReDim $returnFiles[$k+1]
                        $k=$k+1
                    EndIf
                                    
                Next
            
                ReDim $returnFiles[$k-1]
                Return $returnFiles
                            
EndFunc

Func showArray($array=0,$info="")
    
    For $i=0 to UBound($array)-1
        MsgBox(0,$info,$array[$i])
    Next
    
EndFunc

Func getName($allBuffer)
    For $i=0 to 30
        $findCharacter=StringInStr($allBuffer,"\",0,$i)
        If $findCharacter=0 Then ExitLoop
    Next
    
    $findCharacter=StringInStr($allBuffer,"\",0,$i-1)
    
    $name=StringRight($allBuffer,StringLen($allBuffer)-$findCharacter)
;~  MsgBox(0,"",$name)
    return $name
EndFunc

Func progresBarTotal($z,$howMany)
    Local $percent=($z*100)/$howMany
    GUICtrlSetData($progressBarTotal,$percent)
    
EndFunc
    
Func MousePressWindow()
;~      Sleep(5000)
        $registerEvents=0

            Global $mousePos=MouseGetPos()
            Global $WinPos=WinGetPos("Music")
            Global $mWx=$mousePos[0]-$WinPos[0]
            Global $mWy=$mousePos[1]-$WinPos[1]
            
        If $MousePos[0]>$WinPos[0]+300 And $MousePos[0]<$WinPos[0]+400 And $MousePos[1]>$WinPos[1]+35 And $MousePos[1]<$WinPos[1]+140 Then
            $registerEvents=1
        EndIf
        
        If $MousePos[0]>$WinPos[0]+370 And $MousePos[0]<$WinPos[0]+400 And $MousePos[1]>$WinPos[1] And $MousePos[1]<$WinPos[1]+18 Then
            $registerEvents=1
        EndIf
        
        
;~      test()
        IF $registerEvents = 0 then
            While 1
                $msg = GUIGetMsg()
;~              MsgBox(0,"",$msg)
                $mousePos=MouseGetPos() 
                WinMove("Music","",$mousePos[0]-$mWx,$mousePos[1]-$mWy)
;~              If $registerEvents=1 then ExitLoop
                IF $msg=$GUI_EVENT_SECONDARYUP then
                    $registerEvents = 1
                    ExitLoop
                EndIf
                
            Wend
        EndIf
EndFunc

func test($var)
    MsgBox(32,"Prueba de continuidad",$var)
EndFunc

Func dropped()
    $lecture=GUICtrlRead($edit)
    IF Not $allBuffer="" Then
        $lecture=StringReplace($lecture,$allBuffer,"",1)
    EndIf           

    $array=StringSplit($lecture,@CRLF,1)
            
    $i=0
    While 1
        $i=$i+1
        IF $array[$i]="" THEN ExitLoop
        $allBuffer=$array[$i] & @CRLF & $allBuffer
        GUICtrlSetData($edit,"")
        GUICtrlSetData($edit,$allBuffer)
    WEnd
EndFunc

Func addFiles()
    $toBuffer=FileOpenDialog("Agregar Archivos",@DesktopCommonDir,"Archivos de Audio (*.mp3;*.wma;*.cda;*.wav)",4)
    $toBuffer=StringSplit($toBuffer,"|")
        
    If $toBuffer[0]=1 Then 
        $allBuffer=$toBuffer[1] & @CRLF & $allBuffer
        GUICtrlSetData($edit,"")
        GUICtrlSetData($edit,$allBuffer)
    Else
    For $i=2 to $toBuffer[0] 
        $toBuffer[$i]=$toBuffer[1]&"\"&$toBuffer[$i]
        $allBuffer=$toBuffer[$i] & @CRLF & $allBuffer
                    
        GUICtrlSetData($edit,"")
        GUICtrlSetData($edit,$allBuffer)
    Next
    EndIf
EndFunc

Func addDirectorys()
    $toBuffer=FileSelectFolder("Agregar Directorios",@DesktopCommonDir,2)
    $allBuffer=$toBuffer & @CRLF & $allBuffer
    GUICtrlSetData($edit,"")
    GUICtrlSetData($edit,$allBuffer)
EndFunc
        
Func resizeButton()
    
    If Not $allBuffer="" Then   
        $pathSave=FileSelectFolder("Agregar Directorios",@DesktopCommonDir,3) 
        $allBuffer=processBuffer($pathSave,$allBuffer)

        Global $howMany=UBound($allBuffer)
        Global $z=0
        For $z=0 to Ubound($allBuffer)-1

            $name=getName($allBuffer[$z])
            $status="Status: I am working on file "& $name & " Please wait..." 
            progresBarTotal($z+1,$howMany)
            GUICtrlSetData($label,$status)
            resize($allBuffer[$z],$pathSave)
            
            If $z=Ubound($allBuffer)-1 then GUICtrlSetData($label,"Status: Finiiiiiiiish")
            If $z=Ubound($allBuffer)-1 then progresBarTotal(0,$howMany)
        next
    Else
        MsgBox(0,"Corregir","no hay canciones que comprimir")
    EndIf
EndFunc
Edited by buzonjl
Added CODE tags and zapped duplicate :)

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0