Skip to content

Instantly share code, notes, and snippets.

@tcz
Last active July 26, 2016 02:14
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tcz/7412631 to your computer and use it in GitHub Desktop.
Save tcz/7412631 to your computer and use it in GitHub Desktop.
Copy Hypem favorites to Spotify
<?php
if ($argc !== 2)
{
die("Usage: php {$argv[0]} hypem_user_name\n\n");
}
$user = $argv[1];
$page = 1;
$all_songs = array();
do
{
$json = @file_get_contents("http://hypem.com/playlist/loved/$user/json/$page/data.js");
$object = json_decode($json, true);
$page_songs = array();
$index = 0;
while (isset($object[$index]))
{
$page_songs[] = $object[$index]['artist'] . " " . $object[$index]['title'];
$index++;
}
$page++;
$all_songs = array_merge($all_songs, $page_songs);
} while(count($page_songs));
$spotify_hrefs = array();
foreach ($all_songs as $song)
{
$json = @file_get_contents("https://api.spotify.com/v1/search?type=track&q=".urlencode($song));
$object = json_decode($json, true);
if (empty($object["tracks"]["items"]))
{
echo "$song not found.\n";
continue;
}
$spotify_hrefs[] = $object["tracks"]["items"][0]["uri"];
}
echo "\nFound " . count($spotify_hrefs) . " songs out of " . count($all_songs) . ".\n\n";
echo "1. Select a playlist in Spotify\n2. Copy and paste the following:\n\n";
echo implode("\n", $spotify_hrefs);
echo "\n\n";
@tcz
Copy link
Author

tcz commented Nov 11, 2013

Usage:

php hypem.php hypem_user_name

@oimctony
Copy link

oimctony commented Aug 6, 2014

works like a charm. ( for all the songs Spotify have in DB.)

@TP18
Copy link

TP18 commented Aug 14, 2014

works great. now Spotify just needs to add a delete duplicates button, so i can run this more often. ;)

@gardnersmitha
Copy link

Ran today and no songs on Spotify were found - wondering if they're changed the format and no results are being returned from Spotify query?

@jesse-c
Copy link

jesse-c commented Nov 7, 2014

I just ran it and it was fine.

@fitzmaro
Copy link

Complete newbie to this; how would I go about running this? Desperate but it appears that @jesse-c got it working not long ago..

@jesse-c
Copy link

jesse-c commented Jan 22, 2015

@fitzmaro, you need a machine running PHP to execute the script. PHP can be easily installed on your local machine or if you already have a server somewhere with it, you can use that.

To execute it you run this command on a machine that has PHP:

php hypem.php hypem_user_name

This will then output some text that you can copy/paste into a playlist in Spotify. If you want to save the output of the script to a file, run a command like this:

php hypem.php hypem_user_name > favourites.txt

@oradcliffe
Copy link

Is there a way to get this to work with Google Play?

@mshelman12
Copy link

Can someone please give a step by step here? Would love to be able do this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment