NAME

StreamFinder::SoundCloud - Fetch actual raw streamable URLs from song-entry websites on SoundCloud.com

AUTHOR

This module is Copyright (C) 2023 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

#!/usr/bin/perl

use strict;

use StreamFinder::SoundCloud;

die "..usage:  $0 ID|ID/ID|URL\n"  unless ($ARGV[0]);

my $song = new StreamFinder::SoundCloud($ARGV[0]);

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

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

my $url = $song->getURL();

print "Stream URL=$url\n";

my $songTitle = $song->getTitle();

print "Title=$songTitle\n";

my $songDescription = $song->getTitle('desc');

print "Description=$songDescription\n";

my $songID = $song->getID();

print "Song-ID ID=$songID\n";

my $genre = $song->{'genre'};

print "Genre=$genre\n"  if ($genre);

my $artist = $song->{'artist'};

print "Artist=$artist\n"  if ($artist);

my $album = $song->{'album'};

print "Album (podcast)=$album\n"  if ($album);

my $albumartist = $song->{'albumartist'};

print "Album Artist=$albumartist\n"  if ($albumartist);

my $icon_url = $song->getIconURL();

if ($icon_url) {   #SAVE THE ICON TO A TEMP. FILE:

	my ($image_ext, $icon_image) = $song->getIconData();

	if ($icon_image && open IMGOUT, ">/tmp/${SongID}.$image_ext") {

		binmode IMGOUT;

		print IMGOUT $icon_image;

		close IMGOUT;

	}

}

my $stream_count = $song->count();

print "--Stream count=$stream_count=\n";

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

foreach my $s (@streams) {

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

}

DESCRIPTION

NOTE: Users should also consider StreamFinder::SoundCloud to now be depreciatedand and may be removed in a later StreamFinder release, as they've added cookie and tracker requirements making it impossible to search for songs on their site without enabling, but song URLs (when known) seem to still work for now, but without channel/artist icons. (Privacy-minded individuals should now be cautious while using this site).

StreamFinder::SoundCloud accepts a valid artist-ID/song-ID, artist-ID, or URL on SoundCloud.com and returns the actual stream URL(s), title, and cover art icon. The purpose is that one needs one of these URLs in order to have the option to stream the song in one's own choice of media 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 play. The author uses his own custom all-purpose media player called "fauxdacious" (his custom hacked version of the open-source "audacious" audio player). "fauxdacious" can incorporate this module to decode and play songs from SoundCloud.com. One or more streams can be returned for each song.

WARNING: SoundCloud streams usually EXPIRE VERY QUICKLY, ie. A FEW MINUTES, and become unplayable (403 ERRORS), requiring re-adding to your playlist!

NOTE: SoundCloud REQUIRES youtube-dl / yt-dlp (StreamFinder::Youtube) to extract the actual stream and only returns a SINGLE valid stream URL for a song based on a boilerplate URL based on the author's + song's ID. However, youtube-dl does NOT return the metadata, which we're able to extract here. This may or may NOT work for a given song (particularly non-free / subscription-required songs, ymmv)! NOTE: If just an artist-ID is specified, then the first (latest?) song for that artist will be returned.

StreamFinder::SoundCloud is not capable of returning multisong playlists. You therefore need to specify both an artist-ID and preferrably a song-ID or a SoundCloud URL containing these, NOT a "set" (playlist/group) URL (ie. "https://soundcloud.com/.../set/...", which will not work)!

Depends:

URI::Escape, HTML::Entities, LWP::UserAgent, Streamfinder::Youtube, and the separate application program: youtube-dl, or a compatable program such as yt-dlp.

SUBROUTINES/METHODS

new(ID|ID/ID|url [, -debug [ => 0|1|2 ]])

Accepts a soundcloud.com valid artist-ID/song-ID, artist-ID, or URL and creates and returns a new song object, or undef if the URL is not a valid SoundCloud song or artist, or no streams are found. The URL can be the full URL, ie. https://soundcloud.com/artist-id/song-id, https://soundcloud.com/artist-id, or just artist-id or artist-id/song-id.

Additional options:

Certain youtube-dl (StreamFinder::Youtube) configuration options, namely -format, -formatonly, -youtube-dl-args, and -youtube-dl-add-args can be overridden here by specifying -youtube-format, -youtube-formatonly, -youtube-dl-args, and -youtube-dl-add-args arguments respectively. It is however, recommended to specify these in the SoundCloud-specific configuration file (see CONFIGURATION FILES below.

-log => "logfile"

Specify path to a log file. If a valid and writable file is specified, A line will be appended to this file every time one or more streams is successfully fetched for a url.

DEFAULT -none- (no logging).

-logfmt specifies a format string for lines written to the log file.

DEFAULT "[time] [url] - [site]: [title] ([total])".

The valid field [variables] are: [stream]: The url of the first/best stream found. [site]: The site name (SoundCloud). [url]: The url searched for streams. [time]: Perl timestamp when the line was logged. [title], [artist], [album], [description], [year], [genre], [total], [albumartist]: The corresponding field data returned (or "-na-", if no value).

$song->get()

Returns an array of strings representing all stream URLs found (usually a single one).

$song->getURL([options])

Similar to get() except it only returns a single stream representing the first valid stream found.

$song->count()

Returns the number of streams found for the song.

$song->getTitle(['desc'])

Returns the song's title, or (long description).

$song->getIconURL(['artist'])

Returns the URL for the song's (or artist's) "cover art" icon image, if any. Most SoundCloud artists have their own art-icon.

$song->getIconData(['artist'])

Returns a two-element array consisting of the extension (ie. "png", "gif", "jpeg", etc.) and the actual icon image (binary data), if any.

NOTE: At most recent testing, artist-icons appear to perhaps no longer be downloadable (embedded SVG images) - ymmv.

$song->getImageURL(['artist'])

Returns the URL for the song's (or artist's) "cover art" (usually larger) banner image, if any. NOTE: SoundCloud songs usually do NOT have a larger art image, but most artists DO.

$song->getImageData(['artist'])

Returns a two-element array consisting of the extension (ie. "png", "gif", "jpeg", etc.) and the actual artist's banner image (binary data).

$song->getType()

Returns the station's type ("SoundCloud").

CONFIGURATION FILES

The default root location directory for StreamFinder configuration files is "~/.config/StreamFinder". To use an alternate location directory, specify it in the "STREAMFINDER" environment variable, ie.: $ENV{STREAMFINDER} = "/etc/StreamFinder".

~/.config/StreamFinder/SoundCloud/config

Optional text file for specifying various configuration options for a specific site (submodule). Each option is specified on a separate line in the format below: NOTE: Do not follow the lines with a semicolon, comma, or any other separator. Non-numeric values should be surrounded with quotes, either single or double. Blank lines and lines beginning with a "#" sign as their first non-blank character are ignored as comments.

'option' => 'value' [,]

and the options are loaded into a hash used only by the specific (submodule) specified. Valid options include -debug => [0|1|2] and most of the LWP::UserAgent options.

Options specified here override any specified in ~/.config/StreamFinder/config.

Among options valid for SoundCloud streams are -youtube options described in the new() function. Also, various youtube-dl (StreamFinder::Youtube) configuration options, namely format, formatonly, youtube-dl-args, and youtube-dl-add-args can be overridden here by specifying youtube-format, youtube-formatonly, youtube-dl-args, and youtube-dl-add-args arguments respectively. NOTE: SoundCloud requires youtube-dl or yt-dlp to retrieve any streams!

~/.config/StreamFinder/config

Optional text file for specifying various configuration options. Each option is specified on a separate line in the format below:

'option' => 'value' [,]

and the options are loaded into a hash used by all sites (submodules) that support them. Valid options include -debug => [0|1|2] and most of the LWP::UserAgent options.

NOTE: Options specified in the options parameter list of the new() function will override those corresponding options specified in these files.

KEYWORDS

soundcloud

DEPENDENCIES

URI::Escape, HTML::Entities, LWP::UserAgent

youtube-dl (or yt-dlp, or other compatable program)

RECCOMENDS

wget

BUGS

Please report any bugs or feature requests to bug-streamFinder-soundcloud at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-SoundCloud. 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 StreamFinder::SoundCloud

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2023 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.