Digital Library of India Books download script

Digital Library of India scanned lot of content (millions of pages or may be books) in English, some foreign and most Indian Languages (yes, books in your mother tongue too!) in different categories, right from epics to latest technologies.  They took all these books from many central libraries of Universities and other major City Libraries in India, and made them available publicly for free.  See the site (Google search for "digital library of India").  This site provides two book viewers but do not offer any software for offline viewing.  The following script downloads the entire book in minutes for offline viewing.  Copy paste the script in a text file and rename it to .vbs file to run the script.  To see how you can do it yourself, check the following YouTube videos.

Introduction - Digital Library - Online Books - Part1
How to download books from it - Digital Library - Online Books - Part2
How to convert them to PDF: Digital Library - Online Books - Part3

Save the following script (copy and paste) into a text file.  Rename text file to .vbs file.  Once you do that it may prompt a warning, do not worry, select Yes to change the file extension.  Either if you do not see the warning or the file icon do not change, you may have to make sure to turn off "Hide extensions of known files" in Windows Explorer.

  • Open Windows Explorer
  • You may not see the menu if you ar using Windows 7 by default.  Just press ALT+T then you will see the menu
  • Go to "Folder Options"
  • You will see "General" Tab.  Click on the next Yab, that is "View" and uncheck "Hide extensions for known file types" and them click OK.
  • Then you should be able to rename the file as filename.vbs instead of filename.vbs.txt.
Once you see the txt file as a script file with changed icon, just run the file.  For more information, see the videos.

'Script Starts here.
'Change History:
'Skip the pages already downloaded - 29 Nov 2012
'Download previous book if not downloaded all pages-08 Dec 2012.

 
Dim oXMLHTTP
Dim oStream
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
J=1

 
userinput = Msgbox ("Do you want to continue/complete previous download?",vbYesNo,"Complete Previous Download?")
If userinput=6 then
Set ObjBookList = ObjFSO.OpenTextFile("BookList.txt",1)
i=0
Do until ObjBookList.AtEndofStream
eachLine = ObjBookList.ReadLine
Loop
ObjBookList.Close
LastLineArr  = Split(eachline,",")
BookTitle = LastLineArr(0)
LastPageNumber = LastLineArr(1)
FirstPageLink = LastLineArr(2)
checkWithUser =  Msgbox("Check if the follwing details are correct." & vbtab & vbcrlf & vbcrlf & _
"Book Title:" & vbtab & BookTitle & vbCrLf & _
"Last Page Number:" & vbtab & LastPageNumber & vbCrLf & _
"First Page URL/Link:" & vbtab & FirstPageLink & vbcrlf & vbcrlf & _
"Do you want to continue?" & vbCrLf & "If any of the details are not correct, download as a new book.",vbYesNo,"Check the details")
If checkWithUser<>6 then
Msgbox "You selected not to continue, exiting the script!!",vbcritical,"Exit Book Download"
Wscript.Quit
End If
Else
BookTitle = Replace(InputBox("Please enter the title of the book.","Book Title to download","Mitra Labham")," ","_")
LastPageNumber = Cint(Inputbox("Please enter the last page number.","Last Page","235"))
FirstPageLink = Inputbox("Enter the first page link","Enter Link","http://www.dli.gov.in/data/upload/0001/770/PTIFF/00000001.tif")
End if

 
WriteToLog("====================================================================================================")
WriteToLog(" DOWANLOADING THE BOOK " & Chr(34) & BookTitle & Chr(34))
WriteToLog("====================================================================================================")

 
Normalized_Link = Left(FirstPageLink,Len(FirstPageLink)-7)

 
If Not ObjFSO.FolderExists(BookTitle) then ObjFSO.CreateFolder(BookTitle)

 
Set ObjBookList = ObjFSO.OpenTextFile("BookList.txt",8,true)
ObjBookList.WriteLine BookTitle & "," & LastPageNumber & "," & FirstPageLink
ObjBookList.Close

 
For j=1 to LastPageNumber
If Len(J)=2 then J= "0" & J
If Len(J)=1 then J= "00" & J
GetThisPage = Normalized_Link & J & ".tif"
If ObjFSO.FileExists(BookTitle & "\" & BookTitle & "_" & J & ".tif") then
WriteToLog("Already downloaded in previous attempt - " & BookTitle & "\" & BookTitle & "_" & J & ".tif")
Else
Call GetWebPage(GetThisPage,BookTitle,J)
If ObjFSO.FileExists(BookTitle & "\" & BookTitle & "_" & J & ".tif") then
WriteToLog("Successfully downloaded - " & BookTitle & "\" & BookTitle & "_" & J & ".tif")
Else
WriteToLog("Downloading failed for - " & BookTitle & "\" & BookTitle & "_" & J & ".tif")
End if
End if
Next
WriteToLog("Completed downloading the book - " & BookTitle)
WriteToLog("This book is found in the location - " & ObjFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & BookTitle)

 
Msgbox Chr(34) & BookTitle & Chr(34) & " is downloaded successfully and can be found in the location - " & ObjFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & BookTitle,vbOK,"Download Complete"

 
Function GetWebPage(GetThisPage,BookTitle,pageNum)
  'http://www.dli.gov.in/data/upload/0001/770/PTIFF/00000008.tif
  'oXMLHTTP.Open "GET", "http://www.new.dli.ernet.in/data/upload/0002/001/PTIFF/00000" & pageNum & ".tif", False
  'oXMLHTTP.Open "GET", "http://www.dli.gov.in/data_copy/upload/0070/506/PTIFF/00000" & pageNum & ".tif", False

 
  oXMLHTTP.Open "GET",GetThisPage,False
  oXMLHTTP.Send
  If oXMLHTTP.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write oXMLHTTP.responseBody
    oStream.SaveToFile BookTitle & "\" & BookTitle & "_" & pageNum & ".tif"
    oStream.Close
  Else
    Msgbox "This web page is not found",vbCritical,"Invalid Link"
    Wscript.Quit 101
  End If
End Function
  
Function WriteToLog(str)
Set ObjOutPutLogFile = ObjFSO.OpenTextFile("BookDownloadLog.txt",8,true)
ObjOutPutLogFile.WriteLine Now & vbtab & str
ObjOutPutLogFile.Close
End Function
 
'Script Ends here.