#!/usr/bin/env python # -*- coding: utf8 -*- import rtorrent import urlparse import os import sys auto_organize_labels = [ "Movie", "Series", ] #\033[94m def sizeof_fmt(num): # http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size for x in ['B','kiB','MiB','GiB', 'TiB']: if num < 1024.0 and num > -1024.0: return "%3.1f%s" % (num, x) num /= 1024.0 return "%3.1f%s" % (num, 'PB') rt = rtorrent.RTorrent("http://rutorrent:_@_._._.com/rtorrent/rpc") for torrent in rt.get_torrents(): print(torrent) torrent.get_files() torrent.get_base_path() label = urlparse.unquote(torrent.get_custom1()) print("Path: " + torrent.base_path.encode("utf8")) print("Label: " + label.encode("utf8")) o_state = torrent.get_custom4() print("Organization status: " + o_state.encode("utf8")) if torrent.complete and \ label in auto_organize_labels and \ torrent.base_path and \ not o_state: sys.stderr.write(str(torrent) + "\n") sys.stderr.write("Path: " + torrent.base_path.encode("utf8") + "\n") sys.stderr.write("Label: " + label.encode("utf8") + "\n") if os.path.isdir(torrent.base_path): os.chdir(torrent.base_path) res = os.system("organize-media .") else: res = os.system("organize-media {}".format(torrent.base_path)) print(res) if not res: torrent.set_custom4("AUTO-ORGANIZED") if res == 256: torrent.set_custom4("PRE-ORGANIZED") # print(torrent.base_) # for file in torrent.files: # files.append(unicode(os.path.join(torrent.base_path, file.path))) #print(files) # if torrent.ratio >= min: # print "{0:03.1f} {1:03.1f} {2} {3} {4}".format(min, torrent.ratio, sizeof_fmt(torrent.size_bytes), sizeof_fmt(torrent.ratio*torrent.size_bytes), torrent.name) # size+=torrent.size_bytes