Skip to content

Commit

Permalink
fixed extension error
Browse files Browse the repository at this point in the history
  • Loading branch information
akhi07rx committed May 29, 2023
1 parent dd87c91 commit adb3806
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions File_Uploader_for_Google_Drive_V_1_217B.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit adb3806

Please sign in to comment.