forked from Shubhanshu1902/mp3player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist.py
86 lines (73 loc) · 2.8 KB
/
playlist.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
from tkinter import *
import mysql.connector
import os
from mysql.connector.cursor import CursorBase
import pygame
import tkinter.filedialog as fd
from functools import partial
my_db=mysql.connector.connect(host="localhost",user="root",passwd='raheja1907',database='playlists') #initiating mysql
cursor=my_db.cursor()
cursor.execute("use playlists")
myresult=[]
def create_playlist(tk):
playname=StringVar()
def submit():
play=playname.get()
cursor.execute("create table "+str(play)+"(id int(3) unsigned auto_increment primary key,song_name varchar(1000) not null);")
myresult.append(play)
playname.set("")
new1.destroy()
new1=Toplevel(tk,bg="#191414")
new1.geometry("500x100")
name_label = Label(new1, text = 'Enter the name of the playlist ', font=('calibre',10, 'bold'),fg="#40704d",bg="#191414")
name=Entry(new1,font=40,textvariable=playname)
b=Button(new1,text="Create",command=submit,bg="#1DB954")
name_label.grid(row=0,column=0)
name.grid(row=0,column=1)
b.grid(row=1,column=1)
def add_songs(n,tk):
filename =fd.askopenfilenames(filetypes=(("mp3","*.mp3"),("All files",".")))
for i in filename:
print(i)
cursor.execute("insert into "+str(myresult[n])[2:-3]+"(song_name) values (\'"+str(i)+"\');")
my_db.commit()
def delete_song(n,tk):
deletewindow =Toplevel(tk,bg="#191414")
cursor.execute("select * from "+str(myresult[n])[2:-3])
songs=cursor.fetchall()
print(songs)
for i in songs:
b=Button(deletewindow,text=i[1],command=partial(cursor.execute,"delete from "+str(myresult[n])[2:-3]+" where id= "+str(i[0])))
b.grid(row=i[0],column=0)
my_db.commit()
def delete_playlist(i,tk):
cursor.execute("Drop table "+str(myresult[i])[2:-3])
my_db.commit()
newwindow.destroy()
myresult.pop(i)
def playlist_names(func,tk):
global newwindow
newwindow=Toplevel(tk,bg="#191414")
newwindow.title("Select Playlist")
newwindow.geometry("500x500")
cursor.execute("Show tables;")
global myresult
myresult = cursor.fetchall()
for i in range(len(myresult)):
b=Button(newwindow,text=myresult[i],command=partial(func,i,tk)).grid(row=i,column=0,padx=8)
#newwindow.destroy()
def play_playlist(n,playlist,tk,):
cursor.execute("select * from "+str(myresult[n])[2:-3])
songs=cursor.fetchall()
for song in songs:
# To Remove Extra Stuffs Getting printed While Adding Song Name in Queue
h=-1
for i in range(len(song)):
if(song[h]=="/"):
song = song.replace(song[0:(h+1)], "")
song = song.replace(".wav", "")
break
else:
h=h-1
# Adding Song To playlist
playlist.insert(tk.END, song)