cyanomiko / dcnnt-py

UI-less tool to connect Android phone with desktop
MIT License
181 stars 7 forks source link

Request: External shared_dirs file #17

Open xxxserxxx opened 2 years ago

xxxserxxx commented 2 years ago

Users can do basic filtering with glob, and filter shared directories with shared_dirs. The ask is to add an external and simplified filter file.

The use case is syncing part of a large music library. There are some hundreds of GB of music, and many duplicates (sources in FLAC, but converted to MP3 for the phone). There's a lot of music I don't want to sync: holiday music, etc. I do not want to have to re-arrange the entire library just for the dcnnt service, and I don't want to duplicate (copy) files into other directories for dccnt.

An ideal solution would be a file of paths, one per line; each line would be converted (internally) to a shared_files item. Example:

# Comment
/media/Audio/Beethoven
/media/Audio/Heilung
/media/Audio/BrittneySpears

with this config:

{
  "device": null,
  "download_directory": "$HOME/Downloads/dcnnt",
  "includes": [ "$HOME/dccnt_shared.txt" ],
  "shared_dirs": [  ]
}

would be internally be converted to this:

[
  {
      "path": "/media/Audio/Beethoven",
      "glob": "*",
      "name": "Beethoven",
      "deep": 100
  },
  {
      "path": "/media/Audio/Heilung",
      "glob": "*",
      "name": "Heilung",
      "deep": 100
  },
  {
      "path": "/media/Audio/BrittneySpears",
      "glob": "*",
      "name": "BrittneySpears",
      "deep": 100
  }
]

The shared_dirs would be merged -- includes appended to whatever is in the config. The external file would be refreshed when it changes, or on sync, or whatever mechanism dccnt currently uses to track FS changes.

This would add value in several ways:

  1. Modifying an external file would be more simple and less error-prone, and easier for users
  2. Lines-of-paths is the most common way to enumerate paths
  3. It's easily scriptable, lending itself well to the output of common Linux tooling
  4. In this particular case, the simple file structure is also a valid defacto-standard Playlist format

Comments would be "nice to have"; Playlists allow comments, but they're also easily filtered out with grep so if the feature didn't include them it'd be OK.

xxxserxxx commented 2 years ago

I've been playing with share_dirs_external and share_dirs. share_dirs_external is pretty close to what I am looking for, although it doesn't appear to work for me. I would expect these to be functionally identical:

file.conf.json

{
  "download_directory": "$HOME/Downloads/dcnnt",
  "shared_dirs": [
    {
      "deep": 3,
      "name": "38 Special",
      "path": "/mnt/audio/38_Special",
      "glob": "*.mp3"
  ]
}

and

$HOME/playlist.txt

/mnt/audio/38_Special/05_-_Caught_Up_In_You.mp3

file.conf.json

{
  "download_directory": "$HOME/Downloads/dcnnt",
  "shared_dirs": [],
  "shared_dirs_external": [
    {
      "deep": 3,
      "glob": "*.mp3",
      "path": "$HOME/playlist.txt"
    }
  ]
}

The first works for me; the second does not.

Would you be able to update the documentation to explain the glob rules? I think it's basic bash glob, so *, ?, and [] work, but extglobs don't -- so you can't, for example, have a glob that says *.{mp3,ogg,opus} to include some audio formats while excluding (e.g.) FLAC and WAV files. Or *.{jpg,jpeg} to get jpegs while excluding PNGs and GIFs.

I think if I can figure out how to get shared_dirs_external to work, then this ticket can be closed as unnecessary.