Exemplo n.º 1
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'):
            pre = 'http://'
            if self.conf('https'):
                pre = 'https://'
            callbackurl = pre + self.conf(
                'callback_host') + '%sdownloader.putio.getfrom/' % Env.get(
                    'api_base'.strip('/'))
        log.debug('callbackurl is %s', callbackurl)
        resp = client.Transfer.add_url(url,
                                       callback_url=callbackurl,
                                       parent_id=putioFolder)
        log.debug('resp is %s', resp.id)
        return self.downloadReturnId(resp.id)
Exemplo n.º 2
0
 def test(self):
     try:
         client = pio.Client(self.conf('oauth_token'))
         if client.File.list():
             return True
     except:
         log.info('Failed to get file listing, check OAUTH_TOKEN')
         return False
Exemplo n.º 3
0
    def putioDownloader(self, fid):

        log.info('Put.io Real downloader called with file_id: %s',fid)
        client = pio.Client(self.conf('oauth_token'))

        log.debug('About to get 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:
            if str(f.id) == str(fid):
                client.File.download(f, dest = downloaddir, delete_after_download = self.conf('delete_file'))
                # Once the download is complete we need to remove it from the running list.
                self.downloading_list.remove(fid)

        return True
Exemplo n.º 4
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking putio download status.')
        client = pio.Client(self.conf('oauth_token'))

        transfers = client.Transfer.list()

        log.debug(transfers)
        release_downloads = ReleaseDownloadList(self)
        for t in transfers:
            if t.id in ids:

                log.debug('downloading list is %s', self.downloading_list)
                if t.status == "COMPLETED" and self.conf('download') == False:
                    status = 'completed'

                # So check if we are trying to download something
                elif t.status == "COMPLETED" and self.conf('download') == True:
                    # Assume we are done
                    status = 'completed'
                    if not self.downloading_list:
                        now = datetime.datetime.utcnow()
                        date_time = datetime.datetime.strptime(
                            t.finished_at, "%Y-%m-%dT%H:%M:%S")
                        # We need to make sure a race condition didn't happen
                        if (now - date_time) < datetime.timedelta(minutes=5):
                            # 5 minutes haven't passed so we wait
                            status = 'busy'
                    else:
                        # If we have the file_id in the downloading_list mark it as busy
                        if str(t.file_id) in self.downloading_list:
                            status = 'busy'
                else:
                    status = 'busy'
                release_downloads.append({
                    'id': t.id,
                    'name': t.name,
                    'status': status,
                    'timeleft': t.estimated_time,
                })

        return release_downloads