odeke-em / drive

Google Drive client for the commandline
Apache License 2.0
6.67k stars 425 forks source link

feature: pull and name by id #998

Open philips opened 6 years ago

philips commented 6 years ago

I use drive to backup my Google Photos to an external SD card. This is possible because Google Photos has a feature to copy into Google Drive. Unfortunately due to how cameras name photos I get lots of name collisions doing this which continuously confuses drive when I use it as my backup tool.

However, the filenames don't really matter to me. So, I would like to write a feature that is drive pull -name-by-id which would take the Google Drive ID of each file and append the proper extension. For example, if the directory looked like this:

drive file-id -depth 2 dup-tests bug-reproductions
# drive file-id -depth 2 dup-tests bug-reproductions
FileId                                           Relative Path
"0By5qKlgRJeV2NB1OTlpmSkg8TFU"                   "/IMG_001.jpg"
"0Bz5wQlgRJeP2QkRSenBTaUowU3c"                   "/IMG_002.jpg"
"0Cu5wQlgRJeV2d2VmY29HV217TFE"                   "/IMG_003.jpg"

Then drive pull -name-by-id would create a directory structure like this:

drive pull -name-by-id
ls -la
0By5qKlgRJeV2NB1OTlpmSkg8TFU.jpg
0Bz5wQlgRJeP2QkRSenBTaUowU3c.jpg
0Cu5wQlgRJeV2d2VmY29HV217TFE.jpg

Any concerns if I write up a patch to do this?

odeke-em commented 6 years ago

Hello @philips, thank you for the feature request and welcome to drive!

It's awesome to know that you use drive too! For sure, sounds like a plan, please go for it, this is exciting!

A problem with the current approach is that it is going to affect folders/directories too as it operators over all the items, perhaps just restrictive it to files might suffice but in later iterations I believe this would be a great idea to make more expressive.

Another idea that might help, is to perhaps introduce some simple renaming/rewriting templating as an option and that'll be run for to match each target file and folder. For example:

{{<fieldOfFile>}} {{matchOperator}} {{regex}} :: {{newlyFormedPath}} -> {{createdPath}}

where:

<ext> {{operator}} {{regex}} :: <name>.<ext> -> <fileId>.<ext>

where the detection would apply a matching template per file and then rename e.g

drive pull --rewrite '<ext> ~ jpe?g|png :: <name>.<ext> -> <fileId>.<ext>

For starters though, please feel free to roll out the patch that you suggested, let's get you unblocked and then later on iterate on the idea, what do you think?