Recently Added

Notes & Bookmarks

  1. Quasars; power and metrics beyond all comprehension. Staggeringly beautiful information... and very well written.
  2. "I'm sorry. I can't come in today. Religious holiday. The feast of...Maximum Occupancy."pic.twitter.com/mkgxPWfNj2
  3. Verifying myself: I am sgnls on Keybase.io. UJa01G4v3YRJYB1LFjDRSf1Nh0bh1sOykCbq / https://keybase.io/sgnls/sigs/UJa01G4v3YRJYB1LFjDRSf1Nh0bh1sOykCbq
  4. Be sure to take care of your own infrastructure(s); purge dumps, tunnel and lock-down egress transit, encrypt and permission CORRECTLY!
  5. It really doesn't matter what else gets released; Sikth's 'The Future in Whose Eyes?' is THE album of 2017. #albumoftheyear @SikthOfficialpic.twitter.com/P5houdf1yx

Data Extraction from Remote XML Feed (Last.fm)

Updated : 12:18:37pm, 28th Feb 2016

This can be adjusted for anything, really, but was intended (as below) for extraction of data from the Last.fm feeds.

As time has gone on, much of the below has been radically adjusted and improved. Much of it is also superfluous considering the APIs and libraries that will do the same with a lot less work. As such, I have filed this under Projects rather than the KnowledgeBase.

Therefore, this code is only here as an archived note of something that once proved very handy, especially after Twitter removed all XML streams...

if(!isset($_GET)){$_GET = &$HTTP_GET_VARS;}
if(!isset($_POST)){$_POST = &$HTTP_POST_VARS;}
if(isset($_GET)){extract($_GET);}
if(isset($_POST)){extract($_POST);}

# Remote File (rf) Manipulator
# Service ~ last.fm (Recent Tracks)
# http://sgnls.net

# Copyright 2008-2012. You may use and distribute this code as
# long as credit is given, and any amendments do not restrict
# it's continued 'free' distribution and informative value.

# location of rf

$lfm_limit = 6;
$lfm_usr = "decades";

if(!$lfm_usr){
	$lfm_usr = "sgnls";
	$lfm_url = "http://ws.audioscrobbler.com/2.0/user/sgnls/recenttracks.xml";
}
else{
	$lfm_url = "http://ws.audioscrobbler.com/2.0/user/" . $lfm_usr . "/recenttracks.xml";
}

# get data using the file_get_contents function

$lfm_rs = file_get_contents($lfm_url,FALSE);

# perform depending on return ^ add if else / or die

if(!$lfm_rs){
	echo "\t\t\t\t\t\t\t\t
    "; echo "\n\t\t\t\t\t\t\t
  • Feed Unavailable.
  • "; echo "\n\t\t\t\t\t\t\t\t
\n"; } else{ echo "
    "; $remove_header = explode("\">",$lfm_rs,2); $all_data = $remove_header[1]; $trim_data = trim($all_data); $destroy = explode("",$trim_data,$lfm_limit); # dictate result returns $split = array_slice($destroy,0,$lfm_limit); # limit results > array_slice(value, offset, limit) foreach($split as $data){ $hunt = array( "www.", ">http", "(.+?)\<\/artist\>#s", $data, $artist_matches); $clean_artist = $artist_matches[2]; $get_song = preg_match("#\(.+?)\<\/name\>#s", $data, $song_matches); $clean_song = $song_matches[1]; $str_song = str_replace($hunt,$swap,$clean_song); $get_album = preg_match("#\(.+?)\<\/album\>#s", $data, $album_matches); $clean_album = $album_matches[2]; $url_album = str_replace($hunt,$swap,$clean_album); $album_url = "$artist_url/$url_album"; if($clean_album == ""){ $when_album = "by"; } else{ $when_album = "from $clean_album by"; } $get_url = preg_match("#\(.+?)\<\/url\>#s", $data, $url_matches); $clean_url = $url_matches[1]; $url_song = str_replace($hunt,$swap,$clean_url); $get_date = preg_match("#\(.+?)\<\/date\>#s", $data, $date_matches); $got_date = $date_matches[2]; $clean_date = str_replace($hunt_date,$swap_date,$got_date); $get_img_s = preg_match("#\#s", $data, $img_s_matches); $get_img_m = preg_match("#\#s", $data, $img_m_matches); $clean_img_s = $img_s_matches[1]; $clean_img_m = $img_m_matches[1]; $url_img_s = str_replace($hunt,$swap,$clean_img_s); $url_img_m = str_replace($hunt,$swap,$clean_img_m); if($url_img_s == ">" || $url_img_m == ">"){ $img_bg_s = "img/nc_s.png"; $img_bg_m = "img/nc_m.png"; } else{ $img_bg_s = $url_img_s; $img_bg_m = $url_img_m; } $get_song_artist = explode("/",$url_song,6); $got_song_artist = $get_song_artist[4]; $song_artist = str_replace($hunt_song,$swap_song,$got_song_artist); $song_url = str_replace($hunt,$swap,$song_artist); $artist_url = "http://last.fm/music/$got_song_artist"; if($clean_artist == "" && !$clean_date == ""){ $quick_clean_array_h = array("+"); $quick_clean_array_r = array(" "); $quick_clean_artist = str_replace($quick_clean_array_h,$quick_clean_array_r,$got_song_artist); $clean_artist = $quick_clean_artist; } // np if($clean_date == "" || $clean_artist == ""){ // add explode on song url for artist echo "\n\t\t\t\t\t\t\t\t\t
  • Now Playing... $clean_artist ~ '$str_song'
  • "; } else{ // rp echo "\n\t\t\t\t\t\t\t\t\t
  • $clean_date $clean_artist ~ '$str_song'
  • "; } } echo "\n\t\t\t\t\t\t\t\t
\n"; }

Update (Feb 2nd, 2015) : This one is a lot neater, and serves, with tweaking (forthcoming) to achieve consolidation of ALL logged tracks;


‹?php

if(!isset($_GET)){$_GET = &$HTTP_GET_VARS;}
if(!isset($_POST)){$_POST = &$HTTP_POST_VARS;}
if(isset($_GET)){extract($_GET);}
if(isset($_POST)){extract($_POST);}

# Remote File (rf) Manipulator
# Service ~ last.fm (Recent Tracks)
# Author ~ Matt Hill (http://sgnls.net)

# Copyright 2008-2015. You may use and distribute this code as
# long as credit is given, and any amendments do not restrict
# it's continued 'free' distribution and informative value.

# location of rf

## etc...
$hunt = array("+","%27","live"," The"," Is","%3F");
$swap = array(" ","'","Live"," the"," is","?");

if(!$lfm_usr){
	$lfm_usr = "sgnls";
	$lfm_url = "http://ws.audioscrobbler.com/2.0/user/sgnls/recenttracks.xml";
}
else{
	$lfm_url = "http://lastfm.com/user/" . $lfm_usr . "/tracks?view=compact&page=1";
#	$lfm_urlb = "http://lastfm.com/user/" . $lfm_usr . "/tracks?view=compact&page=2";
#	$lfm_urlc = "http://lastfm.com/user/" . $lfm_usr . "/tracks?view=compact&page=3";
#	...
#	$lfm_urld = "http://lastfm.com/user/" . $lfm_usr . "/tracks?view=compact&page=2403";
}

$lfm_rsa = file_get_contents($lfm_url);

	$destroya = explode("‹/tr›",$lfm_rsa,$lfm_limit); # dictate result returns
	$splita = array_slice($destroya,1,$lfm_limit); # limit results › array_slice(value, offset, limit)
		
	echo "‹table cellpadding=\"0\" cellspacing=\"1\"›";
	foreach($splita as $dataa){

  		$get_all = preg_match("#\‹a href=\"(.+?)\"\›(.+?)\‹\/a\›(.+?)\‹a href=\"(.+?)\"(.+?)\›(.+?)\‹\/a\›#s", $dataa, $all_matches);
		$get_date = preg_match("#\‹time datetime=\"(.+?)\"›(.+?)\‹\/time\›#s",$dataa,$got_date);
		
		$get_artist = $all_matches[2];
		$get_url = $all_matches[4];
		$date_str = $got_date[2];

		$get_song = explode("_/",$get_url);
		$got_song = $get_song[1];
		$clean_song = str_replace($hunt,$swap,$got_song);

		$clean_artist = str_replace($swap,$hunt,$get_artist);

		echo "‹tr›‹td width=\"20%\"›‹i›$date_str‹/i›‹/td›
		‹td width=\"35%\"›‹b›‹a href=\"http://last.fm/music/$clean_artist\"›$get_artist‹/a›‹/b›‹/td›
		‹td width=\"45%\"›‹a href=\"http://last.fm$get_url\"›'$clean_song'‹/a›‹/td›‹/tr›";
	
	}

	echo "‹/table›";

?›

SGNLS.net © 2006-2017

Comments, submissions and errors to desk[at]sgnls.net.

Material and content adheres to the Creative Commons (NC-SA 4.0) license.

v12.01151