-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For-loop to determine the mood for the lyrics text files #4
Comments
Hm, have you checked that your folder |
The lyrics folder(F:/Music/project/lyrics) contains the lyrics of all songs in mp3s folder |
Looks like it's trying to open the folder |
print(lyrics_fullpaths) gives me this
|
Okay, I see that there's an 'mp3' in the paths e.g., If it should be the latter, you could change
into the following:
PS: Also, I am honestly not sure about the backslashes in windows -- i.e., if that's a problem in Python (never used Python on Windows). |
After changing to 'F:/Music/project/lyrics\01 - Cake By The Ocean.mp3', 'F:/Music/project/lyrics\01 Intro.mp3', 'F:/Music/project/lyrics\01 Lit Like Bic.mp3', 'F:/Music/project/lyrics\01 Ten Thousand Hours.mp3', 'F:/Music/project/lyrics\01-macklemore_and_ryan_lewis-light_tunnels_(feat_mike_slap).mp3', 'F:/Music/project/lyrics\01. Always In My Head.mp3', 'F:/Music/project/lyrics\02 - Here I Am (Come and Take Me).mp3', 'F:/Music/project/lyrics\02 - Pay My Rent.mp3', "F:/Music/project/lyrics\02 Can't Hold Us (feat. Ray Dalton).mp3", 'F:/Music/project/lyrics\02 January 28th.mp3', 'F:/Music/project/lyrics\02 Unlock the Swag (feat. Jace of Two-9).mp3', 'F:/Music/project/lyrics\02-macklemore_and_ryan_lewis-downtown_(feat_eric_nally_melle_mel_kool_moe_dee_and_grandmaster_caz).mp3', 'F:/Music/project/lyrics\02. Cemeteries Of London.mp3', 'F:/Music/project/lyrics\02. Magic.mp3', "F:/Music/project/lyrics\03 - Bring Me Your Cup (7'' Version).mp3", 'F:/Music/project/lyrics\03 - Toothbrush.mp3', 'F:/Music/project/lyrics\03 No Flex Zone.mp3', 'F:/Music/project/lyrics\03 One For the Road.mp3', 'F:/Music/project/lyrics\03 Thrift Shop (feat. Wanz).mp3', 'F:/Music/project/lyrics\03 Wet Dreamz.mp3', 'F:/Music/project/lyrics\03-macklemore_and_ryan_lewis-brad_pitts_cousin_(feat_xp).mp3', 'F:/Music/project/lyrics\03. Ink.mp3', 'F:/Music/project/lyrics\03. Lost!.mp3', 'F:/Music/project/lyrics\04 - Jinx.mp3', 'F:/Music/project/lyrics\04 - One in Ten.mp3', "F:/Music/project/lyrics\04 03' Adolescence.mp3", 'F:/Music/project/lyrics\04 Arabella.mp3', 'F:/Music/project/lyrics\04 My X.mp3', 'F:/Music/project/lyrics\04 Thin Line (feat. Buffalo Madonna).mp3', 'F:/Music/project/lyrics\04-macklemore_and_ryan_lewis-buckshot_(feat_krs_one_and_dj_premier).mp3', 'F:/Music/project/lyrics\04. 42.mp3', 'F:/Music/project/lyrics\04. True Love.mp3', 'F:/Music/project/lyrics\05 - Red Red Wine.mp3', 'F:/Music/project/lyrics\05 A Tale of 2 Citiez.mp3',.. , 'F:/Music/project/lyrics\18 Victory Lap.mp3'] |
and am still getting this error>> with open (lyrics, 'r') as f: |
Hm, that's weird. Can you maybe post the full script that you are using? I can try this on my machine with some example files to see what I get |
import shutil
import os
mp3path='F:/Music/project/mp3s'
happy_mp3path='F:/Music/project/happy_mp3s'
sad_mp3path='F:/Music/project/sad_mp3s'
lyrics='F:/Music/project/lyrics'
mp3s= [f for f in os.listdir(mp3path) if f.endswith('.mp3')]
mp3s_fullpaths=[os.path.join(mp3path, f) for f in mp3s]
happymp3s_fullpaths=[os.path.join(happy_mp3path, f) for f in mp3s]
sadmp3s_fullpaths=[os.path.join(sad_mp3path, f) for f in mp3s]
lyrics_fullpaths = [f.replace('.mp3', '.txt') for f in mp3s_fullpaths]
lyrics_fullpaths = [f.replace('mp3s', 'lyrics') for f in mp3s_fullpaths]
for mp3,happy_mp3, sad_mp3, lyric in zip(mp3s_fullpaths, happymp3s_fullpaths,
sadmp3s_fullpaths, lyrics_fullpaths):
with open (lyrics, 'r') as f:
txt=f.read()
#prediction= None
#processing of txt
#classification of processed txt
if classify(txt) == 'happy':
shutil.move(mp3,happy_mp3)
else:
shutil.move(mp3,sad_mp3)
#print(lyrics_fullpaths) |
Okay, I see you had a typo in the for loop, where you used the variable name import shutil
import os
mp3path='F:/Music/project/mp3s'
happy_mp3path='F:/Music/project/happy_mp3s'
sad_mp3path='F:/Music/project/sad_mp3s'
lyrics='F:/Music/project/lyrics'
mp3s= [f for f in os.listdir(mp3path) if f.endswith('.mp3')]
mp3s_fullpaths=[os.path.join(mp3path, f) for f in mp3s]
happymp3s_fullpaths=[os.path.join(happy_mp3path, f) for f in mp3s]
sadmp3s_fullpaths=[os.path.join(sad_mp3path, f) for f in mp3s]
lyrics_fullpaths = [os.path.join(lyrics,
os.path.basename(f).replace('.mp3', '.txt'))
for f in mp3s_fullpaths]
for mp3,happy_mp3, sad_mp3, lyric in zip(mp3s_fullpaths, happymp3s_fullpaths,
sadmp3s_fullpaths, lyrics_fullpaths):
with open (lyric, 'r') as f:
txt=f.read()
print(txt)
#prediction= None
#processing of txt
#classification of processed txt
#
#if classify(txt) == 'happy':
# shutil.move(mp3,happy_mp3)
#else:
# shutil.move(mp3,sad_mp3)
#print(lyrics_fullpaths) |
am still getting this error >> with open (lyric, 'r') as f: |
Not sure since I don't have much experience with Windows, but maybe replacing the forward slashes by backslashes for the filepaths solves the problem? |
still the same error |
not sure what it is then. Try open the file path (e.g. 'F:\Music\project\lyrics\01 - Cake By The Ocean.txt') from the terminal. If that doesn't work, than there's something about the file path ... maybe the spaces are an issue on win? |
something like this |
There should be an 'r' instead of the 't'. With terminal, I meant opening the command line terminal and using a command line text editor to open the file path. On Linux/MacOS simply doing a
but I am not sure what the windows equivalent of that would be. Typically, I also avoid whitespaces in all my files and folders, because that can cause some problems for certain tools. So, I don't know how to best deal with that, sry. |
the equivalence of cat is type in windows
|
Sorry to hear that. I guess I can not be much of help with that. But maybe search on Google or stackoverflow for something like "how to open a file with whitespaces in Python on Windows" ? |
Finally got the solution to the problem. The lyric file has to have the same name with the songs file ...like Arctic Monkeys - Arabella.txt and Arctic Monkeys - Arabella.mp3 not like mine which was 04 Arabella.mp3 |
Is there a way in which you can solve this problem because the lyric files will not always match with the mp3 files name? |
Glad that it works now in general. Finding lyrics files if they don't match the filename exactly sounds tricky. You could try to a fuzzy-string matching approach maybe. I.e., for each song, you would have to compute the fuzzy matching score for each lyric file, then you would the one with the highest similarity score, and then you would check if it's above a certain minimum threshold (say 80% similarity or sth like that). There's a Python library that could be useful for this: https://github.com/seatgeek/fuzzywuzzy |
I am getting this error message after running
The text was updated successfully, but these errors were encountered: