Virtual Folders - Merge Subfolders
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Virtual Folders - Merge Subfolders
Is there anyway to merge duplicate named subfolders when using virtual folders? Consider the following example:
Where those directories look like:
When I browse the merged Television virtual folder, I will ultimately see two "My Show" directories, one with Season 1 the other Season 2. I'm hoping there is some ability for UMS to merge duplicate subfolder names from the root of the virtual folder, so you end up with one "My Show" containing the two sub folders "Season 1" and "Season 2." I've been browsing the code a little bit, and I'm thinking there is no feature currently, but I wanted to check before I go down the path of figuring out how to implement that.
Code: Select all
virtual_folders = Television|/mnt/exthd1/Television,/mnt/exthd2/Television
Code: Select all
/mnt/exthd1/Television
--> My Show/
-- > Season 1/
/mnt/exthd2/Television
--> My Show/
--> Season 2/
Re: Virtual Folders - Merge Subfolders
Alright so I've only started looking at the source today and answered my own question. I managed to modify it to support the feature I was asking about. Perhaps the more seasoned dev's here can take a look at my code? Here's a diff of what I changed:
So what I ended up doing was roughly figure out how the virtual folders work in the Root, and then implement them in subfolders where this is a duplicate collision. I then recreate that MapFile instance for the duplicate, and append its files to it. I ultimately have a dozen external drives, with multiple seasons spread across multiple drives, and this seems to work. It merges them all together nicely. I think I might add a configuration option to enable this feature for I could see situations where people may not desire it. Also, this only works on directories/folders. It does not handle duplicate file names, it will happily display them side by side like before. I think perhaps a feature where yet another folder is created that sets a forced name to help identify which file is which in such a situation.
Code: Select all
diff --git a/src/main/java/net/pms/dlna/MapFile.java b/src/main/java/net/pms/dlna/MapFile.java
index f75cbc4..c07092e 100644
--- a/src/main/java/net/pms/dlna/MapFile.java
+++ b/src/main/java/net/pms/dlna/MapFile.java
@@ -113,7 +113,31 @@ public class MapFile extends DLNAResource {
if (f.isDirectory() && configuration.isHideEmptyFolders() && !FileUtil.isFolderRelevant(f, configuration)) {
LOGGER.debug("Ignoring empty/non-relevant directory: " + f.getName());
} else { // Otherwise add the file
- addChild(new RealFile(f));
+ if (f.isDirectory()) {
+ DLNAResource existingChild = searchByName(f.getName());
+
+ if (existingChild != null) {
+ if (existingChild instanceof MapFile) {
+ // Already exists mapped, so just add to it.
+ List<File> files = ((MapFile)existingChild).getConf().getFiles();
+ files.add(f);
+ } else {
+ // Convert it into a MapFile now that we have duplicates.
+ MapFileConfiguration mfc = new MapFileConfiguration();
+ mfc.setName(f.getName());
+ List<File> files = new ArrayList<File>();
+ files.add(f);
+ mfc.setFiles(files);
+ MapFile mf = new MapFile(mfc);
+
+ addChild(mf);
+ }
+ } else {
+ addChild(new RealFile(f));
+ }
+ } else {
+ addChild(new RealFile(f));
+ }
}
}
}