You are on page 1of 3

27/9/2019 Get Shoutcast v1/v2 listeners number in VB.

NET | RadioDJ – Free Radio Automation Software

Home Features Download License Support

Get Shoutcast v1/v2 listeners number in VB.NET 0


29 July, 2013-Programming, VB.NET
programming, shoucast, vb.net

Today i was trying to find a solution to grab listeners number from shoutcast servers, but i needed a
something simple and to work with both versions of shoutcast. After a few tests i end up using the shoutcast
generated XML file.

First, i made a class that will hold all members:

Class StreamServer
Public ServerName As String
Public ServerAdress As String
Public ServerPassword As String
Public StreamID As String = 0
Public ListenersCount As Integer

Public Sub New(ByVal sName As String, ByVal sAddress As String, ByVal


sPassword As String, ByVal ServerStreamID As String)
ServerName = sName Search
ServerAdress = sAddress
ServerPassword = sPassword
Type for search
StreamID = ServerStreamID
End Sub

Public Overrides Function ToString() As String Categories


Return ServerName & ": " & ListenersCount
End Function
Awards
End Class
PHP Scripts

Programming
And the function that gets the needed data:
Tutorials

VB.NET
Private Function Get_XMLFile(ByVal ServerID As Integer) As Integer
Dim wcMozilla As New WebClient Video Tutorials
Dim strResponse As String = Nothing

Try
''Add a compatible header
Pages
wcMozilla.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.2; .NET CLR 1.0.3705;)") Cookie Policy

''if we have a StreamID set, we have a shoutcast V2 server Download


If MyServers.Item(ServerID).StreamID > 0 Then
Features List
strResponse =
wcMozilla.DownloadString(MyServers.Item(ServerID).ServerAdress & "/admin.cgi? Frequently Asked Questions
pass=" & MyServers.Item(ServerID).ServerPassword & "&sid=" &
MyServers.Item(ServerID).StreamID & "&mode=viewxml")
Getting Started With RadioDJ
Else License
strResponse =
wcMozilla.DownloadString(MyServers.Item(ServerID).ServerAdress & "/admin.cgi? Screenshots
pass=" & MyServers.Item(ServerID).ServerPassword & "&mode=viewxml")
End If
Recent Posts
Catch ex As WebException
'MsgBox(ex.Message)
Finally Teaser Plugin – How to Setup?

How To Add Hourly Playlists in


End Try
RadioDJ When Using External
If String.IsNullOrEmpty(strResponse) = False Then Music Schedulers?
Try
How to import Internet Streams In
Dim ds As New DataSet
RadioDJ
ds.ReadXml(New StringReader(strResponse), XmlReadMode.Auto)
MyServers.Item(ServerID).ListenersCount = Why Sweepers Are Not Added To
CInt(ds.Tables(0).Rows(0).Item("CURRENTLISTENERS").ToString) The Tracks When A Playlist Is
Catch ex As Exception Generated By Auto DJ?

End Try How to repair a MySQL/MariaDB


Else corrupted database using
MyServers.Item(ServerID).ListenersCount = 0 HeidiSQL?
End If

Return MyServers.Item(ServerID).ListenersCount
End Function

I added a timer that calls the “Get_XMLFile” function every 15 seconds and counts the total listeners, which
is displayed on a label.

This is the entire code:

Imports System.Xml
Imports System.Net
Imports System.Text.RegularExpressions

https://www.radiodj.ro/programming/get-shoutcast-v1v2-listeners-number-in-vb-net.html 1/3
27/9/2019 Get Shoutcast v1/v2 listeners number in VB.NET | RadioDJ – Free Radio Automation Software
Imports System.IO

Public Class Form1

Class StreamServer
Public ServerName As String
Public ServerAdress As String
Public ServerPassword As String
Public StreamID As String = 0
Public ListenersCount As Integer

Public Sub New(ByVal sName As String, ByVal sAddress As String, ByVal


sPassword As String, ByVal ServerStreamID As String)
ServerName = sName
ServerAdress = sAddress
ServerPassword = sPassword
StreamID = ServerStreamID
End Sub

Public Overrides Function ToString() As String


Return ServerName & ": " & ListenersCount
End Function

End Class

Private MyServers As New List(Of StreamServer)


Private ListenerCount As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Dim newServer As New StreamServer("My First Server",
"https://127.0.0.1:8000",
https://127.0.0.1:8000", "changeme", 0)
MyServers.Add(newServer)

newServer = New StreamServer("My Second V2 Server",


"https://127.0.0.1:8050",
https://127.0.0.1:8050", "changeme", 1)
MyServers.Add(newServer)
End Sub

Private Function Get_XMLFile(ByVal ServerID As Integer) As Integer


Dim wcMozilla As New WebClient
Dim strResponse As String = Nothing

Try
''Add a compatible header
wcMozilla.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")

''if we have a StreamID set, we have a shoutcast V2 server


If MyServers.Item(ServerID).StreamID > 0 Then
strResponse =
wcMozilla.DownloadString(MyServers.Item(ServerID).ServerAdress & "/admin.cgi?
pass=" & MyServers.Item(ServerID).ServerPassword & "&sid=" &
MyServers.Item(ServerID).StreamID & "&mode=viewxml")
Else
strResponse =
wcMozilla.DownloadString(MyServers.Item(ServerID).ServerAdress & "/admin.cgi?
pass=" & MyServers.Item(ServerID).ServerPassword & "&mode=viewxml")
End If

Catch ex As WebException
'MsgBox(ex.Message)
Finally

End Try

If String.IsNullOrEmpty(strResponse) = False Then


Try
Dim ds As New DataSet
ds.ReadXml(New StringReader(strResponse), XmlReadMode.Auto)
MyServers.Item(ServerID).ListenersCount =
CInt(ds.Tables(0).Rows(0).Item("CURRENTLISTENERS").ToString)
Catch ex As Exception

End Try
Else
MyServers.Item(ServerID).ListenersCount = 0
End If

Return MyServers.Item(ServerID).ListenersCount
End Function

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick

ListenerCount = 0

For i As Integer = 0 To MyServers.Count - 1


ListenerCount += Get_XMLFile(i).ToString
Next

Me.lbStatus.Text = "Current Listeners: " & ListenerCount.ToString

End Sub
End Class

The only drawnback of this approach is that you need to supply the admin password in order to reach the
shoucast XML.

No comments yet.

https://www.radiodj.ro/programming/get-shoutcast-v1v2-listeners-number-in-vb-net.html 2/3
27/9/2019 Get Shoutcast v1/v2 listeners number in VB.NET | RadioDJ – Free Radio Automation Software

Add a comment
You must be logged in to post a comment.

Recent Articles Categories Older Articles Tags

Teaser Plugin – How to Setup? Awards November 2018 assign Corrupted

How To Add Hourly Playlists in PHP Scripts August 2016 database feeds
RadioDJ When Using External Programming July 2015 instalation install intro MariaDB
Music Schedulers?
How to import Internet Streams In
Tutorials February 2015 mysql overlay php plugin

VB.NET October 2014 podcast programming


RadioDJ
Video Tutorials May 2014 radiodj remote rotations script
Why Sweepers Are Not Added To
February 2014 shoucast sweeper teaser track
The Tracks When A Playlist Is
tracktype type user vb.net WordPress
Generated By Auto DJ? January 2014
How to repair a MySQL/MariaDB December 2013
corrupted database using July 2013
HeidiSQL?
June 2013
May 2013
May 2011
September 2010

https://www.radiodj.ro/programming/get-shoutcast-v1v2-listeners-number-in-vb-net.html 3/3

You might also like