def main(argv):

    if len(sys.argv) != 2:
        sys.stderr.write("Error: please supply the name of a playlist\n")
        exit(-1)

    # Get a MobileClient api
    gm_api = gmusic.login_to_gmusic_with_oauth()
    all_songs = gm_api.get_all_user_playlist_contents()
    pl = next((p for p in all_songs if p['name'] == argv[1]), None)
    all_song_meta_data = gm_api.get_all_songs()

    badtrackID = ''
    count = 0
    for t in pl['tracks']:
        # Check for bad source.
        # '2' indicates hosted on Google Music, '1' otherwise
        if t['source'] == '1':
            badtrackID = t['trackId']
            song = next(t for t in all_song_meta_data if t['id'] == badtrackID)
            song_str = song['title']
            print(song_str, end=", ")
            #break
        else:  # t['source'] == '2'
            print(t['track']['title'], end=", ")
        count += 1
    print("")
    print(count)
Ejemplo n.º 2
0
def main():

    #(u, pw) = get_u_pw()

    # Get a MobileClient api
    gm_api = gmusic.login_to_gmusic_with_oauth()
    all_songs = gm_api.get_all_user_playlist_contents()
    plush = next((p for p in all_songs if p['name'] == 'Moby'), None)
    all_song_meta_data = gm_api.get_all_songs()

    badtrackID = ''
    count  = 0
    for t in plush['tracks']:
        # Check for bad source.
        # '2' indicates hosted on Google Music, '1' otherwise
        if t['source'] == '1':
            badtrackID = t['trackId']
            song = next(t for t in all_song_meta_data if t['id'] == badtrackID)
            song_str = song['title']
            print(song_str, end=", ")
            #break
        else: # t['source'] == '2'
            print(t['track']['title'], end=", ")
        count += 1
    print("")
    print(count)
Ejemplo n.º 3
0
def main():

    # Google Music MobileClient api
    gm_api = gmusic.login_to_gmusic_with_oauth()
    print('Logged in to Google music using ',  getenv('GMUSIC_OAUTH_CREDS_PATH'))
    all_songs = gm_api.get_all_user_playlist_contents()

    # Spotify api
    sp_api = spotify.login2spotify()
    user = sp_api.me()
    print('Logged in to spotify as ', user['display_name'])
    sp_user_id = user['id']

    found = False
    while not found:
        try:
            pl_name = input("Playlist name: ")
            pl = next((p for p in all_songs if p['name'] == pl_name), None)
            if pl == None:
                print('Could not find playlist with name ', pl_name,
                        ', please try again.')
            else:
                found = True
        except EOFError:
            print('Ok yes goodbye')
            sys.exit(1)

    # Found desired playlist, so get data about its tracks
    all_song_meta_data = gm_api.get_all_songs()

    badtrackID = ''
    tracks = []
    count = 0
    for t in pl['tracks']:
        # Check for bad source.
        # '2' indicates hosted on Google Music, '1' otherwise
        if t['source'] == '1':
            badtrackID = t['trackId']
            song = next((t for t in all_song_meta_data if t['id'] == badtrackID), None)

        else: # t['source'] == '2'
            song = t['track']

        if song is not None:
            count += 1

        title = song['title']
        artist = song['artist']
        album = song['album']

        track = Track(title=title, artist=artist, album=album)
        tracks.append(track)

    new_playlist = Playlist(tracks=tracks, plTitle=pl_name)
    print('ok, added ', count, ' songs to Playlist object with length ', new_playlist.length)
    spotify.new_playlist(sp_api, new_playlist, interactive=True)
Ejemplo n.º 4
0
def main():
    """A test main for getting playlist info from a \
    google music playlist."""
    try:
        gmusicapi = gmusic.login_to_gmusic_with_oauth()
    except:
        print("Error logging in to Google Music -- exiting", file=sys.stderr)
        exit(-1)

    all_playlists = gmusicapi.get_all_user_playlist_contents()

    while True:
        try:
            pl_name = input("Playlist name: ")
            desired_playlist = next((p for p in all_playlists \
                                  if p['name'] == pl_name), None)
            if desired_playlist:
                print("Found")
            else:
                print("Bad PL name, not found")

        except EOFError:
            print("Ok all done")
            break
Ejemplo n.º 5
0
#!/usr/bin/env python3
import sys
sys.path.append('../')
import os
import gmusic

title1 = "All songs part 1"
title2 = "All songs part 2"
gm_api = gmusic.login_to_gmusic_with_oauth()
allPlEntries = gm_api.get_all_user_playlist_contents()
allTrackData = gm_api.get_all_songs()
allPt1 = next((p for p in allPlEntries if p['name'] == title1), None)
allPt2 = next((p for p in allPlEntries if p['name'] == title2), None)
badtrackID = ''
storeIdsToAdd = []
# compile a list of storeId's: this gathers storeIds from 'good' plEntries,  or
# gets the corresponding storeId from the allTrackData dict with a matching
# 'id' field. This second process is another search (slower), which is why it's
# not done for every track.
# plEntry['id'] == track['id']
# ^from a playlist    ^from get_all_songs()
for t in allPt1['tracks']:
    if t['source'] == '1':
        badtrackID = t['trackId']
        # match trackId of a 'plEntry' object with id field of 'track' object
        song = next(t for t in allTrackData if t['id'] == badtrackID)
        storeIdsToAdd.append(song['storeId'])
    else:
        storeIdsToAdd.append(t['track']['storeId'])
print(len(storeIdsToAdd))
#print(*storeIdsToAdd)