Skip to content

Commit 8852fd1

Browse files
authored
2.9.1 (#107)
* feat: play random station from favorite list Signed-off-by: Dipankar Pal <dipankarpal5050@gmail.com> * 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 <dipankarpal5050@gmail.com>
1 parent 0ce6278 commit 8852fd1

18 files changed

Lines changed: 688 additions & 159 deletions

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
],
1818
"files.autoSave": "off",
1919
"editor.wordWrap": "wordWrapColumn",
20-
"workbench.colorTheme": "Quiet Light",
20+
"workbench.colorTheme": "GitHub Dark",
2121
"editor.minimap.autohide": true,
2222
"editor.minimap.renderCharacters": false,
2323
"editor.experimentalWhitespaceRendering": "font",
2424
"editor.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",
2525
"editor.codeLensFontFamily": "'Fira Code'",
26-
"editor.fontLigatures": true
26+
"editor.fontLigatures": true,
27+
"editor.defaultFormatter": "ms-python.black-formatter",
28+
"[python]": {
29+
"editor.defaultFormatter": "ms-python.black-formatter"
30+
}
2731
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 2.9.1
2+
3+
1. Play a random station from favorite list `--random`
4+
2. Multiple media player support ( MPV, VLC, FFplay) `--player`
5+
3. Filter search results with `--filter`
6+
4. Play/Pause player from runtime command `p`
7+
5. Default config file support added
8+
6. Fixed minor bugs while giving runtime commands
9+
10+
111
## 2.9.0
212

313
1. Fetch current playing track info from runtime commands 🎶 ⚡

README.md

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
- [x] Finds nearby stations
4343
- [x] Discovers stations by genre
4444
- [x] Discovers stations by language
45+
- [x] VLC, MPV player support
46+
- [x] Default config file
4547
- [ ] I'm feeling lucky! Play Random stations
46-
- [ ] VLC, MPV player support
4748

4849

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

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

8586
on Ubuntu-based system >= 20.04 Run
8687

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

122123

123-
| Argument | Note | Description | Default |
124-
| ------------------ | -------- | ---------------------------------------------- | ------------- |
125-
| `--search`, `-S` | Optional | Station name | None |
126-
| `--play`, `-P` | Optional | A station from fav list or url for direct play | None |
127-
| `--country`, `-C` | Optional | Discover stations by country code | False |
128-
| `--state` | Optional | Discover stations by country state | False |
129-
| `--language` | optional | Discover stations by | False |
130-
| `--tag` | Optional | Discover stations by tags/genre | False |
131-
| `--uuid`, `-U` | Optional | ID of the station | None |
132-
| `--record` , `-R` | Optional | Record a station and save to file | False |
133-
| `--filename`, `-N` | Optional | Filename to used to save the recorded audio | None |
134-
| `--filepath` | Optional | Path to save the recordings | <DEFAULT_DIR> |
135-
| `--filetype`, `-T` | Optional | Format of the recording (mp3/auto) | mp3 |
136-
| `--last` | Optional | Play last played station | False |
137-
| `--sort` | Optional | Sort the result page | name |
138-
| `--limit` | Optional | Limit the # of results in the Discover table | 100 |
139-
| `--volume` , `-V` | Optional | Change the volume passed into ffplay | 80 |
140-
| `--favorite`, `-F` | Optional | Add current station to fav list | False |
141-
| `--add` , `-A` | Optional | Add an entry to fav list | False |
142-
| `--list`, `-W` | Optional | Show fav list | False |
143-
| `--remove` | Optional | Remove entries from favorite list | False |
144-
| `--flush` | Optional | Remove all the entries from fav list | False |
145-
| `--kill` , `-K` | Optional | Kill background radios. | False |
146-
| `--loglevel` | Optional | Log level of the program | Info |
124+
| Options | Note | Description | Default | Values |
125+
| ------------------ | -------- | ---------------------------------------------- | ------------- | ---------------------- |
126+
| (No Option) | Optional | Select a station from menu to play | False | |
127+
| `--search`, `-S` | Optional | Station name | None | |
128+
| `--play`, `-P` | Optional | A station from fav list or url for direct play | None | |
129+
| `--country`, `-C` | Optional | Discover stations by country code | False | |
130+
| `--state` | Optional | Discover stations by country state | False | |
131+
| `--language` | optional | Discover stations by | False | |
132+
| `--tag` | Optional | Discover stations by tags/genre | False | |
133+
| `--uuid`, `-U` | Optional | ID of the station | None | |
134+
| `--record` , `-R` | Optional | Record a station and save to file | False | |
135+
| `--filename`, `-N` | Optional | Filename to used to save the recorded audio | None | |
136+
| `--filepath` | Optional | Path to save the recordings | <DEFAULT_DIR> | |
137+
| `--filetype`, `-T` | Optional | Format of the recording | mp3 | `mp3`,`auto` |
138+
| `--last` | Optional | Play last played station | False | |
139+
| `--random` | Optional | Play a random station from favorite list | False | |
140+
| `--sort` | Optional | Sort the result page | votes | |
141+
| `--filter` | Optional | Filter search results | None | |
142+
| `--limit` | Optional | Limit the # of results in the Discover table | 100 | |
143+
| `--volume` , `-V` | Optional | Change the volume passed into ffplay | 80 | [0-100] |
144+
| `--favorite`, `-F` | Optional | Add current station to fav list | False | |
145+
| `--add` , `-A` | Optional | Add an entry to fav list | False | |
146+
| `--list`, `-W` | Optional | Show fav list | False | |
147+
| `--remove` | Optional | Remove entries from favorite list | False | |
148+
| `--flush` | Optional | Remove all the entries from fav list | False | |
149+
| `--kill` , `-K` | Optional | Kill background radios. | False | |
150+
| `--loglevel` | Optional | Log level of the program | Info | `info`, `warning`, `error`, `debug` |
151+
| `--player` | Optional | Media player to use | ffplay | `vlc`, `mpv`, `ffplay` |
147152

148153
<hr>
149154

@@ -185,7 +190,7 @@ h/H/help/?: Show this help message
185190
q/Q/quit: Quit radioactive
186191
```
187192

188-
### sort parameters
193+
### Sort Parameters
189194

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

206+
### Filter Parameters
207+
208+
Filter search results with `--filter`. Some possible expressions are
209+
- `--filter "name=shows"`
210+
- `--filter "name=shows,talks,tv"`
211+
- `--filter "name!=news,shows"`
212+
- `--filter "country=in"`
213+
- `--filter "language=bengali,nepali"`
214+
- `--filter "bitrate>64"`
215+
- `--filter "votes<500"`
216+
- `--filter "codec=mp3"`
217+
- `--filter "tags!=rock,pop"`
218+
219+
Allowed operators are:
220+
221+
- `=`
222+
- `,`
223+
- `!=`
224+
- `>`
225+
- `<`
226+
- `&`
227+
228+
Allowed keys are: `name`, `country` (countrycode as value), `language`, `bitrate`, `votes`, `codec`, `tags`
229+
230+
Provide multiple filters at one go, use `&`
231+
232+
A complex filter example: `--filter "country!=CA&tags!=islamic,classical&votes>500"`
233+
234+
> NOTE: set `--limit` to a higher value while filtering results
235+
236+
237+
### Default Configs
238+
239+
Default configuration file is added into your home directory as `.radio-active-configs.ini`
240+
241+
```bash
242+
[AppConfig]
243+
loglevel = info
244+
limit = 100
245+
sort = votes
246+
filter = none
247+
volume = 80
248+
filepath = /home/{user}/recordings/radioactive/
249+
filetype = mp3
250+
player = ffplay
251+
```
252+
253+
Do NOT modify the keys, only change the values. you can give any absolute or relative path as filepath.
254+
201255
### Bonus Tips
202256

203257
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"

radioactive/__main__.py

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
from radioactive.alias import Alias
1010
from radioactive.app import App
11+
from radioactive.ffplay import Ffplay, kill_background_ffplays
1112
from radioactive.handler import Handler
1213
from radioactive.help import show_help
1314
from radioactive.last_station import Last_station
1415
from radioactive.parser import parse_options
15-
from radioactive.player import Player, kill_background_ffplays
1616
from radioactive.utilities import (
1717
check_sort_by_parameter,
1818
handle_add_station,
@@ -22,6 +22,7 @@
2222
handle_favorite_table,
2323
handle_listen_keypress,
2424
handle_play_last_station,
25+
handle_play_random_station,
2526
handle_record,
2627
handle_save_last_station,
2728
handle_search_stations,
@@ -34,21 +35,44 @@
3435

3536
# globally needed as signal handler needs it
3637
# to terminate main() properly
38+
ffplay = None
3739
player = None
3840

3941

4042
def final_step(options, last_station, alias, handler):
43+
global ffplay # always needed
4144
global player
45+
4246
# check target URL for the last time
4347
if options["target_url"].strip() == "":
4448
log.error("something is wrong with the url")
4549
sys.exit(1)
4650

51+
if options["audio_player"] == "vlc":
52+
from radioactive.vlc import VLC
53+
54+
vlc = VLC()
55+
vlc.start(options["target_url"])
56+
player = vlc
57+
58+
elif options["audio_player"] == "mpv":
59+
from radioactive.mpv import MPV
60+
61+
mpv = MPV()
62+
mpv.start(options["target_url"])
63+
player = mpv
64+
65+
elif options["audio_player"] == "ffplay":
66+
ffplay = Ffplay(options["target_url"], options["volume"], options["loglevel"])
67+
player = ffplay
68+
69+
else:
70+
log.error("Unsupported media player selected")
71+
sys.exit(1)
72+
4773
if options["curr_station_name"].strip() == "":
4874
options["curr_station_name"] = "N/A"
4975

50-
player = Player(options["target_url"], options["volume"], options["loglevel"])
51-
5276
handle_save_last_station(
5377
last_station, options["curr_station_name"], options["target_url"]
5478
)
@@ -72,6 +96,7 @@ def final_step(options, last_station, alias, handler):
7296

7397
handle_listen_keypress(
7498
alias,
99+
player,
75100
target_url=options["target_url"],
76101
station_name=options["curr_station_name"],
77102
station_url=options["target_url"],
@@ -89,8 +114,6 @@ def main():
89114

90115
options = parse_options()
91116

92-
handle_welcome_screen()
93-
94117
VERSION = app.get_version()
95118

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

130+
handle_welcome_screen()
131+
107132
if options["show_help_table"]:
108133
show_help()
109134
sys.exit(0)
@@ -134,7 +159,10 @@ def main():
134159
# ----------- country ----------- #
135160
if options["discover_country_code"]:
136161
response = handler.discover_by_country(
137-
options["discover_country_code"], options["limit"], options["sort_by"]
162+
options["discover_country_code"],
163+
options["limit"],
164+
options["sort_by"],
165+
options["filter_with"],
138166
)
139167
if response is not None:
140168
(
@@ -148,7 +176,10 @@ def main():
148176
# -------------- state ------------- #
149177
if options["discover_state"]:
150178
response = handler.discover_by_state(
151-
options["discover_state"], options["limit"], options["sort_by"]
179+
options["discover_state"],
180+
options["limit"],
181+
options["sort_by"],
182+
options["filter_with"],
152183
)
153184
if response is not None:
154185
(
@@ -162,7 +193,10 @@ def main():
162193
# ----------- language ------------ #
163194
if options["discover_language"]:
164195
response = handler.discover_by_language(
165-
options["discover_language"], options["limit"], options["sort_by"]
196+
options["discover_language"],
197+
options["limit"],
198+
options["sort_by"],
199+
options["filter_with"],
166200
)
167201
if response is not None:
168202
(
@@ -176,7 +210,10 @@ def main():
176210
# -------------- tag ------------- #
177211
if options["discover_tag"]:
178212
response = handler.discover_by_tag(
179-
options["discover_tag"], options["limit"], options["sort_by"]
213+
options["discover_tag"],
214+
options["limit"],
215+
options["sort_by"],
216+
options["filter_with"],
180217
)
181218
if response is not None:
182219
(
@@ -193,6 +230,7 @@ def main():
193230
and options["search_station_uuid"] is None
194231
and options["direct_play"] is None
195232
and not options["play_last_station"]
233+
and not options["play_random"]
196234
):
197235
(
198236
options["curr_station_name"],
@@ -221,6 +259,7 @@ def main():
221259
options["search_station_name"],
222260
options["limit"],
223261
options["sort_by"],
262+
options["filter_with"],
224263
)
225264
if response is not None:
226265
(
@@ -239,6 +278,13 @@ def main():
239278
)
240279
final_step(options, last_station, alias, handler)
241280

281+
if options["play_random"]:
282+
(
283+
options["curr_station_name"],
284+
options["target_url"],
285+
) = handle_play_random_station(alias)
286+
final_step(options, last_station, alias, handler)
287+
242288
if options["play_last_station"]:
243289
options["curr_station_name"], options["target_url"] = handle_play_last_station(
244290
last_station
@@ -259,11 +305,15 @@ def main():
259305

260306

261307
def signal_handler(sig, frame):
308+
global ffplay
262309
global player
263310
log.debug("You pressed Ctrl+C!")
264311
log.debug("Stopping the radio")
265-
if player and player.is_playing:
312+
if ffplay and ffplay.is_playing:
313+
ffplay.stop()
314+
# kill the player
266315
player.stop()
316+
267317
log.info("Exiting now")
268318
sys.exit(0)
269319

radioactive/alias.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def search(self, entry):
7676

7777
def add_entry(self, left, right):
7878
"""Adds a new entry to the fav list"""
79+
self.generate_map()
7980
if self.search(left) is not None:
8081
log.warning("An entry with same name already exists, try another name")
8182
return False

radioactive/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Version of the current program, (in development mode it needs to be updated in every release)
2+
Version of the current program, (in development mode
3+
it needs to be updated in every release)
34
and to check if an updated version available for the app or not
45
"""
56
import json
@@ -9,7 +10,7 @@
910

1011
class App:
1112
def __init__(self):
12-
self.__VERSION__ = "2.9.0" # change this on every update #
13+
self.__VERSION__ = "2.9.1" # change this on every update #
1314
self.pypi_api = "https://pypi.org/pypi/radio-active/json"
1415
self.remote_version = ""
1516

0 commit comments

Comments
 (0)