fixing check function

This commit is contained in:
dumaresq
2014-09-19 20:26:54 -04:00
parent ef2b8e88b4
commit fba228fd9d
+15 -13
View File
@@ -16,20 +16,21 @@ autoload = 'Putiodownload'
class PutIO(DownloaderBase): class PutIO(DownloaderBase):
protocol = ['torrent', 'torrent_magnet'] protocol = ['torrent', 'torrent_magnet']
status_support = True status_support = True
client_id = '1575'
client_secret = '132qbpseq1ymwn83wus4'
downloadingList = [] downloadingList = []
# This is the location on the Internet of the Oauth helper server
oauthServerURL = "http://sabnzb.dumaresq.ca/index.cgi"
def __init__(self): def __init__(self):
addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { addApiView('downloader.putio.getfrom', self.getFromPutio, docs = {
'desc': 'Allows you to download file from prom Put.io', 'desc': 'Allows you to download file from prom Put.io',
}) })
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 = {}
if not data: data = {} if not data: data = {}
@@ -40,6 +41,7 @@ class PutIO(DownloaderBase):
client = pio.Client(self.conf('oauth_token')) client = pio.Client(self.conf('oauth_token'))
# Need to constuct a the API url a better way. # Need to constuct a the API url a better way.
# Note callback_host is NOT our address, it's the internet host that putio can call too
callbackurl = None callbackurl = None
if self.conf('download'): if self.conf('download'):
callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/'))
@@ -47,6 +49,7 @@ 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'))
@@ -59,7 +62,7 @@ class PutIO(DownloaderBase):
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.info('callback_url is %s', callback_url) log.info('callback_url is %s', callback_url)
target_url = "http://sabnzbd.dumaresq.ca/index.cgi?target=" + callback_url target_url = oauthServerURL + "?target=" + callback_url
log.info('target_url is %s', target_url) log.info('target_url is %s', target_url)
return { return {
'success': True, 'success': True,
@@ -75,6 +78,7 @@ class PutIO(DownloaderBase):
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'))
@@ -83,22 +87,19 @@ class PutIO(DownloaderBase):
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('id is %s', t.id)
log.debug('P.Status is %s',t.id)
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'
# This is Ugly but if we are set to download, and the thing is complete, we need to check the dowlading status # So check if we are trying to download something
# Becuase putio changed the IDs the only thing we can check is the name.
elif t.status == "COMPLETED" and self.conf('download') == True: elif t.status == "COMPLETED" and self.conf('download') == True:
status = 'busy' status = 'busy'
# This is not ideal, right now if we are downloading anything we can't mark anything as completed # This is not ideal, right now if we are downloading anything we can't mark anything as completed
# The name and ID don't match currently so I can't use those... # The name and ID don't match currently so I can't use those...
if not self.downloadingList: if not self.downloadingList:
now = datetime.datetime.now() now = datetime.datetime.utcnow()
log.debug ('now is %s', now) date_time = datetime.datetime.strptime(t.finished_at,"%Y-%m-%dT%H:%M:%S")
log.debug ('t.finished_at is %s',t.finished_at) # We need to make sure a race condition didn't happen
if (now - t.finished_at) > datetime.timedelta(5,0): if (now - date_time) > datetime.timedelta(minutes=5):
status = 'completed' status = 'completed'
else: else:
status = 'busy' status = 'busy'
@@ -110,9 +111,9 @@ class PutIO(DownloaderBase):
}) })
log.debug(release_downloads) log.debug(release_downloads)
# Check "getFromPutio" progress
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'))
@@ -128,6 +129,7 @@ class PutIO(DownloaderBase):
return True return True
def getFromPutio(self, **kwargs): def getFromPutio(self, **kwargs):
file_id = str(kwargs.get('file_id')) file_id = str(kwargs.get('file_id'))
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)