Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys
- reload(sys)
- sys.setdefaultencoding("utf-8")
- import os
- from os import path
- # Customizable filebot and script options. Lines starting with # are disbled. Remove # to enable them.
- filebotOptions = [
- '--output media', # where you want to copy/organize you're files i.e: X:/path/to/media
- '--action hardlink', # rename action i.e: move | copy | keeplink | symlink | hardlink
- '--conflict override', # conflict resolution i.e: override | skip | fail
- '--def subtitles=en', # download subtitles i.e: true | false
- '--def artwork=false', # fetch artwork/nfo i.e: true | false
- '--def extractfolder=' + path.join(os.getenv("HOME"), "torrents/extracted"),
- '--def skipExtract=n',
- '--def music=y',
- '--encoding utf8',
- '--def mail=cxxxx.xxxxxxxxx.com:26:[email protected]',
- '--def [email protected]',
- '--def pushbullet=o.pT2jxxxxxxxxxxxxxxxxxxxxxxxx'
- ]
- scriptOptions = {
- 'whitelist': ['nosync'], # only process torrents with this labels. Leave empty [] if you want to process every torrent
- 'growlHostname': '', # address of the machine where you have growl installed
- 'growlPassword': '' # the password you have set in growl preferences after enabling network notifications
- }
- import sys
- import subprocess
- import logging
- from deluge.ui.client import client
- from twisted.internet import reactor
- if sys.argv[1] == 'test':
- logging.basicConfig(level=logging.INFO)
- else:
- logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename=path.abspath(sys.argv[0]).replace('.py', '.log'))
- # get label from deluge
- def on_connect_success(result):
- logging.debug('Connected to Deluge')
- return client.core.get_torrent_status(sys.argv[1], ["label"]).addCallback(on_get_torrent_status)
- def on_connect_fail(result):
- logging.error("Connection failed: %s" % result)
- def on_get_torrent_status(torrent):
- # Don't process with filebot if in label blacklist
- if torrent:
- if torrent["label"] in scriptOptions['whitelist']:
- logging.info("Has blacklist label, nothing to do here.")
- else:
- call_filebot()
- else:
- call_filebot()
- return disconnect()
- # call filebot
- def call_filebot():
- logging.info("Starting filebot")
- cmd = ("filebot -script fn:amc -non-strict --def ut_kind=multi --log all --log-file amc.log --def ut_dir=\"%s/%s\" " % (sys.argv[3], sys.argv[2]) + ' '.join(filebotOptions)).encode(u'utf-8')
- logging.info("Calling:" + cmd)
- envs = os.environ.copy()
- envs["LANG"] = 'en_US.UTF-8'
- envs["PYTHONIOENCODING"] = 'utf-8'
- errorCode = subprocess.call(cmd, shell=True, env=envs)
- if errorCode == 0:
- logging.info("Filebot finished with success")
- return True
- else:
- logging.error("Something happened")
- return False
- # close deluge connection
- def disconnect(result=0):
- logging.debug("Disconnecting from Deluge")
- print "disconnect"
- return client.disconnect().addCallback(stop_reactor)
- def stop_reactor(result=0):
- logging.debug("Stoping reactor")
- print "stop reactor"
- return reactor.stop()
- logging.info("Download complete: %s at %s/%s" % (sys.argv[1], sys.argv[3], sys.argv[2]))
- if sys.argv[1] != 'test' and scriptOptions['whitelist']: # if supplied id is test, just call filebot
- logging.info("Connecting to deluge")
- d = client.connect("localhost",2851, "chris3g", "0xxxxxxxxx")
- d.addCallback(on_connect_success)
- d.addErrback(on_connect_fail)
- reactor.run()
- else:
- call_filebot()
Advertisement
Add Comment
Please, Sign In to add comment