here's my colab notebook:
from google.colab import drive
drive.mount('/content/drive')
!apt-get install python3-libtorrent
!pip install lbry-libtorrent
!apt-get install ffmpeg
import libtorrent as lt
import os
import glob
import shutil
import subprocess
params = {
'save_path': '/content/',
'storage_mode': lt.storage_mode_t(2),
}
link = 'magnet_link'
ses = lt.session()
handle = lt.add_magnet_uri(ses, link, params)
import time
print('Downloading metadata...')
while not handle.has_metadata():
time.sleep(1)
print('Starting download...')
while handle.status().state != lt.torrent_status.seeding:
s = handle.status()
state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating']
print('%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % (
s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]))
time.sleep(5)
# Download Complete
# --- Here the Colab finished and won't proceed, as if this is the end of the code. ---
# Convert videos to 360p using FFmpeg
if not os.path.exists('/content/converted'):
os.makedirs('/content/converted')
for file in glob.glob('/content/*'):
if file.endswith('.mkv') or file.endswith('.avi') or file.endswith('.mov') or file.endswith('.wmv'):
output_file = '/content/converted/' + os.path.splitext(os.path.basename(file))[0] + '.mp4'
subprocess.call(['ffmpeg', '-i', file, '-vf', 'scale=640:360', '-threads', '0', output_file])
# Move converted files to Google Drive
if not os.path.exists('/content/drive/My Drive/Torrents'):
os.makedirs('/content/drive/My Drive/Torrents')
for file in glob.glob('/content/converted/*'):
shutil.move(file, '/content/drive/My Drive/Torrents')
The code works until it is finished downloading the files, and colab gives that green check just like when the processes are finished.
if I put print("Hello, world!") at the end of the code, colab will jump there after downloading and print Hello, world!
I tried giving it another thing to finish and it did. it just ignoress that part of the code.
I expect colab to proceed with the converting after downloading.