Created
July 13, 2012 22:34
-
-
Save BenTheHokie/3107992 to your computer and use it in GitHub Desktop.
Script will ask if you want to use the saved playlist and will ask for the song and match.
This file contains 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
# matching script | |
from printnesteddictionary import print_dict | |
import re | |
import random | |
import unicodedata | |
import pickle | |
plDir = 'directory to save file' | |
playlist = [] | |
lsk_auth = 'auth+live+xxxxxxxx' | |
lsk_userid = '4e7c70bc4fe7d052ef034402' | |
cts_room = '4e24362314169c7c23033e77' | |
def strpAcc(s): | |
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')) | |
def replPunct(strng): #stripping characters function | |
#strng = strpAcc(strng) | |
strng = strng.replace(' ','') | |
strng = strng.replace('.','') | |
strng = strng.replace(',','') | |
strng = strng.replace('?','') | |
strng = strng.replace('/','') | |
strng = strng.replace('\\','') | |
strng = strng.replace("'",'') | |
strng = strng.replace('"','') | |
strng = strng.replace('(','') | |
strng = strng.replace(')','') | |
strng = strng.replace('-','') | |
strng = strng.replace('+','') | |
strng = strng.replace('@','') | |
strng = strng.replace('_','') | |
strng = strng.replace('=','') | |
strng = strng.replace('*','') | |
#strng = strng.replace('&','') #ampersands don't count | |
strng = strng.replace('!','') | |
strng = strng.replace('#','') | |
strng = strng.replace('$','') | |
strng = strng.replace('%%','') | |
strng = strng.replace('^','') | |
strng = strng.replace('_','') | |
strng = strng.replace(':','') | |
strng = strng.replace('[','') | |
strng = strng.replace(']','') | |
strng = strng.replace('<','') | |
strng = strng.replace('>','') | |
strng = strng.replace('{','') | |
strng = strng.replace('}','') | |
strng = strng.replace('|','') | |
strng = strng.replace('^','') | |
strng = strng.replace('~','') | |
strng = strng.replace('`','') | |
strng = strng.replace('\000','') | |
strng = strng.replace(u'\u00F6','o') | |
strng = strng.replace(u'\u00d6','o') | |
strng = strng.replace(u'\u2019','') | |
strng = strng.replace(u'\u2018','') | |
strng = strng.replace('1','') | |
strng = strng.replace('`','') | |
return strng.lower() | |
def match(): | |
global playlist | |
while True: | |
song = raw_input('Song: ') | |
artist = raw_input('Artist: ') | |
print 'Begin matching...' | |
fmtartist = replPunct(artist) | |
fmtsong = replPunct(song) | |
print('Checking for artist: %s and song: "%s"...' % (fmtartist,fmtsong)) | |
possMatch = [] | |
for a in range(len(fmtartist)-3): | |
#print 'Artist to be matched: %s' % fmtartist[a:a+4] | |
for i in range(len(playlist)): | |
#print 'Song to be matched to: %s Artist: %s' % (replPunct(playlist[i]['metadata']['song']),replPunct(playlist[i]['metadata']['artist'])) | |
if (fmtartist[a:a+4] in replPunct(playlist[i]['metadata']['song']) or fmtartist[a:a+4] in replPunct(playlist[i]['metadata']['artist'])): | |
if not(playlist[i]['metadata']['artist'].lower() in artist.lower() or artist.lower() in playlist[i]['metadata']['artist'].lower()): | |
alreadyAdded = False | |
for k in range(len(possMatch)): | |
if possMatch[k]['idx']==i: | |
alreadyAdded = True | |
break | |
if not(alreadyAdded): | |
possMatch.append({'idx':i,'song':playlist[i]['metadata']['song'],'artist':playlist[i]['metadata']['artist'],'match':fmtartist[a:a+4],'length':playlist[i]['metadata']['length']}) | |
#print 'Match: %s' % fmtartist[a:a+4] | |
#print 'Song: %s' % playlist[i]['metadata']['song'].lower().replace(u'\u2019','').replace(u'\u2018','') | |
#print 'Artist: %s' % playlist[i]['metadata']['artist'].lower().replace(u'\u2019','').replace(u'\u2018','') | |
print('Finished artist search...') | |
for a in range(len(fmtsong)-3): | |
for i in range(len(playlist)): | |
if (fmtsong[a:a+4] in replPunct(playlist[i]['metadata']['song']) or fmtsong[a:a+4] in replPunct(playlist[i]['metadata']['artist'])): | |
if not(playlist[i]['metadata']['song'].lower() in song.lower() or song.lower() in playlist[i]['metadata']['song'].lower()): | |
alreadyAdded = False | |
for k in range(len(possMatch)): | |
if possMatch[k]['idx']==i: | |
alreadyAdded = True | |
break | |
if not(alreadyAdded): | |
possMatch.append({'idx':i,'song':playlist[i]['metadata']['song'],'artist':playlist[i]['metadata']['artist'],'match':fmtsong[a:a+4],'length':playlist[i]['metadata']['length']}) | |
#print len(possMatch) | |
print('Finished song search...') | |
for i in range(len(possMatch)): | |
print 'Song: "%s" Artist: %s Match: "%s"' % (possMatch[i]['song'].replace(u'\u2019','').replace(u'\u2018',''),possMatch[i]['artist'].replace(u'\u2019','').replace(u'\u2018',''),possMatch[i]['match']) | |
randSong = random.randint(0,len(possMatch)-1) | |
print('%d available songs found.' % len(possMatch)) | |
print('Selected "%s" by %s with match "%s".' % (possMatch[randSong]['song'].replace(u'\u2019','').replace(u'\u2018',''),possMatch[randSong]['artist'].replace(u'\u2019','').replace(u'\u2018',''),possMatch[randSong]['match'])) | |
if len(possMatch) == 0: | |
for i in range(3): print 'NO MATCHES!!!' | |
ans = ' ' | |
while not(ans[0] == 'y' or ans[0]=='n'): | |
if ans == '': ans = ' ' | |
ans = raw_input('Use saved playlist? (y/n) ') | |
if ans[0]=='n': | |
from ttapi import Bot | |
AUTH = lsk_auth | |
USERID = lsk_userid | |
ROOMID = cts_room | |
bot = Bot(AUTH, USERID, ROOMID) | |
def roomChanged(data): | |
def storePl(pldata): | |
global plDir,playlist | |
filePl = open(plDir,'w') | |
pickle.dump(pldata['list'],filePl) | |
filePl.close() | |
print 'Playlist saved in backup...' | |
playlist = pldata['list'] | |
print playlist | |
print 'Playlist stored in memory...' | |
bot.roomDeregister() | |
print 'Left room...' | |
match() | |
bot.playlistAll(storePl) | |
bot.on('roomChanged',roomChanged) | |
bot.start() | |
elif ans[0]=='y': | |
filePl = open(plDir,'r') | |
playlist = pickle.load(filePl) | |
filePl.close() | |
print playlist | |
print 'Playlist stored in memory...' | |
match() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment