Skip to content

Commit 4a068e0

Browse files
authored
API Server Rotation (#13)
* Initial implementation * Add server find to settings * Update Aminet Readme
1 parent 42179d6 commit 4a068e0

File tree

9 files changed

+239
-33
lines changed

9 files changed

+239
-33
lines changed

assets/aminet/TuneFinderMUI.README

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Short: Search+play online radio stations (MUI)
22
Author: [email protected] (Marcin Spoczynski)
33
Uploader: [email protected] (Marcin Spoczynski)
44
Type: comm/misc
5-
Version: 0.6-beta
5+
Version: 0.7-beta
66
Architecture: m68k-amigaos >= 3.0
77
Requires: MUI 3.8+
88
Distribution: Aminet
@@ -56,4 +56,11 @@ TuneFinderMUI 0.4 beta (1.01.2024)
5656
TuneFinderMUI 0.6 beta (12.01.2024)
5757

5858
- Configurable HTTPS streams filter with state persistence
59-
- Number of small fixes
59+
- Number of small fixes
60+
61+
TuneFinderMUI 0.7 beta (20.04.2025)
62+
- Added automatic Radio Browser API server rotation
63+
- Implemented DNS discovery of available API servers
64+
- Added "Next Server" button to manually switch between servers
65+
- Improved resilience against server outages with multi-server fallback
66+
- Enhanced error recovery with automatic retries on different servers

include/locale.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum {
2525
MSG_ACTION_STOP,
2626
MSG_ACTION_FAV_ADD,
2727
MSG_ACTION_FAV_REMOVE,
28+
MSG_ACTION_SAVE,
2829

2930
// GUI States (20-29)
3031
MSG_STATE_READY = 20,
@@ -134,7 +135,8 @@ enum {
134135
MSG_ASLREQ_SELECT_AMIGAAMP = 140, // "Select AmigaAmp executable"
135136
MSG_STATUS_SEARCH_RESULT = 141, // "Found %ld tune(s), in %lu second(s) [Limit: %lu]"
136137
MSG_STATUS_ALREADY_FAV = 142, // "Station already in favorites"
137-
MSG_STATUS_NOT_IN_FAV = 143 // "Station not in favorites"
138+
MSG_STATUS_NOT_IN_FAV = 143, // "Station not in favorites"
139+
EVENT_SETTINGS_NEXT_SERVER = 200
138140

139141
};
140142

include/main.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
// Application defines
3333
#define APP_NAME "TuneFinder MUI"
34-
#define APP_DATE "12.01.2025"
35-
#define APP_VERSION "0.6-beta"
34+
#define APP_DATE "20.04.2025"
35+
#define APP_VERSION "0.7-beta"
3636
#define APP_VERSTRING "$VER: " APP_NAME " " APP_VERSION " (" APP_DATE ")"
3737
#define APP_AUTHORS "Coding: Marcin Spoczynski\nGUI Design: Philippe Carpentier\nIcons: Thomas Blatt\n"
3838
#define APP_COPYRIGHT "Free to use and distribute"
@@ -48,7 +48,7 @@
4848
// API Settings
4949
#define API_HOST_ACCEPT \
5050
"0123456789abcdefghijklmnopqrstuvwxyz:/?#[]@!$&'()*+,;=%-_.~"
51-
#define API_HOST_DEFAULT "de1.api.radio-browser.info"
51+
#define API_HOST_DEFAULT "de2.api.radio-browser.info"
5252
#define API_HOST_MAX_LEN (1024)
5353

5454
#define API_PORT_ACCEPT "0123456789"
@@ -153,6 +153,8 @@ struct ObjApp {
153153
APTR STR_Settings_AmigaAmp; // String for AmigaAmp path
154154
APTR CHK_Settings_Iconify; // Checkbox for iconify option
155155
APTR CHK_Settings_QuitAmigaAMP;
156+
APTR BTN_Settings_API_Next_Server;
157+
APTR TXT_Settings_Current_Server;
156158
struct CountryConfig countryConfig;
157159

158160
};

include/network.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33

44
#include "data.h"
55
#include "main.h"
6+
#include "settings.h"
7+
68

79
#define API_ENDPOINT "/json/stations/search"
810
#define MAX_URL_LENGTH 2048
911
#define INITIAL_BUFFER_SIZE (64 * 1024) // 64 kb :)
1012
#define MAX_BUFFER_SIZE (64 * 1024 * 1024) // 4MB maximum
1113
#define PREFERRED_BUFFER_SIZE (2 * 1024 * 1024) // 2MB preferred
1214
#define READ_CHUNK_SIZE (8 * 1024) // Read 8KB at a time
15+
#define MAX_API_SERVERS 10
16+
struct APIServerList {
17+
char servers[MAX_API_SERVERS][MAX_HOST_LEN];
18+
int count;
19+
int current;
20+
BOOL initialized;
21+
};
22+
static struct APIServerList g_serverList = {{{0}}, 0, 0, FALSE};
1323

1424
enum {
1525
HTTPS_ALL = 0, // Any stations
@@ -28,6 +38,8 @@ struct Tune *SearchStations(const struct APISettings *settings,
2838
const struct SearchParams *params,
2939
LONG *count);
3040
void UpdateStatusMessage(const char *msg);
31-
41+
BOOL GetAPIServerList(void);
42+
const char *GetNextAPIServer(void);
43+
const char *GetCurrentAPIServer(void);
3244

3345
#endif /* NETWORK_H */

src/app.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "../include/locale.h"
3232
#include "../include/utils.h"
3333
#include "../include/amigaamp.h"
34+
#include "../include/network.h"
3435
#include "../include/countries.h"
3536
#include "../include/country_config.h"
3637
#include "../include/settings.h"
@@ -969,7 +970,7 @@ void CreateWindowSettings(struct ObjApp *obj) {
969970
APTR group0, group1, group2;
970971

971972
// Controls
972-
obj->BTN_Settings_Save = SimpleButton(GetTFString(MSG_ACTION_SAVE_ALL)); // "Save"
973+
obj->BTN_Settings_Save = SimpleButton(GetTFString(MSG_ACTION_SAVE)); // "Save"
973974
obj->BTN_Settings_Cancel = SimpleButton(GetTFString(MSG_ACTION_CANCEL)); // "Cancel"
974975

975976
obj->STR_Settings_AmigaAmp = StringObject,
@@ -1008,6 +1009,7 @@ void CreateWindowSettings(struct ObjApp *obj) {
10081009
MUIA_String_Format, MUIV_String_Format_Left, MUIA_String_MaxLen,
10091010
API_HOST_MAX_LEN, MUIA_String_Contents, API_HOST_DEFAULT,
10101011
MUIA_FixWidthTxt, "wwwwwwwwwwwwwwwwwwwwwwwwww", End;
1012+
obj->BTN_Settings_API_Next_Server = SimpleButton("Next Server");
10111013

10121014
// Port (Integer 0 to 65535)
10131015
obj->STR_Settings_API_Port = StringObject, MUIA_Frame, MUIV_Frame_String,
@@ -1055,7 +1057,10 @@ void CreateWindowSettings(struct ObjApp *obj) {
10551057
MUIA_Frame, MUIV_Frame_Group,
10561058
MUIA_HorizWeight, 200,
10571059
Child, Label(GetTFString(MSG_OPTION_API_HOST)),
1058-
Child, obj->STR_Settings_API_Host,
1060+
Child, HGroup,
1061+
Child, obj->STR_Settings_API_Host,
1062+
Child, obj->BTN_Settings_API_Next_Server,
1063+
End,
10591064
Child, Label(GetTFString(MSG_OPTION_API_PORT)),
10601065
Child, child1,
10611066
Child, Label(GetTFString(MSG_GUI_LIMIT)),
@@ -1128,7 +1133,8 @@ void CreateWindowSettingsEvents(struct ObjApp *obj) {
11281133
//
11291134
DoMethod(obj->BTN_Settings_AmigaAmp_Browse, MUIM_Notify, MUIA_Pressed, FALSE,
11301135
obj->App, 2, MUIM_Application_ReturnID, EVENT_SETTINGS_BROWSE_AMIGAAMP);
1131-
1136+
DoMethod(obj->BTN_Settings_API_Next_Server, MUIM_Notify, MUIA_Pressed, FALSE,
1137+
obj->App, 2, MUIM_Application_ReturnID, EVENT_SETTINGS_NEXT_SERVER);
11321138
// Window
11331139
DoMethod(obj->WIN_Settings, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
11341140
obj->App, 2, MUIM_Application_ReturnID, EVENT_SETTINGS_CANCEL);
@@ -1245,4 +1251,16 @@ BOOL APP_ShowFavorites(void)
12451251
}
12461252

12471253
return TRUE;
1248-
}
1254+
}
1255+
1256+
BOOL APP_Settings_Next_Server(void) {
1257+
DEBUG("%s", "APP_Settings_Next_Server()\n");
1258+
1259+
// Get the next server
1260+
const char *server = GetNextAPIServer();
1261+
1262+
// Update the host field
1263+
set(objApp->STR_Settings_API_Host, MUIA_String_Contents, server);
1264+
1265+
return TRUE;
1266+
}

src/locale.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static const char *built_in_strings[] = {
3636
"Stop Tune", // 16
3737
"Add", // 17
3838
"Delete", // 18
39-
NULL, // 19
39+
"Save", // 19
4040

4141
// GUI States (20-28)
4242
"Ready", // 20

src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ int main(void) {
371371
case EVENT_SETTINGS_CANCEL:
372372
APP_Settings_Cancel();
373373
break;
374+
case EVENT_SETTINGS_NEXT_SERVER:
375+
APP_Settings_Next_Server();
376+
break;
374377
case EVENT_SETTINGS_BROWSE_AMIGAAMP: {
375378
struct FileRequester *req;
376379
char path[256];

0 commit comments

Comments
 (0)