Discussion:
[Icecast] Custom Hooks
Alex Hackney
2018-11-02 23:41:30 UTC
Permalink
I am looking for a way that I can use to send a hook to my api when
particular things happen.

For instance, i need to know when listeners or sources connect or
disconnect and when song meta data changes on a stream.

I see this data on the log and can write a script to do it by monitoring
the log but does icecast have a better way?

Almost looks like the auth block could do it but I don't want to prompt
listeners for a login.

Thanks
Thomas B. Rücker
2018-11-04 11:57:48 UTC
Permalink
Post by Alex Hackney
I am looking for a way that I can use to send a hook to my api when
particular things happen.
For instance, i need to know when listeners or sources connect or
disconnect and when song meta data changes on a stream.
I see this data on the log and can write a script to do it by
monitoring the log but does icecast have a better way?
Almost looks like the auth block could do it but I don't want to
prompt listeners for a login.
That's actually how you do it. You use the URL-auth backend and always
return positive authentication.

Please make sure that you are running version 2.4.4 though. Older
versions have a security issue in the URL-auth code!

Cheers,

TBR
Alex Hackney
2018-11-07 13:08:04 UTC
Permalink
When I stream with winamp, it appears to ask for a username and password
Everytime. If I just set the return to true no matter what, will it prevent
the client from asking for a password?
Post by Thomas B. Rücker
Post by Alex Hackney
I am looking for a way that I can use to send a hook to my api when
particular things happen.
For instance, i need to know when listeners or sources connect or
disconnect and when song meta data changes on a stream.
I see this data on the log and can write a script to do it by
monitoring the log but does icecast have a better way?
Almost looks like the auth block could do it but I don't want to
prompt listeners for a login.
That's actually how you do it. You use the URL-auth backend and always
return positive authentication.
Please make sure that you are running version 2.4.4 though. Older
versions have a security issue in the URL-auth code!
Cheers,
TBR
_______________________________________________
Icecast mailing list
http://lists.xiph.org/mailman/listinfo/icecast
Philipp Schafft
2018-11-07 14:38:24 UTC
Permalink
Good afternoon,
Post by Alex Hackney
When I stream with winamp, it appears to ask for a username and password
Everytime. If I just set the return to true no matter what, will it prevent
the client from asking for a password?
This sounds like there is a configuration problem. Icecast by itself
does not send a 401 without a negative reply from the server (or a
backend failure).

Maybe you can share your <mount> block (with passwords removed (if any))
with us?

Please also check your error.log for any problems. Related lines should
include "auth" somewhere in them.

With best regards,
Post by Alex Hackney
Post by Thomas B. Rücker
Post by Alex Hackney
I am looking for a way that I can use to send a hook to my api when
particular things happen.
For instance, i need to know when listeners or sources connect or
disconnect and when song meta data changes on a stream.
I see this data on the log and can write a script to do it by
monitoring the log but does icecast have a better way?
Almost looks like the auth block could do it but I don't want to
prompt listeners for a login.
That's actually how you do it. You use the URL-auth backend and always
return positive authentication.
Please make sure that you are running version 2.4.4 though. Older
versions have a security issue in the URL-auth code!
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschrÀnkt) Registration number:
Bickinger Straße 21 HRB 12308 CB
04916 Herzberg (Elster) VATIN/USt-ID:
Germany DE305133015
Alex Hackney
2018-11-08 17:45:33 UTC
Permalink
I actually got this to work this morning finally. The problem was on my
auth server.

I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?

Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.


Alex
Post by Philipp Schafft
Good afternoon,
Post by Alex Hackney
When I stream with winamp, it appears to ask for a username and password
Everytime. If I just set the return to true no matter what, will it prevent
the client from asking for a password?
This sounds like there is a configuration problem. Icecast by itself
does not send a 401 without a negative reply from the server (or a
backend failure).
Maybe you can share your <mount> block (with passwords removed (if any))
with us?
Please also check your error.log for any problems. Related lines should
include "auth" somewhere in them.
With best regards,
Post by Alex Hackney
Post by Thomas B. Rücker
Post by Alex Hackney
I am looking for a way that I can use to send a hook to my api when
particular things happen.
For instance, i need to know when listeners or sources connect or
disconnect and when song meta data changes on a stream.
I see this data on the log and can write a script to do it by
monitoring the log but does icecast have a better way?
Almost looks like the auth block could do it but I don't want to
prompt listeners for a login.
That's actually how you do it. You use the URL-auth backend and always
return positive authentication.
Please make sure that you are running version 2.4.4 though. Older
versions have a security issue in the URL-auth code!
_______________________________________________
Icecast mailing list
http://lists.xiph.org/mailman/listinfo/icecast
Philipp Schafft
2018-11-09 09:53:44 UTC
Permalink
Good morning,
Post by Alex Hackney
I actually got this to work this morning finally. The problem was on my
auth server.
Perfect. :)
Post by Alex Hackney
I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?
No. The auth happens long before the client is attached to any source.
In fact in Icecast 2.5.x the auth backend can even redirect the client
to other resources.
Post by Alex Hackney
Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.
There currently isn't one. For 2.5.x there already is a ticket[0] for
that.

What you can do is polling the status XML. You can also use the STATS
interface[1]. Also there is the playlist log. You can watch and follow
that file to see when updates are made.

With best regards,



[0] https://gitlab.xiph.org/xiph/icecast-server/issues/2189
[1] Try it with: wget -qO - --method=STATS
http://admin:***@icecast.example.org:8000/
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschrÀnkt) Registration number:
Bickinger Straße 21 HRB 12308 CB
04916 Herzberg (Elster) VATIN/USt-ID:
Germany DE305133015
Jake
2018-11-09 09:56:04 UTC
Permalink
Couldn't you also just have a client stream locally from icecast that can do things on metadata change? I mean it's a bit icky but it'd work.

---- Philipp Schafft wrote ----
Post by Philipp Schafft
Good morning,
Post by Alex Hackney
I actually got this to work this morning finally. The problem was on my
auth server.
Perfect. :)
Post by Alex Hackney
I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?
No. The auth happens long before the client is attached to any source.
In fact in Icecast 2.5.x the auth backend can even redirect the client
to other resources.
Post by Alex Hackney
Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.
There currently isn't one. For 2.5.x there already is a ticket[0] for
that.
What you can do is polling the status XML. You can also use the STATS
interface[1]. Also there is the playlist log. You can watch and follow
that file to see when updates are made.
With best regards,
[0] https://gitlab.xiph.org/xiph/icecast-server/issues/2189
[1] Try it with: wget -qO - --method=STATS
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92
Bickinger Straße 21 HRB 12308 CB
Germany DE305133015
_______________________________________________
Icecast mailing list
http://lists.xiph.org/mailman/listinfo/icecast
Philipp Schafft
2018-11-09 10:09:53 UTC
Permalink
Good morning,
Post by Jake
Couldn't you also just have a client stream locally from icecast that
can do things on metadata change? I mean it's a bit icky but it'd
work.
If you know any player that can do things on metadata change and works
for the given setup: sure. Why not?

The main downside of this is that it may require a little bit more setup
and requires more resources as the player will likely decode the actual
stream as well.

With best regards,
Post by Jake
---- Philipp Schafft wrote ----
Post by Philipp Schafft
Good morning,
Post by Alex Hackney
I actually got this to work this morning finally. The problem was on my
auth server.
Perfect. :)
Post by Alex Hackney
I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?
No. The auth happens long before the client is attached to any source.
In fact in Icecast 2.5.x the auth backend can even redirect the client
to other resources.
Post by Alex Hackney
Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.
There currently isn't one. For 2.5.x there already is a ticket[0] for
that.
What you can do is polling the status XML. You can also use the STATS
interface[1]. Also there is the playlist log. You can watch and follow
that file to see when updates are made.
With best regards,
[0] https://gitlab.xiph.org/xiph/icecast-server/issues/2189
[1] Try it with: wget -qO - --method=STATS
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92
Bickinger Straße 21 HRB 12308 CB
Germany DE305133015
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschrÀnkt) Registration number:
Bickinger Straße 21 HRB 12308 CB
04916 Herzberg (Elster) VATIN/USt-ID:
Germany DE305133015
jake
2018-11-09 10:53:48 UTC
Permalink
Yeah it is a tad gross but here is my first (and probably only) attempt:

---------------- 8< ----------------
#!/bin/bash

pipe=/tmp/testpipe

trap "rm -f $pipe" EXIT

if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi

mplayer -slave -playlist "http://my.icecast.stream/music" >
/tmp/testpipe 2> /dev/null &

while true
do
if read line <$pipe; then
echo $line
/bin/dothing "$line"
fi
done

echo "Reader exiting"
---------------- 8< ----------------

Basically use mplayer to stream, redirecting its output to a named pipe.
Then, read line on the pipe for ever, once a line comes in echo it and
call /bin/dothing "$line", then go back to read line.

The script is basic and would need a little work to ignore all lines
that don't start with "ICY Info: " since the output is something like:

---------------- 8< ----------------
Resolving my.icecast.stream for AF_INET6...
Resolving my.icecast.stream for AF_INET...
Connecting to server my.icecast.stream: 80...

Name : name
Genre : Misc
Website: http://savonet.sf.net
Public : yes
Cache size set to 320 KBytes

ICY Info: StreamTitle='Regurgitator - ! (The Song Formerly Known As)';
ICY Info: StreamTitle='Queens of the Stone Age - Walkin' On The
Sidewalks';
ICY Info: StreamTitle='foo - bar';
ICY Info: StreamTitle='Another Metadata Change';
...
...
...
...
---------------- 8< ----------------

but yeah something like this might work fine until a better solution
comes along.

Jake

~
Post by Philipp Schafft
Good morning,
Post by Jake
Couldn't you also just have a client stream locally from icecast that
can do things on metadata change? I mean it's a bit icky but it'd
work.
If you know any player that can do things on metadata change and works
for the given setup: sure. Why not?
The main downside of this is that it may require a little bit more setup
and requires more resources as the player will likely decode the actual
stream as well.
With best regards,
Post by Jake
---- Philipp Schafft wrote ----
Post by Philipp Schafft
Good morning,
Post by Alex Hackney
I actually got this to work this morning finally. The problem was on my
auth server.
Perfect. :)
Post by Alex Hackney
I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?
No. The auth happens long before the client is attached to any source.
In fact in Icecast 2.5.x the auth backend can even redirect the client
to other resources.
Post by Alex Hackney
Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.
There currently isn't one. For 2.5.x there already is a ticket[0] for
that.
What you can do is polling the status XML. You can also use the STATS
interface[1]. Also there is the playlist log. You can watch and follow
that file to see when updates are made.
With best regards,
[0] https://gitlab.xiph.org/xiph/icecast-server/issues/2189
[1] Try it with: wget -qO - --method=STATS
--
Philipp Schafft (CEO/Geschäftsführer)
Telephon: +49.3535 490 17 92
Bickinger Straße 21 HRB 12308 CB
Germany DE305133015
_______________________________________________
Icecast mailing list
http://lists.xiph.org/mailman/listinfo/icecast
Philipp Schafft
2018-11-09 11:19:43 UTC
Permalink
Good Afternoon,
See a few comments inline. :)
Post by jake
---------------- 8< ----------------
#!/bin/bash
pipe=/tmp/testpipe
There are tools to make tempfiles such as mktemp(1). You can also
consider using $$.
Post by jake
trap "rm -f $pipe" EXIT
if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi
mplayer -slave -playlist "http://my.icecast.stream/music" >
/tmp/testpipe 2> /dev/null &
I'm not sure if this is the way to go, reading it's stdout that is. The
use of -slave is already a big step. Please also note the comments on
-playlist's safety.
Post by jake
while true
do
if read line <$pipe; then
echo $line
/bin/dothing "$line"
fi
done
Is there a reason you did not try somthing like this (more classic
pattern)?

while read line
do
printf "%s" "$line"
/bin/dothing "$line"
done < "$pipe"
Post by jake
echo "Reader exiting"
---------------- 8< ----------------
Basically use mplayer to stream, redirecting its output to a named pipe.
Then, read line on the pipe for ever, once a line comes in echo it and
call /bin/dothing "$line", then go back to read line.
The script is basic and would need a little work to ignore all lines
---------------- 8< ----------------
Resolving my.icecast.stream for AF_INET6...
Resolving my.icecast.stream for AF_INET...
Connecting to server my.icecast.stream: 80...
Name : name
Genre : Misc
Website: http://savonet.sf.net
Public : yes
Cache size set to 320 KBytes
ICY Info: StreamTitle='Regurgitator - ! (The Song Formerly Known As)';
ICY Info: StreamTitle='Queens of the Stone Age - Walkin' On The
Sidewalks';
ICY Info: StreamTitle='foo - bar';
ICY Info: StreamTitle='Another Metadata Change';
...
...
...
...
---------------- 8< ----------------
I think the problem here is that mplayer does provide the metadata in
different formats depending on wich part does provide them and how it
provides them. So the format will be different for different streams.
Post by jake
but yeah something like this might work fine until a better solution
comes along.
Thank you for sharing your concept with the list.

With best regards,
Post by jake
Post by Philipp Schafft
Good morning,
Post by Jake
Couldn't you also just have a client stream locally from icecast that
can do things on metadata change? I mean it's a bit icky but it'd
work.
If you know any player that can do things on metadata change and works
for the given setup: sure. Why not?
The main downside of this is that it may require a little bit more setup
and requires more resources as the player will likely decode the actual
stream as well.
With best regards,
Post by Jake
---- Philipp Schafft wrote ----
Post by Philipp Schafft
Good morning,
Post by Alex Hackney
I actually got this to work this morning finally. The problem was on my
auth server.
Perfect. :)
Post by Alex Hackney
I see the source auth hook being sent a lot, is there anyway to get the
current metadata in that hook?
No. The auth happens long before the client is attached to any source.
In fact in Icecast 2.5.x the auth backend can even redirect the client
to other resources.
Post by Alex Hackney
Ideally, every time the source is updated, I'd like to get a hook so I
can track the songs that are being played. Alternatively, the only way I
can see doing it, is to make a get request every X seconds and watch for
the song to change.
There currently isn't one. For 2.5.x there already is a ticket[0] for
that.
What you can do is polling the status XML. You can also use the STATS
interface[1]. Also there is the playlist log. You can watch and follow
that file to see when updates are made.
With best regards,
[0] https://gitlab.xiph.org/xiph/icecast-server/issues/2189
[1] Try it with: wget -qO - --method=STATS
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschrÀnkt) Registration number:
Bickinger Straße 21 HRB 12308 CB
04916 Herzberg (Elster) VATIN/USt-ID:
Germany DE305133015
Paul Martin
2018-11-09 16:48:18 UTC
Permalink
Post by Philipp Schafft
Post by jake
pipe=/tmp/testpipe
There are tools to make tempfiles such as mktemp(1). You can also
consider using $$.
Post by jake
mkfifo $pipe
mktemp makes actual files, not pipes/fifos.
--
Paul Martin <***@nowster.me.uk>
Philipp Schafft
2018-11-10 09:54:21 UTC
Permalink
Good morning,
Post by Paul Martin
Post by Philipp Schafft
Post by jake
pipe=/tmp/testpipe
There are tools to make tempfiles such as mktemp(1). You can also
consider using $$.
Post by jake
mkfifo $pipe
mktemp makes actual files, not pipes/fifos.
That is true unless -u is given. That just selects a unique name for
you. This is still an unsafe operation but much safer.

You should also consider setting -e or using something like:
mkfifo "$pipe" || exit 1;

That will at least terminate the script in case the file already exists
and will not write things to it.

With best regards,
--
Philipp Schafft (CEO/GeschÀftsfÌhrer)
Telephon: +49.3535 490 17 92

Löwenfelsen UG (haftungsbeschrÀnkt) Registration number:
Bickinger Straße 21 HRB 12308 CB
04916 Herzberg (Elster) VATIN/USt-ID:
Germany DE305133015
Fred Gleason
2018-11-09 12:14:51 UTC
Permalink
Post by Philipp Schafft
If you know any player that can do things on metadata change and works
for the given setup: sure. Why not?
I know of at least one:

https://github.com/RadioFreeAsia/GlassPlayer

Which can be invoked so as to output received metadata synchronously on STDOUT in a well-defined format. The intended use cases are things like event cueing such as is used in classic radio broadcast applications. The metadata is derived from the actual received bitstream —i.e. no mucking about with polling the administrative interface — so good timing accuracy can be maintained.

Cheers!


|----------------------------------------------------------------------|
| Frederick F. Gleason, Jr. | Chief Developer |
| | Paravel Systems |
|----------------------------------------------------------------------|
| A room without books is like a body without a soul. |
| -- Cicero |
|----------------------------------------------------------------------|
Continue reading on narkive:
Loading...