Merge branch 'develop' of github.com:RuudBurger/CouchPotatoServer into develop
This commit is contained in:
@@ -28,6 +28,11 @@ config = [{
|
||||
'description': 'This is the OAUTH_TOKEN from your putio API',
|
||||
'advanced': True,
|
||||
},
|
||||
{
|
||||
'name': 'folder',
|
||||
'description': ('The folder on putio where you want the upload to go','Must be a folder in the root directory'),
|
||||
'default': 0,
|
||||
},
|
||||
{
|
||||
'name': 'callback_host',
|
||||
'description': 'External reachable url to CP so put.io can do it\'s thing',
|
||||
|
||||
@@ -28,20 +28,32 @@ class PutIO(DownloaderBase):
|
||||
|
||||
return super(PutIO, self).__init__()
|
||||
|
||||
def convertFolder(self, client, folder):
|
||||
if folder == 0:
|
||||
return 0
|
||||
else:
|
||||
files = client.File.list()
|
||||
for f in files:
|
||||
if f.name == folder and f.content_type == "application/x-directory":
|
||||
return f.id
|
||||
#If we get through the whole list and don't get a match we will use the root
|
||||
return 0
|
||||
|
||||
def download(self, data = None, media = None, filedata = None):
|
||||
if not media: media = {}
|
||||
if not data: data = {}
|
||||
|
||||
log.info('Sending "%s" to put.io', data.get('name'))
|
||||
url = data.get('url')
|
||||
|
||||
client = pio.Client(self.conf('oauth_token'))
|
||||
putioFolder = self.convertFolder(client, self.conf('folder'))
|
||||
log.debug('putioFolder ID is %s', putioFolder)
|
||||
# It might be possible to call getFromPutio from the renamer if we can then we don't need to do this.
|
||||
# Note callback_host is NOT our address, it's the internet host that putio can call too
|
||||
callbackurl = None
|
||||
if self.conf('download'):
|
||||
callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/'))
|
||||
resp = client.Transfer.add_url(url, callback_url = callbackurl)
|
||||
callbackurl = 'http://' + self.conf('callback_host') + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/'))
|
||||
resp = client.Transfer.add_url(url, callback_url = callbackurl, parent_id = putioFolder)
|
||||
log.debug('resp is %s', resp.id);
|
||||
return self.downloadReturnId(resp.id)
|
||||
|
||||
@@ -124,7 +136,9 @@ class PutIO(DownloaderBase):
|
||||
client = pio.Client(self.conf('oauth_token'))
|
||||
|
||||
log.debug('About to get file List')
|
||||
files = client.File.list()
|
||||
putioFolder = self.convertFolder(client, self.conf('folder'))
|
||||
log.debug('PutioFolderID is %s', putioFolder)
|
||||
files = client.File.list(parent_id=putioFolder)
|
||||
downloaddir = self.conf('download_dir')
|
||||
|
||||
for f in files:
|
||||
|
||||
+5
-4
@@ -154,13 +154,14 @@ class _File(_BaseResource):
|
||||
return [cls(f) for f in files]
|
||||
|
||||
@classmethod
|
||||
def upload(cls, path, name=None):
|
||||
def upload(cls, path, name=None, parent_id=0):
|
||||
with open(path) as f:
|
||||
if name:
|
||||
files = {'file': (name, f)}
|
||||
else:
|
||||
files = {'file': f}
|
||||
d = cls.client.request('/files/upload', method='POST', files=files)
|
||||
d = cls.client.request('/files/upload', method='POST',
|
||||
data={'parent_id': parent_id}, files=files)
|
||||
|
||||
f = d['file']
|
||||
return cls(f)
|
||||
@@ -239,7 +240,7 @@ class _Transfer(_BaseResource):
|
||||
@classmethod
|
||||
def add_url(cls, url, parent_id=0, extract=False, callback_url=None):
|
||||
d = cls.client.request('/transfers/add', method='POST', data=dict(
|
||||
url=url, parent_id=parent_id, extract=extract,
|
||||
url=url, save_parent_id=parent_id, extract=extract,
|
||||
callback_url=callback_url))
|
||||
t = d['transfer']
|
||||
return cls(t)
|
||||
@@ -249,7 +250,7 @@ class _Transfer(_BaseResource):
|
||||
with open(path) as f:
|
||||
files = {'file': f}
|
||||
d = cls.client.request('/files/upload', method='POST', files=files,
|
||||
data=dict(parent_id=parent_id,
|
||||
data=dict(save_parent_id=parent_id,
|
||||
extract=extract,
|
||||
callback_url=callback_url))
|
||||
t = d['transfer']
|
||||
|
||||
Reference in New Issue
Block a user