Skip to content

Commit

Permalink
Improved
Browse files Browse the repository at this point in the history
Ability to insert multiple download links: The code now allows the user to enter multiple download links one after the other until they choose to exit the program by typing "exit".

Option to exit the program: The user can type "exit" to quit the program instead of providing a download link.

Improved user interface: A line break is added before the "Enter the download link" prompt, creating visual separation between each prompt and making it easier to read.
  • Loading branch information
akhi07rx committed May 29, 2023
1 parent e0adc16 commit d4fbd2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
47 changes: 29 additions & 18 deletions File_Uploader_for_Google_Drive_V_1_217B.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,44 @@
"\n",
"drive.mount('/content/drive')\n",
"\n",
"download_link = input(\"Enter the download link: \")\n",
"\n",
"destination_folder = '/content/drive/MyDrive/downloads/'\n",
"destination_folder = '/content/drive/MyDrive/Downloads/'\n",
"\n",
"if not os.path.exists(destination_folder):\n",
" os.makedirs(destination_folder)\n",
"\n",
"response = requests.head(download_link, allow_redirects=True)\n",
"file_size = int(response.headers.get('content-length', 0))\n",
"progress_bar = tqdm(total=file_size, unit='B', unit_scale=True)\n",
"while True:\n",
" print(\"\\n\")\n",
" user_input = input(\"Enter the download link (or 'exit' to quit): \")\n",
"\n",
" if user_input.lower() == 'exit':\n",
" break\n",
"\n",
" response = requests.get(user_input, stream=True)\n",
" response.raise_for_status()\n",
" file_size = int(response.headers.get('content-length', 0))\n",
" progress_bar = tqdm(total=file_size, unit='B', unit_scale=True)\n",
"\n",
" parsed_url = urlparse(user_input)\n",
" file_name = unquote(parsed_url.path.split('/')[-1])\n",
"\n",
" file_path = os.path.join(destination_folder, file_name)\n",
"\n",
" with open(file_path, 'wb') as file:\n",
" for chunk in response.iter_content(chunk_size=8192):\n",
" if chunk:\n",
" file.write(chunk)\n",
" progress_bar.update(len(chunk))\n",
"\n",
"parsed_url = urlparse(download_link)\n",
"file_name = unquote(parsed_url.path.split('/')[-1])\n",
" progress_bar.close()\n",
"\n",
"response = requests.get(download_link, stream=True)\n",
"response.raise_for_status()\n",
" file_extension = response.headers.get('content-type').split('/')[-1]\n",
"\n",
"file_path = os.path.join(destination_folder, file_name)\n",
"with open(file_path, 'wb') as file:\n",
" for chunk in response.iter_content(chunk_size=8192):\n",
" if chunk:\n",
" file.write(chunk)\n",
" progress_bar.update(len(chunk))\n",
" new_file_path = os.path.splitext(file_path)[0] + '.' + file_extension\n",
" os.rename(file_path, new_file_path)\n",
"\n",
"progress_bar.close()\n",
" print(f\"File '{file_name}' uploaded successfully with its original extension to '{destination_folder}'.\")\n",
"\n",
"print(f\"File '{file_name}' uploaded successfully to '{destination_folder}'.\")\n"
"print(\"Exiting the program.\")\n"
]
}
],
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

This repository contains a Google Colab notebook that allows you to upload files from a given download link to your Google Drive with real-time progress tracking. The code is written in Python and utilizes the `requests` library for file download and the `tqdm` library for progress tracking.

<br />

## Features

- Upload files to Google Drive from a download link.
- Real-time progress tracking using a progress bar.
- Preserve the original file name during the upload process.
- Automatically create a destination folder if it doesn't already exist.
- Ability to insert multiple download links: The code now allows the user to enter multiple download links one after the other until they choose to exit the program by typing "exit".

- Option to exit the program: The user can type "exit" to quit the program instead of providing a download link.

- Improved user interface: A line break is added before the "Enter the download link" prompt, creating visual separation between each prompt and making it easier to read.

<br />

Expand Down

0 comments on commit d4fbd2d

Please sign in to comment.