示例#1
0
def UserFavoriteSongsMenu():
    oc = ObjectContainer(title1="Favorite Songs")

    songs = grooveshark.api_call("getUserFavoriteSongs", {})

    for song in songs["result"]["songs"]:
        oc.add(GetTrack(song))

    return oc
示例#2
0
文件: get_id.py 项目: viperfx/gsmx
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
示例#3
0
def SearchArtists(query):
    oc = ObjectContainer(title1="Search - Artists")

    artists = grooveshark.api_call("getArtistSearchResults", {"query": query})

    for artist in artists["result"]["artists"]:
        oc.add(DirectoryObject(key=Callback(SearchArtists, query=query), title=artist["ArtistName"]))  # ArtistID

    oc.add(DirectoryObject(key=Callback(SearchArtists, query=query), title=JSON.StringFromObject(artists)))

    return oc
示例#4
0
文件: views.py 项目: kaitlin/wedding
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)
示例#5
0
文件: views.py 项目: kaitlin/wedding
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})
示例#6
0
文件: get_id.py 项目: viperfx/gsmx
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
    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"
    else:
示例#8
0
def PlayAudio(songID):
    COUNTRY_OBJECT = grooveshark.api_call("getCountry", {})["result"]
    stream_info = grooveshark.api_call("getSubscriberStreamKey", {"songID": songID, "country": COUNTRY_OBJECT})

    return Redirect(stream_info["result"]["url"])