diff --git a/.vscode/settings.json b/.vscode/settings.json index c92b3be..59e2557 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,11 @@ "psutil", "pyradios", "stationuuid" + ], + "grammarly.selectors": [ + { + "language": "markdown", + "scheme": "file" + } ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a305e..f674e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,27 @@ +## 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 @@ -21,7 +29,7 @@ 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 @@ -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) @@ -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 diff --git a/radioactive/__main__.py b/radioactive/__main__.py index 88cdd73..8c0e2e9 100755 --- a/radioactive/__main__.py +++ b/radioactive/__main__.py @@ -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 @@ -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() @@ -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, @@ -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") @@ -177,14 +181,15 @@ 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: @@ -192,15 +197,24 @@ def main(): 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 @@ -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 @@ -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 @@ -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, @@ -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 @@ -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 diff --git a/radioactive/alias.py b/radioactive/alias.py index 0f41b08..3913a43 100644 --- a/radioactive/alias.py +++ b/radioactive/alias.py @@ -1,6 +1,7 @@ import os.path from zenlog import log + class Alias: def __init__(self): self.alias_map = [] @@ -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 diff --git a/radioactive/app.py b/radioactive/app.py index 6cc3f7f..3dc81e5 100644 --- a/radioactive/app.py +++ b/radioactive/app.py @@ -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 = "" diff --git a/radioactive/handler.py b/radioactive/handler.py index ceb5806..5aea08c 100644 --- a/radioactive/handler.py +++ b/radioactive/handler.py @@ -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""" @@ -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: diff --git a/radioactive/help.py b/radioactive/help.py index d51edd2..5233763 100644 --- a/radioactive/help.py +++ b/radioactive/help.py @@ -12,9 +12,10 @@ def show_help(): """ :radio: Play any radios around the globe right from this Terminal [yellow][blink]:zap:[/blink][/yellow]! :smile: Author: Dipankar Pal - :question: Type '--help' for more details on avaliable commands. + :question: Type '--help' for more details on available commands. :bug: Visit https://github.com/deep5050/radio-active to submit issues :star: Show some love by starring the project on GitHub [red][blink]:heart:[/blink][/red] + :dollar: You can donate me at https://deep5050.github.io/payme/ """, title="[rgb(250,0,0)]RADIO[rgb(0,255,0)]ACTIVE", width=85, @@ -31,12 +32,16 @@ def show_help(): table.add_row( "--station , -S", "yes", - "A station name to play", + "A station name to search on the internet", "", "Optional from second run", ) table.add_row( - "--uuid , -U", "yes", "A station UUID to play", "", "Optional from second run" + "--uuid , -U", + "yes", + "A station UUID to play it directly", + "", + "Optional from second run", ) table.add_row( "--log-level , -L", @@ -48,23 +53,22 @@ def show_help(): table.add_row( "--add-station , -A", "no", - "Add a station to your favourite list", + "Add a station to your favorite list", "False", "Optional", ) table.add_row( - "--add-to-favourite, -F ", + "--add-to-favorite, -F ", "yes", - "Add current station to favourite list with custom name", + "Add current station to favorite list with custom name", "False", "Optional", ) - table.add_row( - "--show-favourite-list, -W ", + "--show-favorite-list, -W ", "no", - "Show your favourite list", + "Show your favorite list", "False", "Optional", ) @@ -112,19 +116,11 @@ def show_help(): table.add_row( "--volume", "yes", - "Volume of radio between 0 and 100", + "Volume of the radio between 0 and 100", "50", "Optional", ) - table.add_row("--flush", "no", "Clear your favourite list", "False", "Optional") - - - - - - - - + table.add_row("--flush", "no", "Clear your favorite list", "False", "Optional") console.print(table) diff --git a/radioactive/player.py b/radioactive/player.py index eb8ced1..3e4a8b5 100644 --- a/radioactive/player.py +++ b/radioactive/player.py @@ -47,8 +47,8 @@ def __init__(self, URL, volume): self.is_playing = True log.info("Radio started successfully") else: - log.error("Radio could not be stared, may be a dead station") - raise RuntimeError("Radio startup failed") + log.error("Radio could not be stared, may be a dead station. please try again") + sys.exit(1) except subprocess.CalledProcessError as e: log.error("Error while starting radio: {}".format(e))