ls: removed hasMusicSuffix() and get_archive_by_suffix()
Determine the suffix manually, and use decoder_plugin_from_suffix() and archive_plugin_from_suffix() instead. This way, song_file_update_inarchive() can be optimized: it does not have to translate its path.
This commit is contained in:
35
src/ls.c
35
src/ls.c
@@ -19,8 +19,6 @@
|
|||||||
#include "ls.h"
|
#include "ls.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "decoder_list.h"
|
|
||||||
#include "archive_list.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -66,36 +64,3 @@ const char *getSuffix(const char *utf8file)
|
|||||||
|
|
||||||
return dot != NULL ? dot + 1 : NULL;
|
return dot != NULL ? dot + 1 : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct decoder_plugin *
|
|
||||||
hasMusicSuffix(const char *utf8file, unsigned int next)
|
|
||||||
{
|
|
||||||
const struct decoder_plugin *ret = NULL;
|
|
||||||
|
|
||||||
const char *s = getSuffix(utf8file);
|
|
||||||
if (s) {
|
|
||||||
ret = decoder_plugin_from_suffix(s, next);
|
|
||||||
} else {
|
|
||||||
g_debug("hasMusicSuffix: The file: %s has no valid suffix\n",
|
|
||||||
utf8file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
|
||||||
const struct archive_plugin *
|
|
||||||
get_archive_by_suffix(const char *utf8file)
|
|
||||||
{
|
|
||||||
const struct archive_plugin *ret = NULL;
|
|
||||||
|
|
||||||
const char *s = getSuffix(utf8file);
|
|
||||||
if (s) {
|
|
||||||
ret = archive_plugin_from_suffix(s);
|
|
||||||
} else {
|
|
||||||
g_debug("get_archive_by_suffix: The file: %s has no valid suffix\n",
|
|
||||||
utf8file);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
6
src/ls.h
6
src/ls.h
@@ -34,12 +34,6 @@ bool uri_has_scheme(const char *uri);
|
|||||||
|
|
||||||
bool isRemoteUrl(const char *url);
|
bool isRemoteUrl(const char *url);
|
||||||
|
|
||||||
const struct decoder_plugin *
|
|
||||||
hasMusicSuffix(const char *utf8file, unsigned int next);
|
|
||||||
|
|
||||||
const struct archive_plugin *
|
|
||||||
get_archive_by_suffix(const char *utf8file);
|
|
||||||
|
|
||||||
void printRemoteUrlHandlers(struct client *client);
|
void printRemoteUrlHandlers(struct client *client);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
47
src/song.c
47
src/song.c
@@ -101,13 +101,23 @@ song_free(struct song *song)
|
|||||||
bool
|
bool
|
||||||
song_file_update(struct song *song)
|
song_file_update(struct song *song)
|
||||||
{
|
{
|
||||||
|
const char *suffix;
|
||||||
char *path_fs;
|
char *path_fs;
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
unsigned int next = 0;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
|
/* check if there's a suffix and a plugin */
|
||||||
|
|
||||||
|
suffix = getSuffix(song->url);
|
||||||
|
if (suffix == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
plugin = decoder_plugin_from_suffix(suffix, false);
|
||||||
|
if (plugin == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
path_fs = map_song_fs(song);
|
path_fs = map_song_fs(song);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return false;
|
return false;
|
||||||
@@ -124,9 +134,13 @@ song_file_update(struct song *song)
|
|||||||
|
|
||||||
song->mtime = st.st_mtime;
|
song->mtime = st.st_mtime;
|
||||||
|
|
||||||
while (song->tag == NULL &&
|
do {
|
||||||
(plugin = hasMusicSuffix(path_fs, next++)))
|
|
||||||
song->tag = plugin->tag_dup(path_fs);
|
song->tag = plugin->tag_dup(path_fs);
|
||||||
|
if (song->tag != NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
plugin = decoder_plugin_from_suffix(suffix, true);
|
||||||
|
} while (plugin != NULL);
|
||||||
|
|
||||||
g_free(path_fs);
|
g_free(path_fs);
|
||||||
return song->tag != NULL;
|
return song->tag != NULL;
|
||||||
@@ -135,29 +149,30 @@ song_file_update(struct song *song)
|
|||||||
bool
|
bool
|
||||||
song_file_update_inarchive(struct song *song)
|
song_file_update_inarchive(struct song *song)
|
||||||
{
|
{
|
||||||
char *path_fs;
|
const char *suffix;
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
path_fs = map_song_fs(song);
|
/* check if there's a suffix and a plugin */
|
||||||
if (path_fs == NULL)
|
|
||||||
|
suffix = getSuffix(song->url);
|
||||||
|
if (suffix == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (song->tag != NULL) {
|
plugin = decoder_plugin_from_suffix(suffix, false);
|
||||||
|
if (plugin == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (song->tag != NULL)
|
||||||
tag_free(song->tag);
|
tag_free(song->tag);
|
||||||
song->tag = NULL;
|
|
||||||
}
|
|
||||||
//accept every file that has music suffix
|
//accept every file that has music suffix
|
||||||
//because we dont support tag reading throught
|
//because we dont support tag reading throught
|
||||||
//input streams
|
//input streams
|
||||||
plugin = hasMusicSuffix(path_fs, 0);
|
song->tag = tag_new();
|
||||||
g_free(path_fs);
|
|
||||||
if (plugin) {
|
return true;
|
||||||
song->tag = tag_new();
|
|
||||||
//tag_add_item(tag, TAG_ITEM_TITLE, f->title);
|
|
||||||
}
|
|
||||||
return song->tag != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
10
src/update.c
10
src/update.c
@@ -24,6 +24,7 @@
|
|||||||
#include "ls.h"
|
#include "ls.h"
|
||||||
#include "mapper.h"
|
#include "mapper.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "decoder_list.h"
|
||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
#include "event_pipe.h"
|
#include "event_pipe.h"
|
||||||
#include "condition.h"
|
#include "condition.h"
|
||||||
@@ -351,7 +352,12 @@ static void
|
|||||||
update_regular_file(struct directory *directory,
|
update_regular_file(struct directory *directory,
|
||||||
const char *name, const struct stat *st)
|
const char *name, const struct stat *st)
|
||||||
{
|
{
|
||||||
if (hasMusicSuffix(name, 0)) {
|
const char *suffix = getSuffix(name);
|
||||||
|
|
||||||
|
if (suffix == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (decoder_plugin_from_suffix(suffix, false) != NULL) {
|
||||||
struct song *song = songvec_find(&directory->songs, name);
|
struct song *song = songvec_find(&directory->songs, name);
|
||||||
|
|
||||||
if (song == NULL) {
|
if (song == NULL) {
|
||||||
@@ -371,7 +377,7 @@ update_regular_file(struct directory *directory,
|
|||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
} else if ((archive = get_archive_by_suffix(name))) {
|
} else if ((archive = archive_plugin_from_suffix(suffix))) {
|
||||||
struct archive_file *archfile;
|
struct archive_file *archfile;
|
||||||
char pathname[MPD_PATH_MAX];
|
char pathname[MPD_PATH_MAX];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user