pcwii / usb-music

Mycroft.ai skill to automagically read music from a usb stick and play based on requests
GNU General Public License v3.0
9 stars 5 forks source link

"I'm not sure how to play the artist..." #3

Closed JohnMcLear closed 3 years ago

JohnMcLear commented 3 years ago

Post installation using msm install https://github.com/pcwii/usb-music.git on picroft the commands are not working with no errors on the UI.

 play music by the artist the cat empire                        
 >> Just a second                                                                                                                        
 >> **I'm not configured to play music yet. You can setup music services such as Pandora and Spotify at home dot mycroft dot ai.**           

In skills.log I get

2021-05-08 14:51:03.637 | INFO     |   798 | mycroft.skills.skill_manager:_unload_removed_skills:331 | removing usb-music.pcwii
2021-05-08 14:51:03.637 | INFO     |   798 | msm.mycroft_skills_manager | invalidating skills cache
2021-05-08 14:51:03.639 | INFO     |   798 | msm.mycroft_skills_manager | building SkillEntry objects for all skills
2021-05-08 14:51:13.032 | INFO     |   798 | mycroft.skills.skill_loader:load:185 | ATTEMPTING TO LOAD SKILL: usb-music.pcwii
2021-05-08 14:51:13.061 | ERROR    |   798 | mycroft.skills.skill_loader:_load_skill_source:279 | Failed to load skill: usb-music.pcwii (ModuleNotFoundError("No module named 'pyudev'"))
Traceback (most recent call last):
  File "/home/pi/mycroft-core/mycroft/skills/skill_loader.py", line 276, in _load_skill_source
    skill_module = load_skill_module(main_file_path, self.skill_id)
  File "/home/pi/mycroft-core/mycroft/skills/skill_loader.py", line 72, in load_skill_module
    spec.loader.exec_module(mod)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 16, in <module>
    from .usbScan import usbdev
  File "/opt/mycroft/skills/usb-music.pcwii/usbScan/__init__.py", line 2, in <module>
    from .usbdev import getDevData
  File "/opt/mycroft/skills/usb-music.pcwii/usbScan/usbdev.py", line 2, in <module>
    from pyudev import Context, Monitor, MonitorObserver
ModuleNotFoundError: No module named 'pyudev'
2021-05-08 14:51:13.065 | ERROR    |   798 | mycroft.skills.skill_loader:_communicate_load_status:351 | Skill usb-music.pcwii failed to load

and post installation of pyudev I get:

021-05-08 14:56:02.350 | ERROR    |   798 | mycroft.skills.skill_loader:_create_skill_instance:295 | Skill __init__ failed with NameError("no function 'libvlc_new'")
Traceback (most recent call last):
  File "/home/pi/mycroft-core/mycroft/skills/skill_loader.py", line 292, in _create_skill_instance
    self.instance = skill_module.create_skill()
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 529, in create_skill
    return USBMusicSkill()
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 48, in __init__
    self.mediaplayer = VlcService(config={'low_volume': 10, 'duck': True})
  File "/home/pi/mycroft-core/mycroft/audio/services/vlc/__init__.py", line 24, in __init__
    self.instance = vlc.Instance("--no-video")
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/vlc.py", line 1551, in __new__
    return libvlc_new(len(args), args)
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/vlc.py", line 3903, in libvlc_new
    ctypes.c_void_p, ctypes.c_int, ListPOINTER(ctypes.c_char_p))
  File "/home/pi/mycroft-core/.venv/lib/python3.7/site-packages/vlc.py", line 246, in _Cfunction
    raise NameError('no function %r' % (name,))
NameError: no function 'libvlc_new'
2021-05-08 14:56:02.352 | ERROR    |   798 | mycroft.skills.skill_loader:_communicate_load_status:351 | Skill usb-music.pcwii failed to load

Resolution

pip install pyudev
sudo apt-get install vlc
sudo reboot
msm remove https://github.com/pcwii/usb-music.git
msm install https://github.com/pcwii/usb-music.git

Permanent fix?

Perhaps the installation docs should also include steps to include deps? Perhaps the installation should error if it fails during msm install? -- upstream issue will let maintainer decide best course of action.

Related to https://github.com/pcwii/usb-music/issues/2

Successful output

021-05-08 15:01:00.228 | INFO     |   808 | msm.mycroft_skills_manager | invalidating skills cache
2021-05-08 15:01:00.229 | INFO     |   808 | msm.mycroft_skills_manager | building SkillEntry objects for all skills
2021-05-08 15:01:05.719 | INFO     |   808 | mycroft.skills.skill_loader:load:185 | ATTEMPTING TO LOAD SKILL: usb-music.pcwii
2021-05-08 15:01:05.777 | INFO     |   808 | usb-music_pcwii:<module>:33 | Attempting to reload usbScan Module: usb-music_pcwii.usbScan
2021-05-08 15:01:05.801 | INFO     |   808 | usb-music_pcwii:<module>:33 | Attempting to reload usbScan Module: usb-music_pcwii.usbScan.usbdev
2021-05-08 15:01:05.805 | INFO     |   808 | mycroft.skills.settings:get_local_settings:83 | /home/pi/.config/mycroft/skills/usb-music.pcwii/settings.json
2021-05-08 15:01:05.844 | INFO     |   808 | usb-music_pcwii:__init__:71 | USB Music Skill Loaded!
2021-05-08 15:01:05.945 | INFO     |   808 | usb-music_pcwii:initialize:76 | USB Music Skill Initialized!
2021-05-08 15:01:05.948 | ERROR    |   808 | usb-music_pcwii:halt_usb_monitor_thread:127 | join() missing 1 required positional argument: 'self'
2021-05-08 15:01:05.953 | INFO     |   808 | usb-music_pcwii:start_usb_thread:258 | USB Monitoring Loop Started!
2021-05-08 15:01:05.954 | INFO     |   808 | usb-music_pcwii:on_websettings_changed:94 | USB-Music Settings Changed, Command Enable now: False
2021-05-08 15:01:05.956 | INFO     |   808 | usb-music_pcwii:on_websettings_changed:95 | USB-Music Settings Changed, AutoPlay now: False
2021-05-08 15:01:05.959 | INFO     |   808 | usb-music_pcwii:on_websettings_changed:96 | USB-Music Settings Changed, SMB Path now: //192.168.0.20/SMBMusic
2021-05-08 15:01:05.962 | INFO     |   808 | usb-music_pcwii:on_websettings_changed:97 | USB-Music Settings Changed, Local Path now: ~/Music
2021-05-08 15:01:05.964 | INFO     |   808 | mycroft.skills.skill_loader:_communicate_load_status:344 | Skill usb-music.pcwii loaded successfully
2021-05-08 15:01:05.970 | INFO     |   808 | mycroft.skills.skill_manager:put:80 | Updating settings meta during runtime...
2021-05-08 15:01:05.972 | INFO     |   808 | msm.mycroft_skills_manager | invalidating skills cache
2021-05-08 15:01:05.974 | INFO     |   808 | msm.mycroft_skills_manager | building SkillEntry objects for all skills

It appears indexing of music does then work but playback does not.

No playback still.,.

2021-05-08 15:03:03.072 | INFO     |   808 | usb-music_pcwii:parse_music_utterance:147 | Parse Music Received: my music
2021-05-08 15:03:03.077 | INFO     |   808 | ReSpeaker_4mic_hat | Pixel Ring: Off
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
2021-05-08 15:03:03.083 | INFO     |   808 | usb-music_pcwii:parse_music_utterance:169 | Primary Regex Key Not Found
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
2021-05-08 15:03:03.101 | ERROR    |   808 | mycroft.skills.mycroft_skill.mycroft_skill:on_error:835 | An error occurred while processing a request in USB Music Skill
Traceback (most recent call last):
  File "/home/pi/mycroft-core/mycroft/skills/mycroft_skill/event_container.py", line 66, in wrapper
    handler(message)
  File "/home/pi/mycroft-core/mycroft/skills/common_play_skill.py", line 96, in __handle_play_query
    result = self.CPS_match_query_phrase(search_phrase)
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 392, in CPS_match_query_phrase
    play_request = self.parse_music_utterance(phrase)  # get the requested Music Item
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 171, in parse_music_utterance
    if key_found.group("any"):
AttributeError: 'NoneType' object has no attribute 'group'
2021-05-08 15:03:04.395 | INFO     |   808 | ReSpeaker_4mic_hat | Pixel Ring: Speak
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
2021-05-08 15:03:08.975 | INFO     |   808 | ReSpeaker_4mic_hat | Pixel Ring: Off
pcwii commented 3 years ago

@JohnMcLear, Thank you for the log information as that is helpful. As far as the pip install(s). For some reason the latest Mycroft does not install the required dependencies automatically. It was successful in the previous version. At this point I am not sure why the requirements installation are failing but you are correct I should add the manual installation process to the readme. I noticed from your log that the skill settings are still default. Did you update the settings in your "account.mycroft.ai"? Also after you have done that try issuing the command "update music library". This should index all your files and report what it has found. Thanks for testing this skill

JohnMcLear commented 3 years ago

I went ahead and changed the path to /home/pi/mycroft-core/usb-music and hit save in the settings. I then unplugged and plugged back in my USB stick and it did update the sources.

Trying to do play my music returns

2021-05-08 16:29:35.668 | INFO     |  2496 | Playback Control Skill | Resolving Player for: my music
2021-05-08 16:29:35.676 | INFO     |  2496 | ReSpeaker_4mic_hat | Pixel Ring: Think
2021-05-08 16:29:35.701 | INFO     |  2496 | ReSpeaker_4mic_hat | Pixel Ring: Speak
2021-05-08 16:29:38.400 | INFO     |  2496 | ReSpeaker_4mic_hat | Pixel Ring: Off
2021-05-08 16:29:38.493 | INFO     |  2496 | usb-music_pcwii:CPS_match_query_phrase:389 | USBMusicSkill received the following phrase: my music
2021-05-08 16:29:38.495 | INFO     |  2496 | usb-music_pcwii:CPS_match_query_phrase:391 | USBMusicSkill is Searching for requested media...
2021-05-08 16:29:38.507 | INFO     |  2496 | usb-music_pcwii:parse_music_utterance:147 | Parse Music Received: my music
2021-05-08 16:29:38.509 | INFO     |  2496 | ReSpeaker_4mic_hat | Pixel Ring: Off
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
2021-05-08 16:29:38.517 | INFO     |  2496 | usb-music_pcwii:parse_music_utterance:169 | Primary Regex Key Not Found
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
2021-05-08 16:29:38.538 | ERROR    |  2496 | mycroft.skills.mycroft_skill.mycroft_skill:on_error:835 | An error occurred while processing a request in USB Music Skill
Traceback (most recent call last):
  File "/home/pi/mycroft-core/mycroft/skills/mycroft_skill/event_container.py", line 66, in wrapper
    handler(message)
  File "/home/pi/mycroft-core/mycroft/skills/common_play_skill.py", line 96, in __handle_play_query
    result = self.CPS_match_query_phrase(search_phrase)
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 392, in CPS_match_query_phrase
    play_request = self.parse_music_utterance(phrase)  # get the requested Music Item
  File "/opt/mycroft/skills/usb-music.pcwii/__init__.py", line 171, in parse_music_utterance
    if key_found.group("any"):
AttributeError: 'NoneType' object has no attribute 'group'
2021-05-08 16:29:38.548 | INFO     |  2496 | mycroft.skills.settings:save_settings:116 | Skill settings successfully saved to /home/pi/.config/mycroft/skills/usb-music.pcwii/settings.json
2021-05-08 16:29:39.837 | INFO     |  2496 | ReSpeaker_4mic_hat | Pixel Ring: Speak

So I need a music skill, which one would you recommend? All of the ones I have tested are basically broken ;\

pcwii commented 3 years ago

I wrote this one, as there are no great music skills for local music playback. I have not actually implemented a call for "play my music". I will add this command and see if it does what you expect, give me a couple hours to get it updated on github.

JohnMcLear commented 3 years ago

Ah, great thanks!

Just FYI: I tried "play music by Elton John" too and I think I got an error doing that, would you expect that should work?

pcwii commented 3 years ago

As I have been digging into this I have noticed a couple things that are not working as expected. It may take me a bit to clean it up but I am on it. If you could try a couple things for me that would be helpful.

  1. in the websettings check the box to enable auto play. This will automatically play the music on the usb when it is inserted. image
  2. There seems to be an issue with my scraping the artist name. If you issue the command 'show music library' does your list contain artist names or are they all artist:""?
  3. My regex filtering is a bit of a mess, and I would like to clean that up to make asking for music more intuitive. Can you try the following command and see if that plays as expected play the song <insert song name>?

I appreciate all the testing and feedback you have provided. I will try to get this cleaned up so that you have a music app that is not "broken" ;-) Cheers!

JohnMcLear commented 3 years ago

Will have some test results for you within the hour.

JohnMcLear commented 3 years ago

Thanks for taking your time to help debug, we're making great progress now :)

  1. It was already set to autoplay, I get "I am searching..." then "I am reading music..." then "added x songs to library" (I get this twice for some reason). I then get "now playing your music selection" and this works however it is playing two different songs at once! :) Issuing a "stop" command stops the second audio stream, another "stop" command doesn't work ;\
  2. Artist appears a to be ''.
  3. This command works properly.

Thanks!

pcwii commented 3 years ago

@JohnMcLear Thanks for testing that.

  1. The double playing is likely due to the fact that the skill updated due to my changes yesterday and the usb monitoring daemon loaded a second time. If you restart your device this should correct that problem. I will look for a method to kill any running processes before re-loading the skill.
  2. I am going to need to dig into why the artist field is not populating. I should get some time this week to clean up some of the code and correct a few items. I will push the changes once they are completed. Thanks again!
JohnMcLear commented 3 years ago
  1. Ack, rebooted, confirmed, thanks.
  2. Awesome man thanks! :) Worth noting "play my music" works great now too :)
JohnMcLear commented 3 years ago

Heads up, went to test things today and "play my music" and I got error 2021-05-10 14:15:35.400 | INFO | 800 | usb-music_pcwii:CPS_match_query_phrase:426 | Device or Library Not Ready, Passing on this request

I detatched > attached the USB stick and I get the "im indexing number of songs will take time to complete" but it never completes.

I think the offending mp3 causing an issue is

2021-05-10 14:16:40.366 | INFO     |   800 | usb-music_pcwii:create_library:360 | Validating title: Anymore
2021-05-10 14:16:40.367 | INFO     |   800 | usb-music_pcwii:create_library:368 | Validating artist: The Cat Empire
2021-05-10 14:16:40.379 | INFO     |   800 | usb-music_pcwii:create_library:353 | Checking m4a Tags{'©nam': ['So Many Nights'], '©ART': ['The Cat Empire'], '©wrt': ['Felix Riebl'], '©alb': ['So Many Nights'], '©gen': ['Alternative'], 'trkn': [(1, 14)], 'disk': [(1, 1)], '©day': ['2007'], 'cpil': False, 'pgap': False, 'tmpo': [0], '©too': ['iTunes 10.0.1.22, QuickTime 7.6.8'], '----:com.apple.iTunes:iTunSMPB': [MP4FreeForm(b' 00000000 00000840 00000180 00000000008ED640 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000', <AtomDataType.UTF8: 1>)], '----:com.apple.iTunes:Encoding Params': [MP4FreeForm(b'vers\x00\x00\x00\x01acbf\x00\x00\x00\x02brat\x00\x03\xe8\x00srcq\x00\x00\x00\x7fcdcv\x00\x01\x07\x02', <AtomDataType.IMPLICIT: 0>)], '----:com.apple.iTunes:iTunNORM': [MP4FreeForm(b' 00001326 00001109 00006C33 00008B49 0002DF82 00022C47 00008000 00008000 0000914E 0001A33A', <AtomDataType.UTF8: 1>)], '----:com.apple.iTunes:iTunes_CDDB_IDs': [MP4FreeForm(b'14++', <AtomDataType.UTF8: 1>)], '----:com.apple.iTunes:UFIDhttp://www.cddb.com/id3/taginfo1.html': [MP4FreeForm(b'3CD3N48Q138148622U4181E7F7B7B5F7A453ED7B9FC022F72D2F2P3', <AtomDataType.UTF8: 1>)], 'aART': ['Cat Empire, The']}
(.venv) pi@picroft:/var/log/mycroft $ 
pcwii commented 3 years ago

I have been trying to sort out the issues with the artist last night and added some additional logging to point me to the problem, This logging is causing the indexing to take a very long time. Things may be broken a bit until I can sort it out. Hope to get it cleaned up later today. Thanks for the patience.

pcwii commented 3 years ago

@JohnMcLear Looks like I may have sorted out a couple issues. You should be able to issue the command play music by Elton John now and it should recognize the artist(s) now. Indexing of the library initially is not very fast, I will look at ways to speed it up. It took about 8 minutes to index about 2097 songs on my smb share. Hopefully now you have a working music player for mycroft.

JohnMcLear commented 3 years ago
  1. Removal and insertion now works.
  2. "Play My Music" works
  3. "Play Songs by Elton John" works :)

Good job man! Thanks very much.