-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.py
111 lines (97 loc) · 4.31 KB
/
music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
import fbconsole
import re
import time
import sys
from google import search
from random import choice
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def main():
print "do you wish to add some songs yourself or listen according to your likes?"
choice = raw_input("A--> to add songs \nL--> listen according to your likes. \nEnter your choice: ")
if choice == 'A':
user_input()
elif choice == 'L':
fb_access()
else:
print "wrong option, please try again."
main()
def user_input():
user_input_name = input("Enter your song/artist: ").split(',')
print "please wait while we search for your entries.."
print "opening gaana.com..."
driver = webdriver.Firefox()
driver.get("http://gaana.com")
for name in user_input_name:
song_name = google_search(name)
if song_name!='nothing':
driver.find_element_by_id("keywordsearch").clear()
driver.find_element_by_id("keywordsearch").send_keys(name)
driver.find_element_by_id("btnsearch").click()
time.sleep(1)
driver.find_element_by_css_selector("#tblheader1 > tbody > tr.GridV1BG > th[name=\"checkSelected\"] > div > input[name=\"checkSelected\"]").click()
time.sleep(0.1)
driver.find_element_by_link_text("Add to Queue").click()
else:
print "your option is not present at gaana \n please try again."
user_input()
driver.find_element_by_link_text("Now Playing").click()
driver.find_element_by_css_selector("div.checkbx > input[name=\"chk\"]").click()
driver.find_element_by_xpath("//div[@id='mainPlayer']/div[3]/div[2]/div[6]/a").click()
def google_search(name):
for url in search('%s gaana' %name, stop=1):
if re.search(ur'http://gaana.com', url, re.UNICODE):
return name
else:
return 'nothing'
def fb_access():
""" logs into Facebook account and asks for permission.
Further the music names are extracted from the profile"""
fbconsole.AUTH_SCOPE = ['user_likes','publish_checkins' ]
fbconsole.authenticate()
music = fbconsole.fql("SELECT music FROM user WHERE uid=me()")
music_names(music)
fbconsole.logout()
def music_names(music):
"""the music names are then checked on google
for a valid url, which is then feeded into gaana.com"""
music_list = music[0].values()
for name in music_list: #fetch music names
music_name = (choice(name.split(','))).encode('utf-8')
search = google_search(music_name)
if search!= 'nothing':
option = raw_input('now playing %s, N-> for next song; Press Y-> play; Q--> quit :' %search) #user options
if option == 'N':
music_names(music)
elif option == 'Y':
print "please wait while we search for your entries.."
time.sleep(1)
driver = webdriver.Firefox()
driver.get("http://gaana.com")
driver.find_element_by_id("keywordsearch").clear()
driver.find_element_by_id("keywordsearch").send_keys(search)
driver.find_element_by_id("btnsearch").click()
time.sleep(1)
driver.find_element_by_css_selector("#tblheader1 > tbody > tr.GridV1BG > th[name=\"checkSelected\"] > div > input[name=\"checkSelected\"]").click()
time.sleep(0.1)
driver.find_element_by_link_text("Add to Queue").click()
driver.find_element_by_link_text("Now Playing").click()
driver.find_element_by_css_selector("div.checkbx > input[name=\"chk\"]").click()
driver.find_element_by_xpath("//div[@id='mainPlayer']/div[3]/div[2]/div[6]/a").click()
elif option =='Q':
sys.exit(0)
else:
print "wrong option,please try again."
music_names(music)
else:
option= raw_input( "your like doesn't match any song. N-> for next song; Q--> quit: ")
if option == 'N':
music_names(music)
elif option == 'Q':
sys.exit(0)
else:
print "wrong option,please try again."
music_names(music)
if __name__=='__main__':
main()