├── README.md └── final.py /README.md: -------------------------------------------------------------------------------- 1 | Create a Directory named Songs and store all your songs in that directory. 2 | Install Tkinter , MySQLdb , pyglet modules . 3 | Run the program using command Python final.py. 4 | -------------------------------------------------------------------------------- /final.py: -------------------------------------------------------------------------------- 1 | import Tkinter as tkinter 2 | import MySQLdb as mysql 3 | import pyglet 4 | import os 5 | import fnmatch 6 | 7 | 8 | ''' while player.playing == True: 9 | try: 10 | print '{0:.2f}\r'.format(player.time), 11 | except KeyboardInterrupt: 12 | print "ctrl-c" 13 | sys.exit("song paused") 14 | break 15 | ''' 16 | mydb = mysql.connect(host='localhost',user='beni',passwd='password',db='project') 17 | cur = mydb.cursor() 18 | player = pyglet.media.Player() 19 | 20 | def move(): 21 | flag=0 22 | if listbox.get(0)=='TRACKS' or b.lower()=='tracks': 23 | for i in range(playbox.size()): 24 | if playbox.get(i)==v or v=='TRACKS': 25 | flag=1 26 | break 27 | if flag==0: 28 | playbox.insert('end',v) 29 | elif listbox.get(0)=='ALBUMS' or b.lower()=='albums': 30 | playbox.delete(0,'end') 31 | query = "select tracks.name from tracks,albums where tracks.albumid=albums.id and albums.name='%s'"%(v) 32 | cur.execute(query) 33 | res = cur.fetchall() 34 | for i in res: 35 | playbox.insert('end',i[0]) 36 | elif b.lower()=='genre': 37 | playbox.delete(0,'end') 38 | query = "select tracks.name from tracks,genre where tracks.genreid=genre.id and genre.name='%s'"%(v) 39 | cur.execute(query) 40 | res = cur.fetchall() 41 | for i in res: 42 | playbox.insert('end',i[0]) 43 | elif b.lower()=='artists': 44 | playbox.delete(0,'end') 45 | query="select tracks.name from tracks,albums,artists where artists.id=albums.artistid and albums.id=tracks.albumid and artists.name='%s'"%(v) 46 | cur.execute(query) 47 | res=cur.fetchall() 48 | for i in res: 49 | playbox.insert('end',i[0]) 50 | 51 | 52 | 53 | def playinfo(event): 54 | global pmusic 55 | widget=event.widget 56 | items = widget.curselection() 57 | pmusic = widget.get(items[0]) 58 | ftracks(pmusic) 59 | 60 | def play(): 61 | global d 62 | d = 'songs/' 63 | for i in os.listdir('songs'): 64 | if fnmatch.fnmatch(i.lower(),(pmusic+'*').lower()): 65 | d=d+i 66 | break 67 | 68 | if not d == 'songs/': 69 | # print d 70 | source = pyglet.media.load(d) 71 | # print source 72 | player.queue(source) 73 | player.eos_action = player.EOS_LOOP 74 | player.play() 75 | # print player.playing 76 | else: 77 | print "no song" 78 | 79 | 80 | def pause(): 81 | player.pause() 82 | 83 | def nex(): 84 | 85 | print pmusic,d 86 | player.pause() 87 | play() 88 | player.next() 89 | 90 | 91 | 92 | def dartists(): 93 | listbox.delete(0,'end') 94 | query = "select albums.name,albums.releasedate from albums,artists where artists.id=albums.artistid and artists.name='%s'"%(v) 95 | cur.execute(query) 96 | res = cur.fetchall() 97 | listbox.insert('end',"ALBUMS") 98 | listbox.itemconfig('end', {'bg':'red'}) 99 | for i in res: 100 | value = i[0] 101 | listbox.insert('end',value) 102 | 103 | def dalbums(): 104 | listbox.delete(0,'end') 105 | query = "select tracks.name from tracks,albums where tracks.albumid=albums.id and albums.name='%s'"%(v) 106 | cur.execute(query) 107 | res = cur.fetchall() 108 | listbox.insert('end',"TRACKS") 109 | listbox.itemconfig('end', {'bg':'red'}) 110 | for i in res: 111 | value = i[0] 112 | listbox.insert('end',value) 113 | 114 | def dtracks(): 115 | listbox.delete(0,'end') 116 | query = "select artists.name,albums.name,albums.releasedate,genre.name from artists,albums,genre,tracks where artists.id=albums.artistid and albums.id=tracks.albumid and genre.id=tracks.genreid and tracks.name='%s'"%(v) 117 | cur.execute(query) 118 | res = cur.fetchall() 119 | listbox.insert('end',"TRACK DETAILS") 120 | listbox.itemconfig('end', {'bg':'pink'}) 121 | listbox.insert('end','Track Name : '+v) 122 | for i in res: 123 | value = 'Artist : '+i[0] 124 | listbox.insert('end',value) 125 | value = 'Album : '+i[1] 126 | listbox.insert('end',value) 127 | value = 'Album Releasedate : '+str(i[2]) 128 | listbox.insert('end',value) 129 | value = 'Genre : '+i[3] 130 | listbox.insert('end',value) 131 | 132 | def ftracks(boom): 133 | listbox.delete(0,'end') 134 | query = "select artists.name,albums.name,albums.releasedate,genre.name from artists,albums,genre,tracks where artists.id=albums.artistid and albums.id=tracks.albumid and genre.id=tracks.genreid and tracks.name='%s'"%(boom) 135 | cur.execute(query) 136 | res = cur.fetchall() 137 | listbox.insert('end',"TRACK DETAILS") 138 | listbox.itemconfig('end', {'bg':'pink'}) 139 | listbox.insert('end','Track Name : '+boom) 140 | for i in res: 141 | value = 'Artist : '+i[0] 142 | listbox.insert('end',value) 143 | value = 'Album : '+i[1] 144 | listbox.insert('end',value) 145 | value = 'Album Releasedate : '+str(i[2]) 146 | listbox.insert('end',value) 147 | value = 'Genre : '+i[3] 148 | listbox.insert('end',value) 149 | 150 | 151 | def dgenre(): 152 | listbox.delete(0,'end') 153 | query = "select tracks.name from tracks,genre where tracks.genreid = genre.id and genre.name='%s'"%(v) 154 | cur.execute(query) 155 | res = cur.fetchall() 156 | listbox.insert('end',"TRACKS") 157 | listbox.itemconfig('end', {'bg':'red'}) 158 | for i in res: 159 | value = i[0] 160 | listbox.insert('end',value) 161 | 162 | 163 | def details(): 164 | table = b.lower() 165 | global ca 166 | global cc 167 | global cg 168 | if table=='artists': 169 | cc=0 170 | cg=0 171 | if ca==1: 172 | dartists() 173 | elif ca==2: 174 | dalbums() 175 | elif ca==3: 176 | dtracks() 177 | elif table=='albums': 178 | ca=0 179 | cg=0 180 | if cc==1: 181 | dalbums() 182 | if cc==2: 183 | dtracks() 184 | cc=0 185 | elif table=='tracks': 186 | cc=0 187 | ca=0 188 | cg=0 189 | dtracks() 190 | elif table=='genre': 191 | cc=0 192 | ca=0 193 | if cg==1: 194 | dgenre() 195 | if cg==2: 196 | dtracks() 197 | cg=0 198 | def info(event): 199 | widget=event.widget 200 | items = widget.curselection() 201 | global v 202 | v = widget.get(items[0]) 203 | print b.lower(),v 204 | if b.lower()=='genre': 205 | if v=='TRACKS': 206 | genre() 207 | elif v=='TRACK DETAILS': 208 | temp = (listbox.get(1)).split(': ')[1] 209 | query = "select name from tracks where genreid=(select genreid from tracks where name = '%s')"%(temp) 210 | listbox.delete(0,'end') 211 | cur.execute(query) 212 | res = cur.fetchall() 213 | listbox.insert('end',"TRACKS") 214 | listbox.itemconfig('end', {'bg':'red'}) 215 | for i in res: 216 | value = i[0] 217 | listbox.insert('end',value) 218 | elif b.lower()=='albums': 219 | if v=='TRACKS': 220 | album() 221 | elif v=='TRACK DETAILS': 222 | temp = (listbox.get(1)).split(': ')[1] 223 | query = "select name from tracks where albumid=(select albumid from tracks where name = '%s')"%(temp) 224 | listbox.delete(0,'end') 225 | cur.execute(query) 226 | res = cur.fetchall() 227 | listbox.insert('end',"TRACKS") 228 | listbox.itemconfig('end', {'bg':'red'}) 229 | for i in res: 230 | value = i[0] 231 | listbox.insert('end',value) 232 | elif b.lower()=='tracks' and v=='TRACK DETAILS': 233 | listbox.delete(0,'end') 234 | cur.execute('select name from tracks') 235 | res=cur.fetchall() 236 | for i in res: 237 | value = i[0] 238 | listbox.insert('end',value) 239 | 240 | elif b.lower()=='artists': 241 | if v=='ALBUMS': 242 | artist() 243 | elif v=='TRACKS': 244 | temp = listbox.get(1) 245 | highlight="(select albums.name from albums where albums.id=(select albumid from tracks where name like '%s'))"%(temp) 246 | cur.execute(highlight) 247 | hres=cur.fetchall() 248 | hval=hres[0][0] 249 | query = " select albums.name from albums where albums.artistid=(select albums.artistid from albums where albums.id= (select albums.id from albums where albums.id=(select albumid from tracks where name like '%s')))"%(temp) 250 | listbox.delete(0,'end') 251 | cur.execute(query) 252 | res = cur.fetchall() 253 | listbox.insert('end',"ALBUMS") 254 | listbox.itemconfig('end', {'bg':'red'}) 255 | for i in res: 256 | value = i[0] 257 | listbox.insert('end',value) 258 | if value==hval: 259 | listbox.selection_set('end') 260 | elif v=='TRACK DETAILS': 261 | temp = (listbox.get(1)).split(': ')[1] 262 | query = "select name from tracks where albumid=(select albumid from tracks where name = '%s')"%(temp) 263 | listbox.delete(0,'end') 264 | cur.execute(query) 265 | res = cur.fetchall() 266 | listbox.insert('end',"TRACKS") 267 | listbox.itemconfig('end', {'bg':'red'}) 268 | for i in res: 269 | value = i[0] 270 | listbox.insert('end',value) 271 | 272 | 273 | 274 | 275 | global cc,cg,ca 276 | if ca>3: 277 | ca=1 278 | if cc>2: 279 | cc=1 280 | if cg>2: 281 | cg=1 282 | cc=cc+1 283 | cg=cg+1 284 | ca=ca+1 285 | #print ca,cc,cg,v 286 | 287 | 288 | def artist(): 289 | global b 290 | global ca 291 | ca=0 292 | b = button1.config('text')[-1] 293 | listbox.delete(0,'end') 294 | value = entry.get() 295 | query = "select *from artists where name like '"+value+"%'" 296 | cur.execute(query) 297 | res= cur.fetchall() 298 | for i in res: 299 | value = i[1] 300 | listbox.insert('end',value) 301 | entry.delete(0,'end') 302 | 303 | def album(): 304 | global b 305 | global cc 306 | cc=0 307 | b = button2.config('text')[-1] 308 | listbox.delete(0,'end') 309 | value = entry.get() 310 | query = "select *from albums where name like '"+value+"%'" 311 | cur.execute(query) 312 | res= cur.fetchall() 313 | for i in res: 314 | value = i[2] 315 | listbox.insert('end',value) 316 | entry.delete(0,'end') 317 | 318 | def track(): 319 | global b 320 | b = button3.config('text')[-1] 321 | listbox.delete(0,'end') 322 | value = entry.get() 323 | length = len(value) 324 | if length<=2: 325 | query = "select *from tracks where name like '"+value+"%'" 326 | elif length>2: 327 | query="SELECT * FROM tracks WHERE tracks.name REGEXP '[[:<:]]%s[[:>:]]'"%(value) 328 | cur.execute(query) 329 | res= cur.fetchall() 330 | for i in res: 331 | value = i[2] 332 | listbox.insert('end',value) 333 | entry.delete(0,'end') 334 | 335 | 336 | def genre(): 337 | global b 338 | global cg 339 | cg=0 340 | b = button4.config('text')[-1] 341 | listbox.delete(0,'end') 342 | value = entry.get() 343 | query = "select *from genre where name like '%"+value+"%'" 344 | cur.execute(query) 345 | res= cur.fetchall() 346 | for i in res: 347 | value = i[1] 348 | listbox.insert('end',value) 349 | entry.delete(0,'end') 350 | 351 | root = tkinter.Tk() 352 | BG='light blue' 353 | BUT='grey' 354 | FG='white' 355 | 356 | ca=0 357 | cc=0 358 | cg=0 359 | root.title("DBMS Music Player") 360 | root.geometry("1100x350+200+200") 361 | root.config(bg=BG) 362 | frame1 = tkinter.Frame(root,bg=BG) 363 | label = tkinter.Label(frame1,text='Search:',bg=BUT,fg=FG) 364 | entry = tkinter.Entry(frame1) 365 | label.pack(side='left',anchor='w',pady=4,padx=2) 366 | entry.pack(pady=4) 367 | frame1.pack(pady=12) 368 | 369 | frame2= tkinter.Frame(root,bg=BG) 370 | button1 = tkinter.Button(frame2,text='Artists',command=artist,bg=BUT,fg=FG) 371 | button1.pack(side='left',padx=2) 372 | button2 = tkinter.Button(frame2,text='Albums',command=album,bg=BUT,fg=FG) 373 | button2.pack(side='left',padx=2) 374 | button3 = tkinter.Button(frame2,text='Tracks',command=track,bg=BUT,fg=FG) 375 | button3.pack(side='left',padx=2) 376 | button4 = tkinter.Button(frame2,text='Genre',command=genre,bg=BUT,fg=FG) 377 | button4.pack(side='left',padx=2) 378 | frame2.pack() 379 | 380 | frame3= tkinter.Frame(root,bg=BG,bd=2,relief='sunken') 381 | listbox = tkinter.Listbox(frame3,width=50,height=10) 382 | listbox.pack(pady=12,padx=2,side='left') 383 | listbox.bind("<>",info) 384 | 385 | playbox = tkinter.Listbox(frame3,width=50,height=10) 386 | playbox.pack(pady=12,padx=2,side='right') 387 | playbox.bind("<>",playinfo) 388 | button5 = tkinter.Button(frame3,text='Details',command=details,bg=BUT,fg=FG) 389 | button5.pack(padx=2,side='left') 390 | button6 = tkinter.Button(frame3,text='Move',command=move,bg=BUT,fg=FG) 391 | button6.pack(padx=2,side='right') 392 | frame3.pack(pady=2,padx=2) 393 | 394 | frame4 = tkinter.Frame(root,bg=BG,bd=2) 395 | playbutton = tkinter.Button(frame4,text='Play',command=play) 396 | playbutton.pack(padx=2,side='left') 397 | pausebutton = tkinter.Button(frame4,text='Pause',command=pause) 398 | pausebutton.pack(padx=2,side='left') 399 | nextbutton = tkinter.Button(frame4,text='Next',command=nex) 400 | nextbutton.pack(padx=2,side='left') 401 | 402 | #progress = ttk.Progressbar(frame3,orient='horizontal',mode='determinate') 403 | #progress.pack() 404 | frame4.pack(pady=2,padx=2,side='bottom') 405 | 406 | 407 | root.mainloop() 408 | --------------------------------------------------------------------------------