Skip to content

Commit

Permalink
fix: 🐛 ability to stop different players
Browse files Browse the repository at this point in the history
  • Loading branch information
deep5050 committed Dec 27, 2023
1 parent 42ca986 commit cbcfc75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ Search a station with `radio --search [STATION_NAME]` or simply `radio` :zap: to
| `--record` , `-R` | Optional | Record a station and save to file | False | |
| `--filename`, `-N` | Optional | Filename to used to save the recorded audio | None | |
| `--filepath` | Optional | Path to save the recordings | <DEFAULT_DIR> | |
| `--filetype`, `-T` | Optional | Format of the recording | mp3 | `mp3`,`auto` |
| `--filetype`, `-T` | Optional | Format of the recording | mp3 | `mp3`,`auto` |
| `--last` | Optional | Play last played station | False | |
| `--random` | Optional | Play a random station from favorite list | False | |
| `--sort` | Optional | Sort the result page | name | |
| `--sort` | Optional | Sort the result page | votes | |
| `--filter` | Optional | Filter search results | None | |
| `--limit` | Optional | Limit the # of results in the Discover table | 100 | |
| `--volume` , `-V` | Optional | Change the volume passed into ffplay | 80 | [0-100] |
| `--favorite`, `-F` | Optional | Add current station to fav list | False | |
Expand Down Expand Up @@ -204,7 +205,7 @@ you can sort the result page with these parameters:

### Filter Parameters

Filter search results with `--filter`. Possible expressions are
Filter search results with `--filter`. Some possible expressions are
- `--filter "name=shows"`
- `--filter "name=shows,talks,tv"`
- `--filter "name!=news,shows"`
Expand Down
15 changes: 10 additions & 5 deletions radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
# globally needed as signal handler needs it
# to terminate main() properly
ffplay = None
player = None


def final_step(options, last_station, alias, handler):
global ffplay # always needed
current_player = None
global player

# check target URL for the last time
if options["target_url"].strip() == "":
Expand All @@ -52,18 +53,18 @@ def final_step(options, last_station, alias, handler):

vlc = VLC()
vlc.start(options["target_url"])
current_player = vlc
player = vlc

elif options["audio_player"] == "mpv":
from radioactive.mpv import MPV

mpv = MPV()
mpv.start(options["target_url"])
current_player = mpv
player = mpv

elif options["audio_player"] == "ffplay":
ffplay = Ffplay(options["target_url"], options["volume"], options["loglevel"])
current_player = ffplay
player = ffplay

else:
log.error("Unsupported media player selected")
Expand Down Expand Up @@ -95,7 +96,7 @@ def final_step(options, last_station, alias, handler):

handle_listen_keypress(
alias,
current_player,
player,
target_url=options["target_url"],
station_name=options["curr_station_name"],
station_url=options["target_url"],
Expand Down Expand Up @@ -305,10 +306,14 @@ def main():

def signal_handler(sig, frame):
global ffplay
global player
log.debug("You pressed Ctrl+C!")
log.debug("Stopping the radio")
if ffplay and ffplay.is_playing:
ffplay.stop()
# kill the player
player.stop()

log.info("Exiting now")
sys.exit(0)

Expand Down
3 changes: 2 additions & 1 deletion radioactive/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ def handle_listen_keypress(
handle_add_to_favorite(alias, station_name, station_url)

elif user_input in ["q", "Q", "quit"]:
kill_background_ffplays()
# kill_background_ffplays()
player.stop()
sys.exit(0)
elif user_input in ["w", "W", "list"]:
alias.generate_map()
Expand Down

0 comments on commit cbcfc75

Please sign in to comment.