Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Globals.GlobalResources
- Imports SHDocVw
- Imports System.Net
- Public Class Class1
- Implements Globals.Plgn
- Dim WithEvents Browser As SHDocVw.InternetExplorer ' Browser object
- Dim WithEvents Poller As New Timers.Timer ' timer object
- Dim playlist As New List(Of String) ' list to store playlist
- Dim playing As Boolean = False ' playing status
- Public Sub Config() Implements Globals.Plgn.Config
- ' Displays a message box when trying to configure plugin
- MsgBox("Nothing to configure yet" & vbCrLf & _
- "!ytr <youtube video ID> to add to playlist" & vbCrLf & _
- "Skipping and other feature will come later." & vbCrLf & _
- "This is only a test version")
- End Sub
- Public ReadOnly Property Name As String Implements Globals.Plgn.Name
- Get
- Return "YouTubeRequest - TizzyT"
- End Get
- End Property
- Public Function ProcessMessage(InputMessage As Globals.GlobalResources.Message) As Boolean _
- Implements Globals.Plgn.ProcessMessage
- If InputMessage.Type = MessageType.PRIVMSG Then ' If message is a PRIVMSG ...
- ' Check if the message is from the bot owner, if so ...
- If InputMessage.Nick.Trim().ToLower() = InputMessage.Owner.Trim().ToLower() Then
- ' look to see if command !ytr was issued in message, if so ...
- If InputMessage.Message.StartsWith("!ytr", StringComparison.CurrentCultureIgnoreCase) Then
- ' get video id from command
- Dim VideoID As String = InputMessage.Message.Trim().Split(" ")(1)
- ' grab source from youtube page to get title from ...
- Dim Title As String = New WebClient().DownloadString("https://www.youtube.com/watch?v=" & VideoID)
- ' taking everything right of "<title>" and then ...
- Title = Title.Split(New String() {"<title>"}, StringSplitOptions.None)(1)
- ' taking everything left of "</title>" and remove leading/trailing white space.
- Title = Title.Split(New String() {"</title>"}, StringSplitOptions.None)(0).Trim()
- If Title = "YouTube" Then ' if tite is "YouTube" its an invalid video.
- ' Announce that its an invalid video.
- AddToSend("PRIVMSG " & InputMessage.Target & " :Invalid ID " & InputMessage.Nick)
- ElseIf Title.EndsWith(" - YouTube") Then ' if title ends with " - YouTube" its most likely valid
- Title = Title.Replace(" - YouTube", String.Empty) ' clean up title by removing " - YouTube"
- Me.playlist.Add(VideoID & " ::: " & Title) ' add id and title to playlist
- AddToSend("PRIVMSG " & InputMessage.Target + " :Added: " & Title) ' announce added video
- End If
- End If
- End If
- End If
- Return False ' return false so that this message can be handled my the next plugin
- End Function
- Protected Overrides Sub Finalize()
- playing = False
- Try
- ' try to close the browser object
- Browser.Quit()
- Catch ex As Exception
- ' if ie instance refuses to close, forcefully close all ie instances
- While True
- Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("iexplore")
- If pProcess.Length = 0 Then
- Exit While
- Else
- For Each p As Process In pProcess
- Try
- p.Kill()
- Catch ex1 As Exception
- End Try
- Next
- End If
- End While
- End Try
- MyBase.Finalize()
- End Sub
- ' This function is triggered everytime the browser title changes
- Private Sub Browser_TitleChange(Text As String) Handles Browser.TitleChange
- If Text = "0" Then ' if browser title is 0 (meaning video finished playing) ...
- playing = False ' set playing status to false and ...
- Browser.Quit() ' Close the browser object
- End If
- End Sub
- ' This function is triggered every half second
- Private Sub Poller_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles Poller.Elapsed
- If Not playing Then ' if playing status is false ...
- If playlist.Count > 0 Then ' check how many videos are in the playlist, its greater than 0 ...
- playing = True ' set playing status to true
- Dim Info(2) As String ' create string array to store video info
- Info(0) = playlist(0) ' info(0) = the first video in playlist
- playlist.RemoveAt(0) ' remove first video from playlist
- Info(1) = Info(0).Split(" ::: ")(0) ' info(1) = left side of " ::: " (videoid)
- Info(2) = Info(0).Substring(Info(1).Length + 5) ' info(2) = right side of " ::: " (title)
- Browser = CreateObject("InternetExplorer.Application") ' create a new browser object for video to play
- Browser.Visible = False ' ensures browser is not visible
- ' browser navigates to specified url trailed by videoID
- Browser.Navigate("http://tizzyt-archive.blogspot.com/p/blog-page_3.html?" & Info(1))
- ' Annouce that the video(as title) is now playing.
- AddToSend("PRIVMSG " & GetCurrentChan() & " :Now Playing: " & Info(2))
- End If
- End If
- End Sub
- Public Sub New()
- Poller.Interval = 500
- playing = False
- Poller.Start()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment