Skip to content

Commit

Permalink
Feat: Implement update of webradioDB and population of internal strcut
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jun 23, 2024
1 parent 41504fb commit f7b0fea
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 293 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ https://github.com/jcorporation/myMPD/

This release improves the WebradioDB integration and removes the radiobrowser.info integration. You can use [RadioBrowser](https://github.com/jcorporation/mympd-scripts/tree/main/Radiobrowser) script to query the radiobrowser.info API.

### API changes

- MYMPD_API_WEBRADIODB_UPDATE: new
- MYMPD_API_CLOUD_WEBRADIODB_COMBINED_GET: removed
- MYMPD_API_CLOUD_RADIOBROWSER_NEWEST: removed
- MYMPD_API_CLOUD_RADIOBROWSER_SEARCH: removed
- MYMPD_API_CLOUD_RADIOBROWSER_SERVERLIST: removed
- MYMPD_API_CLOUD_RADIOBROWSER_STATION_DETAIL: removed
- MYMPD_API_CLOUD_RADIOBROWSER_CLICK_COUNT: removed

### Changelog

Upd: Remove radiobrowser integration #1311
Expand Down
26 changes: 13 additions & 13 deletions docs/references/translating_status.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- bg-BG: 1049 missing phrases
- es-AR: fully translated
- bg-BG: 1048 missing phrases
- es-AR: 2 missing phrases
- es-ES: 914 missing phrases
- es-VE: 905 missing phrases
- fi-FI: 902 missing phrases
- fr-FR: fully translated
- it-IT: 30 missing phrases
- ja-JP: fully translated
- ko-KR: fully translated
- nl-NL: fully translated
- pl-PL: 75 missing phrases
- ru-RU: 146 missing phrases
- zh-Hans: 28 missing phrases
- zh-Hant: 75 missing phrases
- es-VE: 904 missing phrases
- fi-FI: 901 missing phrases
- fr-FR: 2 missing phrases
- it-IT: 32 missing phrases
- ja-JP: 2 missing phrases
- ko-KR: 2 missing phrases
- nl-NL: 2 missing phrases
- pl-PL: 77 missing phrases
- ru-RU: 148 missing phrases
- zh-Hans: 30 missing phrases
- zh-Hant: 77 missing phrases
6 changes: 0 additions & 6 deletions docs/scripting/functions/mympd_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ Following API methods are not accessible:
- MYMPD_API_SESSION_LOGIN
- MYMPD_API_SESSION_LOGOUT
- MYMPD_API_SESSION_VALIDATE
- MYMPD_API_CLOUD_RADIOBROWSER_CLICK_COUNT
- MYMPD_API_CLOUD_RADIOBROWSER_NEWEST
- MYMPD_API_CLOUD_RADIOBROWSER_SERVERLIST
- MYMPD_API_CLOUD_RADIOBROWSER_SEARCH
- MYMPD_API_CLOUD_RADIOBROWSER_STATION_DETAIL
- MYMPD_API_CLOUD_WEBRADIODB_COMBINED_GET
4 changes: 2 additions & 2 deletions htdocs/js/apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2274,8 +2274,8 @@ const APImethods = {
}
}
},
"MYMPD_API_CLOUD_WEBRADIODB_COMBINED_GET": {
"desc": "Gets the full WebradioDB.",
"MYMPD_API_WEBRADIODB_UPDATE": {
"desc": "Updates the full WebradioDB.",
"params": {}
}
};
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ target_sources(mympd
lib/timer.c
lib/utility.c
lib/validate.c
lib/webradio.c
mpd_client/autoconf.c
mpd_client/connection.c
mpd_client/errorhandler.c
Expand All @@ -105,6 +106,7 @@ target_sources(mympd
mpd_worker/smartpls.c
mpd_worker/state.c
mpd_worker/song.c
mpd_worker/webradiodb.c
mympd_api/mympd_api.c
mympd_api/albumart.c
mympd_api/browse.c
Expand Down Expand Up @@ -146,7 +148,6 @@ target_sources(mympd
web_server/playlistart.c
web_server/tagart.c
web_server/utility.c
web_server/webradiodb.c
)

if(MYMPD_ENABLE_LUA)
Expand Down
20 changes: 11 additions & 9 deletions src/compile_time.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ extern struct t_mympd_queue *mympd_api_queue;
#define FILENAME_PRESETS "preset_list"
#define FILENAME_TIMER "timer_list"
#define FILENAME_TRIGGER "trigger_list"
#define FILENAME_WEBRADIODB "webradiodb-combined.min.json"
#define FILENAME_WEBRADIODB "webradiodb.mpack"
#define FILENAME_SCRIPTVARS "scriptvars_list"

#define DIR_CACHE_COVER "cover"
#define DIR_CACHE_LYRICS "lyrics"
#define DIR_CACHE_MISC "misc"
#define DIR_CACHE_THUMBS "thumbs"
#define DIR_CACHE_WEBRADIODB "webradiodb"

#define DIR_WORK_CONFIG "config"
#define DIR_WORK_EMPTY "empty"
Expand Down Expand Up @@ -340,12 +339,16 @@ extern struct t_mympd_queue *mympd_api_queue;
#define JSONRPC_TIME_MIN 0 // Do 1. Jan 01:00:00 CET 1970
#define JSONRPC_TIME_MAX 253402297169 // Fr 31. Dez 23:59:29 CET 9999

//some other limits
//timer
#define TIMER_WEBRADIODB_UPDATE_OFFSET 20 //seconds
#define TIMER_WEBRADIODB_UPDATE_INTERVAL 86400 //seconds
#define TIMER_DISK_CACHE_CLEANUP_OFFSET 240 //seconds
#define TIMER_DISK_CACHE_CLEANUP_INTERVAL 86400 //seconds
#define TIMER_SMARTPLS_UPDATE_OFFSET 30 //seconds
#define TIMER_INTERVAL_MIN 0 //seconds
#define TIMER_INTERVAL_MAX 7257600 //12 weeks
#define TIMER_SMARTPLS_UPDATE_OFFSET 30 //seconds
#define TIMER_DISK_CACHE_CLEANUP_OFFSET 60 //seconds
#define TIMER_DISK_CACHE_CLEANUP_INTERVAL 86400 //seconds

//some other limits
#define CACHE_AGE_MIN -1 //days
#define CACHE_AGE_MAX 365 //days
#define VOLUME_MIN 0 //prct
Expand Down Expand Up @@ -400,7 +403,6 @@ extern struct t_mympd_queue *mympd_api_queue;
#define LINE_LENGTH_MAX 8192 // 8 kb
#define LYRICS_SIZE_MAX 10000 //bytes
#define SMARTPLS_SIZE_MAX 2000 //bytes
#define WEBRADIODB_SIZE_MAX 1048576 //bytes, 1 MB
#define SSL_FILE_MAX 8192 // 8 kb

//limits for stickers
Expand All @@ -409,7 +411,7 @@ extern struct t_mympd_queue *mympd_api_queue;

#define PADDING_LENGTH 12

//cloud api hosts
#define WEBRADIODB_HOST "jcorporation.github.io"
//WebradioDB
#define WEBRADIODB_URI "https://jcorporation.github.io/webradiodb/db/index/webradios.min.json"

#endif
20 changes: 10 additions & 10 deletions src/i18n/json/i18n.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"default": {"desc":"Browser default", "missingPhrases": 0},
"de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 0},
"de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 2},
"en-US": {"desc":"English (en-US)", "missingPhrases": 0},
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 0},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 0},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 30},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 0},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 0},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 0},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 75},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 28},
"zh-Hant": {"desc":"简体中文 (zh-Hant)", "missingPhrases": 75}
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 2},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 2},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 32},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 2},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 2},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 2},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 77},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 30},
"zh-Hant": {"desc":"简体中文 (zh-Hant)", "missingPhrases": 77}
}
5 changes: 2 additions & 3 deletions src/i18n/json/phrases.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
{"term":"Context menu"},
{"term":"Copy"},
{"term":"Copy playlist"},
{"term":"Could not connect to %{host}"},
{"term":"Could not create session"},
{"term":"Could not delete preset"},
{"term":"Could not delete script"},
Expand Down Expand Up @@ -284,7 +283,6 @@
{"term":"Enumerate"},
{"term":"Error"},
{"term":"Error accessing %{uri}"},
{"term":"Error connecting to radio-browser.info"},
{"term":"Error creating Lua instance."},
{"term":"Error creating MPD search command"},
{"term":"Error creating MPD search queue command"},
Expand Down Expand Up @@ -403,7 +401,6 @@
{"term":"Invalid pin"},
{"term":"Invalid playlist directory"},
{"term":"Invalid response"},
{"term":"Invalid response from webradiodb backend"},
{"term":"Invalid scale ratio"},
{"term":"Invalid script API request"},
{"term":"Invalid script argument"},
Expand Down Expand Up @@ -982,6 +979,8 @@
{"term":"Webradio favorite successfully saved"},
{"term":"Webradio favorites"},
{"term":"WebradioDB"},
{"term":"WebradioDB update failed"},
{"term":"WebradioDB update started"},
{"term":"Webradioformat"},
{"term":"Webradios"},
{"term":"Webserver"},
Expand Down
3 changes: 2 additions & 1 deletion src/lib/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
X(INTERNAL_API_TAGART) \
X(INTERNAL_API_TIMER_STARTPLAY) \
X(INTERNAL_API_TRIGGER_EVENT_EMIT) \
X(INTERNAL_API_WEBRADIODB_CREATED) \
X(INTERNAL_API_WEBSERVER_NOTIFY) \
X(INTERNAL_API_WEBSERVER_READY) \
X(INTERNAL_API_WEBSERVER_SETTINGS) \
Expand All @@ -48,7 +49,6 @@
X(MYMPD_API_CHANNEL_LIST) \
X(MYMPD_API_CHANNEL_MESSAGE_SEND) \
X(MYMPD_API_CHANNEL_MESSAGES_READ) \
X(MYMPD_API_CLOUD_WEBRADIODB_COMBINED_GET) \
X(MYMPD_API_CONNECTION_SAVE) \
X(MYMPD_API_CACHE_DISK_CLEAR) \
X(MYMPD_API_CACHE_DISK_CROP) \
Expand Down Expand Up @@ -209,6 +209,7 @@
X(MYMPD_API_WEBRADIO_FAVORITE_LIST) \
X(MYMPD_API_WEBRADIO_FAVORITE_RM) \
X(MYMPD_API_WEBRADIO_FAVORITE_SAVE) \
X(MYMPD_API_WEBRADIODB_UPDATE) \
X(TOTAL_API_COUNT)

/**
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mympd_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "src/lib/sds_extras.h"
#include "src/lib/timer.h"
#include "src/lib/utility.h"
#include "src/lib/webradio.h"
#include "src/mpd_client/presets.h"
#include "src/mympd_api/home.h"
#include "src/mympd_api/timer.h"
Expand Down Expand Up @@ -125,6 +126,8 @@ void mympd_state_default(struct t_mympd_state *mympd_state, struct t_config *con
mympd_state->last_played_count = MYMPD_LAST_PLAYED_COUNT;
//poll fds
event_pfd_init(&mympd_state->pfds);
//webradioDB
mympd_state->webradiodb = NULL;
}

/**
Expand Down Expand Up @@ -153,6 +156,8 @@ void mympd_state_free(struct t_mympd_state *mympd_state) {
//caches
album_cache_free(&mympd_state->album_cache);
cache_free(&mympd_state->album_cache);
//webradioDB
webradio_free(mympd_state->webradiodb);
//sds
FREE_SDS(mympd_state->tag_list_search);
FREE_SDS(mympd_state->tag_list_browse);
Expand Down
1 change: 1 addition & 0 deletions src/lib/mympd_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ struct t_mympd_state {
sds info_txt_name; //!< name of album info files
struct t_cache album_cache; //!< the album cache created by the mpd_worker thread
unsigned last_played_count; //!< number of songs to keep in the last played list (disk + memory)
rax *webradiodb; //!< webradioDB
};

/**
Expand Down
94 changes: 94 additions & 0 deletions src/lib/webradio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
SPDX-License-Identifier: GPL-3.0-or-later
myMPD (c) 2018-2024 Juergen Mang <mail@jcgames.de>
https://github.com/jcorporation/mympd
*/

#include "compile_time.h"
#include "src/lib/webradio.h"

#include "src/lib/mem.h"
#include "src/lib/sds_extras.h"

/**
* Creates a new webradio data struct
* @return struct t_webradio_data*
*/
struct t_webradio_data *webradio_data_new(void) {
struct t_webradio_data *data = malloc_assert(sizeof(struct t_webradio_data));
list_init(&data->uris);
list_init(&data->genres);
list_init(&data->languages);
data->name = NULL;
data->image = NULL;
data->homepage = NULL;
data->country = NULL;
data->state = NULL;
data->description = NULL;
return data;
}

/**
* Frees a webradios data struct
* @param data struct to free
*/
void webradio_data_free(struct t_webradio_data *data) {
if (data == NULL) {
return;
}
list_clear(&data->uris);
list_clear(&data->genres);
list_clear(&data->languages);
FREE_SDS(data->name);
FREE_SDS(data->image);
FREE_SDS(data->homepage);
FREE_SDS(data->country);
FREE_SDS(data->state);
FREE_SDS(data->description);
// pointer data itself
FREE_PTR(data);
}

/**
* Frees the webradios rax
* @param webradios rax tree to free
*/
void webradio_free(rax *webradios) {
raxIterator iter;
raxStart(&iter, webradios);
raxSeek(&iter, "^", NULL, 0);
while (raxNext(&iter)) {
webradio_data_free((struct t_webradio_data *)iter.data);
iter.data = NULL;
}
raxStop(&iter);
raxFree(webradios);
}

/**
* Saves the webradios to disk
* @param config pointer to config
* @param webradios webradios rax to write
* @param filename file to write
* @return true on success, else false
*/
bool webradio_save_to_disk(struct t_config *config, rax *webradios, const char *filename) {
(void)config;
(void)webradios;
(void)filename;
//TODO: implement
return true;
}

/**
* Reads the webradios file from disk
* @param config pointer to config
* @param filename file to read
* @return newly allocated rax with webradios
*/
rax *webradio_read_from_disk(struct t_config *config, const char *filename) {
(void)config;
(void)filename;
//TODO: implement
return NULL;
}
34 changes: 34 additions & 0 deletions src/lib/webradio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
SPDX-License-Identifier: GPL-3.0-or-later
myMPD (c) 2018-2024 Juergen Mang <mail@jcgames.de>
https://github.com/jcorporation/mympd
*/

#ifndef MYMPD_LIB_WEBRADIO_H
#define MYMPD_LIB_WEBRADIO_H

#include "dist/rax/rax.h"
#include "dist/sds/sds.h"
#include "src/lib/config_def.h"
#include "src/lib/list.h"

struct t_webradio_data {
sds name;
sds image;
sds homepage;
sds country;
sds state;
sds description;
struct t_list uris;
struct t_list genres;
struct t_list languages;
};

struct t_webradio_data *webradio_data_new(void);
void webradio_data_free(struct t_webradio_data *data);

void webradio_free(rax *webradios);
bool webradio_save_to_disk(struct t_config *config, rax *webradios, const char *filename);
rax *webradio_read_from_disk(struct t_config *config, const char *filename);

#endif
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ static const struct t_subdirs_entry cachedir_subdirs[] = {
{DIR_CACHE_LYRICS, "Lyrics cache dir"},
{DIR_CACHE_MISC, "Misc cache dir"},
{DIR_CACHE_THUMBS, "Thumbs cache dir"},
{DIR_CACHE_WEBRADIODB, "Webradiodb cache dir"},
{NULL, NULL}
};

Expand Down
Loading

0 comments on commit f7b0fea

Please sign in to comment.