Skip to content

Commit

Permalink
2.9.1 (#107)
Browse files Browse the repository at this point in the history
* feat: play random station from favorite list

Signed-off-by: Dipankar Pal <[email protected]>

* fix: 🐛 duplicate favorite entry issue from runtime command

fixes #100

* updates

* feat: ✨ multiple media player support

* fix: 🐛 fails to play a single result

#102

* help docs added

* update

* feat: ✨ Defult config file support

#103

* fix: 🐛 Default recording filepath was ambiguas before

* feat: ✨ toggle playbacks from runtime command

#84

* feat: ✨ filter support added

#86

* fix: 🐛 ability to stop different players

* v2.9.1

---------

Signed-off-by: Dipankar Pal <[email protected]>
  • Loading branch information
deep5050 authored Jan 7, 2024
1 parent 0ce6278 commit 8852fd1
Show file tree
Hide file tree
Showing 18 changed files with 688 additions and 159 deletions.
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
],
"files.autoSave": "off",
"editor.wordWrap": "wordWrapColumn",
"workbench.colorTheme": "Quiet Light",
"workbench.colorTheme": "GitHub Dark",
"editor.minimap.autohide": true,
"editor.minimap.renderCharacters": false,
"editor.experimentalWhitespaceRendering": "font",
"editor.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",
"editor.codeLensFontFamily": "'Fira Code'",
"editor.fontLigatures": true
"editor.fontLigatures": true,
"editor.defaultFormatter": "ms-python.black-formatter",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.9.1

1. Play a random station from favorite list `--random`
2. Multiple media player support ( MPV, VLC, FFplay) `--player`
3. Filter search results with `--filter`
4. Play/Pause player from runtime command `p`
5. Default config file support added
6. Fixed minor bugs while giving runtime commands


## 2.9.0

1. Fetch current playing track info from runtime commands 🎶 ⚡
Expand Down
108 changes: 81 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
- [x] Finds nearby stations
- [x] Discovers stations by genre
- [x] Discovers stations by language
- [x] VLC, MPV player support
- [x] Default config file
- [ ] I'm feeling lucky! Play Random stations
- [ ] VLC, MPV player support


> See my progress ➡️ [here](https://github.com/users/deep5050/projects/5)
Expand Down Expand Up @@ -80,7 +81,7 @@ I recommend installing it using `pipx install radio-active`
### External Dependency

It needs [FFmpeg](https://ffmpeg.org/download.html) to be installed on your
system in order to play the audio
system in order to record the audio

on Ubuntu-based system >= 20.04 Run

Expand Down Expand Up @@ -120,30 +121,34 @@ Search a station with `radio --search [STATION_NAME]` or simply `radio` :zap: to
### Options


| Argument | Note | Description | Default |
| ------------------ | -------- | ---------------------------------------------- | ------------- |
| `--search`, `-S` | Optional | Station name | None |
| `--play`, `-P` | Optional | A station from fav list or url for direct play | None |
| `--country`, `-C` | Optional | Discover stations by country code | False |
| `--state` | Optional | Discover stations by country state | False |
| `--language` | optional | Discover stations by | False |
| `--tag` | Optional | Discover stations by tags/genre | False |
| `--uuid`, `-U` | Optional | ID of the station | None |
| `--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/auto) | mp3 |
| `--last` | Optional | Play last played station | False |
| `--sort` | Optional | Sort the result page | name |
| `--limit` | Optional | Limit the # of results in the Discover table | 100 |
| `--volume` , `-V` | Optional | Change the volume passed into ffplay | 80 |
| `--favorite`, `-F` | Optional | Add current station to fav list | False |
| `--add` , `-A` | Optional | Add an entry to fav list | False |
| `--list`, `-W` | Optional | Show fav list | False |
| `--remove` | Optional | Remove entries from favorite list | False |
| `--flush` | Optional | Remove all the entries from fav list | False |
| `--kill` , `-K` | Optional | Kill background radios. | False |
| `--loglevel` | Optional | Log level of the program | Info |
| Options | Note | Description | Default | Values |
| ------------------ | -------- | ---------------------------------------------- | ------------- | ---------------------- |
| (No Option) | Optional | Select a station from menu to play | False | |
| `--search`, `-S` | Optional | Station name | None | |
| `--play`, `-P` | Optional | A station from fav list or url for direct play | None | |
| `--country`, `-C` | Optional | Discover stations by country code | False | |
| `--state` | Optional | Discover stations by country state | False | |
| `--language` | optional | Discover stations by | False | |
| `--tag` | Optional | Discover stations by tags/genre | False | |
| `--uuid`, `-U` | Optional | ID of the station | None | |
| `--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` |
| `--last` | Optional | Play last played station | False | |
| `--random` | Optional | Play a random station from favorite list | False | |
| `--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 | |
| `--add` , `-A` | Optional | Add an entry to fav list | False | |
| `--list`, `-W` | Optional | Show fav list | False | |
| `--remove` | Optional | Remove entries from favorite list | False | |
| `--flush` | Optional | Remove all the entries from fav list | False | |
| `--kill` , `-K` | Optional | Kill background radios. | False | |
| `--loglevel` | Optional | Log level of the program | Info | `info`, `warning`, `error`, `debug` |
| `--player` | Optional | Media player to use | ffplay | `vlc`, `mpv`, `ffplay` |

<hr>

Expand Down Expand Up @@ -185,7 +190,7 @@ h/H/help/?: Show this help message
q/Q/quit: Quit radioactive
```

### sort parameters
### Sort Parameters

you can sort the result page with these parameters:
- `name` (default)
Expand All @@ -198,6 +203,55 @@ you can sort the result page with these parameters:
- `clicktrend` (currently trending stations)
- `random`

### Filter Parameters

Filter search results with `--filter`. Some possible expressions are
- `--filter "name=shows"`
- `--filter "name=shows,talks,tv"`
- `--filter "name!=news,shows"`
- `--filter "country=in"`
- `--filter "language=bengali,nepali"`
- `--filter "bitrate>64"`
- `--filter "votes<500"`
- `--filter "codec=mp3"`
- `--filter "tags!=rock,pop"`

Allowed operators are:

- `=`
- `,`
- `!=`
- `>`
- `<`
- `&`

Allowed keys are: `name`, `country` (countrycode as value), `language`, `bitrate`, `votes`, `codec`, `tags`

Provide multiple filters at one go, use `&`

A complex filter example: `--filter "country!=CA&tags!=islamic,classical&votes>500"`

> NOTE: set `--limit` to a higher value while filtering results

### Default Configs

Default configuration file is added into your home directory as `.radio-active-configs.ini`

```bash
[AppConfig]
loglevel = info
limit = 100
sort = votes
filter = none
volume = 80
filepath = /home/{user}/recordings/radioactive/
filetype = mp3
player = ffplay
```

Do NOT modify the keys, only change the values. you can give any absolute or relative path as filepath.

### Bonus Tips

1. when using `rf`: you can force the recording to be in mp3 format by adding an extension to the file name. Example "talk-show.mp3". If you don't specify any extension it should auto-detect. Example "new_show"
Expand Down
70 changes: 60 additions & 10 deletions radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from radioactive.alias import Alias
from radioactive.app import App
from radioactive.ffplay import Ffplay, kill_background_ffplays
from radioactive.handler import Handler
from radioactive.help import show_help
from radioactive.last_station import Last_station
from radioactive.parser import parse_options
from radioactive.player import Player, kill_background_ffplays
from radioactive.utilities import (
check_sort_by_parameter,
handle_add_station,
Expand All @@ -22,6 +22,7 @@
handle_favorite_table,
handle_listen_keypress,
handle_play_last_station,
handle_play_random_station,
handle_record,
handle_save_last_station,
handle_search_stations,
Expand All @@ -34,21 +35,44 @@

# 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
global player

# check target URL for the last time
if options["target_url"].strip() == "":
log.error("something is wrong with the url")
sys.exit(1)

if options["audio_player"] == "vlc":
from radioactive.vlc import VLC

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

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

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

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

else:
log.error("Unsupported media player selected")
sys.exit(1)

if options["curr_station_name"].strip() == "":
options["curr_station_name"] = "N/A"

player = Player(options["target_url"], options["volume"], options["loglevel"])

handle_save_last_station(
last_station, options["curr_station_name"], options["target_url"]
)
Expand All @@ -72,6 +96,7 @@ def final_step(options, last_station, alias, handler):

handle_listen_keypress(
alias,
player,
target_url=options["target_url"],
station_name=options["curr_station_name"],
station_url=options["target_url"],
Expand All @@ -89,8 +114,6 @@ def main():

options = parse_options()

handle_welcome_screen()

VERSION = app.get_version()

handler = Handler()
Expand All @@ -104,6 +127,8 @@ def main():
log.info("RADIO-ACTIVE : version {}".format(VERSION))
sys.exit(0)

handle_welcome_screen()

if options["show_help_table"]:
show_help()
sys.exit(0)
Expand Down Expand Up @@ -134,7 +159,10 @@ def main():
# ----------- country ----------- #
if options["discover_country_code"]:
response = handler.discover_by_country(
options["discover_country_code"], options["limit"], options["sort_by"]
options["discover_country_code"],
options["limit"],
options["sort_by"],
options["filter_with"],
)
if response is not None:
(
Expand All @@ -148,7 +176,10 @@ def main():
# -------------- state ------------- #
if options["discover_state"]:
response = handler.discover_by_state(
options["discover_state"], options["limit"], options["sort_by"]
options["discover_state"],
options["limit"],
options["sort_by"],
options["filter_with"],
)
if response is not None:
(
Expand All @@ -162,7 +193,10 @@ def main():
# ----------- language ------------ #
if options["discover_language"]:
response = handler.discover_by_language(
options["discover_language"], options["limit"], options["sort_by"]
options["discover_language"],
options["limit"],
options["sort_by"],
options["filter_with"],
)
if response is not None:
(
Expand All @@ -176,7 +210,10 @@ def main():
# -------------- tag ------------- #
if options["discover_tag"]:
response = handler.discover_by_tag(
options["discover_tag"], options["limit"], options["sort_by"]
options["discover_tag"],
options["limit"],
options["sort_by"],
options["filter_with"],
)
if response is not None:
(
Expand All @@ -193,6 +230,7 @@ def main():
and options["search_station_uuid"] is None
and options["direct_play"] is None
and not options["play_last_station"]
and not options["play_random"]
):
(
options["curr_station_name"],
Expand Down Expand Up @@ -221,6 +259,7 @@ def main():
options["search_station_name"],
options["limit"],
options["sort_by"],
options["filter_with"],
)
if response is not None:
(
Expand All @@ -239,6 +278,13 @@ def main():
)
final_step(options, last_station, alias, handler)

if options["play_random"]:
(
options["curr_station_name"],
options["target_url"],
) = handle_play_random_station(alias)
final_step(options, last_station, alias, handler)

if options["play_last_station"]:
options["curr_station_name"], options["target_url"] = handle_play_last_station(
last_station
Expand All @@ -259,11 +305,15 @@ def main():


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

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

Expand Down
1 change: 1 addition & 0 deletions radioactive/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def search(self, entry):

def add_entry(self, left, right):
"""Adds a new entry to the fav list"""
self.generate_map()
if self.search(left) is not None:
log.warning("An entry with same name already exists, try another name")
return False
Expand Down
5 changes: 3 additions & 2 deletions radioactive/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Version of the current program, (in development mode it needs to be updated in every release)
Version of the current program, (in development mode
it needs to be updated in every release)
and to check if an updated version available for the app or not
"""
import json
Expand All @@ -9,7 +10,7 @@

class App:
def __init__(self):
self.__VERSION__ = "2.9.0" # change this on every update #
self.__VERSION__ = "2.9.1" # change this on every update #
self.pypi_api = "https://pypi.org/pypi/radio-active/json"
self.remote_version = ""

Expand Down
Loading

0 comments on commit 8852fd1

Please sign in to comment.