Skip to content
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

No such file or dir after downloading some songs #162

Closed
pratikbin opened this issue Mar 17, 2021 · 13 comments
Closed

No such file or dir after downloading some songs #162

pratikbin opened this issue Mar 17, 2021 · 13 comments
Labels

Comments

@pratikbin
Copy link

Describe the bug
No such file or dir after downloading around 55 songs

[youtube:search] playlist iann dior, Gunna - Strings Lyrics: Downloading 0 videos
[download] Finished downloading playlist: iann dior, Gunna - Strings Lyrics
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/mutagen/_util.py", line 251, in _openfile
    fileobj = open(filename, "rb+" if writable else "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Emotional RapTrap/iann dior, Gunna - Strings.mp3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/spotify_dl", line 8, in <module>
    sys.exit(spotify_dl())
  File "/usr/lib/python3.9/site-packages/spotify_dl/spotify_dl.py", line 84, in spotify_dl
    download_songs(songs, save_path, args.format_str, args.skip_mp3)
  File "/usr/lib/python3.9/site-packages/spotify_dl/youtube.py", line 52, in download_songs
    song_file = MP3(path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3"),
  File "/usr/lib/python3.9/site-packages/mutagen/_file.py", line 48, in __init__
    self.load(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/mutagen/_util.py", line 154, in wrapper
    with _openfile(self, filething, filename, fileobj,
  File "/usr/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.9/site-packages/mutagen/_util.py", line 272, in _openfile
    raise MutagenError(e)
mutagen.MutagenError: [Errno 2] No such file or directory: 'Emotional RapTrap/iann dior, Gunna - Strings.mp3'
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit

To Reproduce
spotify_dl -V -l https://open.spotify.com/playlist/2EM05rztV3ptTwObSOM9o7\?si\=N6aoBBbTQoeaf2n350_3RA\&nd\=1 -o .

Expected behavior
it should continue to download music

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Arch linux 5.9.16-1-MANJARO
  • Python 3.9.1
  • spotify-dl 7.5.0
@pratikbin pratikbin added the bug label Mar 17, 2021
@pratikbin pratikbin changed the title No such file or dir after downloading around 55 songs No such file or dir after downloading some songs Mar 17, 2021
@ghost
Copy link

ghost commented Mar 17, 2021

Also having this issue, and you can't run as sudo because of the enviroment variables. Comment me if someone finds a fix.

@ghost
Copy link

ghost commented Mar 17, 2021

One fix would be to allow us to pass our spotify or youtube tokens as arguments, I will attempt to make a fork later for that.

@pratikbin
Copy link
Author

FYI im setting envs in rc file

@SathyaBhat
Copy link
Owner

Also having this issue, and you can't run as sudo because of the enviroment variables. Comment me if someone finds a fix.

@TobiWtf

you can pass process specfiic env variables.

sudo SPOTIPY_CLIENT_ID=xxx SPOTIPY_CLIENT_SECRET=xx spotify_dl ..

also what's the reason to use sudo?

@ghost
Copy link

ghost commented Mar 17, 2021

Also having this issue, and you can't run as sudo because of the enviroment variables. Comment me if someone finds a fix.

@TobiWtf

you can pass process specfiic env variables.

sudo SPOTIPY_CLIENT_ID=xxx SPOTIPY_CLIENT_SECRET=xx spotify_dl ..

also what's the reason to use sudo?

Oh my bad, im still decently new to the linux ecosystem.

So, essentially, i am also getting an error occasionally where it will say the same thing as that guy, i can send a full log in a bit, so i was wondering if running with admin perms would allow it to write to the file anyways.

Also as an unrelated side note, the files should have some formatting, the reason i say this is because at the moment, i downloaded some AC/DC songs and the / messed with the file path.

@mcDevnagh
Copy link

The issue seems to be that there is no file, and its being opened to read. A work around I found is editing these 2 lines to the following, as well as adding a line before it:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not skip_mp3 and path.isfile(mp3_file):
            song_file = MP3(mp3_file, ID3=EasyID3)

This fix doesn't actually fix the one song that failed. It just prevents the script from halting in its tracks, and continues.
There's a try/except block right before the line that fails, so idk what's going on, or how to fix it, since the Exception is handled properly.
Note that the script continues on its merry way without downloading any songs that seemingly failed. If you want to know which songs you are now lacking, you can expand it to:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not path.isfile(mp3_file):
            with open('some_error_log.txt', 'a') as log:
                log.write(f"Error in downloading {song.get('artist')} - {song.get('name')}\n")
            continue
        if not skip_mp3:
            song_file = MP3(mp3_file, ID3=EasyID3)

@ghost
Copy link

ghost commented Mar 18, 2021

The issue seems to be that there is no file, and its being opened to read. A work around I found is editing these 2 lines to the following, as well as adding a line before it:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not skip_mp3 and path.isfile(mp3_file):
            song_file = MP3(mp3_file, ID3=EasyID3)

This fix doesn't actually fix the one song that failed. It just prevents the script from halting in its tracks, and continues.
There's a try/except block right before the line that fails, so idk what's going on, or how to fix it, since the Exception is handled properly.
Note that the script continues on its merry way without downloading any songs that seemingly failed. If you want to know which songs you are now lacking, you can expand it to:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not path.isfile(mp3_file):
            with open('some_error_log.txt', 'a') as log:
                log.write(f"Error in downloading {song.get('artist')} - {song.get('name')}\n")
            continue
        if not skip_mp3:
            song_file = MP3(mp3_file, ID3=EasyID3)

Interesting work around, I wonder why it's failing. This seems like it may be an issue with the youtube parser, rather than spotify. Let me take a look.

@ghost
Copy link

ghost commented Mar 18, 2021

The issue seems to be that there is no file, and its being opened to read. A work around I found is editing these 2 lines to the following, as well as adding a line before it:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not skip_mp3 and path.isfile(mp3_file):
            song_file = MP3(mp3_file, ID3=EasyID3)

This fix doesn't actually fix the one song that failed. It just prevents the script from halting in its tracks, and continues.
There's a try/except block right before the line that fails, so idk what's going on, or how to fix it, since the Exception is handled properly.
Note that the script continues on its merry way without downloading any songs that seemingly failed. If you want to know which songs you are now lacking, you can expand it to:

        mp3_file = path.join(download_directory, f"{song.get('artist')} - {song.get('name')}.mp3")
        if not path.isfile(mp3_file):
            with open('some_error_log.txt', 'a') as log:
                log.write(f"Error in downloading {song.get('artist')} - {song.get('name')}\n")
            continue
        if not skip_mp3:
            song_file = MP3(mp3_file, ID3=EasyID3)

Interesting work around, I wonder why it's failing. This seems like it may be an issue with the youtube parser, rather than spotify. Let me take a look.

Took a look. Seems like this is a youtube_dl issue.

@ghost
Copy link

ghost commented Mar 18, 2021

Maybe try re-querying the youtube if the song fails, and restarting the process for said song? Will try to see later.

@pratikbin
Copy link
Author

i tried re-running several times but doesn't work

@SathyaBhat
Copy link
Owner

The error is not from Youtube-dl but rather from Mutagen which is used to write back the metadata to the file

mutagen.MutagenError: [Errno 2] No such file or directory: 'Emotional RapTrap/iann dior, Gunna - Strings.mp3'

probably some mismatch between how mutagen sanitizes the filename vs how the script saves it

@Tristan-Day
Copy link

I was experiencing this issue and it seems to be fixed in #152 providing you still install using pip and replace youtube.py and utils.py with the latest versions from the repository this will resolve the issue

@SathyaBhat
Copy link
Owner

this is released with 7.6 release #174. please update and try it out, if not open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants