Closed porg closed 1 year ago
$ get_dropbox_link.py ~/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4
https://www.dropbox.com/s/•••/Notion-Hide-a-property-via-drag-n-drop.mp4?dl=0
$ echo 'https://www.dropbox.com/s/•••/Notion-Hide-a-property-via-drag-n-drop.mp4?dl=0' | sed 's|?dl=0|?raw=1|g'
https://www.dropbox.com/s/•••/Notion-Hide-a-property-via-drag-n-drop.mp4?raw=1
$ get_dropbox_link.py ~/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4 | sed 's|?dl=0|?raw=1|g'
https://www.dropbox.com/s/•••/Notion-Hide-a-property-via-drag-n-drop.mp4?raw=1
get_dropbox_link.py ~/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4 | less
Less opens and shows the result.
In case of submitting multiple filepath arguments less shows multiple lines just fine.
aliases.zsh
as I use oh-my-zsh )aliases.zsh contains:
alias dropboxlink="get_dropbox_link.py \$1 | sed 's|?dl=0|?raw=1|g'"
Logging in afresh, running command alias:
$ dropboxlink ~/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4
sed: RE error: illegal byte sequence
usage: get_dropbox_link.py [-h] [--verbose] paths [paths ...]
get_dropbox_link.py: error: the following arguments are required: paths
aliases.zsh contains:
alias dropboxlink="get_dropbox_link.py \$1 | less"
Logging in afresh, running command alias:
$ dropboxlink ~/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4
"/Users/•••/Dropbox/Public/Notion-Hide-a-property-via-drag-n-drop.mp4" may be a binary file. See it anyway? usage: get_dropbox_link.py [-h] [--verbose] paths [paths ...]
get_dropbox_link.py: error: the following arguments are required: paths
# Pipe is stuck. Aborting with ⌃-C.
sed's complaint "illegal byte sequence" and your python script's complaint "may be a binary file" indicated that not the argument is piped through, but rather the file.
Thanks for opening the issue. Here is the Dropbox docs page which discusses raw
vs dl
. It's not clear to me that dl=1
would be a better default than dl=0
, but it should be easy enough to add a configuration option to allow for either in post-processing.
As for replacing %20
with +
, I'm wary of making that change since it could corrupt some URLs. Does it successfully match URLs with literal plus characters in them, for example? Can you find any Dropbox documentation saying how they handle encoding spaces in shared URLs?
Hi, glad to hear back from you that soon!
%20
being the only official encoding for the space character, but many webserver/website configs supporting +
as a de facto standard too.I've provided arguments for both of these features now. Give them a try and let me know if they work for you.
To answer my question from before: a URL with a plus in the filename is rendered as file%2Bname.txt
. So plus characters sent in the URL are always turned into spaces, and it's not ambiguous. So it's maybe possible for this to be the default, but I don't plan to change it. Seems safest to just provide the URLs as directly from Dropbox as possible.
Thanks for you initiative!
Tested the current version:
In general the ideal synopsis for CLI apps is arguments first and file(s) last, because if you repeat a previous command (with arrow up) the cursor is at the end of the line, and then you can edit at the end, and the filepath(s) is what you will most likely want to vary on the next invocation.
✅ --query raw=1
worked fine
$ get_dropbox_link.py ~/Dropbox/Public/Click\ and\ lift\ finger\ 1a\ works.mp4 --query raw=1
https://www.dropbox.com/s/xxx/Click%20and%20lift%20finger%201a%20works.mp4?raw=1
❌ --plus-for-space
fails
get_dropbox_link.py ~/Dropbox/Public/Click\ and\ lift\ finger\ 1a\ works.mp4 --plus-for-space
ERROR:root:'PosixPath' object has no attribute 'with_stem'
Using the customization arguments in the Automator script is real easy too:
$HOME/bin/get_dropbox_link.py "$@"
"$@"
:$HOME/bin/get_dropbox_link.py "$@" --query raw=1
Note: When my proposal °1 from the previous post gets implemented, to put the file aruments at the last position, then simply put the formatting arguments before the "$@"
.
Actually, it looks like the long option arguments (with --
) would be best passed before the files. Certainly, they should work when passed before the file paths. I can change the README, but I don't believe a code change is necessary. Can you please confirm it's working this way for you now?
Ad 1) Good news! Tested, and indeed argument --query raw=1
worked fine before and after the files.
Ad 3) --plus-for-space
though fails both when inserted before or after the filepath(s), and per each supplied file returns:
ERROR:root:'PosixPath' object has no attribute 'with_stem'
Which version of Python are you running? It looks like with_stem
is new in 3.9.
I can add a warning about the required Python version to the README.
$ which python
/usr/bin/python
$ python --version
Python 2.7.16
$ which python3
/usr/local/bin/python3
$ python3 --version
Python 3.11.2
#!/usr/bin/python3
shebang, so I guess it should run with python3.xI've revised the feature to account for the new Dropbox shared link style.
Sadly I get a bug, created followup issue:
Thanks for the report. This has been resolved now.
Thanks for offering this script!
Finally being able to assign a keyboard shortcut to the "Copy Dropbox Link" contextual menu item in Finder is a huge time saver.
Feature Ideas
Realized the potential for other fully automated postprocessing features which for now I do:
manually — Change the default
?dl=0
argument to?raw=1
assisted — Find/replace URL encoded space characters in TextEdit from the default ugly
%20
to the better human readable+
Where must I change the script o achieve these two customizations?