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

Sox player_cmd doesn't handle http(s) URIs properly #9

Open
mikejgray opened this issue Apr 10, 2024 · 2 comments
Open

Sox player_cmd doesn't handle http(s) URIs properly #9

mikejgray opened this issue Apr 10, 2024 · 2 comments

Comments

@mikejgray
Copy link

>>> x.player_cmd
'/opt/homebrew/bin/play --type com/watch'
>>> x._now_playing
'https://music.youtube.com/watch?v=bp-EdVb50Lc'
>>> x.play(x._now_playing)
/opt/homebrew/bin/play FAIL formats: no handler for given file type `com/watch'

Comes from these lines:

    @property
    def player_cmd(self):
        """determine the best command to play a stream"""
        # sox should handle almost every format, but fails in some urls
        if self.sox_play:
            track = self._now_playing
            # NOTE: some urls like youtube streams will cause extension detection to fail
            # let's handle it explicitly
            ext = track.split("?")[0].split(".")[-1]
            player = self.sox_play + f" --type {ext}"
@mikejgray
Copy link
Author

Same sort of idea with mpg123, but not exactly:

>>> x.play()
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
        version 1.31.3; written and copyright by Michael Hipp and others
        free software (LGPL) without any warranty but with best wishes
Warning: additional info in content-type ignored ( charset=utf-8)
main: [src/mpg123.c:open_track():755] error: Unknown mpeg MIME type text/html; charset=utf-8 - is it perhaps a playlist (use -@)?
main: [src/mpg123.c:open_track():756] error: If you know the stream is mpeg1/2 audio, then please report this as mpg123 bug

@mikejgray
Copy link
Author

The logic works fine for file:// URIs in both sox and mpg123

>>> x._now_playing = "file:///Users/Mike/Downloads/BoatswainWhistle.mp3"
>>> x.play()
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
        version 1.31.3; written and copyright by Michael Hipp and others
        free software (LGPL) without any warranty but with best wishes

Directory: /Users/Mike/Downloads/

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: BoatswainWhistle.mp3 ...

MPEG 1.0 L III cbr320 44100 j-s

Title:   36 Boatswain Whistle                                            Artist: Neil Norman                                                   
Comment: Cortesia MUNDO ESTELAR                                          Album:  Star Trek Sound Effects                                       
Year:    1988                                                            Genre:  Sountrack                                                     


[0:08] Decoding of BoatswainWhistle.mp3 finished.
>>> exit()
❯ python
Python 3.10.9 (main, Mar  1 2023, 12:20:14) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ovos_media_plugin_simple
^[[A^[[A^[[A2024-04-09 21:35:56.677 - OVOS - ovos_plugin_manager.templates.audio:<module>:14 - WARNING - Deprecation version=0.1.0. Caller=ovos_plugin_manager.templates:8. ovos_plugin_manager.templates.audio has been deprecated on ovos-audio, move to ovos_plugin_manager.templates.media
2024-04-09 21:35:56.764 - OVOS - ovos_plugin_manager.audio:<module>:7 - WARNING - Deprecation version=0.1.0. Caller=ovos_plugin_manager.plugin_entry:4. ovos_plugin_manager.audio has been deprecated on ovos-audio, move to ovos_plugin_manager.media
>>> x=ovos_media_plugin_simple.SimpleAudioService({})
>>> x._now_playing = "file:///Users/Mike/Downloads/BoatswainWhistle.mp3"
>>> x.play()

/Users/Mike/Downloads/BoatswainWhistle.mp3:

 File Size: 342k      Bit Rate: 334k
  Encoding: MPEG audio    
  Channels: 2 @ 16-bit   
Samplerate: 44100Hz      
Replaygain: off         
  Duration: 00:00:08.18  

In:100%  00:00:08.18 [00:00:00.00] Out:392k  [      |      ]        Clip:0    
Done.

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

1 participant