From adb3806b4a3bde862dbcd1a7296081a2161e583c Mon Sep 17 00:00:00 2001 From: akhi07rx <89210430+akhi07rx@users.noreply.github.com> Date: Mon, 29 May 2023 21:04:45 +0530 Subject: [PATCH] fixed extension error --- File_Uploader_for_Google_Drive_V_1_217B.ipynb | 22 ++++++++++--------- README.md | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/File_Uploader_for_Google_Drive_V_1_217B.ipynb b/File_Uploader_for_Google_Drive_V_1_217B.ipynb index d6f28ed..18b1660 100644 --- a/File_Uploader_for_Google_Drive_V_1_217B.ipynb +++ b/File_Uploader_for_Google_Drive_V_1_217B.ipynb @@ -35,28 +35,35 @@ "from google.colab import drive\n", "import os\n", "from urllib.parse import urlparse, unquote\n", + "import os.path\n", "\n", "drive.mount('/content/drive')\n", "\n", + "# Define the destination folder in Google Drive\n", "destination_folder = '/content/drive/MyDrive/Downloads/'\n", "\n", + "# Create the destination folder if it doesn't exist\n", "if not os.path.exists(destination_folder):\n", " os.makedirs(destination_folder)\n", "\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", + " try:\n", + " response = requests.get(user_input, stream=True)\n", + " response.raise_for_status()\n", + " except requests.exceptions.MissingSchema:\n", + " print(\"You have entered a wrong command. Please enter again.\")\n", + " continue\n", + "\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", + " file_name = unquote(os.path.basename(parsed_url.path))\n", "\n", " file_path = os.path.join(destination_folder, file_name)\n", "\n", @@ -68,12 +75,7 @@ "\n", " progress_bar.close()\n", "\n", - " file_extension = response.headers.get('content-type').split('/')[-1]\n", - "\n", - " new_file_path = os.path.splitext(file_path)[0] + '.' + file_extension\n", - " os.rename(file_path, new_file_path)\n", - "\n", - " print(f\"File '{file_name}' uploaded successfully with its original extension to '{destination_folder}'.\")\n", + " print(f\"File '{file_name}' uploaded successfully to '{destination_folder}'.\")\n", "\n", "print(\"Exiting the program.\")\n" ] diff --git a/README.md b/README.md index 045a07f..b0d08bc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# File Uploader for Google Drive V 1.3 +# File Uploader for Google Drive V 1.3.218B 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.