Skip to content

Instantly share code, notes, and snippets.

@Bhupesh-V
Last active September 29, 2021 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bhupesh-V/7ad79f1cf6e007df1be02aeba22ec586 to your computer and use it in GitHub Desktop.
Save Bhupesh-V/7ad79f1cf6e007df1be02aeba22ec586 to your computer and use it in GitHub Desktop.
Extract The Unique Image ID from Google Drive URL

Extract The Unique Image ID from Google Drive URL

Usage

python3 extract.py <drive_image_url>

Demo

The ID as a string, Example :

python3 extract.py https://drive.google.com/file/d/0BwZFRt1DatLLZUt4eF94dFh1ZXJubUthenY3MVZERU5yeV9z/view\?usp\=sharing

Output : 0BwZFRt1DatLLZUt4eF94dFh1ZXJubUthenY3MVZERU5yeV9z

import sys, re
link = str(sys.argv[1])
# extracts the unique ID of the image/file
x = re.search(r"\bd/\w+", link)
print(x.group()[2:])
@NguyenASang
Copy link

I have an id like this:

  • 1agI5lBNv-78XLu-mbf0bsI_teeMlapBu

When it extract:

  • 1agI5lBNv

Can you fix it pls ?

@NguyenASang
Copy link

I fixed that, thanks for your script :3

Here is the new regex:

\bd\/\w+[^/]([A-Za-z0-9-_])*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment