Skip to content

Instantly share code, notes, and snippets.

@dopuskh3
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dopuskh3/88d59f969478483763b1 to your computer and use it in GitHub Desktop.
Save dopuskh3/88d59f969478483763b1 to your computer and use it in GitHub Desktop.
import soundcloud
import sys
from pprint import pprint
from gmusicapi import Mobileclient
import re
track_regex = r"(\d+)*\s*[-_]\s*(.+)\s*[-_]\s*(.+)\s*[-_]\s*(.+){,1}"
REG = re.compile(track_regex)
api = Mobileclient()
api.login("XXXXX@gmail.com", "register-a-google-illimited-account")
client = soundcloud.Client(client_id='create-your-own-client-id')
results = client.get('/users/laurent-garnier/tracks', limit=1000)
def parse_description(descr):
if not descr:
return
for l in descr.splitlines():
g = REG.match(l)
if g:
matches = g.groups()
artist = matches[1]
album = matches[2]
yield (artist.strip(), album.strip())
tracks = []
for r in results:
for artist, album in parse_description(r.description):
tracks.append(( artist, album))
pl = api.create_playlist(sys.argv[1])
for artist, title in tracks:
r = api.search_all_access(' '.join([artist, title]), max_results = 10)
if len(r['song_hits']) > 0:
song = r['song_hits'][0]
print "%s-%s -> %s-%s" % (artist, title, song['track']['artist'], song['track']['title']), song['score'], song['track']['storeId']
res = api.add_songs_to_playlist(pl, [song['track']['storeId']])
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment