Use a script to batch download video files
You have many videos in your account and you are looking for a way to download them all at once to your computer? We have the solution. We have created a script file written in VBScript that runs in Windows Script Host (WSH). By running this script in a Windows command prompt, your video files will be downloaded automatically.
Example
Use a script to download multiple files from your Nimbb account:
Execute the script
Follow these steps:
- Copy the code in a text file and save it with the name "batchDownload.vbs";
- Edit the code and set your developer keys;
- Optional: you can modify the folder where the videos are saved. By default, the folder is "C:\NimbbVideos\";
- Optional: specify start and end dates for a period to search;
- Open a Windows command prompt and type "cscript batchDownload.vbs" to run the script;
- When prompted to download video files, click "Yes".
VBScript code
Option Explicit
Dim strKey, strPrivate, strFolder, strUrlList, strUrlDownload
Dim oXML, oRoot, oList, oNode
Dim strGuid, strFile, strUrl, strStartDate, strEndDate
Dim oFSO, oHTTP, oStream
Dim intAnswer
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1
Const fileFormat = "flv"
' ----------------------------------------------------------------------------------------
' Set values below to your Nimbb's account keys.
' See this page to get the values: http://nimbb.com/User/Dev/Key.aspx
' Optional: modify the folder where to download the files on your computer.
' Optional: set a start and end date as the period to get videos.
' ----------------------------------------------------------------------------------------
strKey = "XXXXXXXXXX" ' Public key
strPrivate = "YYYYYYYYYY" ' Private key
strFolder = "C:\NimbbVideos\" ' Folder where to store video files.
strStartDate = "20140315" ' Start date (optional). Format "yyyymmdd"
strEndDate = "20140415" ' End date (optional). Format "yyyymmdd"
' ----------------------------------------------------------------------------------------
strUrlList = "http://api.nimbb.com/Video/List.aspx?key="&strKey&"&code="&strPrivate&"&startdate="&strStartDate&"&enddate="&strEndDate
strUrlDownload = "http://api.nimbb.com/Video/Download.aspx?key="&strKey&"&code="&strPrivate&"&guid=[GUID]&format="&fileFormat
' If the download folder doesn't exist, create it.
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strFolder) Then
Wscript.echo "Creating folder " & strFolder
oFSO.CreateFolder strFolder
End If
Wscript.echo "Video files will be stored in " & strFolder
' Get video list.
Set oXML = CreateObject("Msxml2.DOMDocument")
oXML.async = false
oXML.load(strUrlList)
Set oRoot = oXML.documentElement
Set oList = oRoot.getElementsByTagName("video")
WScript.Echo "Found " & oList.length & " videos to download."
intAnswer = Msgbox("Found " & oList.length & " videos. Start download?", vbYesNo, "Download Files")
If intAnswer = vbNo Then
WScript.Echo "Exiting."
WScript.Quit
End If
For Each oNode In oList
strGuid = oNode.getElementsByTagName("guid")(0).text
strFile = strGuid & "." & fileFormat
strUrl = Replace(strUrlDownload, "[GUID]", strGuid)
WScript.Echo "Processing guid " & strGuid
' Download the video file.
Set oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.open "GET", strURL, False
oHTTP.send
If oHTTP.Status <> 200 Then
' Failed to download the file
WScript.Echo "Error downloading guid " & strGuid & ". Status: " & oHTTP.Status & ", " & oHTTP.StatusText
Else
' Save file to disk.
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary
oStream.Open
oStream.Write oHTTP.ResponseBody
oStream.SaveToFile oFSO.BuildPath(strFolder, strFile), adSaveCreateOverWrite
oStream.Close
WScript.Echo " -> saved file " & strFolder & strGuid & "." & fileFormat
End If
Next
Take note that this script will download video files in FLV format. If you want to download files that were recorded with the Nimbb Player 2 in MP4 format, simply modify the constant "fileFormat" to value "mp4".
View more tutorials.