All pastes #90200 Raw Edit

Stuff

public text v1 · immutable
#90200 ·published 2006-07-17 13:38 UTC
rendered paste body
   Private Function GetURLInPage(ByVal Page As String)

      Page = GetPage(Page)

      Dim r As Regex = New Regex("")
      Dim m As Match
      Dim mc As MatchCollection

      mc = r.Matches(Page, "embed\ssrc\=[\'\""]([^\>\'\""]+)[\'\""]")

      For Each m In mc
         If m.Value <> "" Then
            Dim URL As String
            URL = m.Groups(1).Value()
            If InStr(URL, "youtube.com", CompareMethod.Text) Then
               Dim youTubeID As String
               youTubeID = ""
               Try
                  youTubeID = r.Match(URL, ".*\/([_0-9A-Za-z]+)").Groups(1).Value
               Catch ex As Exception

               End Try
               If youTubeID <> "" Then
                  'do something with the youtube ID

               End If
               'it's a youtube embed, so extract the ID
            End If
         End If
      Next

      'try to find google embedded (they're so cool coz they dont use embed src...
      mc = r.Matches(Page, "http://video\.google\.com/googleplayer\.swf\?[^""'\<\>]+[""']")
      For Each m In mc
         Try
            Dim googleID As String
            googleID = ""
            Try
               googleID = r.Match(m.Value, "playerId\=([\-0-9]+)").Groups(1).Value
            Catch ex As Exception

            End Try
            If googleID <> "" Then
               'omg do something with google ID now!

            End If
         Catch ex As Exception

         End Try
      Next

      'now just get every other type of link possible and check them to see if they end in avi or something?
      'or whether they are links to youtube?
      mc = r.Matches(Page, "href\=[""']([^""'\<\>]+)[""']")
      For Each m In mc
         Dim link As String
         Try
            link = m.Groups(1).Value
            'we now have the link, check if it's a video
            Select Case LCase(Strings.Right(link, 3))
               Case "mov"
               Case "avi"
               Case "mpg"
               Case "mp4"

               Case Else
                  'this link isn't a video
                  link = ""
            End Select
            If link <> "" Then
               Return link
            End If
         Catch ex As Exception

         End Try
      Next
   End Function