directory: added directory_lookup_song()
Moved code from db_get_song().
This commit is contained in:
parent
36ec2edacf
commit
7f38c3fc78
@ -110,10 +110,6 @@ db_get_directory(const char *name)
|
|||||||
struct song *
|
struct song *
|
||||||
db_get_song(const char *file)
|
db_get_song(const char *file)
|
||||||
{
|
{
|
||||||
struct song *song;
|
|
||||||
struct directory *directory;
|
|
||||||
char *duplicated, *shortname, *dir;
|
|
||||||
|
|
||||||
assert(file != NULL);
|
assert(file != NULL);
|
||||||
|
|
||||||
g_debug("get song: %s", file);
|
g_debug("get song: %s", file);
|
||||||
@ -121,27 +117,7 @@ db_get_song(const char *file)
|
|||||||
if (music_root == NULL)
|
if (music_root == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
duplicated = g_strdup(file);
|
return directory_lookup_song(music_root, file);
|
||||||
shortname = strrchr(duplicated, '/');
|
|
||||||
if (!shortname) {
|
|
||||||
shortname = duplicated;
|
|
||||||
dir = NULL;
|
|
||||||
} else {
|
|
||||||
*shortname = '\0';
|
|
||||||
++shortname;
|
|
||||||
dir = duplicated;
|
|
||||||
}
|
|
||||||
|
|
||||||
directory = db_get_directory(dir);
|
|
||||||
if (directory != NULL)
|
|
||||||
song = songvec_find(&directory->songs, shortname);
|
|
||||||
else
|
|
||||||
song = NULL;
|
|
||||||
|
|
||||||
assert(song == NULL || song->parent == directory);
|
|
||||||
|
|
||||||
g_free(duplicated);
|
|
||||||
return song;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -114,6 +114,36 @@ directory_lookup_directory(struct directory *directory, const char *uri)
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct song *
|
||||||
|
directory_lookup_song(struct directory *directory, const char *uri)
|
||||||
|
{
|
||||||
|
char *duplicated, *base;
|
||||||
|
struct song *song;
|
||||||
|
|
||||||
|
assert(directory != NULL);
|
||||||
|
assert(uri != NULL);
|
||||||
|
|
||||||
|
duplicated = g_strdup(uri);
|
||||||
|
base = strrchr(duplicated, '/');
|
||||||
|
|
||||||
|
if (base != NULL) {
|
||||||
|
*base++ = 0;
|
||||||
|
directory = directory_lookup_directory(directory, duplicated);
|
||||||
|
if (directory == NULL) {
|
||||||
|
g_free(duplicated);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
base = duplicated;
|
||||||
|
|
||||||
|
song = songvec_find(&directory->songs, base);
|
||||||
|
assert(song == NULL || song->parent == directory);
|
||||||
|
|
||||||
|
g_free(duplicated);
|
||||||
|
return song;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
directory_sort(struct directory *directory)
|
directory_sort(struct directory *directory)
|
||||||
{
|
{
|
||||||
|
@ -108,6 +108,16 @@ directory_prune_empty(struct directory *directory);
|
|||||||
struct directory *
|
struct directory *
|
||||||
directory_lookup_directory(struct directory *directory, const char *uri);
|
directory_lookup_directory(struct directory *directory, const char *uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks up a song by its relative URI.
|
||||||
|
*
|
||||||
|
* @param directory the parent (or grandparent, ...) directory
|
||||||
|
* @param uri the relative URI
|
||||||
|
* @return the song, or NULL if none was found
|
||||||
|
*/
|
||||||
|
struct song *
|
||||||
|
directory_lookup_song(struct directory *directory, const char *uri);
|
||||||
|
|
||||||
void
|
void
|
||||||
directory_sort(struct directory *directory);
|
directory_sort(struct directory *directory);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user