converted sonic_id to a string, to support epoupon LMS

This commit is contained in:
Fufu Fang 2019-10-28 01:09:55 +00:00
parent e9c8689f8d
commit 55ad0cd9fc
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
5 changed files with 28 additions and 35 deletions

View File

@ -585,7 +585,7 @@ void Cache_delete(const char *fn)
{
if (CONFIG.sonic_mode) {
Link *link = path_to_Link(fn);
fn = link->sonic_song_id_str;
fn = link->sonic_id;
}
char *metafn = path_append(META_DIR, fn);
@ -678,7 +678,7 @@ int Cache_create(const char *path)
fn = curl_easy_unescape(NULL, this_link->f_url + ROOT_LINK_OFFSET, 0,
NULL);
} else {
fn = this_link->sonic_song_id_str;
fn = this_link->sonic_id;
}
fprintf(stderr, "Cache_create(): Creating cache files for %s.\n", fn);
@ -774,7 +774,7 @@ Cache *Cache_open(const char *fn)
return NULL;
}
} else {
if (!Cache_exist(link->sonic_song_id_str)) {
if (!Cache_exist(link->sonic_id)) {
return NULL;
}
}
@ -788,7 +788,7 @@ Cache *Cache_open(const char *fn)
/* Set the path for the local cache file, if we are in sonic mode */
if (CONFIG.sonic_mode) {
fn = link->sonic_song_id_str;
fn = link->sonic_id;
}
cf->path = strndup(fn, MAX_PATH_LEN);

View File

@ -66,9 +66,9 @@ LinkTable *LinkSystem_init(const char *raw_url)
} else {
sonic_config_init(url, CONFIG.sonic_username, CONFIG.sonic_password);
if (!CONFIG.sonic_id3) {
ROOT_LINK_TBL = sonic_LinkTable_new_index(0);
ROOT_LINK_TBL = sonic_LinkTable_new_index("0");
} else {
ROOT_LINK_TBL = sonic_LinkTable_new_id3(0, 0);
ROOT_LINK_TBL = sonic_LinkTable_new_id3(0, "0");
}
}
return ROOT_LINK_TBL;
@ -356,8 +356,7 @@ void LinkTable_print(LinkTable *linktbl)
}
}
fprintf(stderr, "--------------------------------------------\n");
fprintf(stderr, "LinkTable_print(): Invalid link count: %d, %s.\n", j,
linktbl->links[0]->f_url);
fprintf(stderr, "LinkTable_print(): Invalid link count: %d\n", j);
fprintf(stderr, "--------------------------------------------\n");
}

View File

@ -77,17 +77,13 @@ struct Link {
* - Sub-directory ID (in the XML response, this is the ID on the "child"
* element)
*/
int sonic_id;
char *sonic_id;
/**
* \brief Sonic directory depth
* \details This is used exclusively in ID3 mode to store the depth of the
* current directory.
*/
int sonic_depth;
/**
* \brief The sonic song's ID in character array format.
*/
char *sonic_song_id_str;
};
struct LinkTable {

View File

@ -100,11 +100,11 @@ static char *sonic_gen_url_first_part(char *method)
/**
* \brief generate a getMusicDirectory request URL
*/
static char *sonic_getMusicDirectory_link(const int id)
static char *sonic_getMusicDirectory_link(const char *id)
{
char *first_part = sonic_gen_url_first_part("getMusicDirectory");
char *url = CALLOC(MAX_PATH_LEN + 1, sizeof(char));
snprintf(url, MAX_PATH_LEN, "%s&id=%d", first_part, id);
snprintf(url, MAX_PATH_LEN, "%s&id=%s", first_part, id);
free(first_part);
return url;
}
@ -112,11 +112,11 @@ static char *sonic_getMusicDirectory_link(const int id)
/**
* \brief generate a getArtist request URL
*/
static char *sonic_getArtist_link(const int id)
static char *sonic_getArtist_link(const char *id)
{
char *first_part = sonic_gen_url_first_part("getArtist");
char *url = CALLOC(MAX_PATH_LEN + 1, sizeof(char));
snprintf(url, MAX_PATH_LEN, "%s&id=%d", first_part, id);
snprintf(url, MAX_PATH_LEN, "%s&id=%s", first_part, id);
free(first_part);
return url;
}
@ -124,11 +124,11 @@ static char *sonic_getArtist_link(const int id)
/**
* \brief generate a getAlbum request URL
*/
static char *sonic_getAlbum_link(const int id)
static char *sonic_getAlbum_link(const char *id)
{
char *first_part = sonic_gen_url_first_part("getAlbum");
char *url = CALLOC(MAX_PATH_LEN + 1, sizeof(char));
snprintf(url, MAX_PATH_LEN, "%s&id=%d", first_part, id);
snprintf(url, MAX_PATH_LEN, "%s&id=%s", first_part, id);
free(first_part);
return url;
}
@ -136,12 +136,12 @@ static char *sonic_getAlbum_link(const int id)
/**
* \brief generate a download request URL
*/
static char *sonic_stream_link(const int id)
static char *sonic_stream_link(const char *id)
{
char *first_part = sonic_gen_url_first_part("stream");
char *url = CALLOC(MAX_PATH_LEN + 1, sizeof(char));
snprintf(url, MAX_PATH_LEN,
"%s&format=raw&id=%d", first_part, id);
"%s&format=raw&id=%s", first_part, id);
free(first_part);
return url;
}
@ -186,10 +186,8 @@ static void XMLCALL XML_parser_index(void *data, const char *elem,
for (int i = 0; attr[i]; i += 2) {
if (!strcmp("id", attr[i])) {
link->sonic_id = atoi(attr[i+1]);
link->sonic_song_id_str = calloc(MAX_FILENAME_LEN, sizeof(char));
snprintf(link->sonic_song_id_str, MAX_FILENAME_LEN, "%d",
link->sonic_id);
link->sonic_id = calloc(MAX_FILENAME_LEN + 1, sizeof(char));
strncpy(link->sonic_id, attr[i+1], MAX_FILENAME_LEN);
id_set = 1;
continue;
}
@ -292,14 +290,15 @@ static LinkTable *sonic_url_to_LinkTable(const char *url,
}
LinkTable *sonic_LinkTable_new_index(const int id)
LinkTable *sonic_LinkTable_new_index(const char *id)
{
char *url;
if (id > 0) {
if (strcmp(id, "0")) {
url = sonic_getMusicDirectory_link(id);
} else {
url = sonic_gen_url_first_part("getIndexes");
}
puts(url);
LinkTable *linktbl = sonic_url_to_LinkTable(url, XML_parser_index, 0);
free(url);
return linktbl;
@ -360,7 +359,8 @@ static void XMLCALL XML_parser_id3_root(void *data, const char *elem,
}
if (!strcmp("id", attr[i])) {
link->sonic_id = atoi(attr[i+1]);
link->sonic_id = calloc(MAX_FILENAME_LEN + 1, sizeof(char));
strncpy(link->sonic_id, attr[i+1], MAX_FILENAME_LEN);
id_set = 1;
continue;
}
@ -416,10 +416,8 @@ static void XMLCALL XML_parser_id3(void *data, const char *elem,
char *suffix = "";
for (int i = 0; attr[i]; i += 2) {
if (!strcmp("id", attr[i])) {
link->sonic_id = atoi(attr[i+1]);
link->sonic_song_id_str = calloc(MAX_FILENAME_LEN, sizeof(char));
snprintf(link->sonic_song_id_str, MAX_FILENAME_LEN, "%d",
link->sonic_id);
link->sonic_id = calloc(MAX_FILENAME_LEN + 1, sizeof(char));
strncpy(link->sonic_id, attr[i+1], MAX_FILENAME_LEN);
id_set = 1;
continue;
}
@ -490,7 +488,7 @@ static void XMLCALL XML_parser_id3(void *data, const char *elem,
LinkTable_add(linktbl, link);
}
LinkTable *sonic_LinkTable_new_id3(int depth, int id)
LinkTable *sonic_LinkTable_new_id3(int depth, const char *id)
{
char *url;
LinkTable *linktbl = ROOT_LINK_TBL;

View File

@ -16,7 +16,7 @@ void sonic_config_init(const char *server, const char *username,
/**
* \brief Create a new Sonic LinkTable in index mode
*/
LinkTable *sonic_LinkTable_new_index(const int id);
LinkTable *sonic_LinkTable_new_index(const char *id);
/**
* \brief Create a new Sonic LinkTable in ID3 mode
@ -30,6 +30,6 @@ LinkTable *sonic_LinkTable_new_index(const int id);
* \param[in] depth the level of the requested table
* \param[in] id the id of the requested table
*/
LinkTable *sonic_LinkTable_new_id3(int depth, int id);
LinkTable *sonic_LinkTable_new_id3(int depth, const char *id);
#endif