From d4fbd2d4e9427d61c04b0c441014efd7df2efb3d Mon Sep 17 00:00:00 2001
From: akhi07rx <89210430+akhi07rx@users.noreply.github.com>
Date: Mon, 29 May 2023 16:17:59 +0530
Subject: [PATCH] Improved
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.
---
File_Uploader_for_Google_Drive_V_1_217B.ipynb | 47 ++++++++++++-------
README.md | 6 +++
2 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/File_Uploader_for_Google_Drive_V_1_217B.ipynb b/File_Uploader_for_Google_Drive_V_1_217B.ipynb
index 559f010..d6f28ed 100644
--- a/File_Uploader_for_Google_Drive_V_1_217B.ipynb
+++ b/File_Uploader_for_Google_Drive_V_1_217B.ipynb
@@ -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"
]
}
],
diff --git a/README.md b/README.md
index 8d21222..4ab41b1 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,7 @@
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.
+
## Features
@@ -9,6 +10,11 @@ This repository contains a Google Colab notebook that allows you to upload files
- 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.