<commit_before>from getpass import getpass
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, ID3NoHeaderError
from mutagen.easyid3 import EasyID3
from mutagen import File #TODO: fix this so I am not importing all of mutagen
import httplib
import os as os
import urllib#3
import urllib2
import certifi
from time import sleep
from ID3 import *
import eyed3 as eyed3
from eyed3.id3 import Tag
from eyed3.id3 import ID3_V2_4
import logging
from PIL import Image
import traceback
import re
#import ssl
import mutagen
import sys

import config

from gmusicapi import Mobileclient
folder='C:\\Users\\John\\Music\\google play\\' #'C:\Users\john\Desktop\Unofficial-Google-Music-API-develop\playlists'
conf = config.config()
working_device_id = conf.get_device_id()
del conf

def convert(data):
    if isinstance(data, basestring):
        return str(data)
    elif isinstance(data, collections.Mapping):
        return dict(map(convert, data.iteritems()))
    elif isinstance(data, collections.Iterable):
        return type(data)(map(convert, data))
    else:
        return data

def ask_for_credentials():
    """Make an instance of the api and attempts to login with it.
    Return the authenticated api.
    """

    # We're not going to upload anything, so the Mobileclient is what we want.
    api = Mobileclient()

    logged_in = False
    attempts = 0

    while not logged_in and attempts < 3:
        conf = config.config()
        
        email = conf.get_email()#raw_input('Email: ')
        password = conf.get_password() #get_pass()

        logged_in = api.login(email, password, Mobileclient.FROM_MAC_ADDRESS)
        attempts += 1

    return api

def dlProgress(count, blockSize, totalSize):
    percent = int(count*blockSize*100/totalSize)
    #sys.stdout.write("\r" + "...%d%%" % percent)
    #sys.stdout.flush()
     
def retrev(testfile, url, filePath):
    try:#testfile.retreive
        urllib.urlretrieve(url, filePath, reporthook=dlProgress)
        print('done')
    except Exception, err:
        print(traceback.format_exc())
        #sleep(10)
        return True
        #retrev(testfile, url, filePath)

def resize_image(filename, width, height):
    im1 = Image.open(filename)
    im1 = im1.resize((width, height), Image.ANTIALIAS)
    im1.save(filename)
    f1 = open(filename, 'rb')
    return(f1.read())

def demonstrate():
    """Demonstrate some api features."""

    api = ask_for_credentials()

    if not api.is_authenticated():
        print "Sorry, those credentials weren't accepted."
        return

    print 'Successfully logged in.'
    print

    # Get all of the users songs.
    # library is a big list of dictionaries, each of which contains a single song.
    print 'Loading library...',
    #library = api.get_all_songs()
    print 'done.'

    #print len(library), 'tracks detected.'
    #print
    global plist
    global psongs
    plist = list()
    psongs = list()
    ###############
    #NAME OF PLIST#
    ############### #'better electronic', 'sleep', 'hipster party 8/6/15', 
    pnames = ('sleep', 'awesome indie', 'epic indie', 'before it breaks', 'sleep', 'hipster party 8/6/15')
    #pname = 'Download' #2k
    for pname in pnames:
        playlists = api.get_all_user_playlist_contents() #gets all the playlists
        print('playlists='+str(len(playlists)))
        for playlist in playlists:
            if(playlist['name']==pname):
                plist = playlist['tracks'] #save the id
                #print plist
                break
        #print playlists[0]
        print("playlist length =" + str(len(plist)))<commit_msg>the interface is starting to become a thing<commit_after>from getpass import getpass
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error, ID3NoHeaderError
from mutagen.easyid3 import EasyID3
from mutagen import File #TODO: fix this so I am not importing all of mutagen
import httplib
import os as os
import urllib#3
import urllib2
import certifi
from time import sleep
from ID3 import *
import eyed3 as eyed3
from eyed3.id3 import Tag
from eyed3.id3 import ID3_V2_4
import logging
from PIL import Image
import traceback
import re
#import ssl
import mutagen
import sys
import tkinter as tk

import config

from gmusicapi import Mobileclient
folder='C:\\Users\\John\\Music\\google play\\' #'C:\Users\john\Desktop\Unofficial-Google-Music-API-develop\playlists'
conf = config.config()
working_device_id = conf.get_device_id()
del conf

def convert(data):
    if isinstance(data, basestring):
        return str(data)
    elif isinstance(data, collections.Mapping):
        return dict(map(convert, data.iteritems()))
    elif isinstance(data, collections.Iterable):
        return type(data)(map(convert, data))
    else:
        return data

def ask_for_credentials():
    """Make an instance of the api and attempts to login with it.
    Return the authenticated api.
    """

    # We're not going to upload anything, so the Mobileclient is what we want.
    api = Mobileclient()

    logged_in = False
    attempts = 0

    while not logged_in and attempts < 3:
        conf = config.config()
        
        email = conf.get_email()#raw_input('Email: ')
        password = conf.get_password() #get_pass()

        logged_in = api.login(email, password, Mobileclient.FROM_MAC_ADDRESS)
        attempts += 1

    return api

def dlProgress(count, blockSize, totalSize):
    percent = int(count*blockSize*100/totalSize)
    sys.stdout.write("\r" + "...%d%%" % percent)
    sys.stdout.flush()
     
def retrev(testfile, url, filePath):
    try:#testfile.retreive
        urllib.urlretrieve(url, filePath, reporthook=dlProgress)
        print('done')
    except Exception, err:
        print(traceback.format_exc())
        #sleep(10)
        return True
        #retrev(testfile, url, filePath)

def resize_image(filename, width, height):
    im1 = Image.open(filename)
    im1 = im1.resize((width, height), Image.ANTIALIAS)
    im1.save(filename)
    f1 = open(filename, 'rb')
    return(f1.read())

def Quit(root):
    root.destroy()
    exit(0)

def demonstrate():
    root = tk.Tk()
    message = tk.StringVar()
    message.set("Logging in")
    frame = tk.Frame(root)
    tk.Label(root, textvariable=message).pack()
    tk.Button(root, text="Cancel", command=lambda root=root: Quit(root)).pack()
    root.after(500, lambda root=root, message=message: begin_login(root, message)) #this will start the process after a half a second
    root.mainloop()

def begin_login(root, message):
    
    api = ask_for_credentials()

    if not api.is_authenticated():
        print "Sorry, those credentials weren't accepted."
        return

    print 'Successfully logged in.'
    print

    message.set("loading library")

    # Get all of the users songs.
    # library is a big list of dictionaries, each of which contains a single song.
    print 'Loading library...',
    #library = api.get_all_songs()
    print 'done.'
    root.destroy()
    #print len(library), 'tracks detected.'
    #print
    global plist
    global psongs
    plist = list()
    psongs = list()
    ###############
    #NAME OF PLIST#
    ############### #'better electronic', 'sleep', 'hipster party 8/6/15', 
    pnames = ('sleep', 'awesome indie', 'epic indie', 'before it breaks', 'sleep', 'hipster party 8/6/15')
    #pname = 'Download' #2k
    for pname in pnames:
        playlists = api.get_all_user_playlist_contents() #gets all the playlists
        print('playlists='+str(len(playlists)))
        for playlist in playlists:
            if(playlist['name']==pname):
                plist = playlist['tracks'] #save the id
                #print plist
                break
        #print playlists[0]
        print("playlist length =" + str(len(plist)))
{'fraction_non_alphanumeric': 0.11467181467181467, 'fraction_numerical': 0.011583011583011582, 'mean_word_length': 3.096468107538218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2035843', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2358, 'n_words': 722}