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

ModuleNotFoundError: No module named 'youtube_dl' #253

Open
1marc1 opened this issue Oct 31, 2024 · 16 comments
Open

ModuleNotFoundError: No module named 'youtube_dl' #253

1marc1 opened this issue Oct 31, 2024 · 16 comments

Comments

@1marc1
Copy link

1marc1 commented Oct 31, 2024

My issue is very similar to this issue.

I am running Mopidy as a service as the user mopidy. I have tried using both youtube_dl and yt-dlp. In both cases, when I want to play a track, I see the following in the logs:

Oct 31 22:44:09 rpi3.home.com mopidy[2279]: ERROR    [YouTubeCoreListener-11 (_actor_loop)] mopidy.listener Triggering event failed: tracklist_changed()
Oct 31 22:44:09 rpi3.home.com mopidy[2279]: Traceback (most recent call last):
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/lib/python3/dist-packages/mopidy/listener.py", line 44, in on_event
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     getattr(self, event)(**kwargs)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/backend.py", line 61, in tracklist_changed
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     [video.audio_url for video in videos]
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/backend.py", line 61, in <listcomp>
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     [video.audio_url for video in videos]
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:      ^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/youtube.py", line 38, in wrapper
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     func(self)  # should create the future
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     ^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/local/lib/python3.11/dist-packages/mopidy_youtube/youtube.py", line 390, in audio_url
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     youtube_dl = importlib.import_module(youtube_dl_package)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:     return _bootstrap._gcd_import(name[level:], package, level)
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
Oct 31 22:44:09 rpi3.home.com mopidy[2279]:   File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
Oct 31 22:44:09 rpi3.home.com mopidy[2279]: ModuleNotFoundError: No module named 'youtube_dl'
Oct 31 22:44:30 rpi3.home.com mopidy[2279]: ERROR    [YouTubeBackend-4 (_actor_loop)] mopidy_youtube translate_uri error "No module named 'youtube_dl'"
Oct 31 22:44:30 rpi3.home.com mopidy[2279]: WARNING  [Core-7 (_actor_loop)] mopidy.core.tracklist Track is not playable: youtube:video:3tmd-ClpJxA

When I uninstall youtube_dl and install yt-dlp, then the "missing" module is listed as yt_dlp.
Where my issue differs from the other issue is that when I run python and manually try to import the modules, I get a SyntaxError:

pi@rpi3:~ $ python 
Python 3.11.2 (main, May  2 2024, 11:59:08) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ytmusicapi
>>> import yt-dlp
  File "<stdin>", line 1
    import yt-dlp
             ^
SyntaxError: invalid syntax

The above also happens for when I run python as the root user or the mopidy user.

The commands I use to install youtube_dl and yt_dlp are:

$ sudo python3 -m pip install youtube_dl --break-system-packages
$ sudo python3 -m pip install yt-dlp --break-system-packages
$ yt-dlp --version
2024.10.22

The relevant section of my /etc/mopidy/mopidy.conf file is:

[youtube]
enabled = true
allow_cache = true
#youtube_api_key = ********
#api_enabled = true
musicapi_enabled = true
youtube_dl_package = yt-dlp

To simplify things, I disabled the API key initially when it wasn't working.

Any help is much appreciated.

Thank you.

@kingosticks
Copy link
Collaborator

import yt-dlp

Should be import yt_dlp. You can't have a hyphen in a module name (invalid syntax, as it says) so hyphens in package names must be swapped for underscores in modules. You can see this in their examples.

@1marc1
Copy link
Author

1marc1 commented Oct 31, 2024

Thank you for pointing that out. It brings me a step closer. When I now do a search and select a track to play, the following shows in the log:

Nov 01 08:26:34 rpi3.home.com mopidy[2981]: [youtube] Extracting URL: https://music.youtube.com/watch?v=43B27OyLGVc
Nov 01 08:26:34 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading webpage
Nov 01 08:26:35 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading ios player API JSON
Nov 01 08:26:35 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading mweb player API JSON
Nov 01 08:26:36 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading ios music player API JSON
Nov 01 08:26:36 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading player 4e23410d
Nov 01 08:26:56 rpi3.home.com mopidy[2981]: [youtube] 43B27OyLGVc: Downloading m3u8 information
Nov 01 08:26:57 rpi3.home.com mopidy[2981]: [info] 43B27OyLGVc: Downloading 1 format(s): 251
Nov 01 08:26:58 rpi3.home.com mopidy[2981]: [download] Destination: /var/cache/mopidy/youtube/43B27OyLGVc.webm
Nov 01 08:26:58 rpi3.home.com mopidy[2981]: [632B blob data]
Nov 01 08:26:58 rpi3.home.com mopidy[2981]: [302B blob data]

But nothing plays. If I then (in Mopidy-Iris) go to Now playing, I see the song there. If I then hit the *Play button, the following is added to the log, but the song still doesn't play:

Nov 01 08:29:59 rpi3.aureus-group-sb.com mopidy[2981]: ERROR    [MainThread] mopidy.audio.gst GStreamer error: Internal data stream error.

Searching the internet indicates that this may happen if the file to be played has a bad audio format...(?) I searched for a number of different songs (older ones and newer ones), but they all result in the same error.

FWIW, playback of local songs and internet radio works well.

Any idea what could be causing this behaviour?

Thank you.

@1marc1
Copy link
Author

1marc1 commented Oct 31, 2024

I had a further look on the internet and came across this thread, where (you) suggested to remove the resampling from the mopidy.conf file. The OP of that thread likely had a different cause of the error, but the error message was the same as mine. In order to try something, I updated my mopidy.conf file from

[audio]
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! filesink location=/run/snapserver/snapfifo

to

[audio]
output = audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! filesink location=/run/snapserver/snapfifo

then restarted Mopidy, but the result stayed the same.

I changed the mopidy.conf file back to how it was.

@1marc1
Copy link
Author

1marc1 commented Nov 2, 2024

FWIW, I made sure I have the GStreamer "bad" collection of plugins installed and my system is completely up to date.

pi@rpi3:~ $ sudo apt update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian-security bookworm-security InRelease  
Hit:3 http://deb.debian.org/debian bookworm-updates InRelease            
Get:4 https://apt.mopidy.com bookworm InRelease [13.9 kB]                                 
Hit:5 http://archive.raspberrypi.com/debian bookworm InRelease                            
Fetched 13.9 kB in 2s (6,329 B/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

pi@rpi3:~ $ sudo apt-get install gstreamer1.0-plugins-bad
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gstreamer1.0-plugins-bad is already the newest version (1.22.0-4+deb12u5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

I can see files being placed in /var/cache/mopidy/youtube. Could it be that somehow GStreamer is not able to read them? Permissions and file ownership seems to be good.

pi@rpi3:/var/cache/mopidy/youtube $ ll
total 37400
drwxr-xr-x 2 mopidy audio    4096 Nov  2 23:54 .
drwxr-xr-x 3 mopidy audio    4096 Oct 31 19:27 ..
       ### Removed a bunch to improve readability ###
-rw-r--r-- 1 mopidy audio     356 Nov  1 07:38 _tjIde4U_rw.json
-rw-r--r-- 1 mopidy audio 3462053 May  3  2024 _tjIde4U_rw.webm
-rw-r--r-- 1 mopidy audio   16121 Nov  1 07:38 _tjIde4U_rw.webp
-rw-r--r-- 1 mopidy audio     368 Nov  2 23:53 v075Ut3xL-4.json
-rw-r--r-- 1 mopidy audio 4029018 May  5 16:49 v075Ut3xL-4.webm
-rw-r--r-- 1 mopidy audio    7528 Nov  2 23:53 v075Ut3xL-4.webp

@kingosticks
Copy link
Collaborator

kingosticks commented Nov 2, 2024

Are you able to remove that output config setting and just test things play locally?

You can even try using output = fakesink to ensure you can get an error-less setup (of course you can't hear anything with fakesink though!).

Can you run with the env variable GST_DEBUG=3 set to see if any hints. Maybe it is actually a conversion problem with webm. There's also a gstreamer plugins-ugly package.

@kingosticks
Copy link
Collaborator

Oh, and also check the mopidy user has permission to create a fifo in /run/snapserver/snapfifo

@natumbri
Copy link
Owner

natumbri commented Nov 2, 2024

Sorry to be late to this party! Have you tried with allow cache turned off? Sometimes permission or disk space issues manifest like this.

Given local and radio extensions play, it sounds to me more like a mopidy-youtube bug/misconfiguration, rather than a snapcast/gstreamer issue... Fair to say, the mopidy-youtube code isn't very robust...

@1marc1
Copy link
Author

1marc1 commented Nov 3, 2024

I set output = fakesink, but that doesn't make a difference. I then had a look at the permissions and set GST_DEBUG=3 for the mopidy user.

pi@rpi3:~ $ grep mopidy /etc/passwd
mopidy:x:113:29::/var/lib/mopidy:/usr/sbin/nologin

pi@rpi3:~ $ grep mopidy /etc/group
audio:x:29:pi,pulse,snapserver,snapclient,mopidy
video:x:44:mopidy,pi,vnc

pi@rpi3:~ $ ll /run/snapserver/
total 0
drwxrwxr-x  2 snapserver audio        60 Nov  3 10:35 .
drwxr-xr-x 36 root       root       1060 Nov  3 10:36 ..
prw-rw-rw-  1 snapserver snapserver    0 Nov  3 10:35 snapfifo

pi@rpi3:~ $ cat /etc/environment 
GST_DEBUG=3
pi@rpi3:~ $ sudo su -l mopidy -s /bin/bash
mopidy@rpi3:~$ echo $GST_DEBUG
3

After a restart, we have some more detail. Output below taken from journalctl -f

Nov 03 10:53:39 rpi3.home.com mopidy[1011]: [youtube] Extracting URL: https://music.youtube.com/watch?v=hkp6sJkqj5U
Nov 03 10:53:39 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading webpage
Nov 03 10:53:40 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading ios player API JSON
Nov 03 10:53:40 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading mweb player API JSON
Nov 03 10:53:40 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading ios music player API JSON
Nov 03 10:53:41 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading player 4e23410d
Nov 03 10:53:59 rpi3.home.com mopidy[1011]: [youtube] hkp6sJkqj5U: Downloading m3u8 information
Nov 03 10:54:01 rpi3.home.com mopidy[1011]: [info] hkp6sJkqj5U: Downloading 1 format(s): 251
Nov 03 10:54:01 rpi3.home.com mopidy[1011]: [download] Destination: /var/cache/mopidy/youtube/hkp6sJkqj5U.webm
Nov 03 10:54:02 rpi3.home.com snapserver[953]: No data since 120 ms, switching to idle
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: [757B blob data]
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: 0:01:27.383478622  1011   0x7f7004a520 WARN                 basesrc gstbasesrc.c:3132:gst_base_src_loop:<source> error: streaming stopped, reason error (-5)
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: 0:01:27.383894403  1011   0x7f7004a520 WARN                typefind gsttypefindelement.c:1012:gst_type_find_element_chain_do_typefinding:<typefindelement0> error: Stream doesn't contain enough data.
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: 0:01:27.383952841  1011   0x7f7004a520 WARN                typefind gsttypefindelement.c:1012:gst_type_find_element_chain_do_typefinding:<typefindelement0> error: Can't typefind stream
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: ERROR    [MainThread] mopidy.audio.gst GStreamer error: Internal data stream error.
Nov 03 10:54:02 rpi3.home.com mopidy[1011]: [180B blob data]

I can confirm that when I download the .webm file from the cache to my local computer, it plays without any issues.

Finally, I tried with disabling the cache. The relevant youtube section in /etc/mopidy/mopidy.conf now reads:

[youtube]
enabled = true
allow_cache = false
musicapi_enabled = true
youtube_dl_package = yt_dlp

This also didn't make a difference.

@1marc1
Copy link
Author

1marc1 commented Dec 8, 2024

Between my last post and now, I have rebuilt my Raspberry Pi 3: latest Bookwork Lite OS, all updates, etc. I am now having mixed results using Mopidy-Youtube. Unfortunately, the mix is still tipping in the direction of "it not working". Perhaps the problem is outside of Mopidy-Youtube.

I have enabled logging verbosity level 4. I observe the following:

  1. I am able to search and get results from Youtube.
  2. When I play a selected item, I can see that the appropriate files are downloaded in the /var/cache/mopidy/youtube directory.
  3. However, it never gets to play the file.

After some testing, I ended up with the following:

pi@rpi3:/var/cache/mopidy/youtube $ ll
total 28108
drwxr-xr-x 2 mopidy audio    4096 Dec  8 15:04 .
drwxr-xr-x 3 mopidy audio    4096 Dec  8 14:19 ..
-rw-r--r-- 1 mopidy audio     331 Dec  8 15:01 cGlrJTH34IU.json
-rw-r--r-- 1 mopidy audio 2973575 May  3  2024 cGlrJTH34IU.webm
-rw-r--r-- 1 mopidy audio   76840 Dec  8 15:01 cGlrJTH34IU.webp
-rw-r--r-- 1 mopidy audio     355 Dec  8 14:43 Dko6eQl4w2s.json
-rw-r--r-- 1 mopidy audio 5601670 Nov 26  2019 Dko6eQl4w2s.webm
-rw-r--r-- 1 mopidy audio   91209 Dec  8 14:43 Dko6eQl4w2s.webp
-rw-r--r-- 1 mopidy audio     362 Dec  8 14:55 HhJqhMZODLI.json
-rw-r--r-- 1 mopidy audio 3217295 May  1  2024 HhJqhMZODLI.webm
-rw-r--r-- 1 mopidy audio   96863 Dec  8 14:55 HhJqhMZODLI.webp
-rw-r--r-- 1 mopidy audio     342 Dec  8 15:04 Kh8KXTG73Cc.json
-rw-r--r-- 1 mopidy audio 2965025 Aug  1  2019 Kh8KXTG73Cc.webm
-rw-r--r-- 1 mopidy audio   17153 Dec  8 15:04 Kh8KXTG73Cc.webp
-rw-r--r-- 1 mopidy audio     357 Dec  8 14:34 nC7GjU7Sm4U.json
-rw-r--r-- 1 mopidy audio 3180098 Sep 28  2022 nC7GjU7Sm4U.webm
-rw-r--r-- 1 mopidy audio   78776 Dec  8 14:34 nC7GjU7Sm4U.webp
-rw-r--r-- 1 mopidy audio     341 Dec  8 14:39 pTg9drcfzA4.json
-rw-r--r-- 1 mopidy audio 2828871 Dec  8  2014 pTg9drcfzA4.m4a
-rw-r--r-- 1 mopidy audio   10242 Dec  8 14:39 pTg9drcfzA4.webp
-rw-r--r-- 1 mopidy audio     339 Dec  8 14:59 rDBfGrfUuug.json
-rw-r--r-- 1 mopidy audio 2972424 May  5  2024 rDBfGrfUuug.webm
-rw-r--r-- 1 mopidy audio   64539 Dec  8 14:27 rDBfGrfUuug.webp
-rw-r--r-- 1 mopidy audio     343 Dec  8 14:57 YLUh70zp0LE.json
-rw-r--r-- 1 mopidy audio 4522401 Sep 12 06:09 YLUh70zp0LE.webm
-rw-r--r-- 1 mopidy audio   13080 Dec  8 14:57 YLUh70zp0LE.webp

From all these files, only 1 plays. The rest doesn't. Here is a log example whereby playback works:

https://pastebin.com/EzicQzYb

And here is a log example whereby playback does not work:

https://pastebin.com/GvXgTamf

It would be great if someone could have a look to see why it works in one case, but not in others.

Thank you.

@natumbri
Copy link
Owner

natumbri commented Dec 8, 2024

Is the m4a file the only one that plays (ie. none of the webm files play)?

@1marc1
Copy link
Author

1marc1 commented Dec 8, 2024

I played around some more and I think we are on to something. Indeed the m4a files play properly, but the webm files do not.

@natumbri
Copy link
Owner

natumbri commented Dec 8, 2024 via email

@1marc1
Copy link
Author

1marc1 commented Dec 9, 2024

I have just downloaded all webm files from /var/cache/mopidy/youtube and can play all of them using VLC on my desktop.

@kingosticks
Copy link
Collaborator

Can gstreamer play your files OK?

gst-launch-1.0 playbin uri=file:///var/cache/mopidy/youtube/foo.webm`

gst-launch-1.0 uridecodebin uri=file:///var/cache/mopidy/youtube/foo.webm  ! audioconvert ! audioresample ! autoaudiosink

@1marc1
Copy link
Author

1marc1 commented Dec 9, 2024

Audio plays in both cases. I tried with a number of webm files from /var/cache/mopidy/youtube. They all play and audio works as expected.

@1marc1
Copy link
Author

1marc1 commented Dec 9, 2024

The following command plays audio as well:

sudo -H -u mopidy gst-launch-1.0 uridecodebin uri=file:///var/cache/mopidy/youtube/Kh8KXTG73Cc.webm ! audioconvert ! audioresample ! autoaudiosink

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

No branches or pull requests

3 participants