Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shadow-prince/b1419486762815f515212b304bbd3504 to your computer and use it in GitHub Desktop.
Save shadow-prince/b1419486762815f515212b304bbd3504 to your computer and use it in GitHub Desktop.
Torrent_To_Google_Drive_Downloader.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Torrent_To_Google_Drive_Downloader.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"accelerator": "GPU",
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"03d0974b6a694ba2b9cbfda9e6bc7716": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatSliderModel",
"state": {
"_view_name": "FloatSliderView",
"style": "IPY_MODEL_2ab82e7126084c1bae95ef077795c517",
"_dom_classes": [],
"description": "Avatar The Last Airbender Book 1,2,3[Water,Earth,Fire] Complete episods Salman Sk Silver RG 2771.255 kB/s downloading",
"step": 0.01,
"_model_name": "FloatSliderModel",
"orientation": "horizontal",
"max": 100,
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": 99.97869729995728,
"_view_count": null,
"disabled": true,
"_view_module_version": "1.5.0",
"min": 0,
"continuous_update": true,
"readout_format": ".2f",
"description_tooltip": null,
"readout": true,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_c28f8f30f5bd4c6ea27c10fd03313e71"
}
},
"2ab82e7126084c1bae95ef077795c517": {
"model_module": "@jupyter-widgets/controls",
"model_name": "SliderStyleModel",
"state": {
"_view_name": "StyleView",
"handle_color": null,
"_model_name": "SliderStyleModel",
"description_width": "initial",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"c28f8f30f5bd4c6ea27c10fd03313e71": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": "auto",
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/shadow-prince/b1419486762815f515212b304bbd3504/torrent_to_google_drive_downloader.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aQuWDmfm9YOi",
"colab_type": "text"
},
"source": [
"# Torrent To Google Drive Downloader "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qYk44mBwJf6E",
"colab_type": "text"
},
"source": [
"**Important Note:** To get more disk space:\n",
"> Go to Runtime -> Change Runtime and give GPU as the Hardware Accelerator. You will get around 384GB to download any torrent you want."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NaFa7M-e9YOr",
"colab_type": "text"
},
"source": [
"### Install libtorrent and Initialize Session"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "m6hF0emftx4h",
"outputId": "344c6ae9-07db-4def-cfe2-91c4fb3e56c5",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 496
}
},
"source": [
"!apt install python3-libtorrent\n",
"\n",
"import libtorrent as lt\n",
"\n",
"ses = lt.session()\n",
"ses.listen_on(6881, 6891)\n",
"downloads = []"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"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,121 kB/s)\n",
"Selecting previously unselected package libtorrent-rasterbar9.\n",
"(Reading database ... 144429 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) ...\n",
"/sbin/ldconfig.real: /usr/local/lib/python3.6/dist-packages/ideep4py/lib/libmkldnn.so.0 is not a symbolic link\n",
"\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Uf90U73y9YOj",
"colab_type": "text"
},
"source": [
"### Mount Google Drive\n",
"To stream files we need to mount Google Drive."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "oWM9l2fvtuvO",
"outputId": "eff094fa-f592-4291-b328-6b7b681cb8e9",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 125
}
},
"source": [
"from google.colab import drive\n",
"\n",
"drive.mount(\"/content/drive\")"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n",
"\n",
"Enter your authorization code:\n",
"··········\n",
"Mounted at /content/drive\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "R_1XuuIf9YOn",
"colab_type": "text"
},
"source": [
"### Add From Torrent File\n",
"You can run this cell to add more files as many times as you want"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "0et2A6N3udA0",
"colab": {}
},
"source": [
"from google.colab import files\n",
"\n",
"source = files.upload()\n",
"params = {\n",
" \"save_path\": \"/content/drive/My Drive/Torrent\",\n",
" \"ti\": lt.torrent_info(list(source.keys())[0]),\n",
"}\n",
"downloads.append(ses.add_torrent(params))"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "WD-6M6eZyzmj",
"colab_type": "text"
},
"source": [
"### Add From Magnet Link\n",
"You can run this cell to add more files as many times as you want"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Cwi1GMlxy3te",
"colab_type": "code",
"outputId": "d517ecb8-a2a9-40c9-854e-c9dda612f729",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 72
}
},
"source": [
"params = {\"save_path\": \"/content/drive/My Drive/Torrent\"}\n",
"\n",
"while True:\n",
" magnet_link = input(\"Enter Magnet Link Or Type Exit: \")\n",
" if magnet_link.lower() == \"exit\":\n",
" break\n",
" downloads.append(\n",
" lt.add_magnet_uri(ses, magnet_link, params)\n",
" )\n"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"Enter Magnet Link Or Type Exit: magnet:?xt=urn:btih:9d0caf1c62a668412fe4aaf93751c0c30d4b6fbc&tr=udp://tracker.openbittorrent.com:80&tr=udp://tracker.publicbt.com:80&tr=udp://tracker.ccc.de:80\n",
"Enter Magnet Link Or Type Exit: exit\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "m-a1CUP39YOu",
"colab_type": "text"
},
"source": [
"### Start Download\n",
"Source: https://stackoverflow.com/a/5494823/7957705 and [#3 issue](https://github.com/FKLC/Torrent-To-Google-Drive-Downloader/issues/3) which refers to this [stackoverflow question](https://stackoverflow.com/a/6053350/7957705)"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "DBNoYYoSuDBT",
"outputId": "1881961f-87d0-4ee1-b195-2ee00c327943",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34,
"referenced_widgets": [
"03d0974b6a694ba2b9cbfda9e6bc7716",
"2ab82e7126084c1bae95ef077795c517",
"c28f8f30f5bd4c6ea27c10fd03313e71"
]
}
},
"source": [
"import time\n",
"from IPython.display import display\n",
"import ipywidgets as widgets\n",
"\n",
"state_str = [\n",
" \"queued\",\n",
" \"checking\",\n",
" \"downloading metadata\",\n",
" \"downloading\",\n",
" \"finished\",\n",
" \"seeding\",\n",
" \"allocating\",\n",
" \"checking fastresume\",\n",
"]\n",
"\n",
"layout = widgets.Layout(width=\"auto\")\n",
"style = {\"description_width\": \"initial\"}\n",
"download_bars = [\n",
" widgets.FloatSlider(\n",
" step=0.01, disabled=True, layout=layout, style=style\n",
" )\n",
" for _ in downloads\n",
"]\n",
"display(*download_bars)\n",
"\n",
"while downloads:\n",
" next_shift = 0\n",
" for index, download in enumerate(downloads[:]):\n",
" bar = download_bars[index + next_shift]\n",
" if not download.is_seed():\n",
" s = download.status()\n",
"\n",
" bar.description = \" \".join(\n",
" [\n",
" download.name(),\n",
" str(s.download_rate / 1000),\n",
" \"kB/s\",\n",
" state_str[s.state],\n",
" ]\n",
" )\n",
" bar.value = s.progress * 100\n",
" else:\n",
" next_shift -= 1\n",
" ses.remove_torrent(download)\n",
" downloads.remove(download)\n",
" bar.close() # Seems to be not working in Colab (see https://github.com/googlecolab/colabtools/issues/726#issue-486731758)\n",
" download_bars.remove(bar)\n",
" print(download.name(), \"complete\")\n",
" time.sleep(1)\n"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "03d0974b6a694ba2b9cbfda9e6bc7716",
"version_minor": 0,
"version_major": 2
},
"text/plain": [
"FloatSlider(value=0.0, disabled=True, layout=Layout(width='auto'), step=0.01, style=SliderStyle(description_wi…"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "stream",
"text": [
"Avatar The Last Airbender Book 1,2,3[Water,Earth,Fire] Complete episods Salman Sk Silver RG complete\n"
],
"name": "stdout"
}
]
}
]
}
@Thaafis
Copy link

Thaafis commented Sep 27, 2023

is there any way to use other clouds for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment