Skip to content

Commit

Permalink
use regex to extract fileId from GDrive links
Browse files Browse the repository at this point in the history
  • Loading branch information
JaskaranSM committed May 4, 2020
1 parent b02990d commit 4d964b6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib.parse as urlparse
from urllib.parse import parse_qs

import re
import json
import requests

Expand Down Expand Up @@ -67,7 +68,11 @@ def speed(self):
@staticmethod
def getIdFromUrl(link: str):
if "folders" in link or "file" in link:
return link.rsplit('/')[-1]
regex = r"https://drive\.google\.com/(drive)?/?u?/\d?/?mobile?/?(file)?(folders)?/?d?/([-\w]+)[?+]?/?(w+)?"
res = re.search(regex,link)
if res is None:
raise IndexError("GDrive ID not found.")
return res.group(4)
parsed = urlparse.urlparse(link)
return parse_qs(parsed.query)['id'][0]

Expand Down

0 comments on commit 4d964b6

Please sign in to comment.