coderholic / pyradio

Curses based internet radio player
www.coderholic.com/pyradio
MIT License
971 stars 129 forks source link

[FEAT] Shortcut to quit pyradio and launch standalone player (e.g. mpv) with currently selected station #252

Open wturrell opened 3 months ago

wturrell commented 3 months ago

i.e. supposing you want to use mpv rather than pyradio occasionally, because of its ability to pause/rewind/fast-forward a stream.

Rather than typing the command yourself and finding and manually copying/pasting the stream URL, you could just press a button in pyradio: it would quit and then launch the appropriate mpv command in your terminal. Maybe call it "play in command line" or similar.

s-n-g commented 1 month ago

Hi @wturrell It took me a while to reply, sorry about that...

What exactly are you trying to do with this?

What you've asked can be achieved with the following script, which will start mpv and exit, but then what do you want to do with it?

import subprocess
import sys

command = ['mpv', '--no-video', '--quiet', '--profile=pyradio', '--input-ipc-server=/tmp/mpvsocket', '--playlist=http://somafm.com/illstreet.pls']

# print the command to be executed
print(' '.join(command))

# Start the media player
process = subprocess.Popen(command)

# Exit the script while leaving the media player running
sys.exit()

You can save this to a file, pplay.py for example, and execute it from a terminal as python pplay.py

mpv will be executed in the background, but the only way to communicate with it it through socat, and then again you need to know mpv's IPC commands... Other than that, you can just kill it killall mpv

fidodido48 commented 6 days ago

They just want to play/extract the url/stream in a separate mpv process for better player control. Here's a little workaround (for linux):

  1. Play your desired pyradio station
  2. While playing run the following: mpv $(ps uax |grep -i pyradio |grep -oP 'https?\://[^ ]+')

This is manual way of doing it. They ask to implement it directly in pyradio and i also think it's a good idea.

Independent player means:

  1. No playing interruption while interacting with the pyradio's UI
  2. Allows to control mpv with its standard keybinds.

You could also add a kill-switch to have control over a separate mpv process (i.e. to cleanup any already running pyradio mpv players): kill $(ps uax |grep -i pyradio |tr -s ' ' |cut -f2 -d ' ')

s-n-g commented 6 days ago

Do you mean something like this?

Download this file: https://github.com/s-n-g/pyradio/archive/refs/heads/tmp.zip

Unzip it and you will get a folder named pyradio-tmp

Then

cd pyradio-tmp
./devel/build_install_pyradio

Start pyradio select a station and press "X"

s-n-g commented 5 days ago

I have pushed an update to this...

Always at https://github.com/s-n-g/pyradio/archive/refs/heads/tmp.zip

Now you cane even execute like this

pyradio -p21 -x

which will play (with the external player) station No 21 in the default playlist

Installation and testing instructions as above :wink: