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

2.9.1.1 #109

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"files.autoSave": "off",
"editor.wordWrap": "wordWrapColumn",
"workbench.colorTheme": "Quiet Light",
"workbench.colorTheme": "GitHub Light High Contrast",
"editor.minimap.autohide": true,
"editor.minimap.renderCharacters": false,
"editor.experimentalWhitespaceRendering": "font",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.9.1

1. Play a random station from favorite list `--random`
2. Multiple media player support ( MPV, VLC, FFplay) `--player`
3. Default config file support added
4. Fixed minor bugs while giving runtime commands


## 2.9.0

1. Fetch current playing track info from runtime commands 🎶 ⚡
Expand Down
72 changes: 47 additions & 25 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 @@ -120,30 +121,33 @@ 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 | name | |
| `--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 @@ -198,6 +202,24 @@ you can sort the result page with these parameters:
- `clicktrend` (currently trending stations)
- `random`


### Default configs

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

```bash
[AppConfig]
loglevel = info
limit = 100
sort = votes
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
47 changes: 37 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,39 @@

# globally needed as signal handler needs it
# to terminate main() properly
player = None
ffplay = None


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

# 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"])

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

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

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

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 Down Expand Up @@ -89,8 +108,6 @@ def main():

options = parse_options()

handle_welcome_screen()

VERSION = app.get_version()

handler = Handler()
Expand All @@ -104,6 +121,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 @@ -193,6 +212,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 @@ -239,6 +259,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 +286,11 @@ def main():


def signal_handler(sig, frame):
global player
global ffplay
log.debug("You pressed Ctrl+C!")
log.debug("Stopping the radio")
if player and player.is_playing:
player.stop()
if ffplay and ffplay.is_playing:
ffplay.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
2 changes: 1 addition & 1 deletion radioactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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
39 changes: 33 additions & 6 deletions radioactive/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

from zenlog import log

from radioactive.config import Configs


# load default configs
def load_default_configs():
# load config file and apply configs
configs = Configs()
default_configs = configs.load()
return default_configs


class Parser:

Expand All @@ -11,6 +21,7 @@ class Parser:
def __init__(self):
self.parser = None
self.result = None
self.defaults = load_default_configs()

self.parser = argparse.ArgumentParser(
description="Play any radio around the globe right from the CLI ",
Expand Down Expand Up @@ -54,6 +65,14 @@ def __init__(self):
help="Play last played station.",
)

self.parser.add_argument(
"--random",
action="store_true",
default=False,
dest="play_random_station",
help="Play random station from fav list.",
)

self.parser.add_argument(
"--uuid",
"-U",
Expand All @@ -65,7 +84,7 @@ def __init__(self):
self.parser.add_argument(
"--loglevel",
action="store",
default="info",
default=self.defaults["loglevel"],
dest="log_level",
help="Specify log level",
)
Expand Down Expand Up @@ -103,15 +122,15 @@ def __init__(self):
"-L",
action="store",
dest="limit",
default=100,
default=self.defaults["limit"],
help="Limit of entries in discover table",
)

self.parser.add_argument(
"--sort",
action="store",
dest="stations_sort_by",
default="name",
default=self.defaults["sort"],
help="Sort stations",
)

Expand Down Expand Up @@ -161,7 +180,7 @@ def __init__(self):
"-V",
action="store",
dest="volume",
default=80,
default=self.defaults["volume"],
type=int,
choices=range(0, 101, 10),
help="Volume to pass down to ffplay",
Expand Down Expand Up @@ -189,7 +208,7 @@ def __init__(self):
"--filepath",
action="store",
dest="record_file_path",
default="",
default=self.defaults["filepath"],
help="specify the audio format for recording",
)

Expand All @@ -207,10 +226,18 @@ def __init__(self):
"-T",
action="store",
dest="record_file_format",
default="mp3",
default=self.defaults["filetype"],
help="specify the audio format for recording. auto/mp3",
)

self.parser.add_argument(
"--player",
action="store",
dest="audio_player",
default=self.defaults["player"],
help="specify the audio player to use. ffplay/vlc/mpv",
)

def parse(self):
self.result = self.parser.parse_args()
if self.result is None:
Expand Down
Loading