onnowhere / youtube_music_playlist_downloader

YouTube Music Playlist Downloader
MIT License
133 stars 11 forks source link

[13996] Failed to execute script 'youtube_music_playlist_downloader' due to unhandled exception! #7

Closed ShadicSlash closed 1 year ago

ShadicSlash commented 1 year ago

Hello. I am not knowledgeable with python and in coding in general but I would really love to use your downloader. Since I posted this I read a bit and managed to install all requirements using Python 3.9. I also added ffmpeg to PATHs. After all my troubleshooting, I still have the same exact error:

C:\Users\Shadic\Desktop>youtube_music_playlist_downloader.exe Traceback (most recent call last): File "yt_dlp\compat\compat_utils.py", line 36, in getattribute File "yt_dlp\compat\compat_utils.py", line 56, in getattr AttributeError: module yt_dlp.dependencies.Cryptodome.Cipher has no attribute AES

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "youtube_music_playlist_downloader.py", line 14, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp__init__.py", line 18, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\cookies.py", line 18, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\aes.py", line 5, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\dependencies__init.py", line 76, in File "yt_dlp\compat\compat_utils.py", line 43, in getattribute File "yt_dlp\compat\compat_utils.py", line 56, in getattr__ AttributeError: module yt_dlp.dependencies.Cryptodome.Cipher has no attribute AES [13996] Failed to execute script 'youtube_music_playlist_downloader' due to unhandled exception!

I would really love for it to work, can you guys help and know what's going on? Thank you in advance.

onnowhere commented 1 year ago

https://github.com/onnowhere/youtube_music_playlist_downloader/releases/tag/1.2.1

Try re-downloading. I have updated the yt-dlp version again to the latest, which may fix the issue.

If that does not fix it, perhaps you can try pip install --upgrade yt-dlp

If it still does not work, try running these in succession: pip install yt-dlp==2023.1.6 pip install yt-dlp==2023.02.17

ShadicSlash commented 1 year ago

After all that, it looks like the same error unfortunately. So here what I did since the start, maybe I am just not doing the correct thing because I just started using Python. I went to the yt-dlp page and fell into a rabbit hole. Looks like all my errors are related to pycrypto or crypto something and I can't manage to fix it. So basically it looks like it's not your program's fault.

D:\Shadic\Downloads>youtube_music_playlist_downloader.exe Traceback (most recent call last): File "yt_dlp\compat\compat_utils.py", line 36, in getattribute File "yt_dlp\compat\compat_utils.py", line 56, in getattr AttributeError: module yt_dlp.dependencies.Cryptodome.Cipher has no attribute AES

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "youtube_music_playlist_downloader.py", line 14, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp__init__.py", line 18, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\cookies.py", line 18, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\aes.py", line 5, in File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "yt_dlp\dependencies__init.py", line 76, in File "yt_dlp\compat\compat_utils.py", line 43, in getattribute File "yt_dlp\compat\compat_utils.py", line 56, in getattr__ AttributeError: module yt_dlp.dependencies.Cryptodome.Cipher has no attribute AES [7172] Failed to execute script 'youtube_music_playlist_downloader' due to unhandled exception!

onnowhere commented 1 year ago

Are you still using the executable or have you tried using the file in the repo directly? It seems like since you're installing python yourself and everything, you wouldn't need to use the exe since the exe should be able to run without it and comes packaged with its own yt-dlp. Perhaps also try pip uninstall yt-dlp and reinstall it?

onnowhere commented 1 year ago

Ah, I just tried the executable on my end and I'm hitting the issue... I'll try to look into it more but for now avoid using the exe since it seems you have everything installed yourself already

onnowhere commented 1 year ago

I've also updated the exe and hopefully fixed the issue. There were some changes I needed to make to make it compile yt-dlp properly. If you do decide to use the exe instead of running it from the source files, reminder that it uses its own version of yt-dlp and other install requirements and doesn't need python installed to run.

ShadicSlash commented 1 year ago

So without knowing, all I've done is reproducing what the .exe does by itself... all right. At least I've learned stuff. It's now working thank you. My only concern is it possible for it to download 320kbps .mp3 quality instead of only 124kbps? Is there a higher option than "bestaudio/best"? On youtube it sounds way better. I don't know how your program gets the songs but I have youtube premium where you can select either Low Quality or High Quality. My guess is that it's only getting the low quality version.

onnowhere commented 1 year ago

Hmm, by default yt-dlp should already hey best quality. You could try setting the audio format to an empty string to try the default or maybe change it to just "bestaudio" but I'm not sure the result will be any different. I think the main reason may be the audio format where I believe opus is the highest quality version YouTube stores from my basic research about it... Perhaps you could set the audio codec to something else to see if you get a higher quality, like opus or vorbis, and then convert it to mp3 manually? I can't experiment with it right now.

Does YouTube premium give an mp3?

ShadicSlash commented 1 year ago

It doesn't, it works like Spotify and all files are encrypted. I used flac as audio codec and the quality is really good but the metadata does not apply. Ill have to find a codec which does then downgrade to mp3.

onnowhere commented 1 year ago

You can try using ytdlp directly to see if you find any settings that provide better audio. If you do find something let me know. I'll try to look into it too. I'm wondering if YouTube premium just does something we can't.

ShadicSlash commented 1 year ago

Sorry I'm always editing my comments.

onnowhere commented 1 year ago

https://github.com/yt-dlp/yt-dlp/issues/1091 It looks like premium audio is indeed a locked feature. You may have to provide your cookies to yt-dlp for it to access the authentication through your account to grab premium audio. I can perhaps look into adding a cookies option to the config as well.

ShadicSlash commented 1 year ago

From what I understand, the mp3 codec get a low bitrate webm version of the video then converts it to 124kbps mp3... But when I change the codec to flac, I see a webm file for a very short moment before it becomes a flac.. but the flac has really good quality and is around 1500kbps, so I guess it takes the highest quality there. The problem there is that it doesn't have the metadata and as a typical flac... really big file. I am not knowledgable enough in that python thing to make the mp3 320kbps with it's metadata. I mean I could always convert them myself to mp3 at it's best quality but again... I'm not gonna create the metadata for 200 songs. Anyways, no rush. Ima wait if I have to, I love that project

onnowhere commented 1 year ago

Can you provide a link that has that behavior to reproduce it just in case? I'm assuming you got that without YouTube premium cookies. If possible, maybe try converting the flac with an online converter to see if the audio actually outputs higher quality just to be sure?

ShadicSlash commented 1 year ago

Like I said, looks like I was wrong with the Premium thing, or it takes the cookies with my logged in connexion. I changed the codec to flac in the json settings and it downloads at it's max bitrates (around 1500kbps) and the quality is superb. The problem with that codec is that flac is a huge file and the metadata does not apply.

ShadicSlash commented 1 year ago

So would it be possible to download the high quality FLAC then converts it to 320kbps mp3 then it applies the metadata? Like that we would be able to have the best mp3 quality with all it's metadata.

onnowhere commented 1 year ago

Sorry I haven't had time to take a look yet, will get back when I get a chance

onnowhere commented 1 year ago

From what I understand, without premium, it should only be offering the quality currently available. When we convert it to other formats, flac/mp3, it still depends on this highest quality option available on the YouTube servers. In this case, I'm inclined to believe the flac file you got is a placebo, or it was upscaled(?) on your local computer by ffmpeg, and that after converting to mp3 it would be no better than the original mp3. I tried setting the audio format to flac on my end but unfortunately I can't tell a difference versus the normal mp3, and I do not have YouTube premium to compare against an actual confirmed high quality song.

https://www.reddit.com/r/youtubedl/comments/qypms2/are_flac_audio_downloads_truly_flac_quality/

https://www.reddit.com/r/youtubedl/comments/jawnjv/audio_file_type_flac_vs_mp3/

You aren't downloading FLAC from YouTube. You are downloading a lossy codec and then you are converting it to FLAC. This will always result in a huge file with no gain.

onnowhere commented 1 year ago

Actually, you can give this a shot. I've updated to include an audio_quality field (adjustable in the config file). By default it is the same as ytdlp's default: 5. If you want the best, set it to 0, worst is 10. I was able to get a higher quality output when I did this. Apparently it also supports using custom quality like 128K but I wasn't quite able to verify if that works. You can run with the option Generate default playlist config first, edit the config, then update the playlist to download with the proper settings on first run.

Let me know if it works!

onnowhere commented 1 year ago

FYI, this update also includes a cookies_from_browser option. You can specify your browser name here such as chrome and it will pull in cookies to use for yt-dlp, such as to get YouTube Premium videos. You can find more info about it here: https://github.com/yt-dlp/yt-dlp

--cookies-from-browser BROWSER[+KEYRING][:PROFILE][::CONTAINER] The name of the browser to load cookies from. Currently supported browsers are: brave, chrome, chromium, edge, firefox, opera, safari, vivaldi. Optionally, the KEYRING used for decrypting Chromium cookies on Linux, the name/path of the PROFILE to load cookies from, and the CONTAINER name (if Firefox) ("none" for no container) can be given with their respective seperators. By default, all containers of the most recently accessed profile are used. Currently supported keyrings are: basictext, gnomekeyring, kwallet

If you want to use a cookie file instead, it's available through putting the path in the cookie_file option (--cookies in yt-dlp's readme).

ShadicSlash commented 1 year ago

I’ve been testing it since 2 days now. Using the cookies thing with my Brave browser and it’s been getting automatically. On 90 songs, there’s one that it won’t download but I think that’s a youtube problem. For the quality, i’ve been using 0 instead of 5 and I can’t find a difference in audio by listening at both youtube music and the downloaded file. Even though it’s not up to 320kbps but the bitrate is variable, I guess there’s no better audio coming from youtube music than that. Now for the metadata there’s 2 things that’s bothering me a little. There’s no way to turn off the value for the track number so I always have to remove it afterwards. (Youtube music doesn’t have that value for albums anyway I think). The other is that the artwork is kind of low quality. The one on youtube music is higher quality so idk if there’s anything you can do in your code to allow higher quality album covers. Another things that’s been a little annoying is that it’s always asking if I want to change the settings of the saved playlist. I’d prefer to just select the playlist I want to update the songs and that’s it. It would be nice if you just make another option in the main menu to change the playlist settings for saved playlist instead.

In conclusion. Thank you for the follows up and good job

onnowhere commented 1 year ago

For track number you can disable track_num_in_name in the config file for the playlist if you mean the number in the file name. Unless you mean the track number in the mp3 metadata? The reason that originally existed was to maintain the identical ordering from your playlist in YouTube including when updating, but let me know which one you meant. As for a quick update menu option and thumbnail I can look into it. Thanks for the feedback!

ShadicSlash commented 1 year ago

I meant the one in the mp3 metadata.

onnowhere commented 1 year ago

Can you link the video you have thumbnail quality issues with, as well as a link to the thumbnail you found that has higher quality? I believe the default is 720p, and it should get the best available iirc. Sometimes the best thumbnail listed in a video is actually 720p despite being listed as 1080p. I made a change to zoom in the crop on thumbnails that come with black bars due to aspect ratios that aren't 16:9, not sure if this fixes the issue. On my end it feels like the quality is pretty closely matching, what app are you using to view the cover art on a song file? If you look really closely I suppose you can see some slight jpg compression - I chose jpg currently as the default to reduce the size, but I can add an option for png potentially?

onnowhere commented 1 year ago

I've released a new update with all the changes so far including option to choose png as the image type. If you want to update all your metadata to match your settings, you'll have to pick the Modify previously saved playlist option and choose to force update all names and metadata after adjusting the config. Just in case, you can get the config file to show the new options with proper formatting just by doing a normal quick update on the playlist (the new option added in this release).

Sample settings:

    "image_format": "png",
    "include_metadata": {
        "title": true,
        "cover": true,
        "track": false,
        "artist": true,
        "album": true,
        "date": true
    }
onnowhere commented 1 year ago

Closing as assumed resolved