Name "Test Download And Convert Video"
Caption "Test Download And Convert Video"
OutFile "Test Download And Convert Video.exe"
InstallDir "$TEMP\Test Download And Convert Video"
# Compress
SetCompressor /SOLID /FINAL lzma
# Include
!include "MUI2.nsh"
!include "WinCore.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"
!insertmacro GetFileName
!insertmacro GetParameters
!insertmacro DriveSpace
!insertmacro GetParent
!insertmacro GetOptions
!insertmacro GetDrives
!insertmacro GetRoot
!insertmacro GetSize
# Runtime
RequestExecutionLevel Admin
ShowInstDetails hide
ShowInstDetails nevershow
XPStyle off
BrandingText /TRIMRIGHT " "
# Page
Page instfiles "" ""
!insertmacro MUI_LANGUAGE "English"
Function .onInit
FunctionEnd
var /GLOBAL LINK
var /GLOBAL YOUVIDEO
var /GLOBAL BASEFILENAME
Section "Main" SEC001
DetailPrint `Check FFMPeg if exist ...`
IfFileExists "$EXEDIR\FFMpeg\FFMpeg.exe" "NSIS.Detect.FFMPeg.App" "NSIS.Download.FFMPeg.App"
NSIS.Download.FFMPeg.App:
DetailPrint `Downloading FFMpeg ...`
System::Call 'kernel32::CreateDirectoryW(w "$TEMP\FFMpeg", i0)i.r0?e'
inetc::get "https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20170221-a5c1c7a-win32-static.zip" "$TEMP\FFMpeg\ffmpeg-20170221-a5c1c7a-win32-static.zip" /END
Pop $0
StrCmp $0 "OK" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$0.Error Downloading!"
Goto Cancelled
System::Call 'kernel32::CreateDirectoryW(w "$EXEDIR\FFMpeg", i0)i.r0?e'
nsisunz::UnzipToLog "$TEMP\FFMpeg\ffmpeg-20170221-a5c1c7a-win32-static.zip" "$TEMP\FFMpeg"
Pop $0
StrCmp $0 "success" ok
DetailPrint "$0" ;print error message to log
ok:
ClearErrors
SetShellVarContext "all"
nsExec::ExecToStack '"$SYSDIR\xcopy.exe" /y /r "$TEMP\FFMpeg\ffmpeg-20170221-a5c1c7a-win32-static\bin\*.*" /d "$EXEDIR\FFMpeg"' $0
Pop $0
Pop $1
IfFileExists "$EXEDIR\FFMpeg\FFMpeg.exe" "NSIS.Detect.FFMPeg.App" "Next.Step"
GoTo Next.Step
NSIS.Detect.FFMPeg.App:
GoTo Next.Step
Next.Step:
DetailPrint `Check Youtube-dl if exist ...`
IfFileExists "$EXEDIR\Youtube-dl\youtube-dl.exe" "NSIS.Detect.Youtube-dl.App" "NSIS.Download.Youtube-dl.App"
NSIS.Download.Youtube-dl.App:
DetailPrint `Downloading Youtube-dl ...`
System::Call 'kernel32::CreateDirectoryW(w "$EXEDIR\Youtube-dl", i0)i.r0?e'
inetc::get "https://yt-dl.org/downloads/2017.02.17/youtube-dl.exe" "$EXEDIR\Youtube-dl\youtube-dl.exe" /END
Pop $0
StrCmp $0 "OK" +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$0.Error Downloading!"
Goto Cancelled
IfFileExists "$EXEDIR\Youtube-dl\youtube-dl.exe" "NSIS.Detect.Youtube-dl.App" "Next.Step1"
GoTo Next.Step1
NSIS.Detect.Youtube-dl.App:
GoTo Next.Step1
Next.Step1:
DetailPrint `Downloading your video ...Please wait for a moments ...`
# Download
System::Call 'kernel32::CreateDirectoryW(w "C:\Downloads", i0)i.r0?e'
# YOUTUBE-DL CONFIG
Strcpy $LINK "https://www.youtube.com/watch?v=k85mRPqvMbE"
nsExec::ExecToStack '"$EXEDIR\Youtube-dl\youtube-dl.exe" --skip-download --get-filename "$LINK"' $0
pop $0
pop $1
Strcpy $YOUVIDEO "$1"
DetailPrint `Downloading ...$1`
nsExec::ExecToStack '"$EXEDIR\Youtube-dl\youtube-dl.exe" -q --continue -f mp4 --no-part "$LINK" -o "C:\Downloads\%(title)s-%(id)s.%(ext)s"' $0
pop $0
pop $1
${GetBaseName} "C:\Downloads\$YOUVIDEO" $BASEFILENAME
IfFileExists "C:\Downloads\$BASEFILENAME.mp4" "NSIS.Done.Download.Video" "NSIS.Failed.Download.Video"
NSIS.Done.Download.Video:
DetailPrint `NSIS was sucessfully download your video!`
MessageBox MB_YESNO|MB_USERICON "NSIS was sucessfully download your video!$\n$\nDo you want convert this download video?" IDYES "NSIS.Yes.Convert.Video" IDNO "NSIS.Skyp.And.Continue"
Abort
NSIS.Yes.Convert.Video:
# FFMPeg CONFIG
System::Call 'kernel32::CreateDirectoryW(w "C:\Converts", i0)i.r0?e'
${GetBaseName} "C:\Downloads\$YOUVIDEO" $BASEFILENAME
nsExec::ExecToStack '"$EXEDIR\FFMpeg\FFMpeg.exe" -i "C:\Downloads\$BASEFILENAME.mp4" -s hd1080 -c:v libx264 -crf 23 -c:a aac -strict -2 -pix_fmt yuv420p "C:\Converts\$BASEFILENAME.mp4"' $0
Pop $0
Pop $1
DetailPrint `Converting ... $1`
IfFileExists "C:\Converts\$BASEFILENAME.mp4" "NSIS.Done.Convert.Video" "NSIS.Failed.Convert.Video"
NSIS.Done.Convert.Video:
${GetSize} "C:\Converts" "/M=$BASEFILENAME.mp4 /S=0K" $0 $1 $2
IfErrors 0 +2
StrCpy $0 $0 * 1024
IntCmp $0 100 +3 0 +3
IntCmp $0 0 +2 +2 0
IntOp $0 103 + 0
IntOp $0 $0 * 10
IntOp $0 $0 / 1024
StrCpy $1 "$0" "" -1
IntCmp $0 9 +3 +3 0
StrCpy $0 "$0" -1 ""
Goto +2
StrCpy $0 "0"
DetailPrint `NSIS was succesfully convert your video! ($0.$1 MiB)`
Abort
NSIS.Failed.Convert.Video:
DetailPrint `NSIS was failed convert your video!`
Abort
NSIS.Failed.Download.Video:
DetailPrint `NSIS was failed download your video!`
Abort
NSIS.Skyp.And.Continue:
DetailPrint `NSIS continue installing files ...`
Abort
Cancelled:
DetailPrint `NSIS was failed download files ...`
SetAutoClose true
SectionEnd
Function .onGUIEND
FunctionEnd Download and convert video
NSIS can download and convert video files using external applications