Post Reply

Create playlist based on Thumbs Up playlist??

25th June 2014, 03:47 AM   |  #1  
OP Junior Member
Thanks Meter: 3
 
13 posts
Join Date:Joined: Apr 2014
Is it possible to somehow create a playlist with 1000 songs randomly chosen from Thumbs Up playlist in Goole Music web app or Android app? I currently have over 5000 songs in that playlist. Choosing them manually is kinda painful. I need it, so I could store some music locally on my device while traveling. Thanks!
26th June 2014, 05:05 AM   |  #2  
OP Junior Member
Thanks Meter: 3
 
13 posts
Join Date:Joined: Apr 2014
Solution
Found a way!!!! There is a python project that allows you to manipulate google music. Simon Weber you are the man!

http://unofficial-google-music-api.r...est/index.html

So just installed the PIP, then API and then wrote a python script to create a random playlist. Here is the code:


Code:
from gmusicapi import Mobileclient
import random

#connect to Goole Music
api = Mobileclient()
#set here your login
logged_in = api.login('your@gmail.com', 'app specific password')
print(logged_in) #TRUE means connection was successfull

#get thumbs up songs from all access
liked_tracks = api.get_thumbs_up_songs()
#add rated music from your library to liked_tracks
all_tracks = api.get_all_songs(False, False)
for song in all_tracks:
    if song.has_key('rating'):
        rating = song['rating']
        #print(rating)
        if (float(rating)>3):
            liked_tracks.append(song)

#sample 850 random songs from liked_tracks
length = 850
random.seed()
random_liked_tracks = random.sample(liked_tracks, int(length))

#for a list of track ids used to create new playlist
random_track_ids=[]
for track in random_liked_tracks:
    #sometimes track identified with id and sometimes nid
    if (track.has_key('id')):
        random_track_ids.append(track['id'])
    elif (track.has_key('nid')):  
        random_track_ids.append(track['nid'])

#create new playlist with randomly selected tracks
#note after each run new playlist with same name will be created        
playlist_id = api.create_playlist('Random Thumbs Up')
api.add_songs_to_playlist(playlist_id, random_track_ids)
print('DONE')
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Questions and Answers by ThreadRank