MPD
Welcome, Guest. Please login or register.
September 02, 2010, 10:11:49 am

Login with username, password and session length
Search:     Advanced search
8507 Posts in 1934 Topics by 1469 Members
Latest Member: georgesmith83
* Home Help Search Login Register
+  MPD
|-+  Music Player Daemon
| |-+  Developers' Corner
| | |-+  mpd add absolute path [+patch]
« previous next »
Pages: [1] Print
Author Topic: mpd add absolute path [+patch]  (Read 2438 times)
airbaggins
Newbie
*
Posts: 5


View Profile WWW
« on: May 19, 2005, 08:36:17 am »

Hi.

I have made a little patch on mpd to allow you to give the absolute path of a file to be added. It is a modification to the traverseAllIn function. So it will also affect searches, counts, sums of song times. If the path to be added/searched does not return a true file in the database and starts with the music_dir configuration variable, the traverseAllIn is called once more without the leading music_dir value.

Code:

Index: src/directory.c
===================================================================
--- src/directory.c (revision 3266)
+++ src/directory.c (working copy)
@@ -1174,12 +1174,24 @@
  int (*forEachDir)(FILE *, Directory *, void *),
  void * data) {
  Directory * directory;
+ const char* musicdir;
+ size_t musicdir_len;
 
  if((directory = getDirectory(name))==NULL) {
  Song * song;
  if((song = getSongFromDB(name)) && forEachSong) {
  return forEachSong(fp, song, data);
  }
+ else if(name && (musicdir = getConfigParamValue(CONF_MUSIC_DIR))
+ && (musicdir_len = strlen(musicdir))
+ && musicdir_len<strlen(name)
+ && strncmp(musicdir, name, musicdir_len)==0
+ && (song = getSongFromDB(name+musicdir_len)))
+ {
+ return traverseAllIn(fp, name+musicdir_len,
+ forEachSong, forEachDir, data);
+ }
+        
  commandError(fp, ACK_ERROR_NO_EXIST,
                                 "directory or file not found", NULL);
  return -1;



The reason I wanted it, was that I wanted to implement a drag-and-drop function in the client I have been playing with. I ended up just trying to strip one element of the path off at a time until it worked. I didn't think this was a clean solution:

Code:

                QStringList path=QStringList::split("/",(*i).path());

                while (!path.empty())
                {
                    if (dispatch((QString("add \"")
                                  +path.join("/").replace("\"","\\\"")
                                  +QString("\"\n")).latin1()))
                    {
                        if (fetchOk()) break;
                    }
                    path.pop_front();
                }


The alternative tactic might have been to somehow expose the server's music_dir configuration directive to the client, but this would have required more code and more work on the client side.

I would also have liked to patch mpc so that i could add absolute paths (and use my shell's tab completion from any directory, not just when i'm cd'd into music_dir). However, mpc actually checks to see if the file exists in the database before it even tries to add it.

I'm interested if anyone else has an opinion on this. smiley
Logged
airbaggins
Newbie
*
Posts: 5


View Profile WWW
« Reply #1 on: May 19, 2005, 08:42:18 am »

correction to the previous patch:

Code:

Index: src/directory.c
===================================================================
--- src/directory.c (revision 3266)
+++ src/directory.c (working copy)
@@ -1174,12 +1174,24 @@
  int (*forEachDir)(FILE *, Directory *, void *),
  void * data) {
  Directory * directory;
+ const char* musicdir;
+ size_t musicdir_len;
 
  if((directory = getDirectory(name))==NULL) {
  Song * song;
  if((song = getSongFromDB(name)) && forEachSong) {
  return forEachSong(fp, song, data);
  }
+ else if(name
+ && (musicdir = getConfigParamValue(CONF_MUSIC_DIR))
+ && (musicdir_len = strlen(musicdir))
+ && musicdir_len<strlen(name)
+ && strncmp(musicdir, name, musicdir_len)==0)
+ {
+ return traverseAllIn(fp, name+musicdir_len,
+ forEachSong, forEachDir, data);
+ }
+        
  commandError(fp, ACK_ERROR_NO_EXIST,
                                 "directory or file not found", NULL);
  return -1;
[/code]
Logged
Anonymous
Guest
« Reply #2 on: July 30, 2005, 10:43:19 am »

I think having a command in MPD to return the music_dir would be nice for clients...
Logged
airbaggins
Newbie
*
Posts: 5


View Profile WWW
« Reply #3 on: July 30, 2005, 11:25:43 am »

Yes, this would solve that problem too, however, would it have any security implications?
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!