Skip to content

Commit

Permalink
Add option to set volume (#18)
Browse files Browse the repository at this point in the history
* Add option to set volume

This passes through a value to ffplay setting the initial volume of the stream.

* added: volume option to the player

---------

Co-authored-by: Dipankar Pal <[email protected]>
  • Loading branch information
Yasumoto and deep5050 authored Aug 27, 2023
1 parent 412376e commit 4b14893
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ build.sh
deploy.sh
Makefile

pylint.txt
pylint.txt
.gitpod.yml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<p align=center> Play any radios around the globe right from your terminal </p>

<a href="https://www.producthunt.com/posts/radio-active?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-radio-active" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=305380&theme=dark" alt="radio-active - Play more than 30K radio stations from your terminal | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>

<p align=center ><img align=center src=https://static.pepy.tech/personalized-badge/radio-active?period=total&units=international_system&left_color=black&right_color=green&left_text=TotalInstalls></p>
<p>
<img width="500px" alt="UPI" src="https://user-images.githubusercontent.com/27947066/235618869-8c9d9bce-096d-469e-8f61-c29cc01eacc3.png">
</p>


<p align=center>
<img align=center src=images/example.png >
<hr>
Expand Down Expand Up @@ -106,6 +106,7 @@ Run with `radioactive --station [STATION_NAME]` or as simply `radio -U [UUID] `
| `--discover-by-tag` | Optional | Discover stations by tags/genre | fasle |
| `--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 |


<hr>
Expand Down Expand Up @@ -154,6 +155,5 @@ If you ever face a situation where radio-active quits but the audio (ffplay) run
<img src=https://forthebadge.com/images/badges/built-with-love.svg>



</div>

2 changes: 1 addition & 1 deletion radioactive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def main():

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

# writing the station name to a file, next time if user
# don't specify anything, it will try to start the last station
Expand Down
12 changes: 11 additions & 1 deletion radioactive/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self):
dest="discover_state",
help="Discover stations with state name",
)

self.parser.add_argument(
"--discover-by-language",
action="store",
Expand Down Expand Up @@ -133,6 +133,16 @@ def __init__(self):
help="Flush your favourite list",
)

self.parser.add_argument(
"--volume",
action="store",
dest="volume",
default=50,
type=int,
choices=range(0,101,10),
help="Volume to pass down to ffplay",
)

def parse(self):
self.result = self.parser.parse_args()

Expand Down
5 changes: 3 additions & 2 deletions radioactive/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class Player:
FFmepg required to be installed seperately
"""

def __init__(self, URL):
def __init__(self, URL, volume):
self.url = URL
self.volume = volume
self.is_playing = False
self.process = None
self.exe_path = None
Expand All @@ -34,7 +35,7 @@ def __init__(self, URL):
sys.exit(1)

self.process = Popen(
[self.exe_path, "-nodisp", "-nostats", "-loglevel", "0", self.url],
[self.exe_path, "-nodisp", "-nostats", "-loglevel", "0", "-volume", f"{self.volume}", self.url],
shell=False,
)

Expand Down

0 comments on commit 4b14893

Please sign in to comment.