Last active
August 29, 2015 14:01
-
-
Save dopuskh3/88d59f969478483763b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("[email protected]", "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