├── .gitignore ├── .gitattributes ├── LICENSE ├── File_Uploader_for_Google_Drive_V_1_217B.ipynb └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 akhi07rx 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /File_Uploader_for_Google_Drive_V_1_217B.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "attachments": {}, 5 | "cell_type": "markdown", 6 | "metadata": { 7 | "colab_type": "text", 8 | "id": "view-in-github" 9 | }, 10 | "source": [ 11 | "\"Open" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "metadata": { 18 | "id": "Cd_zws8zoEIc" 19 | }, 20 | "outputs": [ 21 | { 22 | "ename": "", 23 | "evalue": "", 24 | "output_type": "error", 25 | "traceback": [ 26 | "\u001b[1;31mRunning cells with 'c:\\msys64\\mingw64\\bin\\python.exe' requires the ipykernel package.\n", 27 | "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n", 28 | "\u001b[1;31mCommand: 'c:/msys64/mingw64/bin/python.exe -m pip install ipykernel -U --user --force-reinstall'" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "from tqdm import tqdm\n", 34 | "import requests\n", 35 | "from google.colab import drive\n", 36 | "import os\n", 37 | "from urllib.parse import urlparse, unquote\n", 38 | "import os.path\n", 39 | "import sys\n", 40 | "import time\n", 41 | "\n", 42 | "drive.mount('/content/drive')\n", 43 | "\n", 44 | "# Define the destination folder in Google Drive\n", 45 | "destination_folder = '/content/drive/MyDrive/Downloads/'\n", 46 | "\n", 47 | "# Create the destination folder if it doesn't exist\n", 48 | "if not os.path.exists(destination_folder):\n", 49 | " os.makedirs(destination_folder)\n", 50 | "\n", 51 | "try:\n", 52 | " while True:\n", 53 | " try:\n", 54 | " user_input = input(\"\\n\\nEnter the download link (or 'exit' to quit): \")\n", 55 | " except KeyboardInterrupt:\n", 56 | " print(\"\\nKeyboard interrupt detected. Exiting the program.\")\n", 57 | " break\n", 58 | "\n", 59 | " if user_input.lower() == 'exit':\n", 60 | " break\n", 61 | "\n", 62 | " try:\n", 63 | " response = requests.get(user_input, stream=True)\n", 64 | " response.raise_for_status()\n", 65 | " except requests.exceptions.MissingSchema:\n", 66 | " print(\"You have entered a wrong command. Please enter again.\\n\")\n", 67 | " continue\n", 68 | "\n", 69 | " file_size = int(response.headers.get('content-length', 0))\n", 70 | "\n", 71 | " file_size_mb = file_size / (1024 ** 2)\n", 72 | " file_size_gb = file_size / (1024 ** 3)\n", 73 | "\n", 74 | " file_size_str = f\"{file_size_mb:.2f} MB / {file_size_gb:.2f} GB\"\n", 75 | "\n", 76 | " progress_bar = tqdm(total=file_size, unit='B', unit_scale=True, leave=True)\n", 77 | "\n", 78 | " parsed_url = urlparse(user_input)\n", 79 | " file_name = unquote(os.path.basename(parsed_url.path))\n", 80 | "\n", 81 | " file_path = os.path.join(destination_folder, file_name)\n", 82 | "\n", 83 | " start_time = time.time()\n", 84 | "\n", 85 | " with open(file_path, 'wb') as file:\n", 86 | " for chunk in response.iter_content(chunk_size=8192):\n", 87 | " if chunk:\n", 88 | " file.write(chunk)\n", 89 | " progress_bar.update(len(chunk))\n", 90 | " sys.stdout.flush()\n", 91 | "\n", 92 | " progress_bar.close()\n", 93 | "\n", 94 | " end_time = time.time()\n", 95 | " total_time = end_time - start_time\n", 96 | "\n", 97 | " print()\n", 98 | " print(f\"File name: {file_name}\")\n", 99 | " print(f\"File size: {file_size_str}\")\n", 100 | " print(f\"Total Time: {total_time:.2f} seconds\")\n", 101 | " print(f\"Saved location: {file_path}\")\n", 102 | " print(f\"File '{file_name}' uploaded successfully to '{destination_folder}'.\\n\")\n", 103 | "\n", 104 | "except Exception as e:\n", 105 | " print(f\"An error occurred: {str(e)}\")\n", 106 | " print(\"Exiting the program.\")\n", 107 | "\n", 108 | "print(\"Exiting the program.\")\n" 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "colab": { 114 | "authorship_tag": "ABX9TyP40fcm70N1wi0dmqRlKVWR", 115 | "include_colab_link": true, 116 | "provenance": [] 117 | }, 118 | "kernelspec": { 119 | "display_name": "Python 3", 120 | "name": "python3" 121 | }, 122 | "language_info": { 123 | "name": "python", 124 | "version": "3.8.9" 125 | } 126 | }, 127 | "nbformat": 4, 128 | "nbformat_minor": 0 129 | } 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![image](https://img.shields.io/badge/Python-3.8.9-blue) 3 | ![image](https://img.shields.io/github/v/tag/akhi07rx/File-Uploader-for-Google-Drive) 4 | ![image](https://img.shields.io/github/repo-size/akhi07rx/File-Uploader-for-Google-Drive) 5 | ![image](https://img.shields.io/github/languages/code-size/akhi07rx/File-Uploader-for-Google-Drive) 6 | ![image](https://img.shields.io/badge/Google-Drive-brightgreen) 7 | [![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/akhi07rx/File-Uploader-for-Google-Drive/blob/main/LICENSE) 8 | ![image](https://img.shields.io/badge/Made%20with-JUPYTER-orange) 9 | ![Safe](https://img.shields.io/badge/Stay-Safe-red?logo=data:image/svg%2bxml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNTEwIDUxMCIgaGVpZ2h0PSI1MTIiIHZpZXdCb3g9IjAgMCA1MTAgNTEwIiB3aWR0aD0iNTEyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxnPjxnPjxwYXRoIGQ9Im0xNzQuNjEgMzAwYy0yMC41OCAwLTQwLjU2IDYuOTUtNTYuNjkgMTkuNzJsLTExMC4wOSA4NS43OTd2MTA0LjQ4M2g1My41MjlsNzYuNDcxLTY1aDEyNi44MnYtMTQ1eiIgZmlsbD0iI2ZmZGRjZSIvPjwvZz48cGF0aCBkPSJtNTAyLjE3IDI4NC43MmMwIDguOTUtMy42IDE3Ljg5LTEwLjc4IDI0LjQ2bC0xNDguNTYgMTM1LjgyaC03OC4xOHYtODVoNjguMThsMTE0LjM0LTEwMC4yMWMxMi44Mi0xMS4yMyAzMi4wNi0xMC45MiA0NC41LjczIDcgNi41NSAxMC41IDE1LjM4IDEwLjUgMjQuMnoiIGZpbGw9IiNmZmNjYmQiLz48cGF0aCBkPSJtMzMyLjgzIDM0OS42M3YxMC4zN2gtNjguMTh2LTYwaDE4LjU1YzI3LjQxIDAgNDkuNjMgMjIuMjIgNDkuNjMgNDkuNjN6IiBmaWxsPSIjZmZjY2JkIi8+PHBhdGggZD0ibTM5OS44IDc3LjN2OC4wMWMwIDIwLjY1LTguMDQgNDAuMDctMjIuNjQgNTQuNjdsLTExMi41MSAxMTIuNTF2LTIyNi42NmwzLjE4LTMuMTljMTQuNi0xNC42IDM0LjAyLTIyLjY0IDU0LjY3LTIyLjY0IDQyLjYyIDAgNzcuMyAzNC42OCA3Ny4zIDc3LjN6IiBmaWxsPSIjZDAwMDUwIi8+PHBhdGggZD0ibTI2NC42NSAyNS44M3YyMjYuNjZsLTExMi41MS0xMTIuNTFjLTE0LjYtMTQuNi0yMi42NC0zNC4wMi0yMi42NC01NC42N3YtOC4wMWMwLTQyLjYyIDM0LjY4LTc3LjMgNzcuMy03Ny4zIDIwLjY1IDAgNDAuMDYgOC4wNCA1NC42NiAyMi42NHoiIGZpbGw9IiNmZjRhNGEiLz48cGF0aCBkPSJtMjEyLjgzIDM2MC4xMnYzMGg1MS44MnYtMzB6IiBmaWxsPSIjZmZjY2JkIi8+PHBhdGggZD0ibTI2NC42NSAzNjAuMTJ2MzBoMzYuMTRsMzIuMDQtMzB6IiBmaWxsPSIjZmZiZGE5Ii8+PC9nPjwvc3ZnPg==) 10 | 11 | 12 | 13 | # File Uploader for Google Drive 14 | 15 | 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. 16 | 17 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/akhi07rx/File-Uploader-for-Google-Drive/blob/main/File_Uploader_for_Google_Drive_V_1_217B.ipynb) 18 |
19 | 20 | ## Features 21 | 22 | - Upload files to Google Drive from a download link. 23 | - Real-time progress tracking using a progress bar. 24 | - Preserve the original file name during the upload process. 25 | - Automatically create a destination folder if it doesn't already exist. 26 | - 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". 27 | 28 | - Saving the downloaded file to the specified destination folder in your Google Drive. 29 | 30 | - Displaying information about the downloaded file such as its name, size, and saved location. 31 | 32 | - Option to exit the program: The user can type "exit" to quit the program instead of providing a download link. 33 | 34 | 35 |
36 | 37 | ## Screenshots 38 | 39 | ![image](https://github.com/akhi07rx/File-Uploader-for-Google-Drive/assets/89210430/f215a80d-c5ea-4899-81a5-87a0f7174050) 40 | 41 | ![image](https://github.com/akhi07rx/File-Uploader-for-Google-Drive/assets/89210430/81241900-87c2-4004-ab1e-b131c6aa97f9) 42 | 43 | ![image](https://github.com/akhi07rx/File-Uploader-for-Google-Drive/assets/89210430/005edd65-1c32-4bf5-8e1f-0975391ba592) 44 | 45 | 46 |
47 | 48 | ## Prerequisites 49 | 50 | - Google Colab: This code is designed to be run in a Google Colab notebook. If you don't have one, you can create a new notebook on the [Google Colab](https://colab.research.google.com) platform. 51 | 52 |
53 | 54 | ## How to Use 55 | 56 | 1. Open the Google Colab notebook. 57 | 2. Run each cell in the notebook to execute the code. 58 | 3. When prompted, enter the download link of the file you want to upload. 59 | 4. The code will upload the file to a folder named "Downloads" in your Google Drive. 60 | 5. The progress bar will display the real-time progress of the file upload. 61 | 62 |
63 | 64 |
65 | 66 |
67 | 68 | 69 | 1. Mount Google Drive by running the following code in Google Colab: 70 |
71 | 72 | ```python 73 | from google.colab import drive 74 | 75 | drive.mount('/content/drive') 76 | ``` 77 |
78 | 79 | 2. Run the script and provide the download link when prompted: 80 |
81 | 82 | ```python 83 | Enter the download link: [insert download link here] 84 | ``` 85 | 86 |
87 | 88 | 3. The script will create a folder named downloads in your Google Drive if it doesn't exist already. 89 | 90 | 4. The file will be downloaded from the provided URL and saved to the downloads folder. 91 | 92 |
93 | 94 | Please note that the progress of the download will be displayed using a progress bar provided by the tqdm library. 95 | 96 | Once the download is complete, the script will print a success message indicating the name of the downloaded file and the destination folder. 97 | 98 | Make sure to replace ' [insert download link here] ' with the actual URL from which you want to download the file. 99 | 100 | Feel free to modify the destination folder according to your preference by changing the 'destination_folder' variable. 101 | 102 | 103 |
104 | 105 | ## Customizing the Destination Folder 106 | 107 | By default, the code uploads files to the "downloads" folder in your Google Drive. If you want to upload the files to a different folder, you can modify the `destination_folder` variable in the code to specify the desired folder path. 108 | 109 | ```python 110 | destination_folder = '/content/drive/MyDrive/your-folder/' 111 | ``` 112 | 113 |
114 | 115 | ## Code Components 116 |
117 | 118 | - Mounting Google Drive: This step allows the notebook to access your Google Drive and perform file operations. 119 | 120 | - Parsing the Download Link: The download link provided by the user is parsed using the urlparse function to extract the file name. This ensures that the file is saved with its original name. 121 | 122 | - Downloading the File: The code uses the requests library to download the file from the provided link. The file is downloaded in chunks to enable real-time progress tracking. 123 | 124 | - Uploading the File to Google Drive: The downloaded file is then saved to the specified destination folder in Google Drive. The open function is used to create the file in write binary mode, and the file is written in chunks to ensure efficient upload. 125 | 126 | - Progress Tracking: The tqdm library is used to create a progress bar that updates in real time as the file is being uploaded. The progress bar displays the current progress and the total file size. 127 | 128 |
129 |
130 | 131 | ## Limitations 132 |
133 | 134 | **This code is designed for uploading files to Google Drive from a download link. It may not be suitable for other file upload scenarios. 135 | The upload speed is dependent on your internet connection and the server's capacity from which you are downloading the file.** 136 | 137 |
138 | 139 | ## Acknowledgments 140 | 141 | This code was developed with help from various online resources, including documentation for Python libraries such as `requests` and `tqdm`. We would like to thank all contributors who have shared their knowledge and expertise with us. 142 | 143 | 144 | ## License 145 |
146 | 147 | This project is licensed under the MIT License. 148 | --------------------------------------------------------------------------------