Advertisement
DeviousMalcontent

InstaMeta_v2.0.vbs

Aug 2nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Name: InstaMeta CScript Version 2.0
  2. ' File: InstaMeta_v2.0.vbs
  3. ' Licence: N/A
  4. ' Author: Mark Albanese (Devious_Malcontent)
  5. ' Date: 3 August 2014
  6. ' Version: 2.0
  7. ' Release: 1
  8. ' Language: VBScript
  9. ' Compiler: N/A
  10. ' Notes: This script can only be run from cscript.exe command line. Your Instagram account must also be public.
  11. '    Default encoding is ANSI, however this can be changed to UTF by opening the file in notepad and saving it as UTF format.
  12. ' Usage: Save as "InstaMeta_v2.0.vbs"
  13. '    Run this from command line using cscript.exe, eg: cscript C:\path\to\script\InstaMeta_v2.0.vbs username
  14. '    Where username is your Instagram username.
  15.  
  16. Set objFSO = Createobject("Scripting.FileSystemObject")
  17. Set objShell = wscript.createobject("wscript.shell")
  18. Set objStdIn = WScript.StdIn
  19. Set objStdOut = WScript.StdOut
  20.  
  21. If WScript.Arguments.Count = 0 then
  22.     objStdOut.Write "Instagram Username: "
  23.     username = objStdIn.ReadLine
  24.     OutputFileName = username & "_Instagram_Metadata" & Replace(Replace(Replace(FormatDateTime(Now()),"/","."),":",".")," ","_") & ".csv"
  25. Else
  26.     username = WScript.Arguments(0)
  27.     objStdOut.WriteLine "Instagram Username: " & username
  28.     OutputFileName = username & "_Instagram_Metadata" & Replace(Replace(Replace(FormatDateTime(Now()),"/","."),":",".")," ","_") & ".csv"
  29.     If WScript.Arguments.Count = 2 Then
  30.         OutputFileName = WScript.Arguments(1)
  31.     End if
  32. End if
  33.  
  34. it=1
  35.  
  36. strFileURL = "http://www.iphoneogram.com/" & username
  37. strHDLocation = objShell.CurrentDirectory & "\page" & it & ".html"
  38.  
  39. Dim objFile, strLine, out
  40. Set out = objFSO.OpenTextFile(objShell.CurrentDirectory & "\" & OutputFileName, 2, True)
  41.  
  42. Call getMeta(strFileURL,strHDLocation)
  43. objFile.Close
  44.  
  45. objStdOut.WriteLine "Performing clean up..."
  46.  
  47. Do Until it=0
  48.     strHDLocation = objShell.CurrentDirectory & "\page" & it & ".html"
  49.         If objFSO.Fileexists(strHDLocation) Then
  50.             objFSO.DeleteFile strHDLocation
  51.             objStdOut.WriteLine "Deleting temporary file: " & strHDLocation
  52.         End If
  53.     it=it-1
  54. Loop
  55.  
  56. Set objFSO = Nothing
  57.  
  58. objStdOut.WriteLine "Output File Name: " & OutputFileName
  59. objStdOut.WriteLine "Done!"
  60.  
  61. Function ReplacePattern(patrn, replStr, str1)
  62.   Dim regEx
  63.  
  64.   Set regEx = New RegExp
  65.   regEx.Pattern = patrn
  66.   regEx.IgnoreCase = True
  67.  
  68.   ReplacePattern = regEx.Replace(str1, replStr)
  69. End Function
  70.  
  71. Sub getMeta(strFileURL,strHDLocation)
  72. objStdOut.WriteLine "Reading URL: " & strFileURL
  73. objStdOut.WriteLine "To File: " & strHDLocation
  74.    
  75. Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
  76.  
  77. objXMLHTTP.open "GET", strFileURL, false
  78. objXMLHTTP.send()
  79.  
  80. If objXMLHTTP.Status = 200 Then
  81. Set objADOStream = CreateObject("ADODB.Stream")
  82. objADOStream.Open
  83. objADOStream.Type = 1
  84.  
  85. objADOStream.Write objXMLHTTP.ResponseBody
  86. objADOStream.Position = 0
  87.  
  88. If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
  89.     objADOStream.SaveToFile strHDLocation
  90.     objADOStream.Close
  91.     Set objADOStream = Nothing
  92. End if
  93.  
  94. Set objXMLHTTP = Nothing
  95.  
  96. Set objFile = objFSO.OpenTextFile(strHDLocation, 1)
  97.  
  98. Dim strSearchFor1, strSearchFor2, strSearchFor3, strSearchFor4, strSearchFor5
  99. strSearchFor1 = "text com"
  100. strSearchFor2 = "p-time-block"
  101. strSearchFor3 = "Original Image"
  102. strSearchFor4 = "View in Instagram web page"
  103. strSearchFor5 = "id=""next-link"">More"
  104.  
  105. GetNextLine = False
  106.  
  107. Do While Not objFile.AtEndOfStream
  108.         strLine = objFile.readline
  109.        
  110.         If GetNextLine = True Then
  111.             If InStr(1, strLine, "</p>") > 0 then
  112.                 GetNextLine = False
  113.             End If
  114.            
  115.             strLine = Replace(strLine,",","&#44;")
  116.             strLine = Replace(strLine,"</p>"," ")
  117.             strLine = Replace(strLine,vbCrLf,"")
  118.             strLine = Replace(strLine,vbLf,"")
  119.  
  120.             out.Write " " & strLine
  121.             objStdOut.WriteLine "Writing Remaining Description"
  122.         End If
  123.        
  124.         If InStr(1, strLine, strSearchFor1) > 0 then
  125.        
  126.             If InStr(1, strLine, "</p>") = 0 then
  127.                 GetNextLine = True
  128.                
  129.                 strLine = ReplacePattern("target=""_blank"">", "target=""", strLine)
  130.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  131.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  132.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  133.                 strLine = Replace(strLine," &nbsp; ","")
  134.                 strLine = Replace(strLine,",","&#44;")
  135.                 strLine = Replace(strLine,vbCrLf,"")
  136.                 strLine = Replace(strLine,vbLf,"")
  137.  
  138.                 out.Write strLine
  139.                 objStdOut.WriteLine "Writing Half Description"
  140.             Else
  141.                 strLine = ReplacePattern("target=""_blank"">", "target=""", strLine)
  142.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  143.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  144.                 strLine = ReplacePattern("<[^>]*>", "", strLine)
  145.                 strLine = Replace(strLine," &nbsp; ","")
  146.                 strLine = Replace(strLine,",","&#44;")
  147.                 strLine = Replace(strLine,vbCrLf,"")
  148.                 strLine = Replace(strLine,vbLf,"")
  149.  
  150.                 out.Write strLine
  151.                 objStdOut.WriteLine "Writing Description"
  152.             End if
  153.         End If
  154.                    
  155.         If InStr(1, strLine, strSearchFor2) > 0 then
  156.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  157.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  158.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  159.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  160.           strLine = Replace(strLine,vbCrLf,"")
  161.           strLine = Replace(strLine,vbLf,"")
  162.          
  163.           out.Write strLine & vbCrLf
  164.           objStdOut.WriteLine "Writing UNIX Timestamp"
  165.         End If
  166.        
  167.         If InStr(1, strLine, strSearchFor3) > 0 then
  168.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  169.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  170.           strLine = ReplacePattern("<[^>]*>", "", strLine)
  171.           strLine = Replace(strLine,"<a href=","")
  172.           strLine = Replace(strLine,""" target=""_blank"" rel=""nofollow"">Original Image</a></div>","")
  173.           strLine = ReplacePattern("""http://.*/", "", strLine)
  174.           strLine = Replace(strLine," ","")
  175.           strLine = Replace(strLine,vbCrLf,"")
  176.           strLine = Replace(strLine,vbLf,"")
  177.          
  178.           out.Write "," & strLine & ","
  179.           objStdOut.WriteLine "Writing Image file name (ID)"
  180.         End If
  181.        
  182.         If InStr(1, strLine, strSearchFor4) > 0 then
  183.           strLine = Replace(strLine,"<div class=""p-l-block""><span class=""fa fa-instagram""></span> <a href=""","")
  184.           strLine = Replace(strLine,""" target=""_blank"">View in Instagram web page</a></div>","")
  185.           strLine = Replace(strLine,vbCrLf,"")
  186.           strLine = Replace(strLine,vbLf,"")
  187.          
  188.           out.Write strLine & ","
  189.           objStdOut.WriteLine "Writing Instagram URL"
  190.         End If
  191.        
  192.         If InStr(1, strLine, strSearchFor5) > 0 then
  193.  
  194.           objStdOut.WriteLine "Found Next page!"
  195.          
  196.           inurl = Replace(strLine,"<a href=""","")
  197.           inurl = Replace(inurl,""" id=""next-link"">More &raquo;</a>","")
  198.          
  199.           strFileURL = "http://www.iphoneogram.com/" & inurl
  200.           it=it+1
  201.           strHDLocation = objShell.CurrentDirectory & "\page" & it & ".html"
  202.           Call getMeta(strFileURL,strHDLocation)
  203.         End If
  204.     Loop
  205. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement