In this tutorial, I'll show you How to Create a Google Drive Direct Link Generator with 10 lines of python code. It will never show Virus Scan Warning. And the direct link is also supported by IDM, FDM and any other downloader. So Let's get started!
Understanding
Lets see how does it works! Suppose, I have a file link https://drive.google.com/file/d/FILE ID/view?usp=sharing
. Now, I need to get that FILE ID and put that in this URL https://drive.google.com/uc?id=FILE ID&export=download&confirm=t
. In most of the Gdrive Direct Generator, you will not see confirm=t. Because of that, Google shows Virus Scan Warning. It is very simple to do this program in python. Lets code!
Step 1: Import Modules
In order to get FILE ID from URL, we need the help of re
module. It's a built-in python module. We need to import findall
function from re module.
from re import findall
Step 2: Ask user for file link
We can use input()
function to get input from user.
share_link=input('[*] Enter your file link: ')
Step 3: Get File ID from file link
We will use findall function to find the id with pattern. The pattern is d/FILE ID
. And all characters of File id is alphabet. Anyway, this function takes 2 argument. 1st one is pattern and 2nd one is the string where you want to find. This function has own pattern syntax. Since file id is all alphabet, so we will use \w+
. More Syntax are available here.
data=findall(r"d/\w+", share_link)If the pattern is not found, It will return None value. And if it got None value, we want to warn him to enter a valid link and exit the program. So we used if statement here. If the pattern found, it will return
if not data:
print('Please enter a valid link')
exit()
file_id=data[0].split('/')[1]
['d/FILE ID']
. It's in list format. So to get the file id from the list we need the get the string from list: data[0]
then we need to divide the string with slash(/): data[0].split("/")
It will return ['d', 'FILE ID']
. Now to get the file id, we used data[0].split("/")[1]
. Done!Step 4: Put that File ID in direct link
To put that file id in the string. we will use f"string"
.
direct_link=f"https://drive.google.com/uc?id={file_id}&export=download&confirm=t"
Step 5: Print out the link
print('Direct Link:', direct_link){codeBox}
Full Code
from re import findall
share_link=input('[*] Enter your file link: ')
data=findall(r"d/\w+", share_link)
if not data:
print('Please enter a valid link')
exit()
file_id=data[0].split('/')[1]
direct_link=f"https://drive.google.com/uc?id={file_id}&export=download&confirm=t"
print('Direct Link:', direct_link)
Google Drive
ReplyDeleteGoogle Drive
Google Drive
Google Drive
Google Drive
Google Drive
Google Drive
Google Drive
Google Drive
Google Drive Direct Download Link Generator