How can I make a script to recover my Grooveshark playlists now that the service has been shut down?

Peque picture Peque · May 8, 2015 · Viewed 12k times · Source

The Grooveshark music streaming service has been shut down without previous notification. I had many playlists that I would like to recover (playlists I made over several years).

Is there any way I could recover them? A script or something automated would be awesome.

Answer

Peque picture Peque · May 8, 2015

Update [2018-05-11]

Three years have passed since this answer was posted and it seems this script no longer works. If you are still in need to recover your old Grooveshark playlists, it might not be possible anymore. Good luck and, if you find a way to do it, share it here! I will be happy to accept your answer instead. :-)


I made a script that will try to find all the playlists made by the user and download them in an output directory as CSV files. It is made in Python.

  • You must just pass your username as parameter to the script (i.e. python pysharkbackup.py "my_user_name"). Your email address should work as well (the one you used for registering in Grooveshark).
  • The output directory is set by default to ./pysharkbackup_$USERNAME.

Here is the script:

#!/bin/python

import os
import sys
import csv
import argparse
import requests


URI = 'http://playlist.fish/api'

description = 'Download your Grooveshark playlists as CSV.'
parser = argparse.ArgumentParser(description = description)
parser.add_argument('USER', type=str, help='Grooveshar user name')
args = parser.parse_args()
user = args.USER

with requests.Session() as session:
    # Login as user
    data = {'method': 'login', 'params': {'username': user}}
    response = session.post(URI, json=data).json()
    if not response['success']:
        print('Could not login as user "%s"! (%s)' %
              (user, response['result']))
        sys.exit()

    # Get user playlists
    data = {'method': 'getplaylists'}
    response = session.post(URI, json=data).json()
    if not response['success']:
        print('Could not get "%s" playlists! (%s)' %
              (user, response['result']))
        sys.exit()

    # Save to CSV
    playlists = response['result']
    if not playlists:
        print('No playlists found for user %s!' % user)
        sys.exit()
    path = './pysharkbackup_%s' % user
    if not os.path.exists(path):
        os.makedirs(path)
    for p in playlists:
        plid = p['id']
        name = p['n']
        data = {'method': 'getPlaylistSongs', 'params': {'playlistID': plid}}
        response = session.post(URI, json=data).json()
        if not response['success']:
            print('Could not get "%s" songs! (%s)' %
                  (name, response['result']))
            continue
        playlist = response['result']
        f = csv.writer(open(path + '/%s.csv' % name, 'w'))
        f.writerow(['Artist', 'Album', 'Name'])
        for song in playlist:
            f.writerow([song['Artist'], song['Album'], song['Name']])