Exemple #1
0
def upload_to_what(request, book_upload):
    book_upload.full_clean()
    if not book_upload.what_torrent_file:
        raise Exception('what_torrent is no')
    if not book_upload.cover_url:
        raise Exception('cover_url is no')

    print 'Sending request for upload to what.cd'

    what = get_what_client(request)

    payload_files = dict()
    payload_files['file_input'] = ('torrent.torrent',
                                   book_upload.what_torrent_file)

    payload = dict()
    payload['submit'] = 'true'
    payload['auth'] = what.authkey
    payload['type'] = '2'
    payload['title'] = book_upload.author + ' - ' + book_upload.title
    payload['tags'] = get_what_tags(book_upload)
    payload['image'] = book_upload.cover_url
    payload['desc'] = get_what_desc(book_upload)

    old_content_type = what.session.headers['Content-type']
    upload_exception = None
    try:
        del what.session.headers['Content-type']
        response = what.session.post(WHAT_UPLOAD_URL,
                                     data=payload,
                                     files=payload_files)
        if response.url == WHAT_UPLOAD_URL:
            try:
                errors = extract_upload_errors(response.text)
            except Exception:
                errors = ''
            exception = Exception(
                'Error uploading data to what.cd. Errors: {0}'.format(
                    '; '.join(errors)))
            exception.response_text = response.text
            raise exception
    except Exception as ex:
        upload_exception = ex
    finally:
        what.session.headers['Content-type'] = old_content_type

    try:
        new_torrent = safe_retrieve_new_torrent(
            what, get_info_hash_from_data(book_upload.what_torrent_file))
        book_upload.what_torrent = WhatTorrent.get_or_create(
            request, what_id=new_torrent['torrent']['id'])
        book_upload.save()
    except Exception as ex:
        if upload_exception:
            raise upload_exception
        raise ex

    move_to_dest_add(request, book_upload)
    return book_upload.what_torrent
Exemple #2
0
 def retrieve_new_torrent(self, info_hash):
     if self.new_torrent:
         return
     self.new_torrent = safe_retrieve_new_torrent(self.what, info_hash)
Exemple #3
0
 def retrieve_new_torrent(self, info_hash):
     if self.new_torrent:
         return
     self.new_torrent = safe_retrieve_new_torrent(self.what, info_hash)
 def retrieve_new_torrent(self, info_hash):
     if self.new_torrent is None:
         self.new_torrent = safe_retrieve_new_torrent(self.what, info_hash)
         self.migration_status.pth_torrent_id = self.new_torrent['torrent']['id']
         self.migration_status.save()
 def retrieve_new_torrent(self, info_hash):
     if self.new_torrent is None:
         self.new_torrent = safe_retrieve_new_torrent(self.what, info_hash)
         self.migration_status.pth_torrent_id = self.new_torrent['torrent'][
             'id']
         self.migration_status.save()