def upload(self): print("Uploading file to Archive.org...") service = auth(self.user) headers = {} if self.test: headers['x-archive-meta-collection'] = 'test_collection' bucket = service.get_bucket(self.bucket_id, headers=headers) key = boto.s3.key.Key(bucket) key.key = self.key_id pf = ProgressFile(self.pathname, 'r') try: # actually upload ret = key.set_contents_from_file(pf) # ret is the number of bytes in the file if self.debug_mode: import code code.interact(local=locals()) self.new_url = key.generate_url(0) print("archive.org:", self.new_url) ret = True except Exception as e: """ $ curl s3.us.archive.org -v -H x-archive-simulate-error:SlowDown To see a list of errors s3 can simulate, you can do: $ curl s3.us.archive.org -v -H x-archive-simulate-error:help File "post_yt.py", line 234, in do_arc archive_success = uploader.upload() File "/home/juser/veyepar/dj/scripts/archive_uploader.py", line 141, in upload self.ret_text = "internet archive error: %s" % ( e.body ) AttributeError: 'timeout' object has no attribute 'body' >>> e.__class__ <class 'socket.timeout'> """ print(e) # self.ret_text = "internet archive error: %s" % ( e.body ) import code code.interact(local=locals()) ret = False return ret
def upload(self): yt_service = self.auth() if self.unlisted: acl = [ ExtensionElement('accessControl', namespace=YOUTUBE_NAMESPACE, attributes={ 'action': 'list', 'permission': 'denied' }) ] else: acl = [] video_entry = gdata.youtube.YouTubeVideoEntry(media=self.media_group(), extension_elements=acl) if self.meta.has_key('latlon'): video_entry.geo = self.geo() # add some more metadata - more tags # tags = self.meta['tags'] # tags = [tag for tag in tags if " " not in tag] # https://developers.google.com/youtube/2.0/developers_guide_protocol#Assigning_Developer_Tags # video_entry.AddDeveloperTags(tags) pathname = self.files[0]['pathname'] pf = ProgressFile(pathname, 'r') try: # down to the next moduel layer to upload self.new_entry = yt_service.InsertVideoEntry(video_entry, pf) self.ret_text = self.new_entry.__str__() link = self.new_entry.GetHtmlLink() self.new_url = link.href.split('&')[0] ret = True except gdata.youtube.service.YouTubeError, e: self.ret_text = 'request: %s\nerror: %s' % (video_entry.ToString(), e.__str__()) ret = False print "e:", e if self.debug_mode: import code code.interact(local=locals())
def upload(self): youtube = get_authenticated_service(user_key=self.user) if self.debug: print self.pathname pprint.pprint(self.meta) pf = ProgressFile(self.pathname) self.meta['description'] = clean_description(self.meta['description']) status, response = initialize_upload(youtube, pf, self.meta) self.response = response self.new_url = "http://youtu.be/%s" % (response['id']) return True
def upload(self): print("Uploading file to Archive.org...") auth = archive[self.user] ## from dict of credentials md = self.get_metadata() pf = ProgressFile(self.pathname, 'rb') item = ia.get_item(self.slug) try: # actually upload ret = item.upload( pf, metadata=md, access_key=auth['access'], secret_key=auth['secret'], # ignore_preexisting_bucket=True, verbose=self.verbose) if self.debug_mode: import code code.interact(local=locals()) # https://archive.org/details/lca2016-Internet_Archive_Universal_Access_Open_APIs self.new_url = "https://archive.org/details/{}".format(self.slug) print(("ia: {}".format(self.new_url))) ret = True except HTTPError as e: print(("ia_uploader.py", e)) # self.ret_text = "internet archive error: %s" % ( e.body ) import code code.interact(local=locals()) ret = False return ret
def upload(self): print "Uploading file to RackSpace CDN..." pyrax.set_setting("region", self.region) cf = auth(self.user) if self.verbose: print("getting container...") if self.debug_mode: print("cf.get_all_containers", cf.get_all_containers()) container = cf.get_container(self.bucket_id) # check if object already exists: # if same name and same md5, don't bother re-uploading. try: if self.verbose: print("trying to get existing object...") obj = container.get_object(self.key_id) if self.verbose: print("checking for already_there...") already_there = obj.etag == pyrax.utils.get_checksum( self.pathname,) ret = True except pyrax.exceptions.NoSuchObject as e: already_there = False if not already_there: done=False while not done: pf = ProgressFile(self.pathname, 'r') try: # actually upload if self.verbose: print("container.upload_file...") obj = container.upload_file(pf, obj_name = self.key_id) if self.debug_mode: import code code.interact(local=locals()) done = True ret = True except pyrax.exceptions.ClientException as e: print "caught pyrax.exceptions.ClientException as e" print e print e.code, e.details, e.message if e.code in [408,503]: # 408 Request timeout # 503 Service Unavailable - The server is currently unavailable. Please try again at a later time. print "looping..." continue print e # self.ret_text = "rax error: %s" % ( e.body ) import code code.interact(local=locals()) except Exception as e: print "caught Exception as e" """ HTTPSConnectionPool(host='storage101.ord1.clouddrive.com', port=443): Max retries exceeded with url: /v1/MossoCloudFS_fd6d6695-7fe7-4f77-9b4a-da7696e71dc2/fosdem/veyepar/debian/debconf14/dv/plenary/2014-08-23/16_00_03.ogv (Caused by <class 'socket.error'>: [Errno 104] Connection reset by peer) HTTPSConnectionPool(host='storage101.ord1.clouddrive.com', port=443): Max retries exceeded with url: /v1/MossoCloudFS_fd6d6695-7fe7-4f77-9b4a-da7696e71dc2/fosdem/veyepar/debian/debconf14/dv/room338/2014-08-25/10_02_05.ogv (Caused by <class 'socket.error'>: [Errno 32] Broken pipe) """ print e # self.ret_text = "rax error: %s" % ( e.body ) import code code.interact(local=locals()) ret = False # urllib.quote # filenames may have chars that need to be quoted for a URL. # cdn_streaming because.. video? (not sure really) # self.new_url = container.cdn_streaming_uri +"/"+ urllib.quote(obj.name) self.new_url = container.cdn_uri +"/"+ urllib.quote(obj.name.encode('utf-8')) # self.new_url = container.cdn_uri +"/"+ urllib.quote(obj.name) print "Rackspace: ", self.new_url return ret