mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
More code changes
This commit is contained in:
parent
6a74a4443e
commit
012e4913a8
2 changed files with 48 additions and 52 deletions
|
@ -17,48 +17,46 @@ from nzbtomedia.transmissionrpc.client import Client as TransmissionClient
|
||||||
class autoProcessMovie:
|
class autoProcessMovie:
|
||||||
def find_release_info(self, baseURL, download_id, dirName, nzbName):
|
def find_release_info(self, baseURL, download_id, dirName, nzbName):
|
||||||
def search_torrents(releases, nzbName):
|
def search_torrents(releases, nzbName):
|
||||||
for release in releases:
|
tor_hash = None
|
||||||
try:
|
|
||||||
|
try:
|
||||||
|
torrents = []
|
||||||
|
tor_client = create_torrent_class(nzbtomedia.CLIENTAGENT)
|
||||||
|
if nzbtomedia.CLIENTAGENT == "transmission":
|
||||||
|
torrents = tor_client.get_torrents()
|
||||||
|
elif nzbtomedia.CLIENTAGENT == "deluge":
|
||||||
|
torrents = tor_client.get_torrents()
|
||||||
|
elif nzbtomedia.CLIENTAGENT == "utorrent":
|
||||||
|
torrents = tor_client.get_torrents()
|
||||||
|
|
||||||
|
for torrent in torrents:
|
||||||
|
if download_id:
|
||||||
|
if download_id == torrent.hashString:
|
||||||
|
tor_hash = torrent.hashString
|
||||||
|
break
|
||||||
|
|
||||||
|
if nzbName == torrent.name:
|
||||||
|
tor_hash = torrent.hashString
|
||||||
|
break
|
||||||
|
|
||||||
|
for release in releases:
|
||||||
if release['status'] != 'snatched':
|
if release['status'] != 'snatched':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if tor_hash:
|
||||||
|
if release['download_info']['id'] == tor_hash:
|
||||||
|
return release
|
||||||
|
|
||||||
if download_id:
|
if download_id:
|
||||||
if download_id == release['download_info']['id']:
|
if release['download_info']['id'] == download_id:
|
||||||
return release
|
return release
|
||||||
|
except:pass
|
||||||
if imdbid:
|
|
||||||
if imdbid == release['download_info']['id']:
|
|
||||||
return release
|
|
||||||
|
|
||||||
downloader = release['download_info']['downloader'].lower()
|
|
||||||
tor_client = create_torrent_class(downloader)
|
|
||||||
|
|
||||||
torrents = []
|
|
||||||
if downloader == "transmission":
|
|
||||||
torrents = tor_client.get_torrents()
|
|
||||||
elif downloader == "deluge":
|
|
||||||
torrents = tor_client.get_torrents()
|
|
||||||
elif downloader == "utorrent":
|
|
||||||
torrents = tor_client.get_torrents()
|
|
||||||
|
|
||||||
for torrent in torrents:
|
|
||||||
tor_name = torrent.name
|
|
||||||
tor_hash = torrent.hashString
|
|
||||||
|
|
||||||
if download_id:
|
|
||||||
if download_id == tor_hash:
|
|
||||||
return release
|
|
||||||
|
|
||||||
if nzbName == tor_name:
|
|
||||||
return release
|
|
||||||
except:pass
|
|
||||||
|
|
||||||
imdbid = None
|
imdbid = None
|
||||||
release_id = None
|
release_id = None
|
||||||
media_id = None
|
media_id = None
|
||||||
release_status = None
|
release_status = None
|
||||||
matched_release = None
|
matched_release = None
|
||||||
downloader = None
|
|
||||||
|
|
||||||
while(True):
|
while(True):
|
||||||
# find imdbid in nzbName
|
# find imdbid in nzbName
|
||||||
|
@ -93,7 +91,7 @@ class autoProcessMovie:
|
||||||
results = r.json()
|
results = r.json()
|
||||||
for movie in results['movies']:
|
for movie in results['movies']:
|
||||||
if imdbid:
|
if imdbid:
|
||||||
if imdbid != movie['info']['imdb']:
|
if imdbid != movie['identifiers']['imdb']:
|
||||||
continue
|
continue
|
||||||
matched_release = search_torrents(movie['releases'], nzbName)
|
matched_release = search_torrents(movie['releases'], nzbName)
|
||||||
if matched_release:
|
if matched_release:
|
||||||
|
@ -105,28 +103,28 @@ class autoProcessMovie:
|
||||||
media_id = matched_release['media_id']
|
media_id = matched_release['media_id']
|
||||||
release_status = matched_release['status']
|
release_status = matched_release['status']
|
||||||
download_id = matched_release['download_info']['id']
|
download_id = matched_release['download_info']['id']
|
||||||
downloader = matched_release['download_info']['downloader']
|
|
||||||
except:pass
|
except:pass
|
||||||
|
|
||||||
return media_id, download_id, downloader, release_id, release_status
|
return media_id, download_id, release_id, release_status
|
||||||
|
|
||||||
def get_status(self, baseURL, release_id):
|
def get_status(self, baseURL, media_id, release_id):
|
||||||
release_status = None
|
release_status = None
|
||||||
|
|
||||||
logger.debug("Attempting to get current status for release:%s", release_id)
|
logger.debug("Attempting to get current status for movie:%s", media_id)
|
||||||
|
|
||||||
url = baseURL + "/media.get"
|
url = baseURL + "/media.get"
|
||||||
logger.debug("Opening URL: %s", url)
|
logger.debug("Opening URL: %s", url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, params={'id':release_id})
|
r = requests.get(url, params={'id':media_id})
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error("Unable to open URL")
|
logger.error("Unable to open URL")
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = r.json()
|
result = r.json()
|
||||||
release_status = result["media"]["status"]
|
for release in result["media"]['releases']:
|
||||||
|
release_status = release["status"]
|
||||||
except:pass
|
except:pass
|
||||||
|
|
||||||
return release_status
|
return release_status
|
||||||
|
@ -182,10 +180,10 @@ class autoProcessMovie:
|
||||||
|
|
||||||
baseURL = protocol + host + ":" + port + web_root + "/api/" + apikey
|
baseURL = protocol + host + ":" + port + web_root + "/api/" + apikey
|
||||||
|
|
||||||
media_id, download_id, downloader, release_id, release_status = self.find_release_info(baseURL, download_id, dirName, nzbName) # get the CPS database movie id for this movie.
|
media_id, download_id, release_id, release_status = self.find_release_info(baseURL, download_id, dirName, nzbName) # get the CPS database movie id for this movie.
|
||||||
|
|
||||||
if release_status is None:
|
if release_status is None:
|
||||||
logger.error("Could not find a current status for %s on CouchPotatoServer", nzbName)
|
logger.error("Could not find the current status for %s on CouchPotatoServer", nzbName)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# failed to get a download id
|
# failed to get a download id
|
||||||
|
@ -216,8 +214,7 @@ class autoProcessMovie:
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if download_id:
|
if download_id:
|
||||||
if downloader:
|
params['downloader'] = nzbtomedia.CLIENTAGENT
|
||||||
params['downloader'] = downloader or clientAgent
|
|
||||||
params['download_id'] = download_id
|
params['download_id'] = download_id
|
||||||
|
|
||||||
if remote_path:
|
if remote_path:
|
||||||
|
@ -271,7 +268,7 @@ class autoProcessMovie:
|
||||||
delete(dirName)
|
delete(dirName)
|
||||||
return 0 # success
|
return 0 # success
|
||||||
|
|
||||||
if not download_id or not release_id:
|
if not download_id or not media_id or not release_id:
|
||||||
if clientAgent in ['utorrent', 'transmission', 'deluge'] :
|
if clientAgent in ['utorrent', 'transmission', 'deluge'] :
|
||||||
return 1 # just to be sure TorrentToMedia doesn't start deleting files as we havent verified changed status.
|
return 1 # just to be sure TorrentToMedia doesn't start deleting files as we havent verified changed status.
|
||||||
else:
|
else:
|
||||||
|
@ -279,11 +276,8 @@ class autoProcessMovie:
|
||||||
|
|
||||||
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
|
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
|
||||||
timeout = time.time() + 60 * int(wait_for)
|
timeout = time.time() + 60 * int(wait_for)
|
||||||
while (True): # only wait 2 (default) minutes, then return.
|
while (time.time() < timeout): # only wait 2 (default) minutes, then return.
|
||||||
if time.time() > timeout:
|
current_status = self.get_status(baseURL, media_id, release_id)
|
||||||
break
|
|
||||||
|
|
||||||
current_status = self.get_status(baseURL, release_id)
|
|
||||||
if current_status is None:
|
if current_status is None:
|
||||||
logger.error("Could not find a current status for %s on CouchPotatoServer", nzbName)
|
logger.error("Could not find a current status for %s on CouchPotatoServer", nzbName)
|
||||||
return 1
|
return 1
|
||||||
|
@ -292,6 +286,9 @@ class autoProcessMovie:
|
||||||
logger.postprocess("SUCCESS: This release is now marked as status [%s] in CouchPotatoServer", current_status.upper())
|
logger.postprocess("SUCCESS: This release is now marked as status [%s] in CouchPotatoServer", current_status.upper())
|
||||||
return 0 # success
|
return 0 # success
|
||||||
|
|
||||||
|
# pause and let CouchPotatoServer catch its breath
|
||||||
|
time.sleep(10 * int(wait_for))
|
||||||
|
|
||||||
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
|
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
|
||||||
logger.warning("The movie does not appear to have changed status after %s minutes. Please check CouchPotato Logs", wait_for)
|
logger.warning("The movie does not appear to have changed status after %s minutes. Please check CouchPotato Logs", wait_for)
|
||||||
return 1 # failure
|
return 1 # failure
|
|
@ -118,10 +118,7 @@ class autoProcessMusic:
|
||||||
|
|
||||||
# we will now wait 1 minutes for this album to be processed before returning to TorrentToMedia and unpausing.
|
# we will now wait 1 minutes for this album to be processed before returning to TorrentToMedia and unpausing.
|
||||||
timeout = time.time() + 60 * 2
|
timeout = time.time() + 60 * 2
|
||||||
while (True): # only wait 2 (default) minutes, then return.
|
while (time.time() < timeout): # only wait 2 (default) minutes, then return.
|
||||||
if time.time() > timeout:
|
|
||||||
break
|
|
||||||
|
|
||||||
current_status = self.get_status(url, apikey, dirName)
|
current_status = self.get_status(url, apikey, dirName)
|
||||||
if current_status is None:
|
if current_status is None:
|
||||||
logger.error("Could not find a current status for %s on HeadPhones", nzbName)
|
logger.error("Could not find a current status for %s on HeadPhones", nzbName)
|
||||||
|
@ -131,6 +128,8 @@ class autoProcessMusic:
|
||||||
logger.postprocess("SUCCESS: This release is now marked as status [%s] in HeadPhones",current_status.upper())
|
logger.postprocess("SUCCESS: This release is now marked as status [%s] in HeadPhones",current_status.upper())
|
||||||
return 0 # success
|
return 0 # success
|
||||||
|
|
||||||
|
time.sleep(10 * 2)
|
||||||
|
|
||||||
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
|
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.
|
||||||
logger.warning("The music album does not appear to have changed status after %s minutes. Please check HeadPhones Logs",2)
|
logger.warning("The music album does not appear to have changed status after %s minutes. Please check HeadPhones Logs",2)
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue