Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,729,619 Members 46,573 Now Online
XDA Developers Android and Mobile Development Forum

Create playlist based on Thumbs Up playlist??

Tip us?
 
agalenko
Old
#1  
Junior Member - OP
Thanks Meter 3
Posts: 7
Join Date: Apr 2014
Default Create playlist based on Thumbs Up playlist??

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!
 
agalenko
Old
#2  
Junior Member - OP
Thanks Meter 3
Posts: 7
Join Date: Apr 2014
Default 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')
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes