Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Fixes #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
8 changes: 3 additions & 5 deletions config.sample.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ appendLabel = false
deleteFinished = false
# If you want rProcess to ignore torrents with certain labels, define them like: ignoreLabel = movie (separate with | for several labels, eg unwanted|dontwant).
# Needs to have at least one pre-defined value, so don't edit if you don't want to use it
ignoreLabel =
ignoreLabel = dontwant
# If you wish to log debug messages? (true/false)
debug = false

Expand All @@ -37,7 +37,6 @@ label = movies
username =
# Your Couchpotato password (leave blank if you don't use one)
password =

# Using SSL? (true/false)
ssl = false
# Host is the adress to your Couchpotato web ui
Expand All @@ -47,7 +46,7 @@ port = 5050
# Base url alteration (leave blank if you don't use one)
base_url =
# API key for your Couchpotato install
apikey =
apikey =

[Sickbeard]
# True/false depending on if you want to run Sickbeard post-process after rProcess is done
Expand All @@ -57,8 +56,7 @@ label = tv
# Your Sickbeard username (leave blank if you don't use one)
username =
# Your Sickbeard password (leave blank if you don't use one)
password =

password =
# Using SSL? (true/false)
ssl = false
# Host is the address to your Sickbeard web ui
Expand Down
69 changes: 38 additions & 31 deletions rProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import os
import sys
import re
import time
import shutil
import logging
import traceback
Expand Down Expand Up @@ -127,19 +127,18 @@ def process_media(self, post_proc, destination):
host = config.get("CouchPotato", "host") if config.get("CouchPotato", "host") else 'localhost'
port = config.get("CouchPotato", "port") if config.get("CouchPotato", "port") else 5050
base_url = config.get("CouchPotato", "base_url") if config.get("CouchPotato", "base_url") else ''
api_key = config.get("CouchPotato", "apikey")
api_key = config.get("CouchPotato", "apikey") if config.get("CouchPotato", "apikey") else False
api_call = "/renamer.scan/?async=1&movie_folder="

user = config.get("CouchPotato", "username") if config.get("CouchPotato", "username") else ''
password = config.get("CouchPotato", "password") if config.get("CouchPotato", "username") else ''

elif post_proc == "sickbeard":
ssl = config.getboolean("Sickbeard", "ssl") if config.getboolean("Sickbeard", "ssl") else False
host = config.get("Sickbeard", "host") if config.get("Sickbeard", "port") else 'localhost'
host = config.get("Sickbeard", "host") if config.get("Sickbeard", "host") else 'localhost'
port = config.get("Sickbeard", "port") if config.get("Sickbeard", "port") else 8081
base_url = config.get("Sickbeard", "base_url") if config.get("Sickbeard", "baseURL") else ''
api_key = config.get("Sickbeard", "apikey")
api_call = "/home/postprocess/processEpisode?quiet=1&dir="
base_url = config.get("Sickbeard", "base_url") if config.get("Sickbeard", "base_url") else ''
api_call = "home/postprocess/processEpisode?quiet=1&dir="

user = config.get("Sickbeard", "username") if config.get("Sickbeard", "username") else ''
password = config.get("Sickbeard", "password") if config.get("Sickbeard", "password") else ''
Expand All @@ -164,22 +163,33 @@ def process_media(self, post_proc, destination):
else:
protocol = "http://"

if api_key:
url = protocol + host + port + base_url + "api/" + api_key + api_call + destination
else:
url = protocol + host + port + base_url + api_call + destination
if post_proc == "couchpotato":
if api_key:
url = protocol + host + port + base_url + "api/" + api_key + api_call + destination
logger.debug(loggerHeader + "URL: %s", url)
r = requests.get(url)
logger.info(loggerHeader + "Postprocessing with %s :: Opening URL: %s", post_proc, url)
else:
url = protocol + host + port + base_url + api_call + destination
logger.debug(loggerHeader + "URL: %s", url)
r = requests.get(url, auth=(user, password))
logger.info(loggerHeader + "Postprocessing with %s :: Opening URL: %s", post_proc, url)

try:
elif post_proc == "sickbeard":
url = protocol + host + port + base_url + api_call + destination
logger.debug(loggerHeader + "URL: %s", url)
r = requests.get(url, auth=(user, password))
logger.debug(loggerHeader + "Postprocessing with %s :: Opening URL: %s", post_proc, url)
except Exception, e:
logger.error(loggerHeader + "Tried postprocessing with %s :: Unable to open URL: %s %s %s",
(post_proc, url, e, traceback.format_exc()))
raise
logger.info(loggerHeader + "Postprocessing with %s :: Opening URL: %s", post_proc, url)

else:
return

# Sleep for 30 seconds to allow post-processors to complete.
# This is a dirty hackneyed thing to do, and needs better treatment.
time.sleep(30)
text = r.text
logger.debug(loggerHeader + "Requests for PostProcessing returned :: %s" + text)


def main(self, torrent_hash):
output_dir = config.get("General", "outputDirectory")
Expand All @@ -188,11 +198,10 @@ def main(self, torrent_hash):
append_label = config.getboolean("General", "appendLabel")
ignore_label = (config.get("General", "ignoreLabel")).split('|') if (config.get("General", "ignoreLabel")) else ''
client_name = config.get("Client", "client")

couchpotato = config.getboolean("CouchPotato", "active")
couch_label = config.get("CouchPotato", "label")
sickbeard = config.getboolean("Sickbeard", "active")
sick_label = config.get("Sickbeard", "label")
cp_active = config.getboolean("CouchPotato", "active")
cp_label = config.get("CouchPotato", "label")
sb_active = config.getboolean("Sickbeard", "active")
sb_label = config.get("Sickbeard", "label")

# TODO: fix this.. ugly!
if client_name == 'rtorrent':
Expand Down Expand Up @@ -224,7 +233,7 @@ def main(self, torrent_hash):
logger.debug(loggerHeader + "Hash: %s", torrent_info['hash'])
if torrent_info['label']:
logger.info(loggerHeader + "Torrent Label: %s", torrent_info['label'])

if any(word in torrent_info['label'] for word in ignore_label):
logger.error(loggerHeader + "Exiting: Found unwanted label: %s", torrent_info['label'])
sys.exit(-1)
Expand All @@ -239,7 +248,7 @@ def main(self, torrent_hash):
# In some cases uTorrent will do a file lock, to circumvent (and allow post processing) we need
# to stop the torrent while working with files associated with the torrent
if file_action == "move" or file_action == "link":
client.stop_torrent(torrent)
client.stop_torrent(torrent_hash)
logger.debug(loggerHeader + "Stopping seeding torrent with hash: %s", torrent_hash)

# Loop through media_files and copy/link/move files
Expand All @@ -260,18 +269,16 @@ def main(self, torrent_hash):

# If label in torrent client matches CouchPotato label set in config call CouchPotato/Sick-Beard
# to do additional post processing (eg. renaming etc.)
if couchpotato and any(word in torrent_info['label'] for word in couch_label): # call CP postprocess
if cp_active and (torrent_info['label'] == cp_label):
logger.debug(loggerHeader + "Calling CouchPotato to post-process: %s", torrent_info['name'])
self.process_media("couchpotato", destination)

elif sickbeard and any(word in torrent_info['label'] for word in sick_label): # call SB postprocess
logger.debug(loggerHeader + "Calling Sick-Beard to post-process: %s", torrent_info['name'])
elif sb_active and (torrent_info['label'] == sb_label):
logger.debug(loggerHeader + "Calling Sickbeard to post-process: %s", torrent_info['name'])
self.process_media("sickbeard", destination)

else:
logger.debug(loggerHeader + "PostProcessor call params not met.")

# Delete the torrent (wand associated files) if its enabled in config.
# Delete the torrent (and associated files) if its enabled in config.
# Note that it will also delete torrent/files where file action is set to move as there wouldn't be any
# files to seed when they've been successfully moved.
if delete_finished or file_action == "move":
Expand All @@ -283,7 +290,7 @@ def main(self, torrent_hash):
# Start the torrent again to continue seeding
if file_action == "link":
# TODO: it would be best if rProcess checked to see if the post-processing completed successfully first - how?
client.start_torrent(torrent)
client.start_torrent(torrent_hash)
logger.debug(loggerHeader + "Starting seeding torrent with hash: %s", torrent_hash)

logger.info(loggerHeader + "We're all done here!")
Expand Down