Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FKLC
GitHub Repository: FKLC/Torrent-To-Google-Drive-Downloader
Path: blob/master/Torrent_To_Google_Drive_Downloader.ipynb
124 views
Kernel: Python 3

Open In Colab

Torrent To Google Drive Downloader

Important Note: To get more disk space:

Go to Runtime -> Change Runtime and give GPU as the Hardware Accelerator. You will get around 384GB to download any torrent you want.

Install libtorrent and Initialize Session

!apt install python3-libtorrent import libtorrent as lt ses = lt.session() ses.listen_on(6881, 6891) downloads = []

Mount Google Drive

To stream files we need to mount Google Drive.

from google.colab import drive drive.mount("/content/drive")

Add From Torrent File

You can run this cell to add more files as many times as you want

from google.colab import files source = files.upload() params = { "save_path": "/content/drive/My Drive/Torrent", "ti": lt.torrent_info(list(source.keys())[0]), } downloads.append(ses.add_torrent(params))

You can run this cell to add more files as many times as you want

params = {"save_path": "/content/drive/My Drive/Torrent"} while True: magnet_link = input("Enter Magnet Link Or Type Exit: ") if magnet_link.lower() == "exit": break downloads.append( lt.add_magnet_uri(ses, magnet_link, params) )

Start Download

Source: https://stackoverflow.com/a/5494823/7957705 and #3 issue which refers to this stackoverflow question

import time from IPython.display import display import ipywidgets as widgets state_str = [ "queued", "checking", "downloading metadata", "downloading", "finished", "seeding", "allocating", "checking fastresume", ] layout = widgets.Layout(width="auto") style = {"description_width": "initial"} download_bars = [ widgets.FloatSlider( step=0.01, disabled=True, layout=layout, style=style ) for _ in downloads ] display(*download_bars) while downloads: next_shift = 0 for index, download in enumerate(downloads[:]): bar = download_bars[index + next_shift] if not download.is_seed(): s = download.status() bar.description = " ".join( [ download.name(), str(s.download_rate / 1000), "kB/s", state_str[s.state], ] ) bar.value = s.progress * 100 else: next_shift -= 1 ses.remove_torrent(download) downloads.remove(download) bar.close() # Seems to be not working in Colab (see https://github.com/googlecolab/colabtools/issues/726#issue-486731758) download_bars.remove(bar) print(download.name(), "complete") time.sleep(1)