Old 21st February 2017, 14:55   #1
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 41
Download and convert video

NSIS can download and convert video files using external applications

PHP Code:
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 
$"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 
$"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 
$"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" $$$2
IfErrors 0 
+2
StrCpy 
$$1024
IntCmp 
$0 100 +3 0 +3
 IntCmp 
$0 0 ++2 0
 IntOp 
$0 103 0
IntOp 
$$10
IntOp 
$$1024
StrCpy 
$"$0" "" -1
IntCmp 
$0 9 ++3 0
 StrCpy 
$"$0" -""
 
Goto +2
 StrCpy 
$"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 
Attached Files
File Type: nsi Test Download And Video Convert.nsi (5.0 KB, 21 views)
Coby is offline   Reply With Quote
Old 22nd February 2017, 06:05   #2
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 854
You don't need to use "System::Call 'kernel32::CreateDirectoryW'", use the nsis command CreateDirectory.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 22nd February 2017, 11:35   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,610
Quote:
Originally Posted by JasonFriday13 View Post
You don't need to use "System::Call 'kernel32::CreateDirectoryW'", use the nsis command CreateDirectory.
...and he uses ?e without pop'ing.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 23rd February 2017, 04:05   #4
need9989
Junior Member
 
Join Date: Feb 2017
Posts: 1
How to get real progress when ‘Youtube-dl download’ ?
need9989 is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump