Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.Text
- Imports System.Text.RegularExpressions
- Imports System.IO
- Imports System.Runtime.InteropServices
- Public Class Form1
- Private Sub AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNew.Click
- Dim item As String = NewID.Text
- If item.Contains("youtube.com") Then
- item = item & "</"
- Dim r As New System.Text.RegularExpressions.Regex("v=(.*?)<\/")
- Dim matches As MatchCollection = r.Matches(item)
- Dim ID As String
- For Each itemcode As Match In matches
- ID = itemcode.ToString
- ID = ID.Replace("v=", "")
- ID = ID.Replace("</", "")
- Next
- If ID.Length > 7 Then
- Stats.Rows.Add(ID)
- Else
- MsgBox("Please write a valid video ID!")
- Exit Sub
- End If
- Else
- If item.Length > 7 Then
- Stats.Rows.Add(item)
- Else
- MsgBox("Please write a valid video ID!")
- Exit Sub
- End If
- End If
- Ref()
- End Sub
- #Region "Delay"
- Private Sub Delay(ByVal DelayInSeconds As Integer)
- Dim ts As TimeSpan
- Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
- Do
- ts = targetTime.Subtract(DateTime.Now)
- Application.DoEvents() ' keep app responsive
- System.Threading.Thread.Sleep(50) ' reduce CPU usage
- Loop While ts.TotalSeconds > 0
- End Sub
- #End Region
- Private Sub ClearSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearSelected.Click
- If Not Stats.Rows.Count = 0 Then
- If Stats.CurrentRow.Index >= 0 Then
- Stats.Rows.RemoveAt(Stats.CurrentRow.Index)
- End If
- Else
- MsgBox("Please add some videos!")
- Exit Sub
- End If
- End Sub
- Private Sub ClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAll.Click
- If Stats.Rows.Count = 0 Then
- MsgBox("Please add some videos!")
- Else
- Stats.Rows.Clear()
- End If
- End Sub
- Sub GetData(ByVal str As String)
- Try
- Dim inStream As StreamReader
- Dim WebRequest As WebRequest
- Dim Webresponse As WebResponse
- Dim Data As String
- WebRequest = WebRequest.Create("http://gdata.youtube.com/feeds/api/videos/" & str & "?v=2")
- Webresponse = WebRequest.GetResponse()
- inStream = New StreamReader(Webresponse.GetResponseStream())
- Data = inStream.ReadToEnd()
- If Data.ToLower.Contains("video not found") Or Data.ToLower.Contains("private video") Then
- NotFound = "Yes"
- ElseIf Not Data.ToLower.Contains("video not found") Or Not Data.ToLower.Contains("private video") Then
- ScrapeTitle(Data)
- ScrapeLikes(Data)
- ScrapeDisLikes(Data)
- ScrapeViews(Data)
- ScrapeDate(Data)
- ScrapeComments(Data)
- End If
- Catch ex As Exception
- NotFound = "Yes"
- End Try
- End Sub
- Public Sub ScrapeTitle(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("<title>(.*?)<\/title>")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- FinalTitle = itemcode.ToString
- FinalTitle = FinalTitle.Replace("<title>", "")
- FinalTitle = FinalTitle.Replace("</title>", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Public Sub ScrapeLikes(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("numLikes='(.*?)'")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- Likess = itemcode.ToString
- Likess = Likess.Replace("numLikes='", "")
- Likess = Likess.Replace("'", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Public Sub ScrapeDisLikes(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("numDislikes='(.*?)'")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- Dislikess = itemcode.ToString
- Dislikess = Dislikess.Replace("numDislikes='", "")
- Dislikess = Dislikess.Replace("'", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Public Sub ScrapeViews(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("viewCount='(.*?)'")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- Viewss = itemcode.ToString
- Viewss = Viewss.Replace("viewCount='", "")
- Viewss = Viewss.Replace("'", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Public Sub ScrapeDate(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("<yt:uploaded>(.*?)<\/yt:uploaded>")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- DateUp = itemcode.ToString
- DateUp = DateUp.Replace("<yt:uploaded>", "")
- DateUp = DateUp.Replace("</yt:uploaded>", "")
- DateUp = DateUp.Replace("T", " at ")
- DateUp = DateUp.Replace(".000Z", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Public Sub ScrapeComments(ByVal str As String)
- Try
- Dim r As New System.Text.RegularExpressions.Regex("countHint='(.*?)'")
- Dim matches As MatchCollection = r.Matches(str)
- For Each itemcode As Match In matches
- Comments = itemcode.ToString
- Comments = Comments.Replace("countHint='", "")
- Comments = Comments.Replace("'", "")
- Next
- Catch ex As Exception
- Return
- End Try
- End Sub
- Dim FinalTitle As String
- Dim Likess As String
- Dim Dislikess As String
- Dim Viewss As String
- Dim NotFound As String
- Dim DateUp As String
- Dim Comments As String
- Private Sub RefreshAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshAll.Click
- If Stats.Rows.Count = 0 Then
- MsgBox("Please add some videos!")
- Exit Sub
- End If
- Ref()
- End Sub
- Sub Ref()
- Dim f As Integer = Stats.Rows.Count
- For Each row As DataGridViewRow In Stats.Rows
- Dim r As String
- r = row.Cells(0).Value
- NotFound = "No"
- GetData(r)
- If NotFound = "Yes" Then
- Stats.Rows.Add(New String() {row.Cells(0).Value, "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "DOWN"})
- ElseIf NotFound = "No" Then
- Stats.Rows.Add(New String() {row.Cells(0).Value, FinalTitle, Viewss, Likess, Dislikess, Comments, DateUp, "UP"})
- End If
- If Stats.Rows.Count = f * 2 Then
- For s = 0 To f - 1
- Stats.Rows.RemoveAt(0)
- Next
- Exit For
- End If
- Next
- End Sub
- Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
- If Not Stats.Rows.Count = 0 Then
- Dim all As String = Stats.Rows.Count
- For Each row As DataGridViewRow In Stats.Rows
- Dim r As String
- r = row.Cells(0).Value
- all = all & ":" & r
- Next
- My.Settings.Videos = all
- Else
- My.Settings.Videos = ""
- End If
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- If Not My.Settings.Videos = "" Then
- Dim S As String() = My.Settings.Videos.Split(":")
- Dim n As Integer = 0
- Dim p As Integer = S(0)
- For i = 0 To p - 1
- n = n + 1
- Stats.Rows.Add(S(n))
- Next
- If Not Stats.Rows.Count > 5 Then
- Dim Th As New Threading.Thread(AddressOf Ref)
- Th.Start()
- End If
- End If
- End Sub
- Private Sub LoadIt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadIt.Click
- Using Ofd As New OpenFileDialog
- Ofd.Filter = "Text Files|*.txt"
- If Ofd.ShowDialog = 1 Then
- For Each Line In My.Computer.FileSystem.ReadAllText(Ofd.FileName).Split(Environment.NewLine)
- Dim item As String
- item = Line & "</"
- If item.Contains("youtube.com") Then
- Dim r As New System.Text.RegularExpressions.Regex("v=(.*?)<\/")
- Dim matches As MatchCollection = r.Matches(item)
- Dim ID As String
- For Each itemcode As Match In matches
- ID = itemcode.ToString
- ID = ID.Replace("v=", "")
- ID = ID.Replace("</", "")
- Next
- If ID.Length > 7 Then
- Stats.Rows.Add(ID)
- End If
- Else
- If Line.Length > 7 Then
- Stats.Rows.Add(Line)
- End If
- End If
- skip:
- Next
- End If
- End Using
- Ref()
- End Sub
- Private Sub RankCheckerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RankCheckerButton.Click
- If Stats.Rows.Count = 0 Then
- MsgBox("Please add some videos!")
- Exit Sub
- Else
- RankChecker.Show()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement