I am working on a virtual assistant using python. When I ask him to play the recently downloaded music, he is supposed to search for the recent music file and then play it. But, this is where the problem arises. There are also some other files other the 'mp4'. So, it open an image every time. I can delete or move that file, but I don't want to happen it with my users when they use it. So I trying to write a script that automatically searches the latest file with a specific extension and the play.
Here is my code:-
elif 'play downloaded music' in query or 'play downloaded song' in query or 'play that song' in query or 'play the downloaded song' in query or 'play the downloaded music' in query:
try:
latest_song = os.path.join(music_path, (max([os.path.join(music_path, basename) for basename in (os.listdir(music_path))], key=os.path.getctime)))
os.startfile(latest_song)
holdon()
except:
print("Sorry! No song found.")
speak("Sorry! No song found.")