Skip to content

Instantly share code, notes, and snippets.

@EricTendian
Created August 12, 2012 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricTendian/3335096 to your computer and use it in GitHub Desktop.
Save EricTendian/3335096 to your computer and use it in GitHub Desktop.
Subsonic song sharing via fbcmd
<?php
// This script posts a song to your Facebook wall.
// Author: Eric Tendian (erict15) erictendian[at]gmail[dot]com
// Last Modified: Aug 12 2012 @ 22:42GMT
// NOTE: Change the REST version (v. 1.8.0) based on Subsonic version. See http://www.subsonic.org/pages/api.jsp for more info.
// server and login info
$user = "username"; //Subsonic username (must have sharing permissions)
$pass = "password"; //Subsonic password
$serverURL = "http://hostname:port"; //Subsonic server URL
//request URLs
$randomSongURL = "/rest/getRandomSongs.view?u=".$user."&p=".$pass."&v=1.8.0&c=fbcmd&size=1";
$shareURL = "/rest/createShare.view?u=".$user."&p=".$pass."&v=1.8.0&c=fbcmd&id=";
$req1 = simplexml_load_string(file_get_contents($serverURL.$randomSongURL)); //get one random song
$songID = $req1->randomSongs->song['id']; //find the ID of song to insert into second command
$req2 = simplexml_load_string(file_get_contents($serverURL.$shareURL.$songID)); //get the share link
$serverURL = "http://hostname:port"; //set to internet address (used when behind router)
//generate post data
$postText = sprintf("Today's song of the day: '%s' by %s\n%s", $req1->randomSongs->song['title'], $req1->randomSongs->song['artist'], $req2->shares->share['url']);
$postName = sprintf("%s - %s", $req1->randomSongs->song['title'], $req1->randomSongs->song['artist']);
$postURL = $req2->shares->share['url'];
//execute the post command, return output
exec(sprintf('/usr/local/bin/fbcmd POST "%s" "%s" "%s"', $postText, $postName, $postURL),$out);
print_r($out);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment