Put.IO cleanup

This commit is contained in:
Ruud committed 2014-12-01 16:49:27 +01:00
1 parent c6d326f973
commit fe56a69e8f
1 file changed
+23 -12
+23 -12
View File
@@ -4,7 +4,7 @@ from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownlo
from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.helpers.variable import cleanHost
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.environment import Env from couchpotato.environment import Env
import api as pio from pio import api as pio
import datetime import datetime
log = CPLog(__name__) log = CPLog(__name__)
@@ -13,12 +13,14 @@ autoload = 'Putiodownload'
class PutIO(DownloaderBase): class PutIO(DownloaderBase):
protocol = ['torrent', 'torrent_magnet'] protocol = ['torrent', 'torrent_magnet']
status_support = True status_support = True
downloadingList = [] downloadingList = []
# This is the location on the Internet of the Oauth helper server
oauthServerURL = "http://sabnzbd.dumaresq.ca/index.cgi"
# This is the location on the Internet of the Oauth helper server
#oauthServerURL = 'https://api.couchpota.to/validate/putio/'
oauthServerURL = 'http://localhost:3000/authorize/putio/'
def __init__(self): def __init__(self):
addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { addApiView('downloader.putio.getfrom', self.getFromPutio, docs = {
@@ -27,8 +29,8 @@ class PutIO(DownloaderBase):
addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) addApiView('downloader.putio.auth_url', self.getAuthorizationUrl)
addApiView('downloader.putio.credentials', self.getCredentials) addApiView('downloader.putio.credentials', self.getCredentials)
addEvent('putio.download', self.putioDownloader) addEvent('putio.download', self.putioDownloader)
return super(PutIO, self).__init__()
return super(PutIO, self).__init__()
def download(self, data = None, media = None, filedata = None): def download(self, data = None, media = None, filedata = None):
if not media: media = {} if not media: media = {}
@@ -47,7 +49,6 @@ class PutIO(DownloaderBase):
log.debug('resp is %s', resp.id); log.debug('resp is %s', resp.id);
return self.downloadReturnId(resp.id) return self.downloadReturnId(resp.id)
def test(self): def test(self):
try: try:
client = pio.Client(self.conf('oauth_token')) client = pio.Client(self.conf('oauth_token'))
@@ -57,39 +58,44 @@ class PutIO(DownloaderBase):
log.info('Failed to get file listing, check OAUTH_TOKEN') log.info('Failed to get file listing, check OAUTH_TOKEN')
return False return False
def getAuthorizationUrl(self, host = None, **kwargs): def getAuthorizationUrl(self, host = None, **kwargs):
callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/'))
log.debug('callback_url is %s', callback_url) log.debug('callback_url is %s', callback_url)
target_url = self.oauthServerURL + "?target=" + callback_url target_url = self.oauthServerURL + "?target=" + callback_url
log.debug('target_url is %s', target_url) log.debug('target_url is %s', target_url)
return { return {
'success': True, 'success': True,
'url': target_url, 'url': target_url,
} }
def getCredentials(self, **kwargs): def getCredentials(self, **kwargs):
try: try:
oauth_token = kwargs.get('oauth') oauth_token = kwargs.get('oauth')
except: except:
return 'redirect', Env.get('web_base') + 'settigs/downloaders/' return 'redirect', Env.get('web_base') + 'settings/downloaders/'
log.debug('oauth_token is: %s', oauth_token) log.debug('oauth_token is: %s', oauth_token)
self.conf('oauth_token', value = oauth_token); self.conf('oauth_token', value = oauth_token);
return 'redirect', Env.get('web_base') + 'settings/downloaders/' return 'redirect', Env.get('web_base') + 'settings/downloaders/'
def getAllDownloadStatus(self, ids): def getAllDownloadStatus(self, ids):
log.debug('Checking putio download status.')
log.debug('Checking putio download status.')
client = pio.Client(self.conf('oauth_token')) client = pio.Client(self.conf('oauth_token'))
transfers = client.Transfer.list() transfers = client.Transfer.list()
log.debug(transfers); log.debug(transfers);
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for t in transfers: for t in transfers:
if t.id in ids: if t.id in ids:
log.debug('downloading list is %s', self.downloadingList) log.debug('downloading list is %s', self.downloadingList)
if t.status == "COMPLETED" and self.conf('download') == False : if t.status == "COMPLETED" and self.conf('download') == False :
status = 'completed' status = 'completed'
# So check if we are trying to download something # So check if we are trying to download something
elif t.status == "COMPLETED" and self.conf('download') == True: elif t.status == "COMPLETED" and self.conf('download') == True:
# Assume we are done # Assume we are done
@@ -113,15 +119,18 @@ class PutIO(DownloaderBase):
'status': status, 'status': status,
'timeleft': t.estimated_time, 'timeleft': t.estimated_time,
}) })
return release_downloads return release_downloads
def putioDownloader(self, fid): def putioDownloader(self, fid):
log.info('Put.io Real downloader called with file_id: %s',fid) log.info('Put.io Real downloader called with file_id: %s',fid)
client = pio.Client(self.conf('oauth_token')) client = pio.Client(self.conf('oauth_token'))
log.debug('About to get file List') log.debug('About to get file List')
files = client.File.list() files = client.File.list()
downloaddir = self.conf('download_dir') downloaddir = self.conf('download_dir')
for f in files: for f in files:
if str(f.id) == str(fid): if str(f.id) == str(fid):
client.File.download(f, dest = downloaddir, delete_after_download = self.conf('delete_file')) client.File.download(f, dest = downloaddir, delete_after_download = self.conf('delete_file'))
@@ -130,14 +139,15 @@ class PutIO(DownloaderBase):
return True return True
def getFromPutio(self, **kwargs): def getFromPutio(self, **kwargs):
try: try:
file_id = str(kwargs.get('file_id')) file_id = str(kwargs.get('file_id'))
except: except:
return { return {
'success' : False, 'success' : False,
} }
log.info('Put.io Download has been called file_id is %s', file_id) log.info('Put.io Download has been called file_id is %s', file_id)
if file_id not in self.downloadingList: if file_id not in self.downloadingList:
self.downloadingList.append(file_id) self.downloadingList.append(file_id)
@@ -145,6 +155,7 @@ class PutIO(DownloaderBase):
return { return {
'success': True, 'success': True,
} }
return { return {
'success': False, 'success': False,
} }