-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
103 lines (82 loc) · 3.31 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""Settings module for rtl_sdr_fm_player"""
import configparser
import os
def app_res_path(the_file):
"""Return application resource path for given file"""
return os.path.join(os.path.dirname(__file__), the_file)
def add_station(freq):
"""Add preset"""
config['Stations'][freq] = ''
write_config()
def remove_station(freq):
"""Remove preset"""
config.remove_option('Stations', freq)
write_config()
def get_stations():
"""Return stations from config file"""
return dict({i: config['Stations'][i] for i in config['Stations']})
def update_stations(preset_list):
"""Update presets"""
old_stations = get_stations()
old_preset_list = list(old_stations.keys())
new_preset_list = preset_list
for preset in old_preset_list:
remove_station(preset)
for preset_id, preset in enumerate(new_preset_list):
if preset_id < 8 and preset != 'Preset':
add_station(preset)
new_stations = get_stations()
new_frequencies = list(stations.keys())
return (new_stations, new_frequencies)
def write_config():
"""Write changes to config file"""
with open(app_res_path('settings.ini'), 'w') as configfile:
config.write(configfile)
config = configparser.ConfigParser()
if os.path.exists(app_res_path('settings.ini')):
config.read(app_res_path('settings.ini'))
# settings.ini will be created from example-settings.ini
else:
config.read(app_res_path('settings.ini'))
use_server = config.getboolean('rtl_fm_streamer', 'rtl_fm_streamer')
start_server = config.getboolean('rtl_fm_streamer', 'start_server')
host = config.get('rtl_fm_streamer', 'ip_address')
port = config.get('rtl_fm_streamer', 'server_port')
api_port = config.get('rtl_fm_streamer', 'server_api_port')
use_rds = config.getboolean('rtl_fm', 'redsea_rds')
rtl_fm_streamer_command = 'rtl_fm_streamer -P %d &' % int(port)
if use_server:
play_string = (
'%s http://%s:%s/freq/%s' % (
config.get('rtl_fm_streamer', 'player_command'),
host, port,
config.get('rtl_fm_streamer', 'stereo')))
else:
if use_rds:
play_string = (
'truncate -s0 rds_log_path;%s | redsea -u -e 2>> rds_log_path | %s' % (
config.get('rtl_fm', 'rtl_fm_command'),
config.get('rtl_fm', 'player_command')))
else:
play_string = (
' %s | %s' % (
config.get('rtl_fm', 'rtl_fm_command'),
config.get('rtl_fm', 'player_command')))
stations = get_stations()
frequencies = list(stations.keys())
current_frequency = config['Session']['frequency']
volume_down_command = 'xdotool key F7'
volume_up_command = 'xdotool key F8'
background_color = config.get('GUI', 'background_color')
font_color = config.get('GUI', 'text_color')
border_color = config.get('GUI', 'button_border')
button_color = config.get('GUI', 'button_color')
if button_color == 'black':
icon_path = app_res_path('icons/white_icons/')
else:
icon_path = app_res_path('icons/black_icons/')
#play_string = ('truncate -s0 ' + rds_log_path + ';'
# 'rtl_fm -M fm -l 0 -A std -p 0 -s 171k -F 9 -f %sM -E deemp | '
# 'redsea -u -e 2>> ' + rds_log_path + ' | '
# 'play -q -r 171k -t raw -e s -b 16 -c 1 -V1 - lowpass 16k')
# 'aplay -D pulse -t raw -r 171000 -c 1 -f S16_LE')