Create Google Drive Direct Link Generator in Python (No Virus Warning)


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!

{tocify}

Understanding

Lets see how does it works! Suppose, I have a file link https://drive.google.com/file/d/FILE ID/view?usp=sharing{code}. 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{code}. 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{code} module. It's a built-in python module. We need to import findall{code} function from re module. 

from re import findall{codeBox}

Step 2: Ask user for file link

We can use input(){code} function to get input from user.

share_link=input('[*] Enter your file link: '){codeBox}

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{code}. 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+{code}. More Syntax are available here

data=findall(r"d/\w+", share_link)
if not data:
    print('Please enter a valid link')
    exit()
file_id=data[0].split('/')[1]{codeBox}
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 ['d/FILE ID']{code}. It's in list format. So to get the file id from the list we need the get the string from list: data[0]{code} then we need to divide the string with slash(/): data[0].split("/"){code} It will return ['d', 'FILE ID']{code}. Now to get the file id, we used data[0].split("/")[1]{code}. Done!

Step 4: Put that File ID in direct link

To put that file id in the string. we will use f"string"{code}

direct_link=f"https://drive.google.com/uc?id={file_id}&export=download&confirm=t"{codeBox}

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){codeBox}

Screenshots



Post a Comment

Previous Post Next Post