Last active
November 21, 2024 20:15
-
-
Save brunobord/eb82e7d72aa6b68634bb6e305a43a6e3 to your computer and use it in GitHub Desktop.
Command Line Radioparadise Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import random | |
import os | |
import argparse | |
from radiotools import check_volume, players, volume_options | |
streams = { | |
"inter": "http://direct.franceinter.fr/live/franceinter-midfi.mp3", | |
"basque": "http://direct.francebleu.fr/live/fbpaysbasque-midfi.mp3", | |
"fip-main": "https://stream.radiofrance.fr/fip/fip.m3u8", | |
"fip-bordeaux": "http://direct.fipradio.fr/live/fipbordeaux-midfi.mp3", | |
"fip-nantes": "http://direct.fipradio.fr/live/fipnantes-midfi.mp3", | |
"fip-strasbourg": "http://direct.fipradio.fr/live/fipstrasbourg-midfi.mp3", | |
"fip-electro": "https://stream.radiofrance.fr/fipelectro/fipelectro.m3u8", | |
"fip-rock": "https://stream.radiofrance.fr/fiprock/fiprock.m3u8", | |
"fip-jazz": "https://stream.radiofrance.fr/fipjazz/fipjazz.m3u8", | |
"fip-groove": "https://stream.radiofrance.fr/fipgroove/fipgroove.m3u8", | |
"fip-monde": "https://stream.radiofrance.fr/fipworld/fipworld.m3u8", | |
"fip-nouveau": "https://stream.radiofrance.fr/fipnouveautes/fipnouveautes.m3u8", | |
"fip-reggae": "https://stream.radiofrance.fr/fipreggae/fipreggae.m3u8", | |
"fip-metal": "https://stream.radiofrance.fr/fipmetal/fipmetal.m3u8", | |
"info": "https://stream.radiofrance.fr/franceinfo/franceinfo.m3u8", | |
} | |
default_stream = "inter" | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser("Radiofrance Player") | |
parser.add_argument( | |
"--player", | |
"-p", | |
default="mpv", | |
choices=players.keys(), | |
help="Command line player. Default is 'mpv'.", | |
) | |
parser.add_argument( | |
"--stream", | |
"-s", | |
default=default_stream, | |
choices=list(streams.keys()), | |
metavar="STREAM", | |
help="Stream type choice. Choices: [%(choices)s]. Default is '%(default)s'.", | |
) | |
parser.add_argument( | |
"--volume", | |
"-v", | |
default=40, | |
type=check_volume, | |
metavar="[0-100]", | |
help="Choose a volume level between 0 and 100.", | |
) | |
parser.add_argument( | |
"--random", | |
default=False, | |
action="store_true", | |
help="Pick a random FIP stream. Incompatible with the option `--stream`.", | |
) | |
parser.add_argument( | |
"--dry-run", | |
action="store_true", | |
default=False, | |
help="Do not run the player, just print the command.", | |
) | |
args = parser.parse_args() | |
if args.random: | |
if args.stream: | |
print("Incompatible options: random + stream. Priority to random...") | |
keys = streams.keys() | |
keys = filter(lambda x: x.startswith("fip"), keys) | |
stream_key = random.choice(list(keys)) | |
print(f"Current stream: {stream_key}") | |
else: | |
stream_key = args.stream or default_stream | |
stream = streams[stream_key] | |
player = players[args.player] | |
volume_option = volume_options[args.player] | |
command = f"{player} {stream} {volume_option}{args.volume}" | |
print(command) | |
if not args.dry_run: | |
os.system(command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import os | |
from radiotools import check_volume, players, volume_options | |
if __name__ == "__main__": | |
# Sources: https://radioparadise.com/listen/stream-links | |
streams = { | |
"main": { | |
"high": "http://stream.radioparadise.com/aac-320", | |
"medium": "http://stream.radioparadise.com/aac-128", | |
"low": "http://stream.radioparadise.com/aac-32", | |
"flac": "http://stream.radioparadise.com/flac", | |
}, | |
"ogg": { | |
"high": "http://icy-7.radioparadise.com/rp_192m.ogg", | |
"medium": "http://icy-4.radioparadise.com/rp_96.ogg", | |
"low": "http://icy-7.radioparadise.com/rp_32.ogg", | |
}, | |
"mellow": { | |
"high": "http://stream.radioparadise.com/mellow-320", | |
"medium": "http://stream.radioparadise.com/mellow-128", | |
"low": "http://stream.radioparadise.com/mellow-32", | |
"flac": "http://stream.radioparadise.com/mellow-flac", | |
}, | |
"eclectic": { | |
"high": "http://stream.radioparadise.com/eclectic-320", | |
"medium": "http://stream.radioparadise.com/eclectic-128", | |
"low": "http://stream.radioparadise.com/eclectic-32", | |
"flac": "http://stream.radioparadise.com/eclectic-flac", | |
}, | |
"rock": { | |
"high": "http://stream.radioparadise.com/rock-320", | |
"medium": "http://stream.radioparadise.com/rock-128", | |
"low": "http://stream.radioparadise.com/rock-32", | |
"flac": "http://stream.radioparadise.com/rock-flac", | |
}, | |
"serenity": { | |
"high": "http://stream.radioparadise.com/serenity", | |
}, | |
} | |
parser = argparse.ArgumentParser("Radio Paradise Player") | |
parser.add_argument( | |
"--player", | |
"-p", | |
default="mpv", | |
choices=players.keys(), | |
help="Command line player. Default is 'mpv'.", | |
) | |
parser.add_argument( | |
"--stream", | |
"-s", | |
default="main", | |
choices=streams.keys(), | |
help="Stream type choice. Default is 'main'.", | |
) | |
parser.add_argument( | |
"--quality", | |
"-q", | |
default="high", | |
choices=["high", "medium", "low", "flac"], | |
help=( | |
"Stream quality. Default is 'high'." | |
" Notes: 'flac' is incompatible with 'ogg' stream;" | |
" the serenity has only one quality." | |
), | |
) | |
parser.add_argument( | |
"--volume", | |
"-v", | |
default=40, | |
type=check_volume, | |
metavar="[0-100]", | |
help="Choose a volume level between 0 and 100.", | |
) | |
parser.add_argument( | |
"--dry-run", | |
action="store_true", | |
default=False, | |
help="Do not run the player, just print the command.", | |
) | |
args = parser.parse_args() | |
stream = streams[args.stream] | |
stream = stream[args.quality] | |
player = players[args.player] | |
volume_option = volume_options[args.player] | |
command = f"{player} {stream} {volume_option}{args.volume}" | |
print(command) | |
if not args.dry_run: | |
os.system(command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
def check_volume(value): | |
""" | |
Volume checker. | |
""" | |
value = int(value) | |
if value > 100 or value < 0: | |
raise argparse.ArgumentTypeError(f"{value} is an invalid volume value") | |
return value | |
check_volume.__name__ = "volume" | |
players = {"mpv": "mpv", "mplayer": "mplayer -really-quiet"} | |
volume_options = {"mpv": "--volume=", "mplayer": "-volume "} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment