109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
__author__ = 'dev'
|
|
|
|
from feed.entry_handler import EntryHandler
|
|
import urllib
|
|
import os
|
|
import shutil
|
|
from config.config import Config
|
|
import utilities.file_methods as fm
|
|
import subprocess
|
|
|
|
|
|
class TorrentCliEntryHandler(EntryHandler):
|
|
|
|
Transmission_Settings = {
|
|
"alt-speed-down": 50,
|
|
"alt-speed-enabled": False,
|
|
"alt-speed-time-begin": 540,
|
|
"alt-speed-time-day": 127,
|
|
"alt-speed-time-enabled": False,
|
|
"alt-speed-time-end": 1020,
|
|
"alt-speed-up": 50,
|
|
"bind-address-ipv4": "0.0.0.0",
|
|
"bind-address-ipv6": "::",
|
|
"blocklist-enabled": False,
|
|
"blocklist-url": "http://www.example.com/blocklist",
|
|
"cache-size-mb": 4,
|
|
"dht-enabled": True,
|
|
"download-dir": "tmp",
|
|
"download-queue-enabled": True,
|
|
"download-queue-size": 5,
|
|
"encryption": 2,
|
|
"idle-seeding-limit": 30,
|
|
"idle-seeding-limit-enabled": False,
|
|
"incomplete-dir": "/home/dev/Downloads",
|
|
"incomplete-dir-enabled": False,
|
|
"lpd-enabled": False,
|
|
"message-level": 2,
|
|
"peer-congestion-algorithm": "",
|
|
"peer-id-ttl-hours": 6,
|
|
"peer-limit-global": 200,
|
|
"peer-limit-per-torrent": 50,
|
|
"peer-port": 51413,
|
|
"peer-port-random-high": 65535,
|
|
"peer-port-random-low": 49152,
|
|
"peer-port-random-on-start": False,
|
|
"peer-socket-tos": "default",
|
|
"pex-enabled": True,
|
|
"port-forwarding-enabled": True,
|
|
"preallocation": 1,
|
|
"prefetch-enabled": 1,
|
|
"queue-stalled-enabled": True,
|
|
"queue-stalled-minutes": 30,
|
|
"ratio-limit": 2,
|
|
"ratio-limit-enabled": False,
|
|
"rename-partial-files": True,
|
|
"rpc-authentication-required": False,
|
|
"rpc-bind-address": "0.0.0.0",
|
|
"rpc-enabled": False,
|
|
"rpc-password": "{7788eba16f883ebbda75ba83697c6db606a86ad1aMLMCwny",
|
|
"rpc-port": 9091,
|
|
"rpc-url": "/transmission/",
|
|
"rpc-username": "",
|
|
"rpc-whitelist": "127.0.0.1",
|
|
"rpc-whitelist-enabled": True,
|
|
"scrape-paused-torrents-enabled": True,
|
|
"script-torrent-done-enabled": False,
|
|
"script-torrent-done-filename": "",
|
|
"seed-queue-enabled": False,
|
|
"seed-queue-size": 10,
|
|
"speed-limit-down": 100,
|
|
"speed-limit-down-enabled": False,
|
|
"speed-limit-up": 100,
|
|
"speed-limit-up-enabled": False,
|
|
"start-added-torrents": True,
|
|
"trash-original-torrent-files": False,
|
|
"umask": 18,
|
|
"upload-slots-per-torrent": 14,
|
|
"utp-enabled": True
|
|
}
|
|
SettingFile = Config["TorrentStorageFolder"] + "/settings.json"
|
|
|
|
@staticmethod
|
|
def download_torrent(torrent_url):
|
|
torrent_folder = Config["TorrentStorageFolder"]
|
|
if not os.path.exists(torrent_folder):
|
|
TorrentCliEntryHandler.init_torrent_folder(torrent_folder)
|
|
file_name = torrent_folder + "/" + os.path.basename(torrent_url)
|
|
|
|
if os.path.exists(torrent_url):
|
|
shutil.copy2(torrent_url, file_name)
|
|
|
|
else:
|
|
with urllib.request.urlopen(torrent_url) as response, open(file_name, 'wb') as out_file:
|
|
data = response.read()
|
|
out_file.write(data)
|
|
|
|
@staticmethod
|
|
def init_torrent_folder(torrent_folder):
|
|
if os.path.exists(torrent_folder):
|
|
return
|
|
os.mkdir(torrent_folder)
|
|
TorrentCliEntryHandler.Transmission_Settings["incomplete-dir"] = torrent_folder + "/Downloads"
|
|
TorrentCliEntryHandler.Transmission_Settings["download-dir"] = torrent_folder + "/tmp"
|
|
fm.write_json_file(TorrentCliEntryHandler.SettingFile, TorrentCliEntryHandler.Transmission_Settings)
|
|
|
|
@staticmethod
|
|
def start_torrent(torrent_url, torrent_folder, download_folder):
|
|
pass
|
|
#tc = subprocess.call("transmission-cli -er -g" + torrent_folder + " -w " + download_folder + " " + torrent_url, shell=True) |