Skip to content

Commit

Permalink
fix: 🐛 Default recording filepath was ambiguas before
Browse files Browse the repository at this point in the history
  • Loading branch information
deep5050 committed Dec 18, 2023
1 parent 5da240a commit 49f5175
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
- [x] Finds nearby stations
- [x] Discovers stations by genre
- [x] Discovers stations by language
- [ ] I'm feeling lucky! Play Random stations
- [x] VLC, MPV player support
- [x] Default config file
- [ ] I'm feeling lucky! Play Random stations


> See my progress ➡️ [here](https://github.com/users/deep5050/projects/5)
Expand Down Expand Up @@ -202,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
1 change: 0 additions & 1 deletion radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def final_step(options, last_station, alias, handler):
)



def main():
log.level("info")

Expand Down
12 changes: 9 additions & 3 deletions radioactive/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# load configs from a file and apply.
# If any options are given on command line it will override the configs
import configparser
import getpass
import os
import sys

Expand All @@ -17,7 +18,7 @@ def write_a_sample_config_file():
"limit": "100",
"sort": "votes",
"volume": "80",
"filepath": "/home/radioactive/recordings",
"filepath": "/home/{user}/recordings/radioactive/",
"filetype": "mp3",
"player": "ffplay",
}
Expand All @@ -33,7 +34,7 @@ def write_a_sample_config_file():
with open(file_path, "w") as config_file:
config.write(config_file)

log.info(f"A sample configuration file added at: {file_path}")
log.info(f"A sample default configuration file added at: {file_path}")

except Exception as e:
print(f"Error writing the configuration file: {e}")
Expand All @@ -56,6 +57,11 @@ def load(self):
options["sort"] = self.config.get("AppConfig", "sort")
options["limit"] = self.config.get("AppConfig", "limit")
options["filepath"] = self.config.get("AppConfig", "filepath")
# if filepath has any placeholder, replace
# {user} to actual user map
options["filepath"] = options["filepath"].replace(
"{user}", getpass.getuser()
)
options["filetype"] = self.config.get("AppConfig", "filetype")
options["player"] = self.config.get("AppConfig", "player")

Expand All @@ -65,5 +71,5 @@ def load(self):
log.error("Something went wrong while parsing the config file")
# write the example config file
write_a_sample_config_file()
log.info("Rerun radioative")
log.info("Re-run radioative")
sys.exit(1)
4 changes: 3 additions & 1 deletion radioactive/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def handle_record(

elif not record_file_path:
log.debug("filepath: fallback to default path")
record_file_path = os.path.join(os.path.expanduser("~"), "Music/radioactive")
record_file_path = os.path.join(
os.path.expanduser("~"), "Music/radioactive"
) # fallback path
try:
os.makedirs(record_file_path, exist_ok=True)
except Exception as e:
Expand Down

0 comments on commit 49f5175

Please sign in to comment.