Jim Turner

NAME

IHeartRadio::Streams - Fetch actual raw streamable URLs from radio-station websites on IHeartRadio.com

AUTHOR

This module is Copyright (C) 2017 by

Jim Turner, <turnerjw784 at yahoo.com>

Email: turnerjw784@yahoo.com

All rights reserved.

You may distribute this module under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

SYNOPSIS

        use strict;

        use IHeartRadio::Streams;

        my $station = new IHeartRadio::Streams(<url>);

        die "Invalid URL or no streams found!\n"  unless ($station);

        my @streams = $station->get();

        my $first = $station->get();

        my $best = $station->getBest();

        print "Best stream URL=".$best->{'Url'}."\n";

        my $besturl = $station->getBest('Url');

        my $stationTitle = $station->getStationTitle();
        
        print "Best stream URL=$besturl, Title=$stationTitle\n";

        my @allfields = $station->validFields();

        for (my $i=0; $i<$station->count(); $i++) {

                foreach my $field (@allfields) {

                        print "--$field: ".$streams[$i]->{$field}."\n";

                }

        }
        

DESCRIPTION

IHeartRadio::Streams accepts a valid radio station URL on http://iheart.com and returns the urls and other information properties for the actual stream URLs available for that station. The purpose is that one needs one of these URLs in order to have the option to stream the station in one's own choice of audio player software rather than using their web browser and accepting any / all flash, ads, javascript, cookies, trackers, web-bugs, and other crapware that can come with that method of playing. The author uses his own custom all-purpose audio player called "fauxdacious" (his custom hacked version of the open-source "audacious" media player. "fauxdacious" incorporates this module to decode and play iheart.com streams.

One or more streams can be returned for each station. The available properties for each stream returned are normally: Bandwidth, HasPlaylist (1|0), MediaType (ie. MP3, AAC, etc.), Reliability (1-100), StreamId (numeric), Type (ie. Live) and Url.

EXAMPLES

        #!/usr/bin/perl

        use strict;

        use IHeartRadio::Streams;

        my $wbap = new IHeartRadio::Streams('https://www.iheart.com/live/news-talk-820-5350/',
                        'secure_shoutcast', 'secure', 'any', '!rtmp');

        die "Invalid URL or no streams found!\n"  unless ($wbap);

        my $streamurl = $wbap->getStream();  #OR:  $wbap->get('stream');

        my $stationname = $wbap->getStationTitle();  #OR: $wbap->get('title');

        my $stationid = $wbap->getStationID();  #OR:  $wbap->get('id');

        my $stationcallletters = $wbap->getFccID();  #OR: $wbap->get('fccid');

        my @allfields = $wbap->validFields();

        my $stationdata = $wbap->get();
        
        print "--$stationid ($stationcallletters): name=$stationname stream=$streamurl\n==========\n";

        foreach my $field (@allfields) {

                print "--$field: ".$stationdata->{$field}."\n";

        }

        print "=========\n";

        my @streamlist = $wbap->get('streams');

        foreach my $stream (@streamlist) {

                print "--stream=$stream\n";

        }

This would print:

--5350 (WBAP-AM): name=Dallas' WBAP - News Talk 820 stream=https://17263.live.streamtheworld.com:443/WBAPAMAAC_SC

==========

--cnt: 6

--fccid: WBAP-AM

--iconurl: https://iscale.iheart.com/catalog/live/5350?ops=fit(100%2C100)

--id: 5350

--imageurl: https://iscale.iheart.com/catalog/live/5350

--plsid: WBAPAMAAC

--streams: ARRAY(0x80c466a8)

--streamtype: secure_pls_stream

--streamurl: https://playerservices.streamtheworld.com/pls/WBAPAMAAC.pls

--title: Dallas' WBAP - News Talk 820

=========

--stream=https://17523.live.streamtheworld.com:443/WBAPAMAAC_SC

--stream=https://16143.live.streamtheworld.com:443/WBAPAMAAC_SC

--stream=https://18653.live.streamtheworld.com:443/WBAPAMAAC_SC

--stream=https://17483.live.streamtheworld.com:443/WBAPAMAAC_SC

--stream=https://17263.live.streamtheworld.com:443/WBAPAMAAC_SC

--stream=https://19293.live.streamtheworld.com:443/WBAPAMAAC_SC

SUBROUTINES/METHODS

new(url [, streamtype... ] )

Accepts an iheart.com URL and creates and returns a new station object, or undef if the URL is not a valid iHeartRadio station or no streams are found.

The optional streamtype can be one of: any, secure, secure_pls, pls, secure_hls, hls, secure_shortcast, shortcast, secure_rtmp, rtmp, etc. More than one value can be specified to control order of search. A streamtype can be preceeded by an exclamantion point ("!") to reject that type of stream.

For example, the list: 'secure_shoutcast', 'secure', 'any', '!rtmp' would try to find a "secure_shoutcast" (https) shortcast stream, if none found, would then look for any secure (https) stream, failing that, would look for any valid stream (http or https). All the while skipping any that are "rtmp" streams. Searching stops when a stream matching the criteria is found.

$station->get([property])

Returns the value for the property or a hash reference to all the properties. If the property is 'stream' then either a randomly-selected stream from the list of valid streams is returned or an array of all the valid streams (depending on context). If the property is 'streams' then either an array or an array reference to all the valid streams (depending on context).

$station->getStream([ [stream-index] ])

Similar to get('stream') except it returns a single stream from the list corresponding to the numeric [stream-index] position in the list. If negative, then indexed from the last position in the list. If out of bounds, then either the first element (if negative) or last (if positive).

If [stream-index] is not specified, a random index value is used and thus a random (but valid) stream url is returned.

$station->count()

Returns the number of streams found for the station.

$station->validFields()

Returns an array containing all the valid property names found. This list is normally: (cnt, fccid, plsid, iconurl, imageurl, stream, streams, and streamurl). These can be used in the get functions and as the keys in the hash references returned to fetch the corresponding property values.

$station->getStationID()

Returns the station's IHeartRadio ID, for eample, the station: 'https://www.iheart.com/live/news-talk-820-5350/' would return "5350".

$station->getStationTitle()

Returns the station's title (description). for eample, the station: 'https://www.iheart.com/live/news-talk-820-5350/' would return: "Dallas' WBAP - News Talk 820".

$station->getIconURL()

Returns the url for the station's "cover art" icon image.

$station->getImageURL()

Returns the url for the station's IHeartRadio site's banner image.

KEYWORDS

iheartradio iheart

DEPENDENCIES

LWP::Simple

BUGS

Please report any bugs or feature requests to bug-iheartradio-streams at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IHeartRadio-Streams. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc IHeartRadio::Streams

You can also look for information at:

ACKNOWLEDGEMENTS

The idea for this module came from a Python script that does this same task named "getstream", but I wanted a Perl module that could be called from within another program! I do not know the author of getstream.py.

LICENSE AND COPYRIGHT

Copyright 2017 Jim Turner.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.