Skip to content

Commit

Permalink
2.5.2 (#44)
Browse files Browse the repository at this point in the history
* added: --kill to stop background radios
sometimes radioactive exists without terminating
the ffplay process. find and kill those unwanted processes.

* Feat: new pypi project structure

* license year updated

* README using remote images instead of local

* fix: project restructured

* minor fix

* fix: saving empty last station

* fix: build warning

* Added: project Makefile

* twine added
  • Loading branch information
deep5050 committed Sep 13, 2023
1 parent 0db19d2 commit 2c735d8
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 49 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ dmypy.json
last_station.json
build.sh
deploy.sh
Makefile

pylint.txt
.gitpod.yml
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.5.2

1. Added `--kill` option to stop background radios if any.
2. Project restructured.
3. Fixed saving empty last station information.



## 2.5.1

1. Fixed RuntimeError with empty selection menu on no options provided to radio.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Dipankar Pal
Copyright (c) 2023 Dipankar Pal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include *.py
include README.md
include LICENSE
include requirements.txt
include requirements-dev.txt
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SHELL := /bin/bash
PYTHON = python3
TEST_PATH = ./tests/
FLAKE8_EXCLUDE = venv,.venv,.eggs,.tox,.git,__pycache__,*.pyc
SRC_DIR = "radioactive"
TEST_DIR = "test"

all: clean install-dev test

check:
${PYTHON} -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude ${FLAKE8_EXCLUDE}
${PYTHON} -m flake8 . --count --exit-zero --max-complexity=10 --max-line-length=79 --statistics --exclude ${FLAKE8_EXCLUDE}

clean:
@find . -name '*.pyc' -exec rm --force {} +
@find . -name '*.pyo' -exec rm --force {} +
@find . -name '*~' -exec rm --force {} +
rm -rf build
rm -rf dist
rm -rf *.egg-info
rm -f *.sqlite
rm -rf .cache

dist: clean
${PYTHON} setup.py sdist bdist_wheel

deploy:
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

test-deploy: dist
@echo "-------------------- sending to testpypi server ------------------------"
@twine upload -r testpypi dist/*

help:
@echo "---------------------------- help --------------------------------------"
@echo " clean"
@echo " Remove python artifacts and build artifacts."
@echo " isort"
@echo " Sort import statements."
@echo " check"
@echo " Check style with flake8."
@echo " test"
@echo " Run pytest"

isort:
@echo "Sorting imports..."
isort $(SRC_DIR) $(TEST_DIR)

build:
python3 setup.py build

install:
pip install -e .

install-dev: install
pip install --upgrade pip
pip install -e .[dev]

test:
${PYTHON} -m pytest ${TEST_PATH}
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align=center>
<p align=center><img src=images/logo.png width=250px></p>
<p align=center><img src=https://user-images.githubusercontent.com/27947066/267328833-3e81a98e-2acb-4291-89cb-f3f9bed6c299.png width=250px></p>
<h1 align=center> RADIO-ACTIVE </h1>
<p align=center> Play any radios around the globe right from your terminal </p>

Expand All @@ -11,7 +11,7 @@
</p>

<p align=center>
<img align=center src=images/example.png >
<img align=center src=https://github.com/deep5050/random-shits-happen-here/assets/27947066/250dcd05-c142-442a-a9a3-66347adb69c5 >
<hr>
<img alt="GitHub" src="https://img.shields.io/github/license/deep5050/radio-active?style=for-the-badge">
<img alt="PyPI" src="https://img.shields.io/pypi/v/radio-active?style=for-the-badge">
Expand All @@ -37,7 +37,7 @@
- [x] Discovers stations by genre
- [x] Discovers stations by language
- [ ] I'm feeling lucky ! Play Random stations
- [ ] No external media player dependency!


> See my progress [here](https://github.com/deep5050/radio-active/projects/1)
Expand Down Expand Up @@ -83,7 +83,7 @@ Run with `radioactive --station [STATION_NAME]` or as simply `radio -U [UUID] `

### Demo

<a align=center href="https://www.youtube.com/watch?v=X-NfK5XbM90" target="_blank"> <img align=center src=images/maxresdefault.jpg/> </a>
<a align=center href="https://www.youtube.com/watch?v=X-NfK5XbM90" target="_blank"> <img align=center src=https://user-images.githubusercontent.com/27947066/267328820-f7264e02-edc1-46f3-9548-5dfb50a6627d.jpg /> </a>
<hr>
<a align=center href="https://asciinema.org/a/412285" target="_blank"><img src="https://asciinema.org/a/412285.svg" /></a>

Expand All @@ -92,22 +92,22 @@ Run with `radioactive --station [STATION_NAME]` or as simply `radio -U [UUID] `
### Options


| Argument | Note | Description | Default |
| ---------------------------- | ------------------------------------ | -------------------------------------------- | ------- |
| Argument | Note | Description | Default |
| ---------------------------- | ----------------------------------- | -------------------------------------------- | ------- |
| `--station`, `-S` | Required (Optional from second run) | Station name | None |
| `--uuid`, `-U` | Optional | ID of the station | None |
| `--log-level`, `-L` | Optional | Log level of the program | Info |
| `--add-station` , `-A` | Optional | Add an entry to fav list | False |
| `--show-favorite-list`,`-W` | Optional | Show fav list | False |
| `--add-to-favorite`,`-F` | Optional | Add current station to fav list | False |
| `--flush` | Optional | Remove all the entries from fav list | False |
| `--discover-by-country`,`-D` | Optional | Discover stations by country code | False |
| `--discover-by-state` | Optional | Discover stations by country state | False |
| `--discover-by-tag` | Optional | Discover stations by tags/genre | False |
| `--discover-by-language` | optional | Discover stations by | False |
| `--limit` | Optional | Limit the # of results in the Discover table | 100 |
| `--volume` | Optional | Change the volume passed into ffplay | 50 |

| `--uuid`, `-U` | Optional | ID of the station | None |
| `--log-level`, `-L` | Optional | Log level of the program | Info |
| `--add-station` , `-A` | Optional | Add an entry to fav list | False |
| `--show-favorite-list`,`-W` | Optional | Show fav list | False |
| `--add-to-favorite`,`-F` | Optional | Add current station to fav list | False |
| `--flush` | Optional | Remove all the entries from fav list | False |
| `--discover-by-country`,`-D` | Optional | Discover stations by country code | False |
| `--discover-by-state` | Optional | Discover stations by country state | False |
| `--discover-by-tag` | Optional | Discover stations by tags/genre | False |
| `--discover-by-language` | optional | Discover stations by | False |
| `--limit` | Optional | Limit the # of results in the Discover table | 100 |
| `--volume` | Optional | Change the volume passed into ffplay | 50 |
| `--kill` | Optional | Kill background radios. | False |

<hr>

Expand Down Expand Up @@ -143,17 +143,20 @@ If you ever face a situation where radio-active quits but the audio (ffplay) run


### Support

<p>
<a href=https://deep5050.github.io/payme>Visit my contribution page for more payment options.
</p>
<p align=center><a href="https://www.buymeacoffee.com/deep5050" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 40px !important;width: 117px !important;" ></a></p>

### Acknowledgements

<div>Icons made by <a href="https://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>


<div align=center>
<img src=images/footer.png width=400px >
<img src=https://github.com/deep5050/random-shits-happen-here/assets/27947066/83d08065-c209-4012-abb7-9c0aa64d761b width=400px >
<p align=center> Happy Listening </p>
<img src=https://forthebadge.com/images/badges/built-with-love.svg>


</div>

Expand Down
26 changes: 18 additions & 8 deletions radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from radioactive.handler import Handler
from radioactive.help import show_help
from radioactive.last_station import Last_station
from radioactive.player import Player
from radioactive.player import Player, kill_background_ffplays


# using sentry to gather unhandled errors at production and will be removed on next major update.
Expand All @@ -27,9 +27,6 @@

sentry_sdk.init(
dsn="https://[email protected]/5749950",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
)

Expand Down Expand Up @@ -63,6 +60,7 @@ def main():
add_to_favorite = args.add_to_favorite
show_favorite_list = args.show_favorite_list
flush_fav_list = args.flush
kill_ffplays = args.kill_ffplays
########################################

VERSION = app.get_version()
Expand Down Expand Up @@ -123,10 +121,20 @@ def main():
else:
log.debug("Update not available")

# flush ?
if flush_fav_list:
# exit radio after deleting fav stations
sys.exit(alias.flush())

# -------------- kill background ffplay PIDs --------------------#
# sometimes radio exits while ffplay is still running.
# actively trying to prevent these scenarios. until then use this

if kill_ffplays:
kill_background_ffplays()
sys.exit(0)

# ----------------- favorite list ---------------- #
if show_favorite_list:
log.info("Your favorite station list is below")
table = Table(show_header=True, header_style="bold magenta")
Expand All @@ -140,6 +148,7 @@ def main():
log.info("You have no favorite station list")
sys.exit(0)

# --------------------------- add a station --------------------------#
if add_station:
left = input("Enter station name:")
right = input("Enter station stream-url or radio-browser uuid:")
Expand Down Expand Up @@ -172,8 +181,7 @@ def main():
if station_name is None and station_uuid is None:
# Add a selection list here. first entry must be the last played station
# try to fetch the last played station's information
# log.warn(
# "No station information provided, trying to play the last station")

try:
last_station_info = last_station.get_info()
except:
Expand Down Expand Up @@ -209,7 +217,7 @@ def main():
)
sys.exit(0)

_ , index = pick(options, title, indicator="-->")
_, index = pick(options, title, indicator="-->")

# check if there is direct URL or just UUID
station_option_url = station_selection_urls[index]
Expand Down Expand Up @@ -326,7 +334,9 @@ def main():
last_played_station["alias"] = True

if not skip_saving_current_station:
last_station.save_info(last_played_station)
log.debug(f"Saving the current station: {last_played_station}")
if last_played_station:
last_station.save_info(last_played_station)

# TODO: handle error when favouring last played (aliased) station (BUG) (LOW PRIORITY)
if add_to_favorite:
Expand Down
2 changes: 1 addition & 1 deletion radioactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

Expand Down
10 changes: 8 additions & 2 deletions radioactive/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ def __init__(self):
"--volume",
action="store",
dest="volume",
default=50,
default=80,
type=int,
choices=range(0,101,10),
help="Volume to pass down to ffplay",
)

self.parser.add_argument(
"--kill",
action="store_true",
dest="kill_ffplays",
default=False,
help="kill all the ffplay process initiated by radioactive",
)
def parse(self):
self.result = self.parser.parse_args()

Expand Down
3 changes: 2 additions & 1 deletion radioactive/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ def show_help():
"--volume",
"yes",
"Volume of the radio between 0 and 100",
"50",
"80",
"Optional",
)

table.add_row("--flush", "no", "Clear your favorite list", "False", "Optional")
table.add_row("--kill", "no", "Stop background radios", "False", "Optional")

console.print(table)
Loading

0 comments on commit 2c735d8

Please sign in to comment.