Advertisement
Guest User

Untitled

a guest
Nov 4th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. Imports System.Net
  2. Imports System.Text
  3. Imports System.Text.RegularExpressions
  4. Imports System.IO
  5. Imports System.Runtime.InteropServices
  6.  
  7. Public Class Form1
  8. Private Sub AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNew.Click
  9. Dim item As String = NewID.Text
  10. If item.Contains("youtube.com") Then
  11. item = item & "</"
  12. Dim r As New System.Text.RegularExpressions.Regex("v=(.*?)<\/")
  13. Dim matches As MatchCollection = r.Matches(item)
  14. Dim ID As String
  15.  
  16. For Each itemcode As Match In matches
  17. ID = itemcode.ToString
  18. ID = ID.Replace("v=", "")
  19. ID = ID.Replace("</", "")
  20. Next
  21. If ID.Length > 7 Then
  22. Stats.Rows.Add(ID)
  23. Else
  24. MsgBox("Please write a valid video ID!")
  25. Exit Sub
  26. End If
  27. Else
  28. If item.Length > 7 Then
  29. Stats.Rows.Add(item)
  30. Else
  31. MsgBox("Please write a valid video ID!")
  32. Exit Sub
  33. End If
  34. End If
  35. Ref()
  36. End Sub
  37.  
  38. #Region "Delay"
  39. Private Sub Delay(ByVal DelayInSeconds As Integer)
  40. Dim ts As TimeSpan
  41. Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
  42. Do
  43. ts = targetTime.Subtract(DateTime.Now)
  44. Application.DoEvents() ' keep app responsive
  45. System.Threading.Thread.Sleep(50) ' reduce CPU usage
  46. Loop While ts.TotalSeconds > 0
  47. End Sub
  48. #End Region
  49.  
  50. Private Sub ClearSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearSelected.Click
  51. If Not Stats.Rows.Count = 0 Then
  52. If Stats.CurrentRow.Index >= 0 Then
  53. Stats.Rows.RemoveAt(Stats.CurrentRow.Index)
  54. End If
  55. Else
  56. MsgBox("Please add some videos!")
  57. Exit Sub
  58. End If
  59. End Sub
  60.  
  61. Private Sub ClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAll.Click
  62. If Stats.Rows.Count = 0 Then
  63. MsgBox("Please add some videos!")
  64. Else
  65. Stats.Rows.Clear()
  66. End If
  67. End Sub
  68.  
  69. Sub GetData(ByVal str As String)
  70. Try
  71. Dim inStream As StreamReader
  72. Dim WebRequest As WebRequest
  73. Dim Webresponse As WebResponse
  74. Dim Data As String
  75.  
  76. WebRequest = WebRequest.Create("http://gdata.youtube.com/feeds/api/videos/" & str & "?v=2")
  77. Webresponse = WebRequest.GetResponse()
  78. inStream = New StreamReader(Webresponse.GetResponseStream())
  79. Data = inStream.ReadToEnd()
  80.  
  81. If Data.ToLower.Contains("video not found") Or Data.ToLower.Contains("private video") Then
  82. NotFound = "Yes"
  83. ElseIf Not Data.ToLower.Contains("video not found") Or Not Data.ToLower.Contains("private video") Then
  84. ScrapeTitle(Data)
  85. ScrapeLikes(Data)
  86. ScrapeDisLikes(Data)
  87. ScrapeViews(Data)
  88. ScrapeDate(Data)
  89. ScrapeComments(Data)
  90. End If
  91.  
  92. Catch ex As Exception
  93. NotFound = "Yes"
  94. End Try
  95. End Sub
  96.  
  97. Public Sub ScrapeTitle(ByVal str As String)
  98. Try
  99. Dim r As New System.Text.RegularExpressions.Regex("<title>(.*?)<\/title>")
  100. Dim matches As MatchCollection = r.Matches(str)
  101.  
  102. For Each itemcode As Match In matches
  103. FinalTitle = itemcode.ToString
  104. FinalTitle = FinalTitle.Replace("<title>", "")
  105. FinalTitle = FinalTitle.Replace("</title>", "")
  106. Next
  107. Catch ex As Exception
  108. Return
  109. End Try
  110. End Sub
  111.  
  112. Public Sub ScrapeLikes(ByVal str As String)
  113. Try
  114. Dim r As New System.Text.RegularExpressions.Regex("numLikes='(.*?)'")
  115. Dim matches As MatchCollection = r.Matches(str)
  116.  
  117. For Each itemcode As Match In matches
  118. Likess = itemcode.ToString
  119. Likess = Likess.Replace("numLikes='", "")
  120. Likess = Likess.Replace("'", "")
  121. Next
  122. Catch ex As Exception
  123. Return
  124. End Try
  125. End Sub
  126.  
  127. Public Sub ScrapeDisLikes(ByVal str As String)
  128. Try
  129. Dim r As New System.Text.RegularExpressions.Regex("numDislikes='(.*?)'")
  130. Dim matches As MatchCollection = r.Matches(str)
  131.  
  132. For Each itemcode As Match In matches
  133. Dislikess = itemcode.ToString
  134. Dislikess = Dislikess.Replace("numDislikes='", "")
  135. Dislikess = Dislikess.Replace("'", "")
  136. Next
  137. Catch ex As Exception
  138. Return
  139. End Try
  140. End Sub
  141.  
  142. Public Sub ScrapeViews(ByVal str As String)
  143. Try
  144. Dim r As New System.Text.RegularExpressions.Regex("viewCount='(.*?)'")
  145. Dim matches As MatchCollection = r.Matches(str)
  146.  
  147. For Each itemcode As Match In matches
  148. Viewss = itemcode.ToString
  149. Viewss = Viewss.Replace("viewCount='", "")
  150. Viewss = Viewss.Replace("'", "")
  151. Next
  152. Catch ex As Exception
  153. Return
  154. End Try
  155. End Sub
  156.  
  157. Public Sub ScrapeDate(ByVal str As String)
  158. Try
  159. Dim r As New System.Text.RegularExpressions.Regex("<yt:uploaded>(.*?)<\/yt:uploaded>")
  160. Dim matches As MatchCollection = r.Matches(str)
  161.  
  162. For Each itemcode As Match In matches
  163. DateUp = itemcode.ToString
  164. DateUp = DateUp.Replace("<yt:uploaded>", "")
  165. DateUp = DateUp.Replace("</yt:uploaded>", "")
  166. DateUp = DateUp.Replace("T", " at ")
  167. DateUp = DateUp.Replace(".000Z", "")
  168. Next
  169. Catch ex As Exception
  170. Return
  171. End Try
  172. End Sub
  173.  
  174. Public Sub ScrapeComments(ByVal str As String)
  175. Try
  176. Dim r As New System.Text.RegularExpressions.Regex("countHint='(.*?)'")
  177. Dim matches As MatchCollection = r.Matches(str)
  178.  
  179. For Each itemcode As Match In matches
  180. Comments = itemcode.ToString
  181. Comments = Comments.Replace("countHint='", "")
  182. Comments = Comments.Replace("'", "")
  183. Next
  184. Catch ex As Exception
  185. Return
  186. End Try
  187. End Sub
  188.  
  189. Dim FinalTitle As String
  190. Dim Likess As String
  191. Dim Dislikess As String
  192. Dim Viewss As String
  193. Dim NotFound As String
  194. Dim DateUp As String
  195. Dim Comments As String
  196.  
  197. Private Sub RefreshAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshAll.Click
  198. If Stats.Rows.Count = 0 Then
  199. MsgBox("Please add some videos!")
  200. Exit Sub
  201. End If
  202. Ref()
  203. End Sub
  204.  
  205. Sub Ref()
  206. Dim f As Integer = Stats.Rows.Count
  207. For Each row As DataGridViewRow In Stats.Rows
  208. Dim r As String
  209. r = row.Cells(0).Value
  210.  
  211. NotFound = "No"
  212.  
  213. GetData(r)
  214.  
  215. If NotFound = "Yes" Then
  216. Stats.Rows.Add(New String() {row.Cells(0).Value, "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "DOWN"})
  217. ElseIf NotFound = "No" Then
  218. Stats.Rows.Add(New String() {row.Cells(0).Value, FinalTitle, Viewss, Likess, Dislikess, Comments, DateUp, "UP"})
  219. End If
  220.  
  221. If Stats.Rows.Count = f * 2 Then
  222. For s = 0 To f - 1
  223. Stats.Rows.RemoveAt(0)
  224. Next
  225. Exit For
  226. End If
  227. Next
  228. End Sub
  229.  
  230. Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  231. If Not Stats.Rows.Count = 0 Then
  232. Dim all As String = Stats.Rows.Count
  233. For Each row As DataGridViewRow In Stats.Rows
  234. Dim r As String
  235. r = row.Cells(0).Value
  236.  
  237. all = all & ":" & r
  238. Next
  239. My.Settings.Videos = all
  240. Else
  241. My.Settings.Videos = ""
  242. End If
  243. End Sub
  244.  
  245. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  246. If Not My.Settings.Videos = "" Then
  247. Dim S As String() = My.Settings.Videos.Split(":")
  248. Dim n As Integer = 0
  249. Dim p As Integer = S(0)
  250. For i = 0 To p - 1
  251. n = n + 1
  252.  
  253. Stats.Rows.Add(S(n))
  254. Next
  255. If Not Stats.Rows.Count > 5 Then
  256. Dim Th As New Threading.Thread(AddressOf Ref)
  257. Th.Start()
  258. End If
  259. End If
  260. End Sub
  261.  
  262. Private Sub LoadIt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadIt.Click
  263. Using Ofd As New OpenFileDialog
  264. Ofd.Filter = "Text Files|*.txt"
  265. If Ofd.ShowDialog = 1 Then
  266. For Each Line In My.Computer.FileSystem.ReadAllText(Ofd.FileName).Split(Environment.NewLine)
  267. Dim item As String
  268. item = Line & "</"
  269. If item.Contains("youtube.com") Then
  270. Dim r As New System.Text.RegularExpressions.Regex("v=(.*?)<\/")
  271. Dim matches As MatchCollection = r.Matches(item)
  272. Dim ID As String
  273.  
  274. For Each itemcode As Match In matches
  275. ID = itemcode.ToString
  276. ID = ID.Replace("v=", "")
  277. ID = ID.Replace("</", "")
  278. Next
  279. If ID.Length > 7 Then
  280. Stats.Rows.Add(ID)
  281. End If
  282. Else
  283. If Line.Length > 7 Then
  284. Stats.Rows.Add(Line)
  285. End If
  286. End If
  287. skip:
  288. Next
  289. End If
  290. End Using
  291. Ref()
  292. End Sub
  293.  
  294. Private Sub RankCheckerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RankCheckerButton.Click
  295. If Stats.Rows.Count = 0 Then
  296. MsgBox("Please add some videos!")
  297. Exit Sub
  298. Else
  299. RankChecker.Show()
  300. End If
  301. End Sub
  302. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement