Skip to content

Commit

Permalink
2.5.1 (#41)
Browse files Browse the repository at this point in the history
* fix: exit on flush option

* fix: exit on flush

* v2.5.1

* fix: strip station names

* update: messages updated

* fix: player initialization issues

* v2.5.1

* vscode grammarly added

* v2.5.1
  • Loading branch information
deep5050 authored Sep 6, 2023
1 parent 338407a commit 0db19d2
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 87 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
"psutil",
"pyradios",
"stationuuid"
],
"grammarly.selectors": [
{
"language": "markdown",
"scheme": "file"
}
]
}
26 changes: 17 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
## 2.5.1

1. Fixed RuntimeError with empty selection menu on no options provided to radio.
2. Display the current station name as a panel while starting the radio with `--uuid`
3. Minor typos were fixed in the help message.
4. Station names do not contain any unnecessary spaces now
5. Do not play any stations while `--flush` is given. Just delete the list and exit.

## 2.5.0

1. Added a selection menu while no station information is provided. This will include the last played station and the favorite list.
2. Added `--volume` option to the player. Now you can can pass volume level to the player.
3. ffplay initialization errors handled. Better logic to stop the PID of ffplay
2. Added `--volume` option to the player. Now you can pass the volume level to the player.
3. `ffplay` initialization errors handled. Better logic to stop the PID of `ffplay`
4. Some unhandled errors are now handled
5. Minor typos fixed
6. sentry-sdk added to gater errors (will be removed on next major release)
6. `sentry-sdk` added to gater errors (will be removed on next major release)
7. About section updated to show donation link
8. Upgrade message will now point to this changelog file
8. The upgrade message will now point to this changelog file
9. Updated documentation

## 2.4.0

1. Crashes on Windows fixed
2. Fixed setup related issues (development purpose)
Fixed setup-related issues (development purpose)

## 2.3.0

1. Discover stations by country
2. Discover stations by state
3. Discover stations by genre/tags
4. Discover stations by language
5. More info on multiple results for a stations name
5. More info on multiple results for a station name
6. Shows currently playing radio info as box
7. sentry-SDK removed
8. Help table improved
Expand All @@ -32,7 +40,7 @@
1. Pretty Print welcome message using Rich
2. More user-friendly and gorgeous
3. Added several new options `-F`,`-W`,`-A`,`--flush`
4. Fixed unhandled Exception when try to quit within 3 seconds
4. Fixed unhandled Exception when trying to quit within 3 seconds
5. Supports User-Added stations
6. Alias file now supports both UUID and URL entry
7. Fixed bugs in playing last station (which is actually an alias under fav list)
Expand All @@ -49,10 +57,10 @@

## 2.1.3

1. Fixed bugs in last station
1. Fixed bugs in the last station
2. Typos fixed
3. Formatted codebase
4. Logiing issued fixed
4. Logging issued fixed
5. Sentry Added to collect unhandled Exceptions logs only


Expand Down
114 changes: 63 additions & 51 deletions radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
# using sentry to gather unhandled errors at production and will be removed on next major update.
# I respect your concerns but need this to improve radioactive.
import sentry_sdk

sentry_sdk.init(
dsn="https://e3c430f3b03f49b6bd9e9d61e7b3dc37@o615507.ingest.sentry.io/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,
)

RED_COLOR = "\033[91m"
END_COLOR = "\033[0m"

# globally needed as signal handler needs it
# to terminate main() properly
Expand Down Expand Up @@ -75,8 +77,7 @@ def main():
if log_level in ["info", "error", "warning", "debug"]:
log.level(log_level)
else:
log.warning(
"Correct log levels are: error,warning,info(default),debug")
log.warning("Correct log levels are: error,warning,info(default),debug")

handler = Handler()

Expand Down Expand Up @@ -111,7 +112,9 @@ def main():
if app.is_update_available():
update_msg = (
"\t[blink]An update available, run [green][italic]pip install radio-active=="
+ app.get_remote_version() + "[/italic][/green][/blink]\n See the changes: https://github.com/deep5050/radio-active/blob/main/CHANGELOG.md")
+ app.get_remote_version()
+ "[/italic][/green][/blink]\n See the changes: https://github.com/deep5050/radio-active/blob/main/CHANGELOG.md"
)
update_panel = Panel(
update_msg,
width=85,
Expand All @@ -121,7 +124,8 @@ def main():
log.debug("Update not available")

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

if show_favorite_list:
log.info("Your favorite station list is below")
Expand Down Expand Up @@ -177,30 +181,40 @@ def main():
pass
# print(last_station_info)
log.info("You can search for a station on internet using the --station option")
title = 'Please select a station from your favorite list:'
title = "Please select a station from your favorite list:"
station_selection_names = []
station_selection_urls = []


# add last played station first
if last_station_info:
station_selection_names.append(f"{last_station_info['name']} (last played station)")
station_selection_names.append(
f"{last_station_info['name'].strip()} (last played station)"
)
try:
station_selection_urls.append(last_station_info["stationuuid"])
except:
station_selection_urls.append(last_station_info["uuid_or_url"])

fav_stations = alias.alias_map
for entry in fav_stations:
station_selection_names.append(entry["name"])
station_selection_names.append(entry["name"].strip())
station_selection_urls.append(entry["uuid_or_url"])

options = station_selection_names
option, index = pick(options, title,indicator="-->")
if len(options) == 0:
# setting message color to red. technically it is not an error though.
# doing it just to catch user attention :)
log.info(
f"{RED_COLOR}No stations to play. please search for a station first!{END_COLOR}"
)
sys.exit(0)

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

# check if there is direct URL or just UUID
station_option_url = station_selection_urls[index]
station_name = station_selection_names[index]

if station_option_url.find("://") != -1:
# set direct play to TRUE
direct_play = True
Expand All @@ -209,38 +223,37 @@ def main():
# UUID
station_uuid = station_option_url

##################################

# try:
# if last_station_info["alias"]:
# is_alias = True
# except:
# pass

# if is_alias:
# alias.found = True # save on last_play as an alias too!
# # last station was an alias, don't save it again
# skip_saving_current_station = True
# station_uuid_or_url = last_station_info["uuid_or_url"]
# # here we are setting the name but will not be used for API call
# station_name = last_station_info["name"]
# if station_uuid_or_url.find("://") != -1:
# # Its a URL
# log.debug(
# "Last station was an alias and contains a URL, Direct play set to True"
# )
# direct_play = True
# direct_play_url = station_uuid_or_url
# log.info("Current station: {}".format(
# last_station_info["name"]))
# else:
# # an UUID
# station_uuid = last_station_info["uuid_or_url"]
# else:
# # was not an alias
# station_uuid = last_station_info["stationuuid"]
############################################

##################################

# try:
# if last_station_info["alias"]:
# is_alias = True
# except:
# pass

# if is_alias:
# alias.found = True # save on last_play as an alias too!
# # last station was an alias, don't save it again
# skip_saving_current_station = True
# station_uuid_or_url = last_station_info["uuid_or_url"]
# # here we are setting the name but will not be used for API call
# station_name = last_station_info["name"]
# if station_uuid_or_url.find("://") != -1:
# # Its a URL
# log.debug(
# "Last station was an alias and contains a URL, Direct play set to True"
# )
# direct_play = True
# direct_play_url = station_uuid_or_url
# log.info("Current station: {}".format(
# last_station_info["name"]))
# else:
# # an UUID
# station_uuid = last_station_info["uuid_or_url"]
# else:
# # was not an alias
# station_uuid = last_station_info["stationuuid"]
############################################

# --------------------ONLY UUID PROVIDED --------------------- #
# if --uuid provided call directly
Expand Down Expand Up @@ -272,8 +285,7 @@ def main():
station_uuid = result["uuid_or_url"] # its a UUID

except:
log.warning(
"Station found in favorite list but seems to be invalid")
log.warning("Station found in favorite list but seems to be invalid")
log.warning("Looking on the web instead")
alias.found = False

Expand All @@ -289,7 +301,8 @@ def main():
if not direct_play:
# avoid extra API calls since target url is given
if mode_of_search == "uuid":
handler.play_by_station_uuid(station_uuid)
_station_name = handler.play_by_station_uuid(station_uuid)
station_name = _station_name
else:
if not alias.found:
# when alias was found, we have set the station name to print it correctly,
Expand All @@ -298,8 +311,7 @@ def main():

global player

target_url = direct_play_url if direct_play else handler.target_station[
"url"]
target_url = direct_play_url if direct_play else handler.target_station["url"]
player = Player(target_url, args.volume)

# writing the station name to a file, next time if user
Expand All @@ -326,9 +338,9 @@ def main():
# TODO fix this. when aliasing a station with an existing name curr_station_name is being None
panel_station_name = Text(curr_station_name, justify="center")

station_panel = Panel(panel_station_name,
title="[blink]:radio:[/blink]",
width=85)
station_panel = Panel(
panel_station_name, title="[blink]:radio:[/blink]", width=85
)
console.print(station_panel)
except:
# TODO handle exception
Expand Down
12 changes: 9 additions & 3 deletions radioactive/alias.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
from zenlog import log


class Alias:
def __init__(self):
self.alias_map = []
Expand Down Expand Up @@ -67,6 +68,11 @@ def add_entry(self, left, right):

def flush(self):
"""deletes all the entries in the fav list"""
with open(self.alias_path, "w") as f:
f.flush()
log.info("All entries deleted in your favorite list")
try:
with open(self.alias_path, "w") as f:
f.flush()
log.info("All entries deleted in your favorite list")
return 0
except:
log.error("could not delete your favorite list. something went wrong")
return 1
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.0" # change this on every update #
self.__VERSION__ = "2.5.1" # change this on every update #
self.pypi_api = "https://pypi.org/pypi/radio-active/json"
self.remote_version = ""

Expand Down
6 changes: 4 additions & 2 deletions radioactive/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ def station_validator(self):

# when exactly one response found
if len(self.response) == 1:
log.info("Station found: {}".format(self.response[0]["name"]))
log.info("Station found: {}".format(self.response[0]["name"].strip()))
log.debug(json.dumps(self.response[0], indent=3))
self.target_station = self.response[0]
# register a valid click to increase its popularity
self.API.click_counter(self.target_station["stationuuid"])
# return name
return self.response[0]["name"].strip()

def play_by_station_name(self, _name=None):
"""search and play a station by its name"""
Expand All @@ -90,7 +92,7 @@ def play_by_station_name(self, _name=None):
def play_by_station_uuid(self, _uuid):
"""search and play station by its stationuuid"""
self.response = self.API.station_by_uuid(_uuid)
self.station_validator()
return self.station_validator() # should return a station name also

def discover_by_country(self, _country_code, _limit):
try:
Expand Down
Loading

0 comments on commit 0db19d2

Please sign in to comment.