def test_auth_modes(self, dev): vimeo = VimeoClient(access_token=test_data['access_token'], dev=bool(dev)) r = vimeo.me.videos() assert 'data' in r['body'], "Access token auth should work" vimeo = VimeoClient(client_id=test_data['client_id'], client_secret=test_data['client_secret'], dev=bool(dev)) r = vimeo.users.emmett9001() assert 'uri' in r['body'], "Basic auth with cid and secret should work" vimeo = VimeoClient(client_id=test_data['client_id'], dev=bool(dev)) r = vimeo.users.emmett9001() assert 'uri' in r['body'], "Basic auth with cid should work"
def getVimeo(): config = ConfigParser.RawConfigParser() config.read('config.ini') token = config.get('Vimeo', 'token') secret = config.get('Vimeo', 'secret') Client_Identifier = config.get('Vimeo', 'Client_Identifier') return VimeoClient(token=token, key=Client_Identifier, secret=secret)
def get_folder_contents(self): v = VimeoClient(token=self.vimeo_access_token, key=self.vimeo_client_id, secret=self.vimeo_client_secret) response = v.get('/users/' + self.vimeo_user_id + '/projects/' + self.vimeo_project_id + '/videos') assert response.status_code == 200 return CPSSVimeoCollectionType(response.json())
def get(self): """ Demonstrates synchronous use of VimeoClient Caller does not need to be wrapped in a decorator, result is returned synchronously """ vimeo = VimeoClient("YOUR ACCESS TOKEN") res = vimeo.users.emmett9001() self.write(res) self.finish()
def __init__(self, conf, blog): self.log = getLogger(__name__) self.conf = conf self.blog = blog self.client = VimeoClient( token=self.conf.vimeo_token, key=self.conf.vimeo_client_id, secret=self.conf.vimeo_client_secret )
def get(self): """ Demonstrates asynchronous use of VimeoClient via tornado.gen The caller must be decorated by tornado.gen.coroutine The call to an API function must include the async kwarg set to True The result must be yielded before assignment """ vimeo = VimeoClient("YOUR ACCESS TOKEN") res = yield vimeo.users(query='cats', async=True) self.write(res) self.finish()
def get(self): """ Demonstrates asynchronous use of VimeoClient via callback function Caller must be wrapped in @tornado.web.asynchronous Call to API function must include the callback kwarg """ vimeo = VimeoClient("YOUR ACCESS TOKEN") def callback(result): self.write(result) self.finish() vimeo.users.emmett9001(callback=callback)
def upload_video_to_vimeo(video_id, **kwargs): """docstring for upload_to_vimeo""" """ General 4 steps are given here: http://vimeo.com/api/docs/oauth using the python vimeo library I originally did: from vimeo import VimeoClient import settings vio = VimeoClient(format='json',key= settings.VIMEO_KEY,secret=settings.VIMEO_SECRET), url = vio.get_authorization_url(permission='write') ## this returns a URL to be accessed ## get the verifier value after the url above has redirected to the application callback vio.set_verifier('the-access-verifier-string-from-above') access_token = vio.get_access_token() ## get the oauth token + oauth secret str(access_token) OR access_token.__str__() ## these should be stored; they are valid unless the vimeo account holder deletes them ... ## which is never for me ## for any further calls use initialize the VimeoClient as follows vio = VimeoClient(format='json',key=settings.VIMEO_KEY,secret=settings.VIMEO_SECRET, token=settings.VIMEO_OAUTH_TOKEN, token_secret= settings.VIMEO_OAUTH_TOKEN_SECRET) ## then continue with the upload """ from gelder.models import Video logger = upload_video_to_vimeo.get_logger(**kwargs) videourl = Video.objects.get(id=video_id) vio = VimeoClient(format='json', key=settings.VIMEO_KEY, secret=settings.VIMEO_SECRET, token=settings.VIMEO_OAUTH_TOKEN, token_secret=settings.VIMEO_OAUTH_TOKEN_SECRET) # get quota here or instantiate another vio client and check the quota before uploading uploader = vio.get_uploader() uploader.upload(smart_str(videourl.video.path)) ucresponse = uploader.complete() #if ucresponse is not None and ucresponse['video_id']: videourl.extern = 'vimeo' videourl.externurl = ucresponse['video_id'] videourl.on_extern = True videourl.save() logger.info('(success) Boto s3 uploaded video with id: %s to vimeo', (video_id)) #raise Exception([uresponse, str(uresponse), ucresponse]) return True
def initialize(self, form): """ Prepare the upload form for this service """ # test the authentication if self.token: try: self.v = VimeoClient(token=self.token, token_secret=self.token_secret, verifier=self.verifier) self.v.cache_timeout = 0 self.uploader = self.v.get_uploader() except: # failed to authenticate, erase tokens self.token = None self.token_secret = None self.verifier = None self.settings.app_state["vimeo_token"] = "" self.settings.app_state["vimeo_token_secret"] = "" self.settings.app_state["vimeo_verifier"] = "" # Show error message messagebox.show(_("Validation Error!"), _("Vimeo authentication has expired.")) self.form = form form.lblUsername.set_property("visible", False) form.txtUsername.set_property("visible", False) form.lblPassword.set_property("visible", False) form.txtPassword.set_property("visible", False) if self.token: # already authorized form.login_divider.set_property("visible", False) form.btnAuthorize.set_property("visible", False) form.lblVerification.set_property("visible", False) form.txtVerification.set_property("visible", False) else: # user needs to authorize OpenShot form.login_divider.set_property("visible", True) form.btnAuthorize.set_property("visible", True) form.lblVerification.set_property("visible", True) form.txtVerification.set_property("visible", True) form.lnkForgot.set_label("http://www.vimeo.com") form.lnkForgot.set_uri("http://www.vimeo.com")
from vimeo import VimeoClient vimeo = VimeoClient("fd43cedfe52f09848142cbd3501ea0a5") a = vimeo.channels() b = vimeo.videos(query="battle") c = vimeo.videos.get("87374427") for i in a.items(): print i print print print print print print for i in b.items(): print i print print print print print "Comments" print c.comments() print print "Credits" print c.credits()
def start_crawling(id_file, log_file, video_file, channel_file, initial_number): v = VimeoClient(token=YOUR_ACCESS_TOKEN, key=YOUR_CLIENT_ID, secret=YOUR_CLIENT_SECRET) open(log_file, 'w').close() dot_idx = video_file.rfind('.') video_file_name = video_file[:dot_idx] video_file_format = video_file[dot_idx:] nameid_list = read_data_from_csv(id_file, log_file) if nameid_list is None: return vimeo_channels = [] vimeo_videos = [] requests_counter = 0 for id in nameid_list: video_file_number = initial_number video_file = '{}_{}_{}{}'.format(video_file_name, id, video_file_number, video_file_format) channel_response = get_channel_data(v, id, log_file) if channel_response is not None: channel_response['name_id'] = id vimeo_channels.append(channel_response) try: with open(channel_file, 'w') as f: j_str = dumps(vimeo_channels, indent=4, sort_keys=True) f.write(j_str) except Exception as e: log = '[{}] Save or open to file {} FAILED: {}.\n'.format( strftime('%Y-%m-%d %H:%M:%S'), channel_file, str(e)) with open(log_file, 'a') as f: f.write(log) return fields = { 'uri', 'name', 'description', 'link', 'duration', 'width', 'height', 'language', 'created_time', 'modified_time', 'privacy', 'pictures', 'tags', 'stats', 'metadata', 'user.uri', } cmd = '/channels/{}/videos?fields={}&per_page=50&page=1&sort=date&direction=asc'.format( id, ','.join(fields)) while True: video_response = get_video_data(v, cmd, log_file) if video_response is None: break if 'data' not in video_response: break for ele in video_response['data']: ele['date_time'] = strftime('%Y-%m-%d %H:%M:%S') ele['name_id'] = id vimeo_videos.append(ele) eq_idx = cmd.rfind('=') page = cmd[eq_idx + 1:] log = '[{}] From {} Responce size {} Page {} Videos in list {}.\n'.format( strftime('%Y-%m-%d %H:%M:%S'), id, len(video_response['data']), page, len(vimeo_videos)) with open(log_file, 'a') as f: f.write(log) requests_counter = requests_counter + 1 if requests_counter == MAX_REQUESTS_PER_SAVE: requests_counter = 0 log = '[{}] Saving to file...\n'.format( strftime('%Y-%m-%d %H:%M:%S')) with open(log_file, 'a') as f: f.write(log) try: with open(video_file, 'w') as f: j_str = dumps(vimeo_videos, indent=4, sort_keys=True) f.write(j_str) except Exception as e: log = '[{}] Save or open to file {} FAILED: {}.\n'.format( strftime('%Y-%m-%d %H:%M:%S'), video_file, str(e)) with open(log_file, 'a') as f: f.write(log) return log = '[{}] Successfully saved.\n'.format( strftime('%Y-%m-%d %H:%M:%S')) with open(log_file, 'a') as f: f.write(log) if len(vimeo_videos) >= MAX_VIDEOS_PER_FILE: log = '[{}] Creating new file.\n'.format( strftime('%Y-%m-%d %H:%M:%S')) with open(log_file, 'a') as f: f.write(log) video_file_number = video_file_number + 1 video_file = '{}_{}_{}{}'.format(video_file_name, id, video_file_number, video_file_format) vimeo_videos = [] cmd = video_response['paging']['next'] if not cmd: break log = '[{}] Saving to file...\n'.format(strftime('%Y-%m-%d %H:%M:%S')) with open(log_file, 'a') as f: f.write(log) try: with open(video_file, 'w') as f: j_str = dumps(vimeo_videos, indent=4, sort_keys=True) f.write(j_str) except Exception as e: log = '[{}] Save or open to file {} FAILED: {}.\n'.format( strftime('%Y-%m-%d %H:%M:%S'), video_file, str(e)) with open(log_file, 'a') as f: f.write(log) return log = '[{}] Successfully saved.\n'.format( strftime('%Y-%m-%d %H:%M:%S')) with open(log_file, 'a') as f: f.write(log) vimeo_videos = []
def __init__(self, vimeo_data, channel_file, video_file, log_file): """Creates crawler for dailymotion. Args: vimeo_data (dictionary): Dictionary with vimeo client informations: accessToken, clientId, clientSecret. channel_file (string): Path to a file where metadata from channels will be saved. video_file (string): Path to a file where metadata from videos will be saved. log_file (string): Path to a file where logs will be saved. """ self.v = VimeoClient(token=vimeo_data['accessToken'], key=vimeo_data['clientId'], secret=vimeo_data['clientSecret']) """VimeoClient Object used for sending requests and getting responses using Vimeo API. """ self.channel_file = channel_file """string Path to a file where metadata from channels will be saved. """ dot_idx = video_file.rfind('.') self.video_file_name = video_file[:dot_idx] """string Path to a file without extension where metadata from videos will be saved. """ self.video_file_extension = video_file[dot_idx:] """string Extension for the path to a file where metadata from videos will be saved. """ logging.basicConfig(level=logging.INFO, propagate=False, filename=log_file, format='%(asctime)-15s %(message)s') logging.getLogger("requests").setLevel(logging.WARNING) self.logger = logging.getLogger(__name__) """Logger Object used for logging. """ self.channels_array = [] """array Array that stores names of the channels which will be analyzed. """ self.vimeo_channels = [] """array Array that stores metadata from channels. """ self.total_videos = 0 """int The total number of metadata from videos successfully obtained during crawling. """ self.max_requests_per_save = 10 """int The number of requests after which metadata from videos will be saved to a file. """ self.condition_array = [ '2016-08', '2016-07', '2016-06', '2016-05', '2016-04', '2016-03', '2016-02', '2016-01', '2015-12', '2015-11', '2015-10', '2015-09' ] """array Array that stores permitted dates. Only them fulfill the conditions for filtering. """ self.min_views = 0 """int
def get_authorization_url(self): self.v = VimeoClient() self.v.cache_timeout = 0 return self.v.get_authorization_url(permission="write")
def __init__(self, access_token): #, data): """ Initiate the graph and find the OPENi album """ self.connector = VimeoClient(access_token=access_token)
def setup(dev): global vimeo global test_data test_data = dev_data if dev else prod_data vimeo = VimeoClient(test_data['access_token'], dev=bool(dev))
def client(self): return VimeoClient(token=self.access_token, key=self.client_id, secret=self.client_secret)