import mysql.
connector
import tabulate
from datetime import date
from pygame import mixer
import time
def createdatabase():
mydb=[Link](host='localhost', user='root', passwd='kkss')
mycursor=[Link]()
[Link]('create database if not exists Album')
[Link]('show databases')
for i in mycursor:
print(i)
def createtable():
mydb=[Link](host='localhost', user='root', passwd='kkss',
database='Album')
mycursor=[Link]()
myrecords=[Link]('Create table Musically (S_CODE int(3), primary
key,S_NAME varchar(20), ARTIST varchar(20),R_DATE Date ,PLAYS int(10),)')
[Link]('desc Musically')
for i in mycursor:
print(i)
def display_song():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
[Link]("select * from Musically ORDER BY S_CODE")
rs=[Link]()
print([Link](rs,headers=['S_CODE','S_NAME','ARTIST','R_DATE','PLAY
S'],tablefmt='fancy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_playlist():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
pl_name=input("Enter playlist name:")
[Link]("select * from '{}' ORDER BYS_CODE".format(pl_name))
rs=[Link]()
print([Link](rs,headers=['S_CODE','S_NAME',
'ARTIST','R_DATE','PLAYS'],tablefmt='fancy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_membership():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
pl_name=input("Enter playlist name:")
[Link]("select * from membership")
rs=[Link]()
print([Link](rs,headers=['M_CODE','LEVEL',
'PRICE'],tablefmt='fancy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_Password():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
pl_name=input("Enter playlist name:")
[Link]("select * from password")
rs=[Link]()
print([Link](rs,headers=['U_ID','Pass_W
','U_Name'],tablefmt='fancy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_users():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
pl_name=input("Enter playlist name:")
[Link]("select * from users")
rs=[Link]()
print([Link](rs,headers=['U_ID','U_Name','MEM_TYPE'],tablefmt='fa
ncy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_users_playlists():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
pl_name=input("Enter playlist name:")
[Link]("select * from users_playlists")
rs=[Link]()
print([Link](rs,headers=['P_CODE','playlistname'],tablefmt='fancy_g
rid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def display_backup():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
[Link]("select * from songbackup ORDER BY S_CODE")
rs=[Link]()
print([Link](rs,headers=['S_CODE','S_NAME', 'ARTIST',
'R_DATE','PLAY'],tablefmt='fancy_grid'))
except Exception as e:
print(e)
[Link]()
[Link]()
def sign_admin():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
[Link]("select * from password where TYPE='ADMIN'")
rs=[Link]()
uname=input("Enter the U_Name: ")
for r in rs:
if r[1]==uname and r[3]=="ADMIN":
Pass_Word3=input("Enter the password: ")
if r[2]==Pass_W:
print("Log In Successful !!")
break
else:
print("Sorry, Wrong Password")
print()
sign_admin()
return
else:
print("Sorry, Cannot Log in as an Admin")
print()
sign_admin()
except Exception as e:
print(e)
[Link]()
[Link]()
def update_song():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
display_song()
no=int(input("Enter the Song Code of the Song to be Updated: "))
q="select * from Musically where S_CODE={}".format(no)
[Link](q)
rs=[Link]()
if rs==None:
print("Song Does Not Exist")
else:
print(rs)
udate=input("Enter the Updated Release Date: ")
uplays=int(input("Enter Updated Number of Plays: "))
q1="update Musically set R_DATE='{}',PLAYS={} where
S_CODE={}".format(udate, uplays, no)
[Link](q1)
[Link]()
display_song()
print([Link],"Song Has Been Updated Successfully!!")
except Exception as e:
print(e)
[Link]()
[Link]()
def del_song():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
display_song()
n=int(input("Enter the Number of Musically to be Deleted:"))
for i in range(n):
n=int(input("Enter the Song Code of the Song to be Deleted: "))
q="select * from Musically where S_CODE='{}'".format(n)
[Link](q)
rs=[Link]()
if rs==None:
print("Song Does Not Exist")
else:
ans=input('Are you sure you want to delete? (Y/N)')
if [Link]()=='y':
S_CODE=rs[0]
S_NAME=rs[1]
ARTIST=rs[2]
R_DATE=rs[3]
PLAYS=rs[4]
q0="Select * from SONGBACKUP where S_CODE='{}'".format(n)
[Link](q0)
res=[Link]()
if rs==None:
q1="insert into SONGBACKUP values({},'{}','{}','{}',
{})".format(S_CODE, S_NAME,ARTIST, R_DATE, PLAYS)
[Link](q1)
else:
q3="delete from SONGBACKUP where S_CODE='{}'".format(n)
[Link](q3)
q4="insert into SONGBACKUP values({},'{}','{}','{}',
{})".format(S_CODE, S_NAME,ARTIST, R_DATE, PLAYS)
[Link](q4)
q2="delete from Musically where S_CODE='{}'".format(n)
print([Link], "Musically Have Been Deleted
Sucessfully !!")
[Link](q2)
[Link]()
else:
print('Deletion unsucessful')
display_backup()
except Exception as e:
print(e)
[Link]()
[Link]()
def add_song():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
display_song()
S_CODE=int(input("Enter the Song Code: "))
S_NAME=input("Enter the Song Name: ")
ARTIST=input("Enter the Artist Name: ")
R_DATE=input("Enter the Release Date (YYYY-MM-DD): ")
PLAYS=int(input("Enter the Number of Plays: "))
q="insert into Musically values('{}','{}','{}','{}','{}')".format(S_CODE,
S_NAME, ARTIST, R_DATE, PLAYS)
[Link](q)
[Link]()
display_song()
except Exception as e:
print(e)
[Link]()
[Link]()
def cancel_mem():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
display_users()
cun = input("Enter the U_Name whose membership is to be cancelled: ")
q = "SELECT * FROM users WHERE U_Name = %s"
[Link](q, (cun,))
rs = [Link]()
if rs:
U_M_SHIP = 'NO MEMBERSHIP'
[Link]("UPDATE users SET MEM_TYPE = %s WHERE U_Name =
%s", (U_M_SHIP, cun))
[Link]()
print("Membership cancelled successfully!")
display_users()
else:
print("User not found!")
except Exception as e:
print("Error:", e)
finally:
[Link]()
[Link]()
def update_memdet():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
display_membership()
uno = int(input("Enter the Membership Code you want to update: "))
q = "SELECT * FROM Package WHERE M_CODE = '{}'".format(uno)
[Link](q)
rs = [Link]()
if rs:
print("Current Details:", rs)
PRICE = int(input("Enter updated price: "))
[Link]("UPDATE Package SET PRICE = '{}' WHERE M_CODE =
'{}'".format(PRICE, uno))
[Link]()
print("Membership details updated successfully!")
display_membership()
else:
print("Invalid Membership Code!")
except Exception as e:
print("Error:", e)
finally:
[Link]()
[Link]()
def sign_user():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
[Link]("SELECT * FROM password WHERE TYPE = 'USER'")
rs = [Link]()
U_Name = input("Enter the U_Name: ")
for r in rs:
if r[1] == U_Name and r[3] == "USER":
Pass_Word = input("Enter the Password: ")
if r[2] == Pass_Word:
print("Login Successful!")
return
else:
print("Wrong Password!")
return sign_user()
print("Cannot log in as a User.")
except Exception as e:
print("Error:", e)
finally:
[Link]()
[Link]()
def update_mem():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
U_Name = input("Enter your U_Name: ")
q = "SELECT * FROM USERS WHERE U_Name = '{}'".format(U_Name)
[Link](q)
rs = [Link]()
if not rs:
print("User not found!")
else:
nmem = input("Enter your new membership plan: ")
if [Link]() in ("SILVER", "GOLD", "PLATINUM"):
a=("UPDATE USERS SET MEM_TYPE = '{}' WHERE U_Name =
'{}".format([Link](),U_Name))
[Link](a)
print("Membership updated successfully!")
else:
print("Invalid membership plan!")
[Link]()
display_users()
except Exception as e:
print("Error:", e)
finally:
[Link]()
[Link]()
def search_artist():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
display_song()
art = input("Enter Artist to search for: ")
q = "SELECT * FROM Musically WHERE ARTIST = '{}'".format(art)
[Link](q)
rs = [Link]()
if not rs:
print("Artist not found!")
else:
print(tabulate(rs, headers=['S_CODE', 'S_NAME', 'ARTIST', 'R_DATE',
'PLAYS'], tablefmt='fancy_grid'))
[Link]()
except Exception as e:
print(e)
[Link]()
[Link]()
def create_pl():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur = [Link]()
U_Name = input("Enter your U_Name: ")
q = "SELECT * FROM USERS WHERE U_Name = '{}'".format(U_Name)
[Link](q)
rs = [Link]()
if rs==None:
print("User not found!")
else:
p_code = rs[0]
pl_name = input("Enter a name for your playlist: ")
q = "CREATE TABLE {} (S_CODE INT NOT NULL, S_NAME VARCHAR(30)
NOT NULL, ARTIST VARCHAR(20) NOT NULL)".format(pl_name)
[Link](q)
[Link]()
print("Playlist created! Add songs to it.")
display_song()
n = int(input("Enter the number of songs you want to add: "))
for i in range(n):
song_code = int(input("Enter Song Code: "))
q1 = "SELECT * FROM Musically WHERE S_CODE
='{}'".format(song_code)
[Link](q1)
rss = [Link]()
for r in rss:
S_CODE=rss[0]
S_NAME=rss[1]
ARTIST=rss[2]
q2 = "INSERT INTO {} VALUES ({}, '{}', '{}')".format(pl_name,S_CODE,
S_NAME, ARTIST)
[Link](q2)
print('done!')
x=pl_name
[Link]()
q3 = "INSERT INTO USER_PLAYLISTS (P_CODE, PL_NAME) VALUES ({},
'{}')".format(p_code, pl_name)
[Link](q3)
[Link]()
display_playlist(4)
except Exception as e:
print(e)
[Link]()
[Link]()
def add_songpl():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
U_Name=input("Enter your U_Name: ")
q="SELECT * FROM USERS WHERE U_Name='{}'".format(U_Name)
[Link](q)
rs=[Link]()
if rs==None:
print("USER NOT FOUND")
else:
apl_name= input("Enter the playlist name you want to add Musically
to:")
q1="SELECT FROM USER_PLAYLISTS WHERE
PL_NAME='{}'".format(apl_name)
[Link](q1)
ps=[Link]()
if ps==None:
print("Playlist not found")
else:
n=int(input("Enter the number of Musically you want to add: "))
display_song()
for i in range(n):
song=int(input("Enter Song Code of the Song You Would Like to Add
to Your Playlist: "))
q2="select * from Musically where S_CODE={}".format(song)
[Link](q2)
rss=[Link]()
for r in rss:
S_code=r[0]
S_name=r[1]
artist_name=r[2]
q3="insert into {}
values({},'{}','{}')".format(S_code,S_name,artist_name)
[Link](q3)
print('done!')
[Link]()
x=apl_name
display_playlist()
except Exception as e:
print(e)
[Link]()
[Link]()
def del_songpl():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
U_Name=input("Enter your U_Name:")
q="SELECT * FROM USERS WHERE U_Name='{}'".format(U_Name)
[Link](q)
rs=[Link]()
if rs==None:
print("USER NOT FOUND")
else:
dpl_name=input("Enter the playlist name you want to delete Musically
from:")
q1="SELECT * FROM USER_PLAYLISTS WHERE
PL_NAME='{}'".format(dpl_name)
[Link](q1)
ps=[Link]()
if ps==None:
print("Playlist not found")
else:
n=int(input('Enter the number of Musically you want to delete:'))
display_song()
for i in range(n):
dsong=int(input("Enter Song Code of the Song You Would Like to
delete: "))
q2="delete from {} where S_code={}".format(dpl_name,dsong)
ch=input('Are you sure you want to delete this song from playlist?
(Y/N)')
if [Link]()=='Y':
[Link](q2)
q3="select * from Musically where s_code={}".format(dsong)
[Link](q3)
rec=[Link]()
for r in rec:
S_CODE=r[0]
S_NAME=r[1]
ARTIST=r[2]
R_DATE=r[3]
PLAYS=r[4]
q4="insert into SONGBACKUP
values('{}','{}','{}','{}','{}')".format(S_CODE,S_NAME, ARTIST, R_DATE, PLAYS)
[Link](q4)
[Link]()
print("Deleted sucessfully")
print('Archive of deleted song:')
display_backup()
else:
print("Deletion unsucessful")
[Link]()
x=dpl_name
print('Your updated playlist: ')
display_playlist(x)
except Exception as e:
print(e)
[Link]()
[Link]()
def del_pl():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
U_Name=input("Enter your U_Name: ")
q="SELECT FROM USERS WHERE U_Name='{}'".format(U_Name)
[Link](q)
rs=[Link]()
if rs==None:
print("USER NOT FOUND")
else:
dpl_name=input("Enter the playlist name you want to delete:")
q1="drop table {}".format(dpl_name)
q2="delete from playlists where PL_NAME='{}'".format(dpl_name)
ch=input('Enter Are you sure you want to delete this playlist?(Y/N)')
if [Link]()=='Y':
[Link](q1)
[Link](q2)
print('Deleted sucessfully')
else:
print("Deletion cancelled'")
[Link]()
except Exception as e:
print(e)
[Link]()
[Link]()
def songplayer():
try:
mycon=[Link](host="localhost",
user="root",password="kkss", database="Album")
mycur=[Link]()
display_song()
no = int(input("Enter the Song Code of the Song whose snippet is to be
played: "))
q= "select * from Musically where S_CODE={}".format(no)
[Link](q)
rs=[Link]()
if rs==None:
print("Song Does Not Exist")
else:
Sname = rs [1]
print("The song has started playing...")
play(Sname)
except Exception as e:
print(e)
[Link]()
[Link]()
#MAIN
def main():
print('-'*20, "Welcome to Musically !!",'-'*20)
print()
print("Enter 1 to Sign in as an Admin")
print("Enter 2 to Sign in as a User")
print("Enter 3 to Create a New User Account")
print("Enter X to exit Musically")
sign=input("Enter your Choice: ")
if [Link]()=='X':
exit()
elif sign=='1':
while True:
print()
print("1. Update Song Information (Plays, Years...etc)")
print("2. Delete Musically")
print("3. Add Musically")
print("4. Check Cancellation of User's Membership")
print("5. Update Membership Details")
print("6. Display User Information")
print("7. LOG OUT")
ch=int(input("Enter Your Choice: "))
if ch==1:
update_song()
elif ch==2:
del_song()
elif ch==3:
add_song()
elif ch==4:
cancel_mem()
elif ch==5:
update_memdet()
elif ch==6:
display_users()
elif ch==7:
ans1=input('Do you want to log out? (y/n)')
if [Link]()=='y':
main()
elif int(sign)==2:
sign_user()
while True:
print()
print("1. Updating Membership")
print("2. Search for All Musically by an Artist")
print("3. Create a Playlist and Add Musically")
print("4. Add Musically to an existing Playlist")
print("5. Delete Musically from a Playlist")
print("6. Delete Playlist")
print("7. Play Musically")
print("8. LOG OUT")
ch=int(input("Enter Your Choice: "))
if ch==1:
update_mem()
elif ch==2:
search_artist()
elif ch==3:
create_pl()
elif ch==4:
add_songpl()
elif ch==5:
del_songpl()
elif ch==6:
del_pl()
elif ch==7:
songplayer()
elif ch==8:
ans2=input('Do you want to log out? (y/n)')
if [Link]()=='y':
main()
print("Logged out sucessfully")
elif int(sign)==3:
mycon=[Link](host="localhost",
user="root",password="kkss", database="album")
mycur=[Link]()
U_Name=input("Enter U_Name: ")
U_Code=int(input("Enter the user code:"))
Pass_W=input("Enter Password: ")
Pass_We=input("Enter Your Password Again for Confirmation: ")
print()
if Pass_W!=Pass_We:
print("Password does not match!")
main()
else:
print('Enter')
P_code=int(input("Enter the P_Code:"))
ty=input("Enter the user/admin:")
if ty=='USER':
TYPE='USER'
elif ty=='ADMIN':
TYPE='ADMIN'
q="insert into password
values({},'{}','{}','{}')".format(P_code,U_Name,Pass_W ,TYPE)
[Link](q)
[Link]()
doj=[Link]()
print('Do you want a Musically membership?')
display_membership()
ch=input('Enter membership level if interested and * is membership is
not needed: ')
if [Link]()=='silver':
MEM_TYPE ='SILVER'
elif [Link]()=='gold':
MEM_TYPE='GOLD'
elif [Link]()=='platinum':
MEM_TYPE='PLATINUM'
elif [Link]()=='diamond':
MEM_TYPE='DIAMOND'
elif ch=='*':
MEM_TYPE ='NULL'
q1="insert into users
values('{}','{}','{}','{}'}".format(U_ID,U_Name,doj,MEM_TYPE)
[Link](q1)
[Link]()
while True:
print()
print("1. Updating Membership")
print("2. Search for All Musically by an Artist")
print("3. Create a Playlist and Add Musically")
print("4. Add Musically to an existing Playlist")
print("5. Delete Musically from a Playlist")
print("6. Delete Playlist")
print("7. Play Musically")
print('8. Log out')
ch=int(input("Enter Your Choice: "))
if ch==1:
update_mem()
elif ch==2:
search_artist()
elif ch==3:
create_pl()
elif ch==4:
add_songpl()
elif ch==5:
del_songpl()
elif ch==6:
del_pl()
elif ch==7:
songplayer()
elif ch==8:
ans3=input('Do you want to log out? (y/n)')
if [Link]()=='y':
break
else:
print("Invalid Option")
main()
main()