def perform_upload(self): if self.REAL_RUN: old_content_type = self.what.session.headers['Content-type'] try: del self.what.session.headers['Content-type'] response = self.what.session.post( settings.WHAT_UPLOAD_URL, data=self.payload, files=self.payload_files) if response.url == settings.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 with open('uploaded_error.html', 'w') as error_file: error_file.write(response.text.encode('utf-8')) raise exception except Exception as ex: time.sleep(2) try: self.retrieve_new_torrent(self.torrent_new_infohash) except: raise ex finally: self.retrieve_new_torrent(self.torrent_new_infohash) self.what.session.headers['Content-type'] = old_content_type self.migration_status.status = WhatTorrentMigrationStatus.STATUS_UPLOADED self.migration_status.save() else: print 'Ready with payload' print ujson.dumps(self.payload, indent=4)
def perform_upload(self): if self.REAL_RUN: old_content_type = self.what.session.headers['Content-type'] try: del self.what.session.headers['Content-type'] response = self.what.session.post(settings.WHAT_UPLOAD_URL, data=self.payload, files=self.payload_files) if response.url == settings.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 with open('uploaded_error.html', 'w') as error_file: error_file.write(response.text.encode('utf-8')) raise exception except Exception as ex: time.sleep(2) try: self.retrieve_new_torrent(self.torrent_new_infohash) except: raise ex finally: self.retrieve_new_torrent(self.torrent_new_infohash) self.what.session.headers['Content-type'] = old_content_type self.migration_status.status = WhatTorrentMigrationStatus.STATUS_UPLOADED self.migration_status.save() else: print 'Ready with payload' print ujson.dumps(self.payload, indent=4)
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
def upload_torrent(self): torrent = self.what_torrent print 'Sending request for upload to what.cd' payload_files = dict() payload_files['file_input'] = ('torrent.torrent', open(self.torrent_file_path, 'rb')) payload = dict() payload['submit'] = 'true' payload['auth'] = self.what.authkey payload['type'] = 'Music' payload['groupid'] = torrent['group']['id'] payload['format'] = 'MP3' payload['bitrate'] = { 'V0': 'V0 (VBR)', 'V2': 'V2 (VBR)', '320': '320', }[self.bitrate] payload['media'] = torrent['torrent']['media'] payload[ 'release_desc'] = 'Made with LAME 3.99.3 with -h using karamanolev\'s auto transcoder' \ ' from What.CD Torrent ID {0}.'.format( torrent['torrent']['id']) + ' Resampling or bit depth change (if needed) ' \ 'was done using SoX.' if torrent['torrent']['remastered']: payload['remaster'] = 'on' payload['remaster_year'] = torrent['torrent']['remasterYear'] payload['remaster_title'] = torrent['torrent']['remasterTitle'] payload['remaster_record_label'] = torrent['torrent']['remasterRecordLabel'] payload['remaster_catalogue_number'] = torrent['torrent']['remasterCatalogueNumber'] old_content_type = self.what.session.headers['Content-type'] try: del self.what.session.headers['Content-type'] response = self.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 with open(TRANSCODER_ERROR_OUTPUT, 'w') as error_file: error_file.write(response.text.encode('utf-8')) raise exception except Exception as ex: time.sleep(2) try: self.retrieve_new_torrent(self.new_torrent_info_hash) except: raise ex finally: self.what.session.headers['Content-type'] = old_content_type
def upload_torrent(self): torrent = self.what_torrent print "Sending request for upload to what.cd" payload_files = dict() payload_files["file_input"] = ("torrent.torrent", open(self.torrent_file_path, "rb")) payload = dict() payload["submit"] = "true" payload["auth"] = self.what.authkey payload["type"] = "Music" payload["groupid"] = torrent["group"]["id"] payload["format"] = "MP3" payload["bitrate"] = {"V0": "V0 (VBR)", "V2": "V2 (VBR)", "320": "320"}[self.bitrate] payload["media"] = torrent["torrent"]["media"] payload["release_desc"] = ( "Made with LAME 3.99.3 with -h using karamanolev's auto transcoder from What.CD Torrent ID {0}.".format( torrent["torrent"]["id"] ) + " Resampling or bit depth change (if needed) was done using SoX." ) if torrent["torrent"]["remastered"]: payload["remaster"] = "on" payload["remaster_year"] = torrent["torrent"]["remasterYear"] payload["remaster_title"] = torrent["torrent"]["remasterTitle"] payload["remaster_record_label"] = torrent["torrent"]["remasterRecordLabel"] payload["remaster_catalogue_number"] = torrent["torrent"]["remasterCatalogueNumber"] old_content_type = self.what.session.headers["Content-type"] try: del self.what.session.headers["Content-type"] response = self.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 with open(TRANSCODER_ERROR_OUTPUT, "w") as error_file: error_file.write(response.text.encode("utf-8")) raise exception except Exception as ex: time.sleep(2) try: self.retrieve_new_torrent(self.new_torrent_info_hash) except: raise ex finally: self.what.session.headers["Content-type"] = old_content_type
def upload_torrent(self): torrent = self.what_torrent print 'Sending request for upload to Redacted' payload_files = dict() payload_files['file_input'] = ('torrent.torrent', open(self.torrent_file_path, 'rb')) payload = dict() payload['submit'] = 'true' payload['auth'] = self.what.authkey payload['type'] = 'Music' payload['groupid'] = torrent['group']['id'] payload['format'] = self.format payload['bitrate'] = { 'V0': 'V0 (VBR)', 'V2': 'V2 (VBR)', '320': '320', 'Lossless': 'Lossless', '16BITFLAC': 'Lossless', }[self.bitrate] payload['media'] = torrent['torrent']['media'] if self.format != 'MP3': flac_version = subprocess.check_output("flac -v", shell=True) payload['release_desc'] = 'Made with ' + flac_version.rstrip() else: lame_version = subprocess.check_output( "lame -? | grep -oP '([0-9]+\.[0-9]+\.[0-9]+)'", shell=True) payload['release_desc'] = 'Made with LAME ' + lame_version.rstrip( ) + ' with -h' payload['release_desc'] += ' using karamanolev\'s auto transcoder' \ ' from https://redacted.ch/torrents.php?torrentid={0}'.format(torrent['torrent']['id']) if torrent['torrent']['remastered']: payload['remaster'] = 'on' payload['remaster_year'] = torrent['torrent']['remasterYear'] payload['remaster_title'] = torrent['torrent']['remasterTitle'] payload['remaster_record_label'] = torrent['torrent'][ 'remasterRecordLabel'] payload['remaster_catalogue_number'] = torrent['torrent'][ 'remasterCatalogueNumber'] old_content_type = self.what.session.headers['Content-type'] try: del self.what.session.headers['Content-type'] response = self.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 Redacted. Errors: {0}'.format( '; '.join(errors))) exception.response_text = response.text with open(TRANSCODER_ERROR_OUTPUT, 'w') as error_file: error_file.write(response.text.encode('utf-8')) raise exception except Exception as ex: time.sleep(2) try: self.retrieve_new_torrent(self.new_torrent_info_hash) except: raise ex finally: self.what.session.headers['Content-type'] = old_content_type