Skip to content

Instantly share code, notes, and snippets.

@brunobord
Last active November 9, 2022 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunobord/eb82e7d72aa6b68634bb6e305a43a6e3 to your computer and use it in GitHub Desktop.
Save brunobord/eb82e7d72aa6b68634bb6e305a43a6e3 to your computer and use it in GitHub Desktop.
Command Line Radioparadise Player
__pycache__/
#!/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": "http://direct.fipradio.fr/live/fip-midfi.mp3",
"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": "http://direct.fipradio.fr/live/fip-webradio8.mp3",
"fip-rock": "http://direct.fipradio.fr/live/fip-webradio1.mp3 ",
"fip-jazz": "http://direct.fipradio.fr/live/fip-webradio2.mp3 ",
"fip-groove": "http://direct.fipradio.fr/live/fip-webradio3.mp3 ",
"fip-monde": "http://direct.fipradio.fr/live/fip-webradio4.mp3 ",
"fip-nouveau": "http://direct.fipradio.fr/live/fip-webradio5.mp3 ",
"fip-reggae": "http://direct.fipradio.fr/live/fip-webradio6.mp3",
"fip-metal": "https://chai5she.cdn.dvmr.fr/fip-webradio7.aac",
}
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)
#!/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",
},
}
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'."
" 'flac' is incompatible with 'ogg' stream."),
)
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)
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