Guest User

Untitled

a guest
May 10th, 2017
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. reload(sys)
  5. sys.setdefaultencoding("utf-8")
  6.  
  7. import os
  8. from os import path
  9.  
  10. # Customizable filebot and script options. Lines starting with # are disbled. Remove # to enable them.
  11. filebotOptions = [
  12. '--output media', # where you want to copy/organize you're files i.e: X:/path/to/media
  13. '--action hardlink', # rename action i.e: move | copy | keeplink | symlink | hardlink
  14. '--conflict override', # conflict resolution i.e: override | skip | fail
  15. '--def subtitles=en', # download subtitles i.e: true | false
  16. '--def artwork=false', # fetch artwork/nfo i.e: true | false
  17. '--def extractfolder=' + path.join(os.getenv("HOME"), "torrents/extracted"),
  18. '--def skipExtract=n',
  19. '--def music=y',
  20. '--encoding utf8',
  21. '--def mail=cxxxx.xxxxxxxxx.com:26:[email protected]',
  22. '--def pushbullet=o.pT2jxxxxxxxxxxxxxxxxxxxxxxxx'
  23. ]
  24. scriptOptions = {
  25. 'whitelist': ['nosync'], # only process torrents with this labels. Leave empty [] if you want to process every torrent
  26. 'growlHostname': '', # address of the machine where you have growl installed
  27. 'growlPassword': '' # the password you have set in growl preferences after enabling network notifications
  28. }
  29.  
  30. import sys
  31. import subprocess
  32. import logging
  33. from deluge.ui.client import client
  34. from twisted.internet import reactor
  35.  
  36.  
  37. if sys.argv[1] == 'test':
  38. logging.basicConfig(level=logging.INFO)
  39. else:
  40. logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename=path.abspath(sys.argv[0]).replace('.py', '.log'))
  41.  
  42.  
  43. # get label from deluge
  44. def on_connect_success(result):
  45. logging.debug('Connected to Deluge')
  46. return client.core.get_torrent_status(sys.argv[1], ["label"]).addCallback(on_get_torrent_status)
  47.  
  48. def on_connect_fail(result):
  49. logging.error("Connection failed: %s" % result)
  50.  
  51. def on_get_torrent_status(torrent):
  52. # Don't process with filebot if in label blacklist
  53. if torrent:
  54. if torrent["label"] in scriptOptions['whitelist']:
  55. logging.info("Has blacklist label, nothing to do here.")
  56. else:
  57. call_filebot()
  58. else:
  59. call_filebot()
  60.  
  61. return disconnect()
  62.  
  63.  
  64. # call filebot
  65. def call_filebot():
  66. logging.info("Starting filebot")
  67. 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')
  68. logging.info("Calling:" + cmd)
  69. envs = os.environ.copy()
  70. envs["LANG"] = 'en_US.UTF-8'
  71. envs["PYTHONIOENCODING"] = 'utf-8'
  72. errorCode = subprocess.call(cmd, shell=True, env=envs)
  73.  
  74. if errorCode == 0:
  75. logging.info("Filebot finished with success")
  76. return True
  77. else:
  78. logging.error("Something happened")
  79. return False
  80.  
  81.  
  82. # close deluge connection
  83. def disconnect(result=0):
  84. logging.debug("Disconnecting from Deluge")
  85. print "disconnect"
  86. return client.disconnect().addCallback(stop_reactor)
  87.  
  88.  
  89. def stop_reactor(result=0):
  90. logging.debug("Stoping reactor")
  91. print "stop reactor"
  92. return reactor.stop()
  93.  
  94.  
  95. logging.info("Download complete: %s at %s/%s" % (sys.argv[1], sys.argv[3], sys.argv[2]))
  96.  
  97. if sys.argv[1] != 'test' and scriptOptions['whitelist']: # if supplied id is test, just call filebot
  98. logging.info("Connecting to deluge")
  99. d = client.connect("localhost",2851, "chris3g", "0xxxxxxxxx")
  100. d.addCallback(on_connect_success)
  101. d.addErrback(on_connect_fail)
  102. reactor.run()
  103. else:
  104. call_filebot()
Advertisement
Add Comment
Please, Sign In to add comment