Create Torrents for each file in directory

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Create Torrents for each file in directory

Baffometo

Baffometo

This is a quick python script for creating torrents for each file in directories and sub directories.

We are using the following tools:

  • Python3
  • Python Module Torf
  • Python module OS
import os
from torf import Torrent

#Enter your directory
rootdir = './test'
for subdir, dirs, files in os.walk(rootdir):
       
    for file in files:
        t = Torrent(path=os.path.join(subdir, file),
                    trackers=['https://tracker1.example.org:1234/announce',
                              'https://tracker2.example.org:5678/announce'],
                    comment='This is a comment')
        t.private = True
        t.generate()
        t.write(os.path.join(subdir, file[:-4]) +'.torrent')    

This quick script basically will import both modules if you do not have them you can install them with pip, the root dir variable is your desired folder location.

Using Os module we will interact for each file in the path specified in rootdit variable.

tracker URL will be your private or public tracker link for announcement.

t.private can be changed to False of True depending on your needs.

t.write will remove the last 4 characters of the string in order to hide the extension and not have any type of wrong format and avoid the file.mp4.torrent and will be file.torrent.

Share Post

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Related Posts

smart-home

Home Assistant and Docker

Nowadays smart homes are becoming pretty common and having multiple devices from different manufacturers are becoming a millenial problem where we dont want to have

Read More »

Wanatux URL Shortener

URL Shortener help for faster tracking of clicks and also can help with backlinks, by creating a short URL the service who created the link

Read More »