├── .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 | ""
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 | 
3 | 
4 | 
5 | 
6 | 
7 | [](https://github.com/akhi07rx/File-Uploader-for-Google-Drive/blob/main/LICENSE)
8 | 
9 | 
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 | [](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 | 
40 |
41 | 
42 |
43 | 
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 |