Permalink
Browse files

Fixing invoke, fixing ordering.

  • Loading branch information...
1 parent b9ae7e6 commit a7b5f9c991ffedd2a0d5f53d4ac3626c0d469545 @sjlu committed Jan 25, 2012
Showing with 62 additions and 5 deletions.
  1. +44 −0 invoke.php
  2. +18 −5 itunes-to-rdio.php
View
@@ -0,0 +1,44 @@
+<?php
+
+$playlist_sync = array();
+
+// YOU CAN EDIT THIS SECTION
+$playlist_sync[] = array('rdio_playlist_id' => 526420, 'itunes_url' => 'http://itunes.apple.com/us/rss/topsongs/limit=100/explicit=true/json'); // top songs us
+$playlist_sync[] = array('rdio_playlist_id' => 526666, 'itunes_url' => 'http://itunes.apple.com/us/rss/topsongs/limit=100/genre=18/explicit=true/json'); // top hip-hop/rap us
+$playlist_sync[] = array('rdio_playlist_id' => 526674, 'itunes_url' => 'http://itunes.apple.com/us/rss/topsongs/limit=100/genre=14/explicit=true/json'); // pop
+$playlist_sync[] = array('rdio_playlist_id' => 526679, 'itunes_url' => 'http://itunes.apple.com/us/rss/topsongs/limit=100/genre=20/explicit=true/json'); // alternative
+$playlist_sync[] = array('rdio_playlist_id' => 526683, 'itunes_url' => 'http://itunes.apple.com/us/rss/topsongs/limit=100/genre=21/explicit=true/json'); // rock
+
+// DO NOT EDIT PAST HERE
+require_once 'config.php';
+require_once 'rdio/php/rdio.php';
+
+$rdio = new Rdio(array(RDIO_KEY, RDIO_SECRET));
+
+if (file_exists('.session.json'))
+{
+ $session = json_decode(file_get_contents('.session.json'), true);
+ $rdio->token = array($session['token'], $session['secret']);
+}
+
+if (empty($session))
+{
+ $url = $rdio->begin_authentication('oob');
+ print "Please go to the following URL.\n";
+ print "$url\n\n";
+ print "Please enter the code it provides: ";
+ $verifier = trim(fgets(STDIN));
+ $rdio->complete_authentication($verifier);
+
+ $session['token'] = $rdio->token[0];
+ $session['secret'] = $rdio->token[1];
+
+ $file = fopen('.session.json', 'w');
+ fwrite($file, json_encode($session));
+ fclose($file);
+}
+
+foreach ($playlist_sync as $playlist)
+ exec('php ' . dirname(__FILE__) . '/itunes-to-rdio.php ' . $playlist['rdio_playlist_id'] . ' ' . $playlist['itunes_url'] . ' &');
+
+?>
View
@@ -2,6 +2,12 @@
require_once 'config.php';
require_once 'rdio/php/rdio.php';
+if (empty($argv[1]) || empty($argv[2]))
+ die("Usage: php itunes-to-rdio.php <Rdio Playlist ID> <iTunes URL>\n");
+
+$rdio_playlist_id = $argv[1];
+$itunes_url = $argv[2];
+
// STEP 1: LOGIN TO RDIO
// We need to authenticate to Rdio before we
// can move on with the rest of our script.
@@ -31,7 +37,7 @@
}
// STEP 2: Checking if user has that playlist.
-$playlist_id = 'p'.RDIO_PLAYLIST_ID;
+$playlist_id = 'p'.$rdio_playlist_id;
$playlists = $rdio->call('getPlaylists')->result->owned;
$has_playlist = false;
@@ -49,7 +55,7 @@
// STEP 3: Now we grab the iTunes data!
// And try to find it on Rdio!
-$itunes = file_get_contents(ITUNES_URL);
+$itunes = file_get_contents($itunes_url);
$itunes = json_decode($itunes, true);
$add_songs = array();
@@ -122,15 +128,22 @@
echo "\nAdding songs to Rdio Playlist: " . $playlist_id;
// STEP 5: Adding all the songs into the playlist.
+foreach ($add_songs as $song)
+ $rdio->call('addToPlaylist', array(
+ "playlist" => $playlist_id,
+ "tracks" => $song
+ ));
+
+/*
$rdio->call('addToPlaylist', array(
"playlist" => $playlist_id,
"tracks" => implode(",", $add_songs)
));
-$rdio->call('setPlaylistOrder', array( // for some reason adding does not set order.
+print_r($rdio->call('setPlaylistOrder', array( // for some reason adding does not set order.
"playlist" => $playlist_id,
"tracks" => implode(",", $add_songs)
-));
-
+)));
+*/
echo "\n";
?>

0 comments on commit a7b5f9c

Please sign in to comment.