Jump to content
cyanidemonkey

FFMPEG batch conversion automator

Recommended Posts

cyanidemonkey

This is a small app I wrote awhile back to batch FFMPEG commands of videos. I have a camcorder that saves to a file type .mts and I wanted to convert them to .mp4 but was too lazy to write out the commands one at a time in the CMD window.

 

ffmpegautomator.gif

NOTES:

  • You will need to download ffmpeg, as it is the application doing the actual conversions (http://ffmpeg.org/).
  • It can only do one directory at a time, it will not do recursive directories.
  • The defaults are set up to convert .mts files to .mp4, if you want to change the input, output and command line options you can, however, you may need to read the documentation at the ffmpeg website.
  • If you want to change the input file type, do this before opening the input browse button.
  • The software will steal focus to communicate with the command line interface, It is best to set up a conversion job and leave the computer alone until it is done (hence the option to shutdown after converting files). If you try to use the computer while it is running chances are it will fail to convert one or more videos. Video processing can be PCU intensive, this application was designed to be set and forget.
  • If you don't want to scale down to 720p remove " -s 1280x720 " from command line, remove " -r 30 " if you don't want the frame rate set to 30fps, if you do not require deinterlacing remove " - vf yadif=1 " from the command line options.
  • You can choose to delete the original video files after they are converted to save disc space, but it pays to test one file first to make sure they convert correctly before batch deleting the original files (they are sent to the recycle bin, so you can restore them until you empty the recycle bin).

 

AutoIt Code:

; Build by Marc Rosewarne 2012
; Works with ffmpeg to automate commandline inputs and converts all files in a selected folder.
;--------------------------------- REQUIRED INCLUDES & GLOBAL VARS -------------------------------------;
Opt("WinTitleMatchMode", 3)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>

;----------------------------------------------- MAIN GUI ---------------------------------------------------;
$mainWin = GuiCreate("ffmpeg batch convertion automator", 650, 400)
;VID FILES LOCATION
    GuiCtrlCreateGroup("Input Video File Type and Location", 15, 15, 620, 180)
        $vidFileType = GuiCtrlCreateInput(".mts", 25, 35, 30, 20)
        $vidSourceDir = GuiCtrlCreateInput("Set Input File(s) Location", 60, 35, 500, 20)
        $vidSetSourceDir = GuiCtrlCreateButton("Browse", 565, 34, 60, 22)
        $vidSourceList = GuiCtrlCreateEdit("Video Files: ", 25, 65, 600, 105)
        $vidSourceNum = GUICtrlCreateLabel("Files Found: 0", 25, 173, 110, 15)
        $vidFilesConverted = GUICtrlCreateLabel("Files Converted: 0", 260, 173, 110, 15)
        $vidFilesDeleted = GUICtrlCreateLabel("Files Deleted: 0", 500, 173, 110, 15)
    GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group
; CONVERTION OPTIONS
    GuiCtrlCreateGroup(" ffmpeg.exe Location and Commands ", 15, 200, 620, 100)
        $ffmpegExeLocation = GuiCtrlCreateInput("Set ffmpeg.exe Location", 25, 218, 535, 20)
        $ffmpegBrowseBtn = GuiCtrlCreateButton("Browse", 565, 217, 60, 22)
        GUICtrlCreateLabel("Set ffmpeg commandline: ", 25, 250, 160, 15)
        GUICtrlCreateLabel(" ffmpeg -i [input] ", 25, 270, 80, 15)
        $ffmpegCommand = GuiCtrlCreateInput("-vf yadif=1 -s 1280x720 -r 30 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k", 105, 268, 450, 20)
        GUICtrlCreateLabel("[output].", 560, 270, 40, 15)
        $convertedFileType = GuiCtrlCreateInput("mp4", 600, 268, 30, 20)
    GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group
; EXTRA OPTIONS
    GuiCtrlCreateGroup(" Post Convertion Options ", 15, 310, 620, 40)
        $deleteInput = GUICtrlCreateCheckbox( "Delete original video files", 25, 325)
        GUICtrlCreateLabel("Computer:", 360, 327, 80, 15)
        $o1 = GuiCtrlCreateRadio("Reboot", 420, 323, 50)
        $o2 = GuiCtrlCreateRadio("Shutdown", 485, 323, 65)
        $o3 = GuiCtrlCreateRadio("Nothing", 560, 323, 60)
        GuiCtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

; GO! BUTTON
    $startVidExport = GUICtrlCreateButton(">>> Convert Video Files >>>", 15, 363, 620, 22)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $proggy = GuiCtrlCreateProgress(15, 363, 620, 22)
    GUICtrlSetState($proggy, $GUI_HIDE)
GUISetState(@SW_SHOW)

;---------------------------------------------- FUNCTIONS -------------------------------------------------------;
Func vidSourceDir()
;---SET SOURCE FILE LOCATION
    $message = "Select folder/drive location to find " & StringUpper(StringTrimLeft(GUICtrlRead($vidFileType), 1)) & " files."
    $var = FileSelectFolder($message, "")
    If @error Then
        MsgBox(4096,"","No Folder Selected!")
        Return
    Else
        GUICtrlSetData($vidSourceDir, $var)
        GUICtrlSetData($vidSourceList, GUICtrlRead($vidSourceList) & @CRLF & " > Analysing directory structure - please wait...")
    EndIf
;---ERROR CHK REQUIRED FIELDS B4 MOVING ON
    If GUICtrlRead($vidSourceDir) = "" OR GUICtrlRead($vidSourceDir) = "Set Input File(s) Location" Then
        MsgBox(64, "User Error", "No Source Location Set." & @LF & "Requested action will now terminate.")
        Return
    Else
        If NOT FileExists(GUICtrlRead($vidSourceDir)) Then
            MsgBox(64, "User Error", "The Source Location Does Not Exsist." & @LF & "Requested action will now terminate.")
            Return
        EndIf
    EndIf
;---SEARCH FOR FILES IN SELECTED DIRECTORY
    $fileTotal = DirGetSize( $var,1)
    Global $fileCount = 0
    Global $vidSourceFiles[$fileTotal[1]][2]
    $search = FileFindFirstFile(GUICtrlRead($vidSourceDir) & "\*" & GUICtrlRead($vidFileType))
    $var = GUICtrlRead($vidSourceDir)
    GUICtrlSetData($vidSourceList , StringUpper(StringTrimLeft(GUICtrlRead($vidFileType), 1)) & " Files: ")
    findvidFiles($search, $var)
    If $fileCount <> 0 Then
        ReDim $vidSourceFiles[$fileCount][2]
    EndIf
    FileClose($search)
    If $fileCount <> 0 Then
        GUICtrlSetState($startVidExport, $GUI_ENABLE)
    EndIf
EndFunc

Func ffmpegExeLoc()
;---SET FFMPEG.exe LOCATION
    $message2 = "Select ffmpeg.exe location."
    $var2 = FileOpenDialog($message2, @ProgramFilesDir & "\", "(ffmpeg.exe)")
    If @error Then
        MsgBox(4096,"","No Folder Selected!")
        Return
    Else
        GUICtrlSetData($ffmpegExeLocation, $var2)
    EndIf
;---ERROR CHK REQUIRED FIELDS B4 MOVING ON
    If GUICtrlRead($ffmpegExeLocation) = "" OR GUICtrlRead($ffmpegExeLocation) = "Set ffmpeg.exe Location" Then
        MsgBox(64, "User Error", "No FFMPEG.exe Set." & @LF & "Requested action will now terminate.")
        Return
    Else
        If NOT FileExists(GUICtrlRead($ffmpegExeLocation)) Then
            MsgBox(64, "User Error", "The FFMPEG.exe Location Does Not Exsist." & @LF & "Requested action will now terminate.")
            Return
        EndIf
    EndIf
EndFunc

Func findvidFiles($search, $var)
;---FIND FILES & ADD TO ARRAY CALLED BY vidSourceDir()
    While (True)
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        EndIf
        $vidSourceFiles[$fileCount][0] = $file
        $vidSourceFiles[$fileCount][1] = $var
        GUICtrlSetData($vidSourceNum , "Files Found: " & $fileCount+1)
        GUICtrlSetData($vidSourceList , GUICtrlRead($vidSourceList) & @CRLF & " > Video File Found: " & $var & "\" & $file)
        $fileCount += 1
    WEnd
EndFunc

Func batchFFMPEGConverts()
;---ERROR CHK REQUIRED FIELDS B4 MOVING ON
    If GUICtrlRead($ffmpegExeLocation) = "" OR GUICtrlRead($ffmpegExeLocation) = "Set ffmpeg.exe Location" Then
        MsgBox(64, "User Error", "No FFMPEG.exe Set." & @LF & "Requested action will now terminate.")
        Return
    Else
        If NOT FileExists(GUICtrlRead($ffmpegExeLocation)) Then
            MsgBox(64, "User Error", "The FFMPEG.exe Location Does Not Exsist." & @LF & "Requested action will now terminate.")
            Return
        EndIf
    EndIf
    GUICtrlSetState($startVidExport, $GUI_DISABLE)
    GUICtrlSetState($startVidExport, $GUI_HIDE)
    GUICtrlSetState($proggy, $GUI_SHOW)
    Global $xmlFile
    Global $count = 100/$fileCount

    If NOT WinExists("C:\Windows\system32\cmd.exe") Then
        Run("C:\Windows\system32\cmd.exe", "", @SW_MAXIMIZE)
    EndIf
    WinActivate("C:\Windows\system32\cmd.exe")
    WinWaitActive("C:\Windows\system32\cmd.exe")
    ;create _converted directory
    DirCreate(GUICtrlRead($vidSourceDir) & "\_converted")

;---LOOP THROUGH VIDEO FILES AND SEND FFMPEG COMMAND TO CONVERT IT.
    FOR $i = 0 to UBound($vidSourceFiles)-1
        $file = $vidSourceFiles[$i][0]
        $source = $vidSourceFiles[$i][1]
        $xmlFile = $source & "\" & $file
        ;write out ffmpeg commandline here
        WinActivate("C:\Windows\system32\cmd.exe")
        WinWaitActive("C:\Windows\system32\cmd.exe")
        Send(GUICtrlRead($ffmpegExeLocation) & " -i """ & $xmlFile & """ " & GUICtrlRead($ffmpegCommand) & " """ & $source & "\_converted\" & StringTrimRight($file, 3) & GUICtrlRead($convertedFileType) & """{ENTER}")
        ;update progress bar
        If $count*($i+1) = 100 Then
            GUICtrlSetData($proggy, 99)
        Else
            GUICtrlSetData($proggy, ($count*($i+1)))
        EndIf
        WinWait("C:\Windows\system32\cmd.exe")
        ;change converted number.
        GUICtrlSetData($vidFilesConverted, "Files Converted: " & $i+1)
    NEXT
    GUICtrlSetData($proggy, 100)
    WinClose("C:\Windows\system32\cmd.exe")
    ;delete original video files
    If GUICtrlRead($deleteInput) = 1 Then
        $msg = MsgBox(65, "Delete Original Video Files", "'Delete original video files after convertion' has been selected. This will happen in 10 seconds. Click 'Cancel' to cancel file deletion. (Files will be moved to recycle bin, they can be restored from there untill you empty the recycle bin.)", 10)
        If $msg <> 2 Then
            FOR $i = 0 to UBound($vidSourceFiles)-1
                $vidFile = $vidSourceFiles[$i][1] & "\" & $vidSourceFiles[$i][0]
                ; if file exsist, delete it
                If FileExists($vidFile) Then
                    FileRecycle($vidFile)
                EndIf
                ;change deleted number.
                GUICtrlSetData($vidFilesDeleted, "Files Deleted: " & $i+1)
                GUICtrlSetData($proggy, (100-$count*($i+1)))
            NEXT
        EndIf
    EndIf
    ;shutdown/reboot
    If GUICtrlRead($o1) = 1 Then
        $msg = MsgBox(65, "Automated Reboot", "Computer will reboot in 10 seconds. Click 'Cancel' to cancel reboot.", 10)
        If $msg <> 2 Then
            Shutdown(6)
            Exit
        EndIf
    EndIf
    If GUICtrlRead($o2) = 1 Then
        $msg = MsgBox(65, "Automated Shutdown", "Computer will shutdown in 10 seconds. Click 'Cancel' to cancel shutdown.", 10)
        If $msg <> 2 Then
            Shutdown(5)
            Exit
        EndIf
    EndIf
    GUICtrlSetState($proggy, $GUI_HIDE)
    GUICtrlSetData($proggy, 0)
    GUICtrlSetState($startVidExport, $GUI_SHOW)
    GUICtrlSetState($startVidExport, $GUI_ENABLE)
 EndFunc


;------------------------------------------------ LOOP -------------------------------------------------------;
While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $vidSetSourceDir
            vidSourceDir()
        Case $msg[0] = $startVidExport
            batchFFMPEGConverts()
        Case $msg[0] = $ffmpegBrowseBtn
            ffmpegExeLoc()
        Case $msg[0] = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Hopefully someone may find it usefull? Enjoy.


My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites
legs88

Is it possible to capture the metadata of the mts file and transfer it to the new encoded mp4 file via this same script?

Share this post


Link to post
Share on other sites
GODLYDEVILS

How do I download this app?

I don't know programming, can you help me?

Share this post


Link to post
Share on other sites
JLogan3o13

@GODLYDEVILS this isn't an app, it is code that you would compile into an executable. If you do not have any experience in this, you might want to start more slowly - download AutoIt and install, and start learning how the language works.


√-1 2^3 ∑ π, and it was delicious!

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

  • Similar Content

    • TheSaint
      By TheSaint
      Here is a simple program that some of you might appreciate.
      It is a more full fleshed out version of something I worked on a while back as a proof of concept.
      I will just quote the information found in the Program Information dialog.

      INItoSQL DB.zip
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      I have also included the beginnings of a new UDF (SimpleSQL_UDF) I am working, which you can use with the included 'Check conversion.au3' file to check a resulting conversion ... just modify the values for a few variables to suit your situation.
    • UEZ
      By UEZ
      AutoIt Windows Screenshooter
      Key Features:
      takes easily a screenshot from any visible window capture any region of the desktop incl. freehand capturing capture GUI controls and GUI menus separately capture a marked area every x seconds for a duration of y seconds create a GIF animation from saved frames (Vista or higher os required) capture to AVI file (without audio!) takes a screenshot from web sites (available only on Win7+ os and when Aero is enabled) put images to clipboard to paste to other applications easily color picker save image in different formats and also to PDF! add timestamp to saved images simple image editing options: greyscale, b&w, invert, rotate +-90° send image to printer and default email client preview of captured screens incl. zoom option multi monitor support display pixel color under mouse ruler basic image editor (paint, highlight, ellipse, rectangle, text and some graphic FX) watermark captured image no 3rd party tools or DLLs used - pure AutoIt! fully portable - no installation is needed multi language feature (Eng, Ger, Tur, Fra and Rus only) To do:
      capture content of scrollable window/control capture cascaded menus Due to DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) limitation some windows cannot be captured properly (GDI+, ProgDVB, etc.) but can take screenshots of hidden windows. One workaround is to use full screen capturing (F11/F12) or "Grab Screen" function! Or try double click with rmb on listview items (beta).
      Download source code (6295 downloads previously):  AutoIt Windows Screenshooter v1.81 Build 2018-08-12.7z (version 3.3.12.0+ needed!)
      You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Download compiled Exe only: 4shared / Media Fire / Softpedia (1.54mb)
      Distributing copies of the program in compiled format (exe) must be free of any fee!
      -----> click here to Donate!  
       
      (Current donators: 1. Cuong N.) 
      It is designed for Win7+ operating systems with AERO enabled! E.g. on WinXP machines some functions are not working properly and might crash the application!
      AV scanners may have a negative impact the execution of compiled exe and might report any malware. I guarantee that there is no malicious code in the source code / exe!!! 
      Main GUI:

       
       
      About Intro:

       
       
      Basic Image Editor:

       
       
      Watermark:

       
       
      Click link for an enhanced version of Watermark Image.
      Credits:
      main code by UEZ additional code (alphabetical order) by Authenticity, AutoItObject Team, Eemuli, Eukalyptus, funkey, _Kurt, martin, monoceres, ProgAndy, taietel, trancexx, Ward, wolf9228 and Yashied! mesale0077 for turkish translation wakillon for french translation AZJIO for russian translation Keys:
      Main GUI:
      User your mouse to scroll preview window or
      Numpad 8: Scroll preview window up
      Numpad 2: Scroll preview window down
      Numpad 4: Scroll preview window left
      Numpad 6: Scroll preview window right
      Numpad +: zoom in preview window or mousewheel down
      Numpad -: zoom out preview window or mousewheel up
      F1: capture again on last position
      F5: refresh Windows Name list
      PRINTSCREEN: take screenshot from whole screen
      ALT+PRINTSCR: take a screenshot from active window
      F10: Undo made changes with Image Editing function
      F11: take screenshot from whole screen incl mouse cursor
      F12: take screenshot from whole screen
      Ctrl+Alt+F9 start "Grab Screen" mode
      Ctrl+Alt+F12: take a screenshot from active window using alternative screenshot functionality (beta)!
      Ctrl+r: call ruler
      Ctrl+s: save current displayed image
      Ctrl+x: exit program
      ctrl+w: call web grab input field (availabe only when Aero is enabled)
      Ctrl+i: call image editor
      Ctrl+m: call watermark editor
      Ctrl+z: undo
      Only available on Vista+ os: double click with rmb on list items to use alternative screenshot functionality (beta)!
      When 'Grab Screen' is clicked you can hold down the ctrl key to switch to 'grab controls' mode. Control under mouse will be framed red.
      ctrl + shift will take the screenshot of appropriate control. To capture GUI menues you can press rmb which simulates the lmb. When a menu is opened press shift additionaly to capture it.
      Press and hold only the shift key to capture any region on the desktop using freehand capturing - release it so capture marked regions!
      Or just mark resizeable area which you want to grab. Press CTRL key to grab marked area or right mouse button to capture the marked area every x seconds for a duration of y seconds.
      When saving the image just enter the extension you whish to use (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf). Big thanks to taietel for his PDF UDF!
      Image Editor:
      s: save
      c: copy
      n: send
      h: highlighter
      p: pen
      r: rectangle
      e: ellipse
      a: arrow
      o: color
      t: text
      g: text config
      Ctrl+z: undo
      Watermark editor:
      Ctrl+z: undo
       
      To start the app minimized just call it "Windows Screenshooter.exe /min"
      Maybe it is useful for someone...
      Any kind of comment is welcome.
      Br,
      UEZ
      Change log:
       
    • CYCho
      By CYCho
       
      #include <GUIConstants.au3>
      #include <WindowsConstants.au3>

      Local $oPlayer, $gVideo, $width, $height
      $oPlayer = ObjCreate("WMPlayer.OCX.7")
      $oPlayer.URL = 'http://www.clubbalcony.com/upload/culture/yong(2).wmv'
      Local $srcFound = True
      Local $time1 = TimerInit()
      While 1
          If $oPlayer.playState() = 3 Then
              $width = $oPlayer.currentMedia.imageSourceWidth
              $height = $oPlayer.currentMedia.imageSourceHeight
              ExitLoop
          EndIf
          If TimerDiff($time1) > 5000 Then
              $srcFound = False
              ExitLoop
          EndIf
          Sleep(50)
      WEnd
      If Not $srcFound Or $width = 0 Then
          $oPlayer.Close()
          Exit
      Else
          $gVideo = GUICreate("Video Control", $width, $height+63, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX), $WS_EX_TOPMOST)
          GUICtrlCreateObj($oPlayer, 0, 0, $width, $height+63)
          $oPlayer.uiMode = "Full"
          $oPlayer.stretchToFit = True
          GUISetState(@SW_SHOW, $gVideo)
      EndIf

      While 1
          $Msg = GUIGetMsg(1)
          Switch $Msg[0]
              Case $GUI_EVENT_CLOSE
                  ExitLoop
              Case $GUI_EVENT_RESIZED
                  ;This is where I want to resize the video image to fit the new window size
          EndSwitch
      WEnd
      $oPlayer.Close()
         
      How should I code the $GUI_EVENT_RESIZED portion to resize the video to fit the resized window? Your help will be greatly appreciated.

       
    • BigDaddyO
      By BigDaddyO
      After much searching I finally found a method to get eMails from an Exchange eMail account inbox.  I was hoping for AutoIT or vbscript but I couldn't find any that would read the inbox messages without using Outlook.
      I needed this because I'm testing a web-form that generates an eMail sent to a shared mailbox "not what my current outlook is configured for".  so, I needed to connect to a different account, then get the inbox messages, and see if the auto-generated eMail message body contains what I submitted in the form.
       
      I found a PowerShell script that was close and modified it to do just what I want, but I'd still like it to run in AutoIT but I'm not sure how to use the Microsoft.Exchange.WebServices.dll
      Anybody have some ideas? 
      #To Launch! # C:\Windows\System32> powershell -ExecutionPolicy ByPass #This launches PowerShell and allows execution of .ps1 files # PS C:\Windows\System32> . "C:\Temp\eMail\getInbox.ps1" #The period . in front of the .ps1 file forces PS to display results on-screen # Where is the EWS .DLL file that you are using # Get the installer from https://www.microsoft.com/en-us/download/details.aspx?id=42022 # We only need 2 dll's from the install and they can be stored anywhere: "Microsoft.Exchange.WebServices.Auth.dll" & "Microsoft.Exchange.WebServices.dll" $EWSdll = "C:\Temp\eMail\Microsoft.Exchange.WebServices.dll" # Where do you want the output text file to be saved $Output = "C:\Temp\eMails.txt" # replace with your email address $email = "MyemailAddress@work.net" # only need to populate these if you're impersonating... $username = "myemail" $password = "Sup3rS3cre+" $domain = "ad.work.net" # load the assembly : point to the dll in the location you have the .dll file [void] [Reflection.Assembly]::LoadFile($EWSdll) # set ref to exchange, first references 2007, 2nd is 2010 (default) #$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1) $s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService # use first option if you want to impersonate, otherwise, grab your own credentials with the 3rd one. not sure what the 2nd one is for $s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain) ##$s.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #$s.UseDefaultCredentials = $true # discover the url from your email address $s.AutodiscoverUrl($email) # get a handle to the inbox $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox) #create a property set (to let us access the body & other details not available from the FindItems call) $psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) $psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text; # If you have a set number of items you want to get, use this and insert the # in the () # $items = $inbox.FindItems(5) # If you want to retrieve all items (Server limit is usually at 1000) then use this line # Details on the max returned by server: https://blogs.msdn.microsoft.com/exchangedev/2010/03/12/throttling-policies-and-the-ewsfindcountlimit/ $items = $inbox.FindItems($inbox.TotalCount) # Put some counts at the top of the output Write-host "Total Inbox count: $($inbox.TotalCount)" Write-host "Unread count: $($inbox.UnreadCount)" #These two lines, write the output to the specified text file Add-Content $Output "Total Inbox count: $($inbox.TotalCount)" Add-Content $Output "Unread count: $($inbox.UnreadCount)" foreach ($item in $items.Items) { # load the property set to allow us to get to the body $item.load($psPropertySet) # Get the Body text as-is $bod = $item.Body.Text #if you only want a short summary of the Body, then comment the above line and un-comment these 4 lines # $bod = $item.Body.Text -replace '\s+', ' ' # $bodCutOff = (100,$bod.Length | Measure-Object -Minimum).Minimum # $bod = $bod.Substring(0,$bodCutOff) # $bod = "$bod..." # output the results - first of all the From, Subject, References and Message ID write-host "====================================================================" Write-host "From: $($item.From.Name)" Write-host "Subject: $($item.Subject)" Write-host "Body: $($bod)" write-host "====================================================================" "" # Output the results to the specified Text file Add-Content $Output "" Add-Content $Output "====================================================================" Add-Content $Output "From: $($item.From.Name)" Add-Content $Output "Subject: $($item.Subject)" Add-Content $Output "Body:",$($bod) Add-Content $Output "====================================================================" Add-Content $Output "" } #see these URLs for more info # EWS Stuff # folder members: https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.folder_members%28v=exchg.80%29.aspx # exporting headers: https://www.allabout365.com/2010/10/export-email-headers-exchange-powershell/ # read emails with EWS: https://social.technet.microsoft.com/Forums/en-US/3fbf8348-2945-43aa-a0bc-f3b1d34da27c/read-emails-with-ews?forum=exchangesvrdevelopment  
      Thanks,
      Mike
    • FengHuangWuShen
      By FengHuangWuShen
      So I was playing with INet and downloading files and made a simple video downloader, or it can even be used for any file really.
      Just follow the reference section in INet_Settings.ini , and then run the script.
       
      Main Script #include <INet.au3> #include <InetConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <String.au3> OnAutoItExitRegister('INET_CLOSE') $GET_URL = _INetGetSource(IniRead(@ScriptDir & '\Inet_Settings.ini', 'Request', 'Url', Default)) $STRING_START = IniRead(@ScriptDir & '\Inet_Settings.ini', 'Data', 'Start', Default) $STRING_END = IniRead(@ScriptDir & '\Inet_Settings.ini', 'Data', 'End', Default) $GET_STRING = _StringBetween ($GET_URL, $STRING_START, $STRING_END) $VIDEO_URL = _ArrayToString($GET_STRING) $VIDEO = _URIDecode($VIDEO_URL) If StringLen($VIDEO) > 0 Then Local $VIDEO_DIR = (@ScriptDir & '\' & Random(1, 65535) & '.mp4') Local $DOWNLOAD_VIDEO = InetGet($VIDEO, $VIDEO_DIR, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do Sleep(IniRead(@ScriptDir & '\Inet_Settings.ini', 'Settings', 'Delay', Default)) Until InetGetInfo($DOWNLOAD_VIDEO, $INET_DOWNLOADCOMPLETE) InetClose($DOWNLOAD_VIDEO) Else MsgBox(0, 'DEBUG', "Video doesn't exist") EndIf Func INET_CLOSE() InetClose($DOWNLOAD_VIDEO) EndFunc Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ; ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc Func _URIDecode($sData) ; Prog@ndy Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%") $sData = "" For $i = 2 To $aData[0] $aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2) Next Return BinaryToString(StringToBinary($aData[1],1),4) EndFunc  
      INet_Settings.ini  URL - The target URL of the video you're trying to grab Data - This is the starting string, and ending string reference to look for the download URL itself. Settings - Only setting here currently, is the delay in which to wait for the file to download ### Reference for Start and End points for various websites [Request] Url = https://www.facebook.com/lindseystirlingmusic/videos/1527732263925622/ [Data] Start = hd_src_no_ratelimit:" End = " [Settings] Delay = 250 ################################################################################################### Instagram : https://www.instagram.com/p/Video ID Or : https://www.instagram.com/p/Video ID/?taken-by=User ID Start = video:secure_url" content=" End = " Facebook : https://www.facebook.com/User ID/videos/Video ID/ Or : Right click on the video and copy URL Start = hd_src_no_ratelimit:" End = " Start = sd_src_no_ratelimit:" End = " ###################################################################################################  
      Credits to : https://www.autoitscript.com/forum/profile/31965-progandy/  for the URL Encode and Decode.
×