User info Dynamic subfolders from domain subfolders cloudkicker Apr 12 2012, 6:32 pm Hi Cyan: I'm trying to save files in subfolders that mirror the url path structure. The issue I'm running into is that ASF automatically "flattens" subdirectories by escaping "/" characters to "-" to make the filename "safe". The only way I seem to be able to create subfolders is to explicitly include "\" in the local folder field, but then this makes dealing with urls where the depth of the subdirs is unknown problematic. "Flatting" subdirs (ie. replacing "/" with a "safe" character) or treating subdirs as subfolders (treating "/" as a path separator and creating nested subdirectories for the url subdirs) can both be desirable depending on the circumstances. Downthemall deals with this by letting the user specify the desired behavior in the renaming mask by using either *subdirs* or *flatsubdirs*. It would be great if ASF did something similar. Perhaps an extension to the capture group syntax so that $1d would continue to flatten subdirs like it currently does (to maintain backwards compatibility with existing filters), but a$1dnf (domain capture group 1, nf = no-flatten) would insert a capture group with the "/" characters preserved (or converted to the platform specific directory seperator. I'm not sure if Firefox automatically converts "/" to the platform specific path separator or not, "\" vs "/", but I do know DTA handles this correctly so peeking at the DTA source might help). In case it's not clear what I'm asking, I'll finish with an example. ------------ Say I want to save files from: http://www.example.com/ Here is an example of two different files I might want to save: 1) http://www.example.com/path/to/file/in/subdir/2/1/example.txt 2) http://www.example.com/path/to/file/in/subdir/3/2/1/another_file.txt I want to save the files to: 1) x:\example.com\path\to\file\in\subdir\2\1\example.txt 2) x:\example.com\path\to\file\in\subdir\3\2\1\another_file.txt I'd want to be able to use a regex like: domain: example.com/(.*) local folder: x:\example.com\\$1d Currently, that creates folders of the form "x:\example.com\path-to-file-in-subdir-2-1\" rather than "x:\example.com\path\to\file\in\subdir\2\1\". And as always, thanks for the great addon and congrats on getting "featured"! Post #1 Edit Cyan Apr 13 2012, 10:36 am Hi, I understand what you ask and I'll see what is the best solution. Maybe just adding a list of forbidden characters and letting the user choose the character he wants instead of replacing them all identically. I've checked the path creation code, and it should not replace the forbidden characters with a -, in my script it's set to completely delete them. maybe it's Firefox or the OS which is putting a - I'll have to fix this problem. Thank you for pointing it. Firefox is not replacing the folders delimitation automatically, I need to replace the slash or antislash accordingly in a text string before converting it into a path resource. Firefox is then automatically managing folders and sub-folder once the path is set as a resource. If I convert this string part to a path resource: example\test/download It will create a different folder name depending on the current Operating System. (assuming the forbidden character is replaced with a -) Windows will convert it as example\test-download Linux will convert it as example-test/download I will check DtA! sources to see how it's working with *subdirs* and *flatsubdirs*. Post #2 Edit cloudkicker Apr 13 2012, 10:26 pm I googled around a little and found: http://stackoverflow.com/questions/9170188/is-there-a-standard-cross-platform-way-to-handle-and-store-relative-file-paths Windows *should* treat forward slashes correctly, so converting everything to forward slashes should allow things to work cross platform. That said, if that doesn't seem to be the case from your testing, one option is to create a path resource from only the root/drive specified in the filter, and then take the remainder of the path and pass it to the path resource using the https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsILocalFile interface which seems to deal with paths in a cross platform way. Then you can use the relevant call to create the path from there using https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIFile. I haven't really dabbled with any addon development, but those seemed to be the relevant interfaces for manipulating files in a cross platform way. And yes, I mentioned DTA because they are doing it correctly cross platform, so rather than reinvent the wheel, might be easier to just take a peek at what they are doing and start from there. Good luck Post #3 Edit Cyan Apr 14 2012, 10:21 am Thank you for taking time to search around. It's effectively the XPCOM nsIFile and nsILocalFile which I'm using for cross plateform. I'll check how it's done with dta, but your solution to append subfolder one by one is good too. I'll make some tests. Cyan Post #4 Edit Cyan May 1 2012, 1:50 pm Hi, I did some tests, and I never had the / replaced by - In my tests the slash was fully deleted: This/Domain/Path/ was replaced by ThisDomainPath So I removed the part which deleted the incompatible characters in window and replace it by a converter: / to \ Could you test this version with the test page and let me know if it solves your problem with the / replaced by - ? Version 1.0.5b r117 mod2: http://asf.mangaheart.org/xpi/test/automatic_save_folder-1.0.5bRev0117mod2.xpi test Page: http://asf.mangaheart.org/filters/test_subdomain/test01.php PS: If someone can test it on a Mac, I would be thankful I don't know if I have to replace the / by : or if the Mac is compatible with / as native folder's delimitation. Post #5 Edit cloudkicker May 16 2012, 10:24 am Yup... that did the trick :) Post #6 Edit Cyan May 21 2012, 11:33 am Ok, thanks :) Then I'll make a new beta with these changes. Post #7 Edit / Delete