{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Torrent To Google Drive Downloader v3", "provenance": [], "collapsed_sections": [], "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "aQuWDmfm9YOi" }, "source": [ "# Torrent To Google Drive v3\r\n" ] }, { "cell_type": "markdown", "metadata": { "id": "Uf90U73y9YOj" }, "source": [ "### Mount Google Drive\n", "To stream files we need to mount Google Drive." ] }, { "cell_type": "code", "metadata": { "id": "oWM9l2fvtuvO", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "ab1d3f86-a1de-4aa8-c539-9be5f161eaeb" }, "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Mounted at /content/drive\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "FexiyATtNwTG" }, "source": [ "###Dependency\n", "https://www.libtorrent.org/" ] }, { "cell_type": "code", "metadata": { "id": "m6hF0emftx4h", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "3f5859d7-6c9f-42d0-e160-bcd8c5507ba3" }, "source": [ "!python -m pip install --upgrade pip setuptools wheel\r\n", "!python -m pip install lbry-libtorrent\r\n", "!apt install python3-libtorrent\r\n" ], "execution_count": 2, "outputs": [ { "output_type": "stream", "text": [ "Collecting pip\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB)\n", "\u001b[K |████████████████████████████████| 1.5MB 6.9MB/s \n", "\u001b[?25hRequirement already up-to-date: setuptools in /usr/local/lib/python3.7/dist-packages (54.0.0)\n", "Requirement already up-to-date: wheel in /usr/local/lib/python3.7/dist-packages (0.36.2)\n", "Installing collected packages: pip\n", " Found existing installation: pip 19.3.1\n", " Uninstalling pip-19.3.1:\n", " Successfully uninstalled pip-19.3.1\n", "Successfully installed pip-21.0.1\n", "Collecting lbry-libtorrent\n", " Downloading lbry_libtorrent-1.2.4-py3-none-any.whl (2.4 MB)\n", "\u001b[K |████████████████████████████████| 2.4 MB 6.3 MB/s \n", "\u001b[?25hInstalling collected packages: lbry-libtorrent\n", "Successfully installed lbry-libtorrent-1.2.4\n", "Reading package lists... Done\n", "Building dependency tree \n", "Reading state information... Done\n", "The following additional packages will be installed:\n", " libtorrent-rasterbar9\n", "Suggested packages:\n", " libtorrent-rasterbar-dbg\n", "The following NEW packages will be installed:\n", " libtorrent-rasterbar9 python3-libtorrent\n", "0 upgraded, 2 newly installed, 0 to remove and 29 not upgraded.\n", "Need to get 1,569 kB of archives.\n", "After this operation, 5,718 kB of additional disk space will be used.\n", "Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libtorrent-rasterbar9 amd64 1.1.5-1build1 [1,258 kB]\n", "Get:2 http://archive.ubuntu.com/ubuntu bionic/universe amd64 python3-libtorrent amd64 1.1.5-1build1 [310 kB]\n", "Fetched 1,569 kB in 1s (1,542 kB/s)\n", "Selecting previously unselected package libtorrent-rasterbar9.\n", "(Reading database ... 160975 files and directories currently installed.)\n", "Preparing to unpack .../libtorrent-rasterbar9_1.1.5-1build1_amd64.deb ...\n", "Unpacking libtorrent-rasterbar9 (1.1.5-1build1) ...\n", "Selecting previously unselected package python3-libtorrent.\n", "Preparing to unpack .../python3-libtorrent_1.1.5-1build1_amd64.deb ...\n", "Unpacking python3-libtorrent (1.1.5-1build1) ...\n", "Setting up libtorrent-rasterbar9 (1.1.5-1build1) ...\n", "Setting up python3-libtorrent (1.1.5-1build1) ...\n", "Processing triggers for libc-bin (2.27-3ubuntu1.2) ...\n", "/sbin/ldconfig.real: /usr/local/lib/python3.7/dist-packages/ideep4py/lib/libmkldnn.so.0 is not a symbolic link\n", "\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "tqKcWHZcYRIA" }, "source": [ "### Code to download torrent\n", "Variable **link** stores the link string." ] }, { "cell_type": "code", "metadata": { "id": "b09BxnANO2ep", "colab": { "base_uri": "https://localhost:8080/", "height": 557 }, "outputId": "2788dbea-0c5a-46f6-eb95-1e9c930fb323" }, "source": [ "import libtorrent as lt\n", "import time\n", "import datetime\n", "\n", "ses = lt.session()\n", "ses.listen_on(6881, 6891)\n", "params = {\n", " 'save_path': '/content/drive/Shared drives/Studying Materials'}\n", "link = \"magnet:?xt=urn:btih:b15184c90d71b29fbd37896c8bb00be7e4a14da2&dn=Modern.Family.S05.1080p.WEB-DL.DD5.1.H264-HWD%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2870&tr=udp%3A%2F%2F9.rarbg.to%3A2810\" # PASTE TORRENT/MAGNET LINK HERE\n", "print(link)\n", "\n", "handle = lt.add_magnet_uri(ses, link, params)\n", "ses.start_dht()\n", "\n", "begin = time.time()\n", "print(datetime.datetime.now())\n", "\n", "print ('Downloading Metadata...')\n", "while (not handle.has_metadata()):\n", " time.sleep(1)\n", "print ('Got Metadata, Starting Torrent Download...')\n", "\n", "print(\"Starting\", handle.name())\n", "\n", "while (handle.status().state != lt.torrent_status.seeding):\n", " s = handle.status()\n", " state_str = ['queued', 'checking', 'downloading metadata', \\\n", " 'downloading', 'finished', 'seeding', 'allocating']\n", " print ('%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s ' % \\\n", " (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \\\n", " s.num_peers, state_str[s.state]))\n", " time.sleep(5)\n", "\n", "end = time.time()\n", "print(handle.name(), \"COMPLETE\")\n", "\n", "print(\"Elapsed Time: \",int((end-begin)//60),\"min :\", int((end-begin)%60), \"sec\")\n", "\n", "print(datetime.datetime.now())" ], "execution_count": 5, "outputs": [ { "output_type": "stream", "text": [ "magnet:?xt=urn:btih:b15184c90d71b29fbd37896c8bb00be7e4a14da2&dn=Modern.Family.S05.1080p.WEB-DL.DD5.1.H264-HWD%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2870&tr=udp%3A%2F%2F9.rarbg.to%3A2810\n", "2021-03-03 17:18:05.652481\n", "Downloading Metadata...\n", "Got Metadata, Starting Torrent Download...\n", "Starting Modern.Family.S05.1080p.WEB-DL.DD5.1.H.264-HWD[rartv]\n", "0.00% complete (down: 2.3 kb/s up: 0.1 kB/s peers: 1) downloading \n", "0.00% complete (down: 1.4 kb/s up: 0.1 kB/s peers: 1) downloading \n", "0.00% complete (down: 0.5 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.1 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n", "0.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) downloading \n" ], "name": "stdout" }, { "output_type": "error", "ename": "KeyboardInterrupt", "evalue": "ignored", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0mstate_str\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'queued'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'checking'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'downloading metadata'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'downloading'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'finished'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'seeding'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'allocating'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s '\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprogress\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdownload_rate\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupload_rate\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnum_peers\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstate_str\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 29\u001b[0;31m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 30\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0mend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] } ] } ] }