Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import webbrowser #allows to open websites -> font:https://stackoverflow.com/questions/31715119/how-can-i-open-a-website-in-my-web-browser-using-python
import glob #allows to have a list
import os #provides a portable way of using operating system functionalities
import random #allows to choose randomly an index of a list
"""allows user to see and play the musics inside the music folder, localized in the same directory as the play.py"""
def play(sentence):
mlist = (glob.glob("music/*.mp3")) #gets all the names of the musics inside the folder music, in the same directory as the python files
if "show" in sentence or "list" in sentence:
if "my" not in sentence:
if "all" in sentence:
filt = sentence
if "show" in sentence:
if "all" in sentence:
filt = filt.replace("show all music of ", "") #filters sentence to get the name to identify the music
else:
if "all" in sentence:
filt = filt.replace("list all music of ", "") #filters sentence to get the name to identify the music
filt = filt.lower()
print("All music of :", filt.upper() ," \n")
attp = 0
for i in mlist:
top = i.lower()
i = i[6:] #filter the value in order to get only the name of the music/artist
if filt in top:
print(i) #prints the songs with the name user wanted
attp = 1
if attp < 1:
print("You have no songs with that name")
else:
print("Your music: \n")
for i in mlist:
i = i[6:] #filter the value in order to get only the name of the music/artist
print(i) #prints the song
elif "random" in sentence or "shuffle" in sentence:
shuffle = random.choice(mlist) #chooses one random song
os.startfile(shuffle) #execute the song with that name
shuffle = shuffle[6:] #filters the name of the song to print only the name of the song and artist
print("Playing ", shuffle)
else:
if "play " in sentence:
counter = 0
newS = sentence.replace("play ", "") #gets the name of the song
for i in mlist:
top = i.lower()
newS = newS.lower()
if newS in top: #if finds the name of the song wanted
print("Playing ", i[6:])
os.startfile(i) #plays the music qanted
break
else:
if counter < (len(mlist)-1): #allows to continue searching while there are still musics to search
counter += 1
continue
else: #if doesn't find the song wanted in the list:
uOpen(sentence)
break
"""plays the music wanted in the youtube"""
def uOpen(sentence):
sentence = sentence[5:] #sentence is sentence after play
print("Playing " + sentence)
url = "https://www.youtube.com/results?search_query=" + sentence
webbrowser.open(url) #opens google with that url
"""allows the user to open websites as long as the user knows the link (ex: google.com)"""
def uGoogle(sentence):
sentence = sentence[5:] #sentence is sentence after open
print("Opening " + sentence)
url = "https://www." + sentence
webbrowser.open(url) # opens google with that url