Example #1
0
def main():
    grooveshark.init()
    grooveshark.authenticate_user(YOUR_USERNAME, YOUR_PASSWORD)
    songIDs = []
    songdata = []
    try:
        url = sys.argv[1]
    except:
        print "provide url with trailing slash"
        exit()
    user = url.split("/")[-4]
    mix = url.split("/")[-3]
    mix_id = url.split("/")[-2]
    filename = user + '_' + mix + '_' + mix_id + '.json'
    # check if playlist has been parsed already
    if os.path.isfile(filename) == False:
        proc = subprocess.Popen("scrapy crawl gsmx -a url=%s -o %s -t json" %
                                (url, filename),
                                shell=True)
        return_code = proc.wait()
    # Open json data to get the search queries for tinysong api
    json_data = open(filename)
    data = json.load(json_data)
    json_data.close()
    # if playlist not created already, Iterate through the json file and request the API with the formed query
    if os.path.isfile('playlist_' + filename) == False:
        for item in data:
            query = item['query'].strip('?')
            resp = requests.get(
                'http://tinysong.com/b/%s?format=json&key=0fc107bfb325fdb787d837b406d80d04'
                % (query))
            if resp.json != []:
                print "Found song: %s " % resp.json['SongName']
                songIDs.append(resp.json['SongID'])
                songdata.append(resp.json)
        playlist = open('playlist_' + filename, 'w')
        playlist.write(simplejson.dumps(songdata, indent=4))
        playlist.close()
    else:
        playlist = open('playlist_' + filename, 'r').read()
        # print data
        songdata = simplejson.loads(playlist)
        for item in songdata:
            songIDs.append(item['SongID'])
    print songIDs
    print data[0]['name']
    user_input = raw_input(
        "Do you want to create a playlist on grooveshark? y/n ")
    if user_input == 'y':
        resp = grooveshark.api_call('createPlaylist', {
            'name': data[0]['name'],
            'songIDs': songIDs
        })
        print resp
Example #2
0
def song_search(request):
    try:
        client_ip = request.META['HTTP_X_FORWARDED_FOR']
    except:
        client_ip = request.META['REMOTE_ADDR']
    gs.init()
    search_type = request.GET['search_type']
    search_string = request.GET['search_string']

    results = gs.api_call('get'+search_type+'SearchResults', {'query': search_string, 'country':'USA'}, client_ip)
    r = simplejson.dumps(results['result']['songs'])

    return HttpResponse(client_ip + r)
Example #3
0
def Start():
    Plugin.AddPrefixHandler("/music/grooveshark", Menu, TITLE, ICON, ART)
    # Plugin.AddViewGroup("InfoList", viewMode = "InfoList", mediaType = "items")
    Plugin.AddViewGroup("List", viewMode="List", mediaType="items")

    ObjectContainer.title1 = TITLE
    ObjectContainer.art = R(ART)
    ObjectContainer.view_group = "List"

    DirectoryObject.thumb = R(ICON)
    DirectoryObject.art = R(ART)
    # VideoClipObject.thumb = R(ICON)

    grooveshark.init()
    grooveshark.authenticate_user(Prefs["Username"], Prefs["Password"])
Example #4
0
def main():
	grooveshark.init()
	grooveshark.authenticate_user(YOUR_USERNAME, YOUR_PASSWORD)
	songIDs = []
	songdata = []
	try:
		url = sys.argv[1]
	except:
		print "provide url with trailing slash"
		exit()
	user = url.split("/")[-4]
	mix = url.split("/")[-3]
	mix_id = url.split("/")[-2]
	filename = user+'_'+mix+'_'+mix_id+'.json'
	# check if playlist has been parsed already
	if os.path.isfile(filename) == False:
   		proc = subprocess.Popen("scrapy crawl gsmx -a url=%s -o %s -t json" % (url, filename), shell=True)
		return_code = proc.wait()
	# Open json data to get the search queries for tinysong api
	json_data = open(filename)
	data = json.load(json_data)
	json_data.close()
	# if playlist not created already, Iterate through the json file and request the API with the formed query
	if os.path.isfile('playlist_'+filename) == False:
		for item in data:
			query = item['query'].strip('?')
			resp = requests.get('http://tinysong.com/b/%s?format=json&key=0fc107bfb325fdb787d837b406d80d04' % (query))
			if resp.json != []:
				print "Found song: %s " % resp.json['SongName']
				songIDs.append(resp.json['SongID'])
				songdata.append(resp.json)
		playlist = open('playlist_'+filename, 'w')
		playlist.write(simplejson.dumps(songdata, indent=4))
		playlist.close()
	else:
		playlist = open('playlist_'+filename, 'r').read()
		# print data
		songdata = simplejson.loads(playlist)
		for item in songdata:
			songIDs.append(item['SongID'])
	print songIDs
	print data[0]['name']
	user_input = raw_input("Do you want to create a playlist on grooveshark? y/n ")
	if user_input == 'y':
		resp = grooveshark.api_call('createPlaylist', {'name':data[0]['name'],'songIDs':songIDs})
		print resp
Example #5
0
def add_song(request):
    
    gs.init()
    gs.authenticate_user(GS_USER, GS_PASS)
    songs = gs.api_call('getPlaylistSongs', {'playlistID': PLAYLIST_ID})['result']['songs']
    song_list = []
    for s in songs:
        song_list.append(s['SongID'])


    song_to_add = int(request.GET['SongID'])
    if song_to_add not in song_list:
        song_list.append(song_to_add)
        
        
        update = gs.api_call('setPlaylistSongs', {'playlistID': PLAYLIST_ID, 'songIDs': song_list })

        if update['result']['success'] == 1:
            return render_to_response('songs.html', {'add_success': 1})
        else:
            return render_to_response('songs.html', {'add_success': 0})

    else:
        return render_to_response('songs.html', {'add_success': 2})
def getTrack(query):
    url = "http://ws.spotify.com/search/1/track.json?q=" + urllib.quote(query)
    get = json.load(urllib.urlopen(url))
    res = []

    try:
        res.append(get['tracks'][0]['name'])
        res.append(get['tracks'][0]['artists'][0]['name'])
    except IndexError:
        return res

    return res



gs = grooveshark.init()
call  = grooveshark.api_call('getPlaylistSongs', {'playlistID': '80199741'})
songs = call['result']['songs']
slist = map(lambda x:  [x['SongName'], x['ArtistName']],songs)


for i in slist:
    q = ' '.join(i[::]).encode('ascii', 'ignore')
    print q
    if '(' in i[0] or '[' in i[0]:
        q = i[0].encode('ascii', 'ignore')
    gt = getTrack(q)
    if len(gt) > 0:
        a,b = gt
        print "%s  %s" % (a,b)
        print "\n"